diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 35ea1d7a8..3d4edf63f 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -1,5 +1,5 @@ class Procedure < ActiveRecord::Base - has_many :types_de_piece_justificative, dependent: :destroy + has_many :types_de_piece_justificative, -> { order "order_place ASC" }, dependent: :destroy has_many :types_de_champ, class_name: 'TypeDeChampPublic', dependent: :destroy has_many :types_de_champ_private, dependent: :destroy has_many :dossiers @@ -64,10 +64,6 @@ class Procedure < ActiveRecord::Base types_de_champ_private.order(:order_place) end - def types_de_piece_justificative_ordered - types_de_piece_justificative.order(:order_place) - end - def self.active id Procedure.where(archived: false, published: true).find(id) end @@ -81,7 +77,7 @@ class Procedure < ActiveRecord::Base end def switch_types_de_piece_justificative index_of_first_element - switch_list_order(types_de_piece_justificative_ordered, index_of_first_element) + switch_list_order(types_de_piece_justificative, index_of_first_element) end def switch_list_order(list, index_of_first_element) diff --git a/app/views/admin/pieces_justificatives/_form.html.haml b/app/views/admin/pieces_justificatives/_form.html.haml index 6bdb2c4b4..2499b7cad 100644 --- a/app/views/admin/pieces_justificatives/_form.html.haml +++ b/app/views/admin/pieces_justificatives/_form.html.haml @@ -1,6 +1,6 @@ = form_for [:admin, @procedure], url: admin_procedure_pieces_justificatives_path(@procedure), remote: true do |f| #liste_piece_justificative - = render partial: 'fields', locals: { types_de_piece_justificative: @procedure.types_de_piece_justificative_ordered.decorate, f: f } + = render partial: 'fields', locals: { types_de_piece_justificative: @procedure.types_de_piece_justificative.decorate, f: f } = f.submit "Enregistrer", class: 'btn btn-success', id: :save %hr #new_type_de_piece_justificative diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index e97e10ee1..30da5d76d 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -63,8 +63,8 @@ FactoryGirl.define do trait :with_two_type_de_piece_justificative do after(:build) do |procedure, _evaluator| - rib = create(:type_de_piece_justificative, :rib) - msa = create(:type_de_piece_justificative, :msa) + rib = create(:type_de_piece_justificative, :rib, order_place: 1) + msa = create(:type_de_piece_justificative, :msa, order_place: 2) procedure.types_de_piece_justificative << rib procedure.types_de_piece_justificative << msa