Browse Source

Update display_duplicate_schemes_banner? method

pull/2655/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
3146cd73c8
  1. 1
      app/helpers/schemes_helper.rb
  2. 22
      spec/helpers/schemes_helper_spec.rb

1
app/helpers/schemes_helper.rb

@ -88,6 +88,7 @@ module SchemesHelper
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?
return if organisation.schemes_deduplicated_at.present? && organisation.schemes_deduplicated_at > organisation.absorbed_organisations.map(&:merge_date).max
organisation.owned_schemes.duplicate_sets.any? || organisation.owned_schemes.any? { |scheme| scheme.locations.duplicate_sets.any? }
end

22
spec/helpers/schemes_helper_spec.rb

@ -137,7 +137,7 @@ RSpec.describe SchemesHelper do
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)
build(:organisation, merge_date: Time.zone.yesterday, absorbing_organisation_id: organisation.id).save(validate: false)
end
context "and it has duplicate schemes" do
@ -148,6 +148,26 @@ RSpec.describe SchemesHelper do
it "displays the banner" do
expect(display_duplicate_schemes_banner?(organisation, current_user)).to be_truthy
end
context "and organisation has confirmed duplicate schemes after the most recent merge" do
before do
organisation.update!(schemes_deduplicated_at: Time.zone.today)
end
it "does not display the banner" do
expect(display_duplicate_schemes_banner?(organisation, current_user)).to be_falsey
end
end
context "and organisation has confirmed duplicate schemes before the most recent merge" do
before do
organisation.update!(schemes_deduplicated_at: Time.zone.today - 2.days)
end
it "displays the banner" do
expect(display_duplicate_schemes_banner?(organisation, current_user)).to be_truthy
end
end
end
context "and it has duplicate locations" do

Loading…
Cancel
Save