From 0e3ebfd819d271c477116e83b1028b40dc9db711 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 26 Jun 2017 11:00:36 +0200 Subject: [PATCH] =?UTF-8?q?[Fix=20#183]=20Display=20=E2=80=9Coui=E2=80=9D?= =?UTF-8?q?=20or=20=E2=80=9Cnon=E2=80=9D=20instead=20of=20=E2=80=9Ctrue?= =?UTF-8?q?=E2=80=9D=20or=20=E2=80=9Cfalse=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/dossiers/_infos_dossier.html.haml | 5 ++ spec/factories/procedure.rb | 8 +++ spec/factories/type_de_champ_public.rb | 5 ++ spec/views/dossiers/_infos_dossier_spec.rb | 72 +++++++++++++++++---- 4 files changed, 77 insertions(+), 13 deletions(-) diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index 7de372ba2..f607632e6 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -46,6 +46,11 @@ = dossier.text_summary - else Pas de dossier associé + - elsif champ.type_champ == 'yes_no' + - if champ.decorate.value == 'true' + Oui + - elsif champ.decorate.value == 'false' + Non - else = champ.decorate.value.html_safe diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 9e0b76e7b..0f240362c 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -75,6 +75,14 @@ FactoryGirl.define do end end + trait :with_yes_no do + after(:build) do |procedure, _evaluator| + type_de_champ = create(:type_de_champ_public, :type_yes_no) + + procedure.types_de_champ << type_de_champ + end + end + trait :with_two_type_de_piece_justificative do after(:build) do |procedure, _evaluator| rib = create(:type_de_piece_justificative, :rib, order_place: 1) diff --git a/spec/factories/type_de_champ_public.rb b/spec/factories/type_de_champ_public.rb index b1ef85016..e11b90e33 100644 --- a/spec/factories/type_de_champ_public.rb +++ b/spec/factories/type_de_champ_public.rb @@ -14,5 +14,10 @@ FactoryGirl.define do libelle 'Référence autre dossier' type_champ 'dossier_link' end + + trait :type_yes_no do + libelle 'Yes/no' + type_champ 'yes_no' + end end end diff --git a/spec/views/dossiers/_infos_dossier_spec.rb b/spec/views/dossiers/_infos_dossier_spec.rb index ff2448229..ff7af8d36 100644 --- a/spec/views/dossiers/_infos_dossier_spec.rb +++ b/spec/views/dossiers/_infos_dossier_spec.rb @@ -1,25 +1,71 @@ require 'spec_helper' describe 'dossiers/_infos_dossier.html.haml', type: :view do - let(:dossier) { create(:dossier, :with_entreprise, procedure: create(:procedure, :with_api_carto, :with_type_de_champ)) } + describe "champs rendering" do + let(:dossier) { create(:dossier, :with_entreprise, procedure: create(:procedure, :with_api_carto, :with_type_de_champ)) } - before do - champs.each do |champ| - champ.value = ((0...8).map { (65 + rand(26)).chr }.join) - champ.save + before do + champs.each do |champ| + champ.value = ((0...8).map { (65 + rand(26)).chr }.join) + champ.save + end + + assign(:facade, DossierFacades.new(dossier.id, dossier.user.email)) + render end - assign(:facade, DossierFacades.new(dossier.id, dossier.user.email)) - render + describe 'every champs are present on the page' do + let(:champs) { dossier.champs } + + it { expect(rendered).to have_content(champs.first.libelle) } + it { expect(rendered).to have_content(champs.first.value) } + + it { expect(rendered).to have_content(champs.last.libelle) } + it { expect(rendered).to have_content(champs.last.value) } + end end - describe 'every champs are present on the page' do - let(:champs) { dossier.champs } + describe "oui_non champ rendering" do + let(:dossier_with_yes_no) { create(:dossier, procedure: create(:procedure, :with_yes_no)) } - it { expect(rendered).to have_content(champs.first.libelle) } - it { expect(rendered).to have_content(champs.first.value) } + context "with the true value" do + before do + oui_non_champ = dossier_with_yes_no.champs.first + oui_non_champ.value = 'true' + oui_non_champ.save - it { expect(rendered).to have_content(champs.last.libelle) } - it { expect(rendered).to have_content(champs.last.value) } + assign(:facade, DossierFacades.new(dossier_with_yes_no.id, dossier_with_yes_no.user.email)) + render + end + + it { expect(rendered).to have_content("Oui") } + end + + context "with the false value" do + before do + oui_non_champ = dossier_with_yes_no.champs.first + oui_non_champ.value = 'false' + oui_non_champ.save + + assign(:facade, DossierFacades.new(dossier_with_yes_no.id, dossier_with_yes_no.user.email)) + render + end + + it { expect(rendered).to have_content("Non") } + end + + context "with no value" do + before do + oui_non_champ = dossier_with_yes_no.champs.first + oui_non_champ.value = nil + oui_non_champ.save + + assign(:facade, DossierFacades.new(dossier_with_yes_no.id, dossier_with_yes_no.user.email)) + render + end + + it { expect(rendered).not_to have_content("Oui") } + it { expect(rendered).not_to have_content("Non") } + end end end