diff --git a/app/assets/stylesheets/notifications.scss b/app/assets/stylesheets/notifications.scss index b4e48f9fc..a11b34e89 100644 --- a/app/assets/stylesheets/notifications.scss +++ b/app/assets/stylesheets/notifications.scss @@ -43,60 +43,3 @@ background: #b10e1e; } } - -#campaign-notification { - clear:both; - background-color: $grey-6; - color: #fff; - padding: 2em; - - h1 { - @include core-80; - } - - p { - @include core-24; - padding-right: 25%; - margin-bottom: 0; - } - - a { - color: #fff; - - &.right { - @include core-24; - text-align: right; - padding: 0 0 0 75%; - margin-top: (25 / 19) * -1em; - display: block; - } - } - - @include ie-lte(7){ - width: 960px; - } - - &.green { - background: #fff; - border: 10px solid #28a197; - color: #28a197; - - a { - color: #28a197; - } - } - - &.red { - background: #b10e1e; - } - - &.black { - background: #fff; - border: 10px solid $black; - color: $black; - - a { - color: $black; - } - } -} diff --git a/app/helpers/notification_helper.rb b/app/helpers/notification_helper.rb index 668bfe735..c45b6ec62 100644 --- a/app/helpers/notification_helper.rb +++ b/app/helpers/notification_helper.rb @@ -4,20 +4,9 @@ module NotificationHelper include ActionView::Helpers::TagHelper def banner_notification - node_replacement_notification(NotificationFileLookup.instance.banner, "banner") - end - - # Only used to replace homepage campaigns for urgent matters. - def campaign_replacement_notification - node_replacement_notification(NotificationFileLookup.instance.campaign, "campaign") - end - - private - - def node_replacement_notification(node, type) - if node + if node = NotificationFileLookup.instance.banner content_tag(:section, "
#{node[:file]}
", - {:id => "#{type}-notification", :class => node[:colour]}, false) + {:id => "banner-notification", :class => node[:colour]}, false) else '' end diff --git a/app/views/notifications/campaign.erb.example b/app/views/notifications/campaign.erb.example deleted file mode 100644 index 16fa8bade..000000000 --- a/app/views/notifications/campaign.erb.example +++ /dev/null @@ -1,16 +0,0 @@ - -

A notification is occurring, standby

- -

Your message goes here
-This is the second line of your message!
-This is the third line!

