diff --git a/Gemfile.lock b/Gemfile.lock index fd9c7128..b1beb54c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -200,12 +200,12 @@ GEM railties (>= 5.0.0) faker (3.4.2) i18n (>= 1.8.11, < 2) - faraday (2.10.1) - faraday-net_http (>= 2.0, < 3.2) + faraday (2.11.0) + faraday-net_http (>= 2.0, < 3.4) logger faraday-http-cache (2.5.1) faraday (>= 0.8) - faraday-net_http (3.1.1) + faraday-net_http (3.3.0) net-http faraday-retry (2.2.1) faraday (~> 2.0) @@ -366,7 +366,7 @@ GEM regexp_parser (2.9.2) reline (0.5.9) io-console (~> 0.5) - rexml (3.3.5) + rexml (3.3.6) strscan roo (2.10.1) nokogiri (~> 1) @@ -405,10 +405,10 @@ GEM rubocop (~> 1.41) rubocop-factory_bot (2.26.1) rubocop (~> 1.61) - rubocop-rails (2.25.1) + rubocop-rails (2.26.0) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.33.0, < 2.0) + rubocop (>= 1.52.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) rubocop-rake (0.6.0) rubocop (~> 1.0) diff --git a/app/presenters/pafs_core/project_summary_presenter.rb b/app/presenters/pafs_core/project_summary_presenter.rb index bbeb9b4c..9f99fca2 100644 --- a/app/presenters/pafs_core/project_summary_presenter.rb +++ b/app/presenters/pafs_core/project_summary_presenter.rb @@ -307,15 +307,19 @@ def summary_label(id) end def articles - if project_protects_households? - if risks_started? - all_articles - else - all_articles - [:standard_of_protection] - end - else - all_articles - %i[risks standard_of_protection] - end + articles = if project_protects_households? + if risks_started? + all_articles + else + all_articles - [:standard_of_protection] + end + else + all_articles - %i[risks standard_of_protection] + end + + articles -= %i[funding_calculator] unless pfc_required? + + articles end def not_provided @@ -342,6 +346,10 @@ def kilometres_created_or_enhanced(attribute:, applicable: false) "#{send(attribute)} kilometres" end + def pfc_required? + PROJECT_TYPES_REQUIRE_PFC.include?(project.project_type) + end + private def project diff --git a/app/presenters/pafs_core/validation_presenter.rb b/app/presenters/pafs_core/validation_presenter.rb index b074552d..6b9043c6 100644 --- a/app/presenters/pafs_core/validation_presenter.rb +++ b/app/presenters/pafs_core/validation_presenter.rb @@ -399,6 +399,8 @@ def urgency_complete? end def funding_calculator_complete? + return true if project_type.present? && !pfc_required? + if funding_calculator_file_name.blank? return add_error(:funding_calculator, "Upload the project's partnership funding calculator") end diff --git a/lib/pafs_core/project_types.rb b/lib/pafs_core/project_types.rb index a2304698..399f7a3b 100644 --- a/lib/pafs_core/project_types.rb +++ b/lib/pafs_core/project_types.rb @@ -9,4 +9,7 @@ module PafsCore # STR - strategies # ENV - environmental projects (not SSSI or BAP) PROJECT_TYPES = %w[DEF CM PLP STR ENV_WITH_HOUSEHOLDS ENV_WITHOUT_HOUSEHOLDS].freeze + + # Project types that require a Project Funding Calculator to be provided + PROJECT_TYPES_REQUIRE_PFC = %w[DEF CM].freeze end diff --git a/spec/presenters/pafs_core/project_summary_presenter_spec.rb b/spec/presenters/pafs_core/project_summary_presenter_spec.rb index f4fbbaaf..d1db3969 100644 --- a/spec/presenters/pafs_core/project_summary_presenter_spec.rb +++ b/spec/presenters/pafs_core/project_summary_presenter_spec.rb @@ -707,4 +707,20 @@ def make_coastal_outcome(year, project_id) financial_year: year, project_id: project_id) end + + describe "#pfc_required?" do + context "when project type is DEF or CM" do + it "returns true" do + subject.project_type = "DEF" + expect(subject.pfc_required?).to be true + end + end + + context "when project type is not DEF or CM" do + it "returns false" do + subject.project_type = "PLP" + expect(subject.pfc_required?).to be false + end + end + end end diff --git a/spec/presenters/pafs_core/validation_presenter_spec.rb b/spec/presenters/pafs_core/validation_presenter_spec.rb index 022bc2d3..37c7749c 100644 --- a/spec/presenters/pafs_core/validation_presenter_spec.rb +++ b/spec/presenters/pafs_core/validation_presenter_spec.rb @@ -363,41 +363,56 @@ describe "#funding_calculator_complete?" do subject { described_class.new(project) } - let(:project) { create(:full_project) } + let(:project_type) { "DEF" } + let(:project) { create(:full_project, project_type: project_type) } - context "with no PFC attached" do - it_behaves_like "failed validation example", :funding_calculator_complete? - end - - context "with a PFC attached" do - before do - file_path = Rails.root.join("..", "fixtures", "calculators", filename) - file = File.open file_path - storage = PafsCore::DevelopmentFileStorageService.new - dest_file = File.join(project.storage_path, filename) - storage.upload(file, dest_file) - project.funding_calculator_file_name = filename - end - - context "with a v8 PFC attached" do - let(:filename) { "v8.xlsx" } + context "when project type is not DEF or CM" do + let(:project_type) { "PLP" } + context "with no PFC attached" do it "returns true" do expect(subject.funding_calculator_complete?).to be true end end + end - context "with a 2020 v1 PFC attached" do - let(:filename) { "v9old.xlsx" } + context "when project type is DEF or CM" do + let(:project_type) { "DEF" } + context "with no PFC attached" do it_behaves_like "failed validation example", :funding_calculator_complete? end - context "with a 2020 v2 PFC attached" do - let(:filename) { "v9.xlsx" } + context "with a PFC attached" do + before do + file_path = Rails.root.join("..", "fixtures", "calculators", filename) + file = File.open file_path + storage = PafsCore::DevelopmentFileStorageService.new + dest_file = File.join(project.storage_path, filename) + storage.upload(file, dest_file) + project.funding_calculator_file_name = filename + end - it "returns true" do - expect(subject.funding_calculator_complete?).to be true + context "with a v8 PFC attached" do + let(:filename) { "v8.xlsx" } + + it "returns true" do + expect(subject.funding_calculator_complete?).to be true + end + end + + context "with a 2020 v1 PFC attached" do + let(:filename) { "v9old.xlsx" } + + it_behaves_like "failed validation example", :funding_calculator_complete? + end + + context "with a 2020 v2 PFC attached" do + let(:filename) { "v9.xlsx" } + + it "returns true" do + expect(subject.funding_calculator_complete?).to be true + end end end end