Skip to content

Commit

Permalink
Merge pull request #1211 from alphagov/add-related-links-a-a-test
Browse files Browse the repository at this point in the history
Add related links A/A test to all routes
  • Loading branch information
sihugh authored Jan 18, 2019
2 parents 7a2f754 + dba19d4 commit abc01ff
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery except: :service_sign_in_options

include AATestable

private

def content_item_path
Expand Down
29 changes: 29 additions & 0 deletions app/controllers/concerns/aa_testable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module AATestable
RELATED_LINKS_DIMENSION = 65

def self.included(base)
base.helper_method(
:related_links_variant
)
base.after_action :set_test_response_header
end

def related_links_variant
@related_links_variant ||= related_links_test.requested_variant(request.headers)
end

private

def related_links_test
@related_links_test ||= GovukAbTesting::AbTest.new(
"RelatedLinksAATest",
dimension: RELATED_LINKS_DIMENSION,
allowed_variants: %w(A B),
control_variant: "A"
)
end

def set_test_response_header
related_links_variant.configure_response(response)
end
end
1 change: 1 addition & 0 deletions app/views/development/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<title>
government-frontend development page
</title>
<%= related_links_variant.analytics_meta_tag.html_safe %>
</head>
<body>
<div id="wrapper">
Expand Down
2 changes: 2 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<%= csrf_meta_tags %>
<%= render 'govuk_publishing_components/components/meta_tags', content_item: @content_item.content_item %>

<%= related_links_variant.analytics_meta_tag.html_safe %>

<% if @content_item.description %>
<meta name="description" content="<%= strip_tags(@content_item.description) %>" />
<% end %>
Expand Down
17 changes: 17 additions & 0 deletions test/controllers/development_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'test_helper'

class DevelopmentControllerTest < ActionController::TestCase
include GovukAbTesting::MinitestHelpers

%w(A B).each do |test_variant|
test "RelatedLinksAATest works correctly for each variant (variant: #{test_variant})" do
with_variant RelatedLinksAATest: test_variant do
get :index

ab_test = @controller.send(:related_links_test)
requested = ab_test.requested_variant(request.headers)
assert requested.variant?(test_variant)
end
end
end
end

0 comments on commit abc01ff

Please sign in to comment.