fix(dossier): champs repetable in champs private

This commit is contained in:
Paul Chavard 2022-05-04 15:57:25 +02:00
parent 19edbdbf6a
commit 4523c0590c
2 changed files with 21 additions and 1 deletions

View file

@ -148,7 +148,7 @@ class Champ < ApplicationRecord
# predictable input name. # predictable input name.
def input_name def input_name
if parent_id if parent_id
"#{parent.input_name}[#{champs_attributes_accessor}][#{id}]" "#{parent.input_name}[champs_attributes][#{id}]"
else else
"dossier[#{champs_attributes_accessor}][#{id}]" "dossier[#{champs_attributes_accessor}][#{id}]"
end end

View file

@ -602,5 +602,25 @@ describe Champ do
expect(champ.reload.data).to eq data expect(champ.reload.data).to eq data
end end
end end
context "#input_name" do
let(:champ) { create(:champ_text) }
it { expect(champ.input_name).to eq "dossier[champs_attributes][#{champ.id}]" }
context "when private" do
let(:champ) { create(:champ_text, private: true) }
it { expect(champ.input_name).to eq "dossier[champs_private_attributes][#{champ.id}]" }
end
context "when has parent" do
let(:champ) { create(:champ_text, parent: create(:champ_text)) }
it { expect(champ.input_name).to eq "dossier[champs_attributes][#{champ.parent_id}][champs_attributes][#{champ.id}]" }
end
context "when has private parent" do
let(:champ) { create(:champ_text, private: true, parent: create(:champ_text, private: true)) }
it { expect(champ.input_name).to eq "dossier[champs_private_attributes][#{champ.parent_id}][champs_attributes][#{champ.id}]" }
end
end
end end
end end