Merge pull request #5071 from betagouv/champ-always-find-parent-dossier

champ: return the parent dossier even when discarded
This commit is contained in:
Paul Chavard 2020-04-22 14:58:59 +02:00 committed by GitHub
commit 30b2e11ffb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -1,5 +1,5 @@
class Champ < ApplicationRecord
belongs_to :dossier, inverse_of: :champs, touch: true
belongs_to :dossier, -> { with_discarded }, inverse_of: :champs, touch: true
belongs_to :type_de_champ, inverse_of: :champ
belongs_to :parent, class_name: 'Champ'
has_many :commentaires

View file

@ -3,6 +3,17 @@ describe Champ do
it_should_behave_like "champ_spec"
describe "associations" do
it { is_expected.to belong_to(:dossier) }
context 'when the parent dossier is discarded' do
let(:discarded_dossier) { create(:dossier, :discarded) }
subject(:champ) { discarded_dossier.champs.first }
it { expect(champ.reload.dossier).to eq discarded_dossier }
end
end
describe "validations" do
let(:row) { 1 }
let(:champ) { create(:champ, type_de_champ: create(:type_de_champ), row: row) }