Always use factories in spec

This commit is contained in:
Paul Chavard 2018-02-09 17:50:10 +01:00
parent 793768684e
commit 0c10f2bd47
2 changed files with 10 additions and 10 deletions

View file

@ -47,16 +47,16 @@ describe DropDownList do
end end
context 'when multiple' do context 'when multiple' do
let(:type_de_champ) { TypeDeChamp.new(type_champ: 'multiple_drop_down_list') } let(:type_de_champ) { build(:type_de_champ_public, type_champ: 'multiple_drop_down_list') }
let(:champ) { type_de_champ.champ.build(value: '["1","2"]').decorate }
let(:champ) { Champ.new(value: '["1","2"]').decorate }
it { expect(dropdownlist.selected_options(champ)).to match(['1', '2']) } it { expect(dropdownlist.selected_options(champ)).to match(['1', '2']) }
end end
context 'when simple' do context 'when simple' do
let(:type_de_champ) { TypeDeChamp.new(type_champ: 'drop_down_list') } let(:type_de_champ) { build(:type_de_champ_public, type_champ: 'drop_down_list') }
let(:champ) { type_de_champ.champ.build(value: '1').decorate }
let(:champ) { Champ.new(value: '1').decorate }
it { expect(dropdownlist.selected_options(champ)).to match(['1']) } it { expect(dropdownlist.selected_options(champ)).to match(['1']) }
end end
end end

View file

@ -1,12 +1,12 @@
require 'spec_helper' require 'spec_helper'
describe ChampsService do describe ChampsService do
let!(:champ) { Champ.create(value: 'toto', type_de_champ: TypeDeChamp.new) } let(:type_de_champ) { create(:type_de_champ_public) }
let!(:champ_mandatory_empty) { Champ.create(type_de_champ: TypeDeChamp.new(libelle: 'mandatory', mandatory: true)) } let(:type_de_champ_mandatory) { create(:type_de_champ_public, libelle: 'mandatory', mandatory: true) }
let!(:champ_datetime) do let(:type_de_champ_datetime) { create(:type_de_champ_public, type_champ: :datetime) }
champ_datetime = TypeDeChamp.new(type_champ: 'datetime') let!(:champ) { type_de_champ.champ.create(value: 'toto') }
Champ.create(type_de_champ: champ_datetime) let!(:champ_mandatory_empty) { type_de_champ_mandatory.champ.create }
end let!(:champ_datetime) { type_de_champ_datetime.champ.create }
let!(:champs) { [champ, champ_mandatory_empty, champ_datetime] } let!(:champs) { [champ, champ_mandatory_empty, champ_datetime] }
describe 'save_champs' do describe 'save_champs' do