Skip to content

Commit

Permalink
Move temporary AB test code to private method
Browse files Browse the repository at this point in the history
  • Loading branch information
richardTowers committed Oct 18, 2023
1 parent f922de9 commit 6598eb4
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,7 @@ class ContentItemsController < ApplicationController
def show
load_content_item

# TEMPORARY (author: richard.towers, expected end date: November 30 2023)
# Content specific AB test for the Find your UTR number page
placeholder = "{{ab_test_find_utr_number_video_links}}"
if @content_item.base_path == "/find-utr-number" && @content_item.body.include?(placeholder)
ab_test = GovukAbTesting::AbTest.new(
"find_utr_number_video_links",
dimension: 61, # https://docs.google.com/spreadsheets/d/1h4vGXzIbhOWwUzourPLIc8WM-iU1b6WYOVDOZxmU1Uo/edit#gid=254065189&range=69:69
allowed_variants: %w[A B Z],
control_variant: "Z",
)
@requested_variant = ab_test.requested_variant(request.headers)
@requested_variant.configure_response(response)

replacement = case @requested_variant.variant_name
when "A"
I18n.t("ab_tests.find_utr_number_video_links.A")
when "B"
I18n.t("ab_tests.find_utr_number_video_links.B")
else
I18n.t("ab_tests.find_utr_number_video_links.Z")
end
@content_item.body.sub!(placeholder, replacement)
end
# /TEMPORARY

temporary_ab_test_find_utr_page
set_expiry

if is_service_manual?
Expand Down Expand Up @@ -291,4 +267,32 @@ def csp_connect_src

@content_item.csp_connect_src
end

# TEMPORARY (author: richard.towers, expected end date: February 2024)
# Content specific AB test for the Find your UTR number page
def temporary_ab_test_find_utr_page
placeholder = "{{ab_test_find_utr_number_video_links}}"
if @content_item.base_path == "/find-utr-number" && @content_item.body.include?(placeholder)
ab_test = GovukAbTesting::AbTest.new(
"find_utr_number_video_links",
dimension: 61, # https://docs.google.com/spreadsheets/d/1h4vGXzIbhOWwUzourPLIc8WM-iU1b6WYOVDOZxmU1Uo/edit#gid=254065189&range=69:69
allowed_variants: %w[A B Z],
control_variant: "Z",
)
@requested_variant = ab_test.requested_variant(request.headers)
@requested_variant.configure_response(response)

replacement = case @requested_variant.variant_name
when "A"
I18n.t("ab_tests.find_utr_number_video_links.A")
when "B"
I18n.t("ab_tests.find_utr_number_video_links.B")
else
I18n.t("ab_tests.find_utr_number_video_links.Z")
end
@content_item.body.sub!(placeholder, replacement)
end
end
# /TEMPORARY

Check failure on line 297 in app/controllers/content_items_controller.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body end. (https://rubystyle.guide#empty-lines-around-bodies)
end

0 comments on commit 6598eb4

Please sign in to comment.