Browse Source

Add display duplicate schemes banner method

pull/2655/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
67401e1ba4
  1. 7
      app/helpers/schemes_helper.rb
  2. 97
      spec/helpers/schemes_helper_spec.rb

7
app/helpers/schemes_helper.rb

@ -85,6 +85,13 @@ module SchemesHelper
end end
end end
def display_duplicate_schemes_banner?(organisation, current_user)
return unless organisation.absorbed_organisations.merged_during_open_collection_period.any?
return unless current_user.data_coordinator? || current_user.support?
organisation.owned_schemes.duplicate_sets.any? || organisation.owned_schemes.any? { |scheme| scheme.locations.duplicate_sets.any? }
end
private private
ActivePeriod = Struct.new(:from, :to) ActivePeriod = Struct.new(:from, :to)

97
spec/helpers/schemes_helper_spec.rb

@ -118,4 +118,101 @@ RSpec.describe SchemesHelper do
end end
end end
end end
describe "display_duplicate_schemes_banner?" do
let(:organisation) { create(:organisation) }
let(:current_user) { create(:user, :support) }
context "when organisation has not absorbed other organisations" do
context "and it has duplicate schemes" do
before do
create_list(:scheme, 2, :duplicate, owning_organisation: organisation)
end
it "does not display the banner" do
expect(display_duplicate_schemes_banner?(organisation, current_user)).to be_falsey
end
end
end
context "when organisation has absorbed other organisations in open collection year" do
before do
build(:organisation, merge_date: Time.zone.today, absorbing_organisation_id: organisation.id).save(validate: false)
end
context "and it has duplicate schemes" do
before do
create_list(:scheme, 2, :duplicate, owning_organisation: organisation)
end
it "displays the banner" do
expect(display_duplicate_schemes_banner?(organisation, current_user)).to be_truthy
end
end
context "and it has duplicate locations" do
let(:scheme) { create(:scheme, owning_organisation: organisation) }
before do
create_list(:location, 2, postcode: "AB1 2CD", mobility_type: "A", scheme:)
end
it "displays the banner" do
expect(display_duplicate_schemes_banner?(organisation, current_user)).to be_truthy
end
end
context "and it has no duplicate schemes or locations" do
it "does not display the banner" do
expect(display_duplicate_schemes_banner?(organisation, current_user)).to be_falsey
end
end
context "and it is viewed by data provider" do
let(:current_user) { create(:user, :data_provider) }
before do
create_list(:scheme, 2, :duplicate, owning_organisation: organisation)
end
it "does not display the banner" do
expect(display_duplicate_schemes_banner?(organisation, current_user)).to be_falsey
end
end
end
context "when organisation has absorbed other organisations in closed collection year" do
before do
build(:organisation, merge_date: Time.zone.today - 2.years, absorbing_organisation_id: organisation.id).save(validate: false)
end
context "and it has duplicate schemes" do
before do
create_list(:scheme, 2, :duplicate, owning_organisation: organisation)
end
it "does not display the banner" do
expect(display_duplicate_schemes_banner?(organisation, current_user)).to be_falsey
end
end
context "and it has duplicate locations" do
let(:scheme) { create(:scheme, owning_organisation: organisation) }
before do
create(:location, postcode: "AB1 2CD", mobility_type: "A", scheme:)
end
it "does not display the banner" do
expect(display_duplicate_schemes_banner?(organisation, current_user)).to be_falsey
end
end
context "and it has no duplicate schemes or locations" do
it "does not display the banner" do
expect(display_duplicate_schemes_banner?(organisation, current_user)).to be_falsey
end
end
end
end
end end

Loading…
Cancel
Save