From daaff17e0e64020476d6d7349532595ff6ca4dac Mon Sep 17 00:00:00 2001 From: Shujat Khalid Date: Tue, 12 Nov 2024 05:56:27 +0000 Subject: [PATCH 1/8] add tests for for_existing_country method --- .../support_interface/country_form_spec.rb | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/spec/forms/support_interface/country_form_spec.rb b/spec/forms/support_interface/country_form_spec.rb index 5ff9507da..674572aa6 100644 --- a/spec/forms/support_interface/country_form_spec.rb +++ b/spec/forms/support_interface/country_form_spec.rb @@ -192,4 +192,48 @@ end end end + + describe "#for_existing_country" do + subject(:form) { described_class.for_existing_country(country) } + + let(:country) { create(:country) } + + it "returns a CountryForm" do + expect(subject).to be_a(described_class) + expect(form.eligibility_enabled).to eq(country.eligibility_enabled) + expect(form.eligibility_route).to eq("standard") + expect(form.has_regions).to eq(country.regions.count > 1) + expect(form.region_names).to eq(country.regions.pluck(:name).join("\n")) + expect(form.other_information).to eq(country.other_information) + expect(form.status_information).to eq(country.status_information) + expect(form.sanction_information).to eq(country.sanction_information) + expect(form.teaching_qualification_information).to eq( + country.teaching_qualification_information, + ) + end + + context "when the country is subject limited" do + let(:country) { create(:country, :subject_limited) } + + it "sets the eligibility route to expanded" do + expect(form.eligibility_route).to eq("expanded") + end + end + + context "when the country has eligibility skip questions" do + let(:country) { create(:country, :eligibility_skip_questions) } + + it "sets the eligibility route to reduced" do + expect(form.eligibility_route).to eq("reduced") + end + end + + context "when the country has no regions" do + let(:country) { create(:country, regions: []) } + + it "sets has_regions to false" do + expect(form.has_regions).to be(false) + end + end + end end From 28224f8fa7c4c9540a341363e508856ef2350b7a Mon Sep 17 00:00:00 2001 From: Shujat Khalid Date: Tue, 12 Nov 2024 06:16:08 +0000 Subject: [PATCH 2/8] add in trait for eligibility_skip_questions --- spec/factories/countries.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/factories/countries.rb b/spec/factories/countries.rb index 002d8c8a7..30d3083fc 100644 --- a/spec/factories/countries.rb +++ b/spec/factories/countries.rb @@ -24,6 +24,10 @@ factory :country do sequence :code, Country::CODES.cycle + trait :eligibility_skip_questions do + eligibility_skip_questions { true } + end + trait :subject_limited do subject_limited { true } end From 2e5bb2133eabe5701068bd21b236f2ca11ed7334 Mon Sep 17 00:00:00 2001 From: Shujat Khalid Date: Wed, 13 Nov 2024 02:19:47 +0000 Subject: [PATCH 3/8] made suggested changes --- .../support_interface/country_form_spec.rb | 53 +++++++++++++------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/spec/forms/support_interface/country_form_spec.rb b/spec/forms/support_interface/country_form_spec.rb index 674572aa6..39f93f2be 100644 --- a/spec/forms/support_interface/country_form_spec.rb +++ b/spec/forms/support_interface/country_form_spec.rb @@ -197,26 +197,49 @@ subject(:form) { described_class.for_existing_country(country) } let(:country) { create(:country) } + let(:eligibility_route) { "standard" } + let(:eligibility_enabled) { true } + let(:has_regions) { true } + let(:region_names) { "Madrid\nBarcelona" } + let(:other_information) { "Other information" } + let(:status_information) { "Status information" } + let(:sanction_information) { "Sanction information" } + let(:teaching_qualification_information) do + "Teaching qualification information" + end - it "returns a CountryForm" do - expect(subject).to be_a(described_class) - expect(form.eligibility_enabled).to eq(country.eligibility_enabled) - expect(form.eligibility_route).to eq("standard") - expect(form.has_regions).to eq(country.regions.count > 1) - expect(form.region_names).to eq(country.regions.pluck(:name).join("\n")) - expect(form.other_information).to eq(country.other_information) - expect(form.status_information).to eq(country.status_information) - expect(form.sanction_information).to eq(country.sanction_information) - expect(form.teaching_qualification_information).to eq( - country.teaching_qualification_information, - ) + context do + before do + create(:region, name: "Madrid", country:) + create(:region, name: "Barcelona", country:) + end + + it "returns a CountryForm for the country" do + expect(subject).to have_attributes(eligibility_enabled: true) + expect(subject).to have_attributes(eligibility_route: "standard") + expect(subject).to have_attributes(has_regions: true) + expect(subject).to have_attributes(region_names: "Madrid\nBarcelona") + expect(subject).to have_attributes( + other_information: "Other information", + ) + expect(subject).to have_attributes( + status_information: "Status information", + ) + expect(subject).to have_attributes( + sanction_information: "Sanction information", + ) + expect(subject).to have_attributes( + teaching_qualification_information: + "Teaching qualification information", + ) + end end context "when the country is subject limited" do let(:country) { create(:country, :subject_limited) } it "sets the eligibility route to expanded" do - expect(form.eligibility_route).to eq("expanded") + expect(subject).to have_attributes(eligibility_route: "expanded") end end @@ -224,7 +247,7 @@ let(:country) { create(:country, :eligibility_skip_questions) } it "sets the eligibility route to reduced" do - expect(form.eligibility_route).to eq("reduced") + expect(subject).to have_attributes(eligibility_route: "reduced") end end @@ -232,7 +255,7 @@ let(:country) { create(:country, regions: []) } it "sets has_regions to false" do - expect(form.has_regions).to be(false) + expect(subject).to have_attributes(has_regions: false) end end end From efe92eb604f2b807994c5cca4b056037aed1b5f9 Mon Sep 17 00:00:00 2001 From: Shujat Khalid Date: Wed, 13 Nov 2024 10:46:20 +0000 Subject: [PATCH 4/8] fixed failing tests --- spec/forms/support_interface/country_form_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/forms/support_interface/country_form_spec.rb b/spec/forms/support_interface/country_form_spec.rb index 39f93f2be..c0c6fd3d5 100644 --- a/spec/forms/support_interface/country_form_spec.rb +++ b/spec/forms/support_interface/country_form_spec.rb @@ -196,7 +196,7 @@ describe "#for_existing_country" do subject(:form) { described_class.for_existing_country(country) } - let(:country) { create(:country) } + let(:country) { create(:country, other_information:, status_information:, sanction_information:, teaching_qualification_information:) } let(:eligibility_route) { "standard" } let(:eligibility_enabled) { true } let(:has_regions) { true } From 92bcd2715c549cccd303554d5cd76f28808e2008 Mon Sep 17 00:00:00 2001 From: Shujat Khalid Date: Wed, 13 Nov 2024 11:34:49 +0000 Subject: [PATCH 5/8] made suggested changes --- .../support_interface/country_form_spec.rb | 55 +++++++++---------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/spec/forms/support_interface/country_form_spec.rb b/spec/forms/support_interface/country_form_spec.rb index c0c6fd3d5..877294a10 100644 --- a/spec/forms/support_interface/country_form_spec.rb +++ b/spec/forms/support_interface/country_form_spec.rb @@ -197,10 +197,6 @@ subject(:form) { described_class.for_existing_country(country) } let(:country) { create(:country, other_information:, status_information:, sanction_information:, teaching_qualification_information:) } - let(:eligibility_route) { "standard" } - let(:eligibility_enabled) { true } - let(:has_regions) { true } - let(:region_names) { "Madrid\nBarcelona" } let(:other_information) { "Other information" } let(:status_information) { "Status information" } let(:sanction_information) { "Sanction information" } @@ -208,31 +204,20 @@ "Teaching qualification information" end - context do - before do - create(:region, name: "Madrid", country:) - create(:region, name: "Barcelona", country:) - end - - it "returns a CountryForm for the country" do - expect(subject).to have_attributes(eligibility_enabled: true) - expect(subject).to have_attributes(eligibility_route: "standard") - expect(subject).to have_attributes(has_regions: true) - expect(subject).to have_attributes(region_names: "Madrid\nBarcelona") - expect(subject).to have_attributes( - other_information: "Other information", - ) - expect(subject).to have_attributes( - status_information: "Status information", - ) - expect(subject).to have_attributes( - sanction_information: "Sanction information", - ) - expect(subject).to have_attributes( - teaching_qualification_information: - "Teaching qualification information", - ) - end + it "returns a CountryForm for the country" do + create(:region, name: "Madrid", country: country) + create(:region, name: "Barcelona", country: country) + + expect(subject).to have_attributes( + eligibility_enabled: true, + eligibility_route: "standard", + has_regions: true, + region_names: "Madrid\nBarcelona", + other_information: "Other information", + status_information: "Status information", + sanction_information: "Sanction information", + teaching_qualification_information: "Teaching qualification information" + ) end context "when the country is subject limited" do @@ -251,8 +236,18 @@ end end + context "when the country has regions" do + let(:country) { create(:country) } + + it "sets has_regions to true" do + create(:region, name: "Madrid", country: country) + create(:region, name: "Barcelona", country: country) + expect(subject).to have_attributes(has_regions: true) + end + end + context "when the country has no regions" do - let(:country) { create(:country, regions: []) } + let(:country) { create(:country) } it "sets has_regions to false" do expect(subject).to have_attributes(has_regions: false) From 86b7c2ebea90c29ca5c83623431cdbd804f2ff2a Mon Sep 17 00:00:00 2001 From: Shujat Khalid Date: Wed, 13 Nov 2024 11:35:40 +0000 Subject: [PATCH 6/8] run linter --- .../support_interface/country_form_spec.rb | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/spec/forms/support_interface/country_form_spec.rb b/spec/forms/support_interface/country_form_spec.rb index 877294a10..9bfadd695 100644 --- a/spec/forms/support_interface/country_form_spec.rb +++ b/spec/forms/support_interface/country_form_spec.rb @@ -196,7 +196,15 @@ describe "#for_existing_country" do subject(:form) { described_class.for_existing_country(country) } - let(:country) { create(:country, other_information:, status_information:, sanction_information:, teaching_qualification_information:) } + let(:country) do + create( + :country, + other_information:, + status_information:, + sanction_information:, + teaching_qualification_information:, + ) + end let(:other_information) { "Other information" } let(:status_information) { "Status information" } let(:sanction_information) { "Sanction information" } @@ -205,9 +213,9 @@ end it "returns a CountryForm for the country" do - create(:region, name: "Madrid", country: country) - create(:region, name: "Barcelona", country: country) - + create(:region, name: "Madrid", country:) + create(:region, name: "Barcelona", country:) + expect(subject).to have_attributes( eligibility_enabled: true, eligibility_route: "standard", @@ -216,7 +224,8 @@ other_information: "Other information", status_information: "Status information", sanction_information: "Sanction information", - teaching_qualification_information: "Teaching qualification information" + teaching_qualification_information: + "Teaching qualification information", ) end @@ -240,8 +249,8 @@ let(:country) { create(:country) } it "sets has_regions to true" do - create(:region, name: "Madrid", country: country) - create(:region, name: "Barcelona", country: country) + create(:region, name: "Madrid", country:) + create(:region, name: "Barcelona", country:) expect(subject).to have_attributes(has_regions: true) end end From 1716da6eb79133fe0d32e7e2a2f7b3cd6e6098d8 Mon Sep 17 00:00:00 2001 From: Shujat Khalid Date: Wed, 13 Nov 2024 12:06:03 +0000 Subject: [PATCH 7/8] changed to only have one check for when country has regions --- spec/forms/support_interface/country_form_spec.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spec/forms/support_interface/country_form_spec.rb b/spec/forms/support_interface/country_form_spec.rb index 9bfadd695..fef5e656b 100644 --- a/spec/forms/support_interface/country_form_spec.rb +++ b/spec/forms/support_interface/country_form_spec.rb @@ -213,14 +213,10 @@ end it "returns a CountryForm for the country" do - create(:region, name: "Madrid", country:) - create(:region, name: "Barcelona", country:) - expect(subject).to have_attributes( eligibility_enabled: true, eligibility_route: "standard", - has_regions: true, - region_names: "Madrid\nBarcelona", + has_regions: false, other_information: "Other information", status_information: "Status information", sanction_information: "Sanction information", @@ -251,7 +247,10 @@ it "sets has_regions to true" do create(:region, name: "Madrid", country:) create(:region, name: "Barcelona", country:) - expect(subject).to have_attributes(has_regions: true) + expect(subject).to have_attributes( + has_regions: true, + region_names: "Madrid\nBarcelona", + ) end end From 5784e455acb12e6fe0c411334677f599f5d311f9 Mon Sep 17 00:00:00 2001 From: Shujat Khalid Date: Wed, 13 Nov 2024 13:48:15 +0000 Subject: [PATCH 8/8] made suggested changes to clean up code --- .../forms/support_interface/country_form_spec.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/spec/forms/support_interface/country_form_spec.rb b/spec/forms/support_interface/country_form_spec.rb index fef5e656b..ba2df1f68 100644 --- a/spec/forms/support_interface/country_form_spec.rb +++ b/spec/forms/support_interface/country_form_spec.rb @@ -217,6 +217,7 @@ eligibility_enabled: true, eligibility_route: "standard", has_regions: false, + region_names: "", other_information: "Other information", status_information: "Status information", sanction_information: "Sanction information", @@ -242,24 +243,17 @@ end context "when the country has regions" do - let(:country) { create(:country) } - - it "sets has_regions to true" do + before do create(:region, name: "Madrid", country:) create(:region, name: "Barcelona", country:) + end + + it "sets has_regions to true" do expect(subject).to have_attributes( has_regions: true, region_names: "Madrid\nBarcelona", ) end end - - context "when the country has no regions" do - let(:country) { create(:country) } - - it "sets has_regions to false" do - expect(subject).to have_attributes(has_regions: false) - end - end end end