From 0c10f2bd47482e58942a6b1c41b116b5dce1704b Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 9 Feb 2018 17:50:10 +0100 Subject: [PATCH] Always use factories in spec --- spec/models/drop_down_list_spec.rb | 8 ++++---- spec/services/champs_service_spec.rb | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/models/drop_down_list_spec.rb b/spec/models/drop_down_list_spec.rb index b898201db..3f01f7148 100644 --- a/spec/models/drop_down_list_spec.rb +++ b/spec/models/drop_down_list_spec.rb @@ -47,16 +47,16 @@ describe DropDownList do end 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']) } end 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']) } end end diff --git a/spec/services/champs_service_spec.rb b/spec/services/champs_service_spec.rb index 2912da0e9..108596113 100644 --- a/spec/services/champs_service_spec.rb +++ b/spec/services/champs_service_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' describe ChampsService do - let!(:champ) { Champ.create(value: 'toto', type_de_champ: TypeDeChamp.new) } - let!(:champ_mandatory_empty) { Champ.create(type_de_champ: TypeDeChamp.new(libelle: 'mandatory', mandatory: true)) } - let!(:champ_datetime) do - champ_datetime = TypeDeChamp.new(type_champ: 'datetime') - Champ.create(type_de_champ: champ_datetime) - end + let(:type_de_champ) { create(:type_de_champ_public) } + let(:type_de_champ_mandatory) { create(:type_de_champ_public, libelle: 'mandatory', mandatory: true) } + let(:type_de_champ_datetime) { create(:type_de_champ_public, type_champ: :datetime) } + let!(:champ) { type_de_champ.champ.create(value: 'toto') } + let!(:champ_mandatory_empty) { type_de_champ_mandatory.champ.create } + let!(:champ_datetime) { type_de_champ_datetime.champ.create } let!(:champs) { [champ, champ_mandatory_empty, champ_datetime] } describe 'save_champs' do