Skip to content

Commit

Permalink
Merge branch 'main' of github.com:DEFRA/pafs_core into RUBY-3212-pafs…
Browse files Browse the repository at this point in the history
…-proposals-with-duplicate-names-are-not-sent-to-pipeline
  • Loading branch information
jjromeo committed Sep 4, 2024
2 parents f3f562a + 6e93e31 commit d82629c
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 38 deletions.
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 17 additions & 9 deletions app/presenters/pafs_core/project_summary_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/presenters/pafs_core/validation_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/pafs_core/project_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions spec/presenters/pafs_core/project_summary_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
61 changes: 38 additions & 23 deletions spec/presenters/pafs_core/validation_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d82629c

Please sign in to comment.