Skip to content

Commit

Permalink
Merge pull request #353 from alphagov/remove-campaign-notifications
Browse files Browse the repository at this point in the history
Remove campaign notifications from static
  • Loading branch information
alext committed Dec 20, 2013
2 parents 3adde8b + b36f7a7 commit ff9b486
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 310 deletions.
57 changes: 0 additions & 57 deletions app/assets/stylesheets/notifications.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
15 changes: 2 additions & 13 deletions app/helpers/notification_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<div>#{node[:file]}</div>",
{:id => "#{type}-notification", :class => node[:colour]}, false)
{:id => "banner-notification", :class => node[:colour]}, false)
else
''
end
Expand Down
16 changes: 0 additions & 16 deletions app/views/notifications/campaign.erb.example

This file was deleted.

Empty file.
Empty file.
Empty file.
1 change: 0 additions & 1 deletion app/views/root/campaign.html.erb

This file was deleted.

30 changes: 1 addition & 29 deletions lib/notification_file_lookup.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
87 changes: 0 additions & 87 deletions test/integration/notifications_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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('<p>Green notification</p>')
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 '<p>Green notification</p>', 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('<p>Red campaign</p>')
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 '<p>Red campaign</p>', 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('<p>Black campaign</p>')
end

should "show a black notification on the page" do
visit "/templates/campaign.html.erb"
assert page.has_selector? "#campaign-notification.black"
assert_match '<p>Black campaign</p>', page.body
end
end
end
end
62 changes: 0 additions & 62 deletions test/unit/notification_file_lookup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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('<p>Black message.</p>')

expected = {:file => "<p>Black message.</p>", :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('<p>Nothing to see here.</p>')
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 => "<p>Nothing to see here.</p>", :colour => :green}
assert_equal expected, NotificationFileLookup.instance.campaign
end
end
end
51 changes: 6 additions & 45 deletions test/unit/notification_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,26 @@

describe "when a banner is present" do
it "should return a banner notification" do
campaign = {:file => "<p>You've got notifications!</p>", :colour => :green}
NotificationFileLookup.any_instance.stubs(:banner).returns(campaign)
banner = {:file => "<p>You've got notifications!</p>", :colour => :green}
NotificationFileLookup.any_instance.stubs(:banner).returns(banner)
assert_match "<p>You've got notifications!</p>", banner_notification
end

it "should have a section wrapper with the banner colour for a green notification" do
campaign = {:file => "<p>You've got notifications!</p>", :colour => :green}
NotificationFileLookup.any_instance.stubs(:banner).returns(campaign)
banner = {:file => "<p>You've got notifications!</p>", :colour => :green}
NotificationFileLookup.any_instance.stubs(:banner).returns(banner)

assert_equal "<section class=\"green\" id=\"banner-notification\"><div><p>You've got notifications!</p></div></section>",
banner_notification
end

it "should have a section wrapper with the banner colour for a red notification" do
campaign = {:file => "<p>You've got notifications!</p>", :colour => :red}
NotificationFileLookup.any_instance.stubs(:banner).returns(campaign)
banner = {:file => "<p>You've got notifications!</p>", :colour => :red}
NotificationFileLookup.any_instance.stubs(:banner).returns(banner)

assert_equal "<section class=\"red\" id=\"banner-notification\"><div><p>You've got notifications!</p></div></section>",
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 => "<p>You've got notifications!</p>", :colour => :green}
NotificationFileLookup.any_instance.stubs(:campaign).returns(campaign)
assert_match "<p>You've got notifications!</p>", campaign_replacement_notification
end

it "should have a section wrapper with the campaign colour for a green notification" do
campaign = {:file => "<p>You've got notifications!</p>", :colour => :green}
NotificationFileLookup.any_instance.stubs(:campaign).returns(campaign)

assert_equal "<section class=\"green\" id=\"campaign-notification\"><div><p>You've got notifications!</p></div></section>",
campaign_replacement_notification
end

it "should have a section wrapper with the campaign colour for a red notification" do
campaign = {:file => "<p>You've got notifications!</p>", :colour => :red}
NotificationFileLookup.any_instance.stubs(:campaign).returns(campaign)

assert_equal "<section class=\"red\" id=\"campaign-notification\"><div><p>You've got notifications!</p></div></section>",
campaign_replacement_notification
end

it "should have a section wrapper with the campaign colour for a black notification" do
campaign = {:file => "<p>You've got notifications!</p>", :colour => :black}
NotificationFileLookup.any_instance.stubs(:campaign).returns(campaign)

assert_equal "<section class=\"black\" id=\"campaign-notification\"><div><p>You've got notifications!</p></div></section>",
campaign_replacement_notification
end
end
end
end

0 comments on commit ff9b486

Please sign in to comment.