diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 578390c93..6aa32dde2 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -8,4 +8,8 @@ class Procedure < ActiveRecord::Base validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :description, presence: true, allow_blank: false, allow_nil: false + + def types_de_champ_ordered + types_de_champ.order(:order_place) + end end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index afb8c8c8e..6bb537396 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -36,4 +36,13 @@ describe Procedure do it { is_expected.to allow_value('http://localhost').for(:lien_demarche) } end end + + describe '#types_de_champ_ordered' do + let(:procedure) { create(:procedure) } + let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 1) } + let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 0) } + subject { procedure.types_de_champ_ordered } + it { expect(subject.first).to eq(type_de_champ_1) } + it { expect(subject.last).to eq(type_de_champ_0) } + end end