Skip to content

Commit

Permalink
Move banner into partial
Browse files Browse the repository at this point in the history
This ensures that we can deploy most of the functionality in advance and switch over the banner content in the final deploy.

As we want to be able to deploy just the content, the tests need to support
a partial both with and without content. To do this, we override the view path to stub templates
replacement. This is borrowed from rspec-rails’ `stub_template` method
https://github.com/rspec/rspec-rails/blob/e8054a1cd03044f725030fe8315952
cf3799a395/lib/rspec/rails/example/view_example_group.rb#L86-L88
  • Loading branch information
Rosa-Fox authored and boffbowsh committed Mar 14, 2017
1 parent 17fca5d commit c00fe66
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/helpers/promo_banner_helper.rb
@@ -0,0 +1,5 @@
module PromoBannerHelper
def render_promo_banner
render partial: "promo_banner"
end
end
Empty file.
6 changes: 6 additions & 0 deletions app/views/homepage/_promo_banner_example.html.erb
@@ -0,0 +1,6 @@
<div id="homepage-promo-banner">
<div class="banner-message">
<p><strong>Some Title</strong> On some date something has happened.
<a href="https://something.gov.uk" rel="external nofollow">More&nbsp;information<span class="visuallyhidden"> about things</span></a></p>
</div>
</div>
9 changes: 2 additions & 7 deletions app/views/homepage/index.html.erb
Expand Up @@ -5,7 +5,7 @@
<% content_for :title, "Welcome to GOV.UK" %>
<% content_for :body_classes, "homepage" %>
<%= render :partial => "campaign_notification" %>
<%= campaign_notification_content = render partial: "campaign_notification" %>
<main id="content" class="root-index" role="main">
<header class="homepage-top">
<div class="homepage-top-inner">
Expand Down Expand Up @@ -46,12 +46,7 @@
</div>
</header>

<div id="homepage-promo-banner">
<div class="banner-message">
<p><strong>Some Title</strong> On [some date] [something will happen / has happened].
<a href="https://www.gov.uk" rel="external nofollow">More&nbsp;information</a></p>
</div>
</div>
<%= render_promo_banner if campaign_notification_content.strip.blank? %>

<div id="homepage" class="homepage-content">
<div class="homepage-content-inner">
Expand Down
33 changes: 33 additions & 0 deletions test/functional/homepage_controller_test.rb
Expand Up @@ -11,5 +11,38 @@ class HomepageControllerTest < ActionController::TestCase
get :index
assert_equal "max-age=1800, public", response.headers["Cache-Control"]
end

context "with a blank promo banner partial" do
should "not render the promo banner" do
stub_template "homepage/_promo_banner.html.erb" => "<%# foo %>"

get :index
assert_template "homepage/_promo_banner"
refute @response.body.include?("homepage-promo-banner")
end
end

context "with a promo banner partial" do
should "render promo banner" do
stub_template "homepage/_promo_banner.html.erb" => <<-EOF
<div id="homepage-promo-banner">
<div class="banner-message">
<p><strong>Some Title</strong> On some date something has happened.
<a href="https://something.gov.uk" rel="external nofollow">More&nbsp;information</a></p>
</div>
</div>
EOF

get :index
assert_template "homepage/_promo_banner"
assert @response.body.include?("homepage-promo-banner")
assert @response.body.include?("Some Title")
end
end
end

def stub_template(hash)
require 'action_view/testing/resolvers'
@controller.view_paths.unshift(ActionView::FixtureResolver.new(hash))
end
end

0 comments on commit c00fe66

Please sign in to comment.