- -More information diff --git a/app/views/notifications/campaign_black.erb b/app/views/notifications/campaign_black.erb deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/views/notifications/campaign_green.erb b/app/views/notifications/campaign_green.erb deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/views/notifications/campaign_red.erb b/app/views/notifications/campaign_red.erb deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/views/root/campaign.html.erb b/app/views/root/campaign.html.erb deleted file mode 100644 index 8fdda3b59..000000000 --- a/app/views/root/campaign.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= campaign_replacement_notification %> diff --git a/lib/notification_file_lookup.rb b/lib/notification_file_lookup.rb index a2a73bc4b..bf0bebd97 100644 --- a/lib/notification_file_lookup.rb +++ b/lib/notification_file_lookup.rb @@ -1,7 +1,7 @@ class NotificationFileLookup include Singleton - cattr_accessor :banner_file, :campaign_file + cattr_accessor :banner_file def banner @banner_file ||= identify_banner_file @@ -12,15 +12,6 @@ def banner=(file) @banner_file = file end - def campaign - @campaign_file ||= identify_campaign_file - @campaign_file[:file].blank? ? nil : @campaign_file - end - - def campaign=(file) - @campaign_file = file - end - private def identify_banner_file @@ -36,23 +27,4 @@ def identify_banner_file { :file => nil, :colour => nil } end - - def identify_campaign_file - black = File.read("#{Rails.root}/app/views/notifications/campaign_black.erb").strip - unless black.blank? - return { :file => black, :colour => :black } - end - - red = File.read("#{Rails.root}/app/views/notifications/campaign_red.erb").strip - unless red.blank? - return { :file => red, :colour => :red } - end - - green = File.read("#{Rails.root}/app/views/notifications/campaign_green.erb").strip - unless green.blank? - return { :file => green, :colour => :green } - end - - { :file => nil, :colour => nil } - end end diff --git a/test/integration/notifications_test.rb b/test/integration/notifications_test.rb index 96c1b65bb..7cd14127c 100644 --- a/test/integration/notifications_test.rb +++ b/test/integration/notifications_test.rb @@ -11,20 +11,6 @@ class NotificationsTest < ActionDispatch::IntegrationTest end end - context "campaign files" do - should "have a green file" do - assert File.exist? "#{Rails.root}/app/views/notifications/campaign_green.erb" - end - - should "have a red file" do - assert File.exist? "#{Rails.root}/app/views/notifications/campaign_red.erb" - end - - should "have a black file" do - assert File.exist? "#{Rails.root}/app/views/notifications/campaign_black.erb" - end - end - context "banner notifications" do setup do NotificationFileLookup.instance.banner = nil @@ -79,77 +65,4 @@ class NotificationsTest < ActionDispatch::IntegrationTest end end end - - context "campaign notifications" do - setup do - NotificationFileLookup.instance.campaign = nil - end - - context "given view files are empty" do - setup do - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_green.erb") - .returns('') - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_red.erb") - .returns('') - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_black.erb") - .returns('') - end - - should "not show a campaign notification on the page" do - visit "/templates/campaign.html.erb" - refute page.has_selector? "#campaign-notification" - end - end - - context "given view files are present for a green notification" do - setup do - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_green.erb") - .returns('

Green notification

') - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_red.erb") - .returns('') - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_black.erb") - .returns('') - end - - should "show a green campaign notification on the page" do - visit "/templates/campaign.html.erb" - assert page.has_selector? "#campaign-notification.green" - assert_match '

Green notification

', page.body - end - end - - context "given view files are present for a red notification" do - setup do - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_green.erb") - .returns('') - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_red.erb") - .returns('

Red campaign

') - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_black.erb") - .returns('') - end - - should "show a red notification on the page" do - visit "/templates/campaign.html.erb" - assert page.has_selector? "#campaign-notification.red" - assert_match '

Red campaign

', page.body - end - end - - context "given view files are present for a black notification" do - setup do - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_green.erb") - .returns('') - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_red.erb") - .returns('') - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_black.erb") - .returns('

Black campaign

') - end - - should "show a black notification on the page" do - visit "/templates/campaign.html.erb" - assert page.has_selector? "#campaign-notification.black" - assert_match '

Black campaign

', page.body - end - end - end end diff --git a/test/unit/notification_file_lookup_test.rb b/test/unit/notification_file_lookup_test.rb index 184d2fa6f..f798a9da6 100644 --- a/test/unit/notification_file_lookup_test.rb +++ b/test/unit/notification_file_lookup_test.rb @@ -55,66 +55,4 @@ assert_equal expected, NotificationFileLookup.instance.banner end end - - describe "campaign" do - before do - NotificationFileLookup.instance.campaign = nil - end - - it "returns nil if all three campaign content files are empty" do - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_green.erb") - .returns('') - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_red.erb") - .returns('') - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_black.erb") - .returns('') - - assert_nil NotificationFileLookup.instance.campaign - end - - it "returns the black campaign content if present" do - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_black.erb") - .returns('

Black message.

') - - expected = {:file => "

Black message.

