Skip to content

Commit

Permalink
[#1961] get_value for individual
Browse files Browse the repository at this point in the history
  • Loading branch information
fredZen committed Oct 11, 2018
1 parent 773ed92 commit d2f7320
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
6 changes: 2 additions & 4 deletions app/models/procedure_presentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,8 @@ def get_value(dossier, table, column)
case table
when 'self'
dossier.send(column)
when 'user'
dossier.user.send(column)
when 'etablissement'
dossier.etablissement&.send(column)
when 'user', 'individual', 'etablissement'
dossier.send(table)&.send(column)
when 'type_de_champ'
dossier.champs.find { |c| c.type_de_champ_id == column.to_i }.value
when 'type_de_champ_private'
Expand Down
23 changes: 23 additions & 0 deletions spec/models/procedure_presentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,29 @@
it { is_expected.to eq('bla@yopmail.com') }
end

context 'for individual table' do
let(:table) { 'individual' }
let(:dossier) { create(:dossier, procedure: procedure, individual: create(:individual, nom: 'Martin', prenom: 'Jacques', gender: 'M.')) }

context 'for prenom column' do
let(:column) { 'prenom' }

it { is_expected.to eq('Jacques') }
end

context 'for nom column' do
let(:column) { 'nom' }

it { is_expected.to eq('Martin') }
end

context 'for gender column' do
let(:column) { 'gender' }

it { is_expected.to eq('M.') }
end
end

context 'for etablissement table' do
let(:table) { 'etablissement' }
let(:column) { 'code_postal' } # All other columns work the same, no extra test required
Expand Down

0 comments on commit d2f7320

Please sign in to comment.