Order types_de_piece_justificative on Procedure

So that /spec/controllers/api/v1/
dossiers_controller_spec.rb#L163-L179 (on commit
8852431 for example) does not randomly fail due
to unordered types_de_piece_justificative
This commit is contained in:
gregoirenovel 2017-04-13 14:48:18 +02:00
parent 3e41c648a2
commit d531b02bc5
3 changed files with 5 additions and 9 deletions

View file

@ -1,5 +1,5 @@
class Procedure < ActiveRecord::Base 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, class_name: 'TypeDeChampPublic', dependent: :destroy
has_many :types_de_champ_private, dependent: :destroy has_many :types_de_champ_private, dependent: :destroy
has_many :dossiers has_many :dossiers
@ -64,10 +64,6 @@ class Procedure < ActiveRecord::Base
types_de_champ_private.order(:order_place) types_de_champ_private.order(:order_place)
end end
def types_de_piece_justificative_ordered
types_de_piece_justificative.order(:order_place)
end
def self.active id def self.active id
Procedure.where(archived: false, published: true).find(id) Procedure.where(archived: false, published: true).find(id)
end end
@ -81,7 +77,7 @@ class Procedure < ActiveRecord::Base
end end
def switch_types_de_piece_justificative index_of_first_element 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 end
def switch_list_order(list, index_of_first_element) def switch_list_order(list, index_of_first_element)

View file

@ -1,6 +1,6 @@
= form_for [:admin, @procedure], url: admin_procedure_pieces_justificatives_path(@procedure), remote: true do |f| = form_for [:admin, @procedure], url: admin_procedure_pieces_justificatives_path(@procedure), remote: true do |f|
#liste_piece_justificative #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 = f.submit "Enregistrer", class: 'btn btn-success', id: :save
%hr %hr
#new_type_de_piece_justificative #new_type_de_piece_justificative

View file

@ -63,8 +63,8 @@ FactoryGirl.define do
trait :with_two_type_de_piece_justificative do trait :with_two_type_de_piece_justificative do
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
rib = create(:type_de_piece_justificative, :rib) rib = create(:type_de_piece_justificative, :rib, order_place: 1)
msa = create(:type_de_piece_justificative, :msa) msa = create(:type_de_piece_justificative, :msa, order_place: 2)
procedure.types_de_piece_justificative << rib procedure.types_de_piece_justificative << rib
procedure.types_de_piece_justificative << msa procedure.types_de_piece_justificative << msa