", :colour => :black} - assert_equal expected, NotificationFileLookup.instance.campaign - end - - it "opens each campaign content file only once" do - File.expects(:read).with("#{Rails.root}/app/views/notifications/campaign_green.erb") - .returns('Test') - File.expects(:read).with("#{Rails.root}/app/views/notifications/campaign_red.erb") - .returns('') - File.expects(:read).with("#{Rails.root}/app/views/notifications/campaign_black.erb") - .returns('') - - expected = {:file => "Test", :colour => :green} - 3.times do - assert_equal expected, NotificationFileLookup.instance.campaign - end - end - - it "returns nil if the campaign content only contains whitespace" do - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_green.erb") - .returns("\n\n\r\n\r\n\n\n") - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_red.erb") - .returns('') - File.stubs(:read).with("#{Rails.root}/app/views/notifications/campaign_black.erb") - .returns("\n\n\r\n\r\n\n\n") - - assert_nil NotificationFileLookup.instance.campaign - end - - it "falls back to green if the red and black files are empty" do - File.expects(:read).with("#{Rails.root}/app/views/notifications/campaign_green.erb") - .returns('

Nothing to see here.

') - File.expects(:read).with("#{Rails.root}/app/views/notifications/campaign_red.erb") - .returns('') - File.expects(:read).with("#{Rails.root}/app/views/notifications/campaign_black.erb") - .returns('') - - expected = {:file => "

Nothing to see here.

", :colour => :green} - assert_equal expected, NotificationFileLookup.instance.campaign - end - end end diff --git a/test/unit/notification_helper_test.rb b/test/unit/notification_helper_test.rb index 19e35335f..2d532eada 100644 --- a/test/unit/notification_helper_test.rb +++ b/test/unit/notification_helper_test.rb @@ -11,65 +11,26 @@ describe "when a banner is present" do it "should return a banner notification" do - campaign = {:file => "

You've got notifications!

", :colour => :green} - NotificationFileLookup.any_instance.stubs(:banner).returns(campaign) + banner = {:file => "

You've got notifications!

", :colour => :green} + NotificationFileLookup.any_instance.stubs(:banner).returns(banner) assert_match "

You've got notifications!

", banner_notification end it "should have a section wrapper with the banner colour for a green notification" do - campaign = {:file => "

You've got notifications!

", :colour => :green} - NotificationFileLookup.any_instance.stubs(:banner).returns(campaign) + banner = {:file => "

You've got notifications!

", :colour => :green} + NotificationFileLookup.any_instance.stubs(:banner).returns(banner) assert_equal "

You've got notifications!

", banner_notification end it "should have a section wrapper with the banner colour for a red notification" do - campaign = {:file => "

You've got notifications!

", :colour => :red} - NotificationFileLookup.any_instance.stubs(:banner).returns(campaign) + banner = {:file => "

You've got notifications!

", :colour => :red} + NotificationFileLookup.any_instance.stubs(:banner).returns(banner) assert_equal "

You've got notifications!

", banner_notification end end end - - describe "campaign_replacement_notification" do - it "should return an empty string if no campaign is present" do - NotificationFileLookup.any_instance.stubs(:campaign).returns(nil) - assert_equal "", campaign_replacement_notification - end - - describe "when a campaign is present" do - it "should return a campaign notification" do - campaign = {:file => "

You've got notifications!

", :colour => :green} - NotificationFileLookup.any_instance.stubs(:campaign).returns(campaign) - assert_match "

You've got notifications!

", campaign_replacement_notification - end - - it "should have a section wrapper with the campaign colour for a green notification" do - campaign = {:file => "

You've got notifications!

", :colour => :green} - NotificationFileLookup.any_instance.stubs(:campaign).returns(campaign) - - assert_equal "

You've got notifications!

", - campaign_replacement_notification - end - - it "should have a section wrapper with the campaign colour for a red notification" do - campaign = {:file => "

You've got notifications!

", :colour => :red} - NotificationFileLookup.any_instance.stubs(:campaign).returns(campaign) - - assert_equal "

You've got notifications!

", - campaign_replacement_notification - end - - it "should have a section wrapper with the campaign colour for a black notification" do - campaign = {:file => "

You've got notifications!

", :colour => :black} - NotificationFileLookup.any_instance.stubs(:campaign).returns(campaign) - - assert_equal "

You've got notifications!

", - campaign_replacement_notification - end - end - end end