Skip to content

Commit f3ba54e

Browse files
committed
Return response headers for Explore AB test
At present we're only returning Vary response headers when we get a B variant. We want to do this all the time or it's confusing for Fastly to know how to cache. I've added a test that ensures (using the `with_variant` helper) that the header is being set correctly, and also checks for analytics set up. It's trickier to assert things about the template because slimmer's testing is harder to figure out right now, but it'd be useful to add these at some point too. :-)
1 parent 40b8e30 commit f3ba54e

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

app/controllers/ab_tests/explore_menu_ab_testable.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ def explore_menu_variant
1717
end
1818

1919
def set_explore_menu_response
20-
explore_menu_variant.configure_response(response) if explore_menu_testable?
20+
explore_menu_variant.configure_response(response)
2121
end
2222

23-
def explore_menu_testable?
23+
def explore_menu_variant_b?
2424
explore_menu_variant.variant?("B")
2525
end
2626
end

app/controllers/content_items_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ContentItemsController < ApplicationController
1717
before_action :set_explore_menu_response
1818
after_action :set_slimmer_template
1919

20-
helper_method :explore_menu_variant, :explore_menu_testable?
20+
helper_method :explore_menu_variant, :explore_menu_variant_b?
2121

2222
attr_accessor :content_item, :taxonomy_navigation
2323

@@ -57,7 +57,7 @@ def service_sign_in_options
5757
private
5858

5959
def set_slimmer_template
60-
if explore_menu_testable?
60+
if explore_menu_variant_b?
6161
slimmer_template "core_layout_explore_header"
6262
else
6363
slimmer_template "core_layout"

app/views/layouts/application.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<%= yield :extra_head_content %>
3434
</head>
3535
<body>
36-
<% unless content_for(:simple_header) || explore_menu_testable? %>
36+
<% unless content_for(:simple_header) || explore_menu_variant_b? %>
3737
<%= render 'govuk_publishing_components/components/government_navigation', active: active_proposition %>
3838
<% end %>
3939

test/controllers/explore_ab_test.rb

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require "test_helper"
2+
3+
class ContentItemsControllerTest < ActionController::TestCase
4+
include GovukAbTesting::MinitestHelpers
5+
6+
test "shows new header for variant B" do
7+
for_each_schema do |schema|
8+
with_variant ExploreMenuAbTestable: "B" do
9+
set_up_and_visit_content_item_for_schema(schema)
10+
11+
assert_page_tracked_in_ab_test("ExploreMenuAbTestable", "B", 47)
12+
end
13+
end
14+
end
15+
16+
test "doesn't show new header for variant A" do
17+
for_each_schema do |schema|
18+
with_variant ExploreMenuAbTestable: "A" do
19+
set_up_and_visit_content_item_for_schema(schema)
20+
21+
assert_page_tracked_in_ab_test("ExploreMenuAbTestable", "A", 47)
22+
end
23+
end
24+
end
25+
26+
test "doesn't show new header for variant Z" do
27+
for_each_schema do |schema|
28+
with_variant ExploreMenuAbTestable: "Z" do
29+
set_up_and_visit_content_item_for_schema(schema)
30+
31+
assert_page_tracked_in_ab_test("ExploreMenuAbTestable", "Z", 47)
32+
end
33+
end
34+
end
35+
36+
private
37+
38+
def set_up_and_visit_content_item_for_schema(schema)
39+
content_item = content_store_has_schema_example(schema, schema)
40+
stub_content_store_has_item(content_item["base_path"], content_item)
41+
path = content_item["base_path"][1..]
42+
43+
get :show, params: { path: path }
44+
end
45+
46+
def for_each_schema(&block)
47+
%w[guide answer document_collection].each(&block)
48+
end
49+
end

0 commit comments

Comments
 (0)