Skip to content

Commit

Permalink
Hide user research recruitment banner permanently
Browse files Browse the repository at this point in the history
Trello: https://trello.com/c/yGMU3sR2

If the user clicks on "Find out more" then we assume that they've
completed the Google Form and therefore we don't want to annoy them by
continuing to show them the recruitment banner.

To achieve this we set
User#current_user.user_research_recruitment_banner_hidden to true before
sending them off to the Google Form.
  • Loading branch information
floehopper committed Aug 10, 2023
1 parent 1ec7263 commit bf4af43
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/controllers/root_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def signin_required
private

def show_user_research_recruitment_banner?
!cookies[:dismiss_user_research_recruitment_banner]
!cookies[:dismiss_user_research_recruitment_banner] && !current_user.user_research_recruitment_banner_hidden?
end
helper_method :show_user_research_recruitment_banner?
end
8 changes: 7 additions & 1 deletion app/controllers/user_research_recruitment_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
class UserResearchRecruitmentController < ApplicationController
USER_RESEARCH_RECRUITMENT_FORM_URL = "https://docs.google.com/forms/d/1Bdu_GqOrSR4j6mbuzXkFTQg6FRktRMQc8Y-q879Mny8/viewform".freeze

before_action :authenticate_user!
skip_after_action :verify_authorized

def update
if params[:choice] == "dismiss-banner"
case params[:choice]
when "participate"
current_user.update!(user_research_recruitment_banner_hidden: true)
redirect_to USER_RESEARCH_RECRUITMENT_FORM_URL, allow_other_host: true
when "dismiss-banner"
cookies[:dismiss_user_research_recruitment_banner] = true
redirect_to root_path
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/root/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<p class="user-research-recruitment-banner__intro govuk-body">We're holding research sessions to make Publishing work better.</p>
<%= form_tag user_research_recruitment_update_path, method: :put do %>
<div class="user-research-recruitment-banner__buttons govuk-button-group">
<button class="govuk-!-font-size-24 govuk-!-font-weight-bold govuk-button govuk-button--start govuk-button--inverse" type="submit">
<button class="govuk-!-font-size-24 govuk-!-font-weight-bold govuk-button govuk-button--start govuk-button--inverse" type="submit" name="choice" value="participate">
<span>Find out more</span>
<svg class="govuk-button__start-icon govuk-!-display-none-print" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" focusable="false" aria-hidden="true">
<path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUserResearchRecruitmentBannerHiddenToUsers < ActiveRecord::Migration[7.0]
def change
add_column :users, :user_research_recruitment_banner_hidden, :boolean, default: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_08_02_095323) do
ActiveRecord::Schema[7.0].define(version: 2023_08_04_094159) do
create_table "batch_invitation_application_permissions", id: :integer, charset: "utf8mb3", force: :cascade do |t|
t.integer "batch_invitation_id", null: false
t.integer "supported_permission_id", null: false
Expand Down Expand Up @@ -209,6 +209,7 @@
t.boolean "require_2sv", default: false, null: false
t.string "reason_for_2sv_exemption"
t.date "expiry_date_for_2sv_exemption"
t.boolean "user_research_recruitment_banner_hidden", default: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["invitation_token"], name: "index_users_on_invitation_token"
t.index ["invited_by_id"], name: "index_users_on_invited_by_id"
Expand Down
35 changes: 29 additions & 6 deletions test/controllers/user_research_recruitment_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ class UserResearchRecruitmentControllerTest < ActionController::TestCase
attr_reader :choice

context "#update" do
should "require users to be signed in" do
put :update

assert_redirected_to new_user_session_path
end

context "when user clicks the button to dismiss the banner" do
setup do
@choice = "dismiss-banner"
end

should "require signed in users" do
put :update, params: { choice: }

assert_redirected_to new_user_session_path
end

should "set session cookie" do
sign_in create(:user)

Expand All @@ -31,5 +31,28 @@ class UserResearchRecruitmentControllerTest < ActionController::TestCase
assert_redirected_to root_path
end
end

context "when user clicks the button to participate in user research" do
setup do
@choice = "participate"
end

should "set user_research_recruitment_banner_hidden to true for the current_user" do
user = create(:user)
sign_in user

put :update, params: { choice: }

assert user.user_research_recruitment_banner_hidden?
end

should "redirect to the Google Form" do
sign_in create(:user)

put :update, params: { choice: }

assert_redirected_to UserResearchRecruitmentController::USER_RESEARCH_RECRUITMENT_FORM_URL
end
end
end
end
36 changes: 35 additions & 1 deletion test/integration/user_research_recruitment_banner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UserResearchRecruitmentBannerTest < ActionDispatch::IntegrationTest
signin_with(user)

assert has_content?(user_research_recruitment_banner_title)
assert has_css?("form", text: "Find out more")
assert has_css?("form[action='#{user_research_recruitment_update_path}']", text: "Find out more")
end

should "not display the banner on any page other than the dashboard" do
Expand Down Expand Up @@ -52,9 +52,43 @@ class UserResearchRecruitmentBannerTest < ActionDispatch::IntegrationTest
end
end

should "hide the banner permanently if the user clicks the button to participate in user research" do
user = create(:user, name: "user-name", email: "user@example.com")

using_session("Session 1") do
visit new_user_session_path
signin_with(user)

assert has_content?(user_research_recruitment_banner_title)

within ".user-research-recruitment-banner" do
allowing_request_to_user_research_recruitment_google_form do
click_on "Find out more"
end
end

visit root_path

assert_not has_content?(user_research_recruitment_banner_title)
end

using_session("Session 2") do
visit new_user_session_path
signin_with(user)

assert_not has_content?(user_research_recruitment_banner_title)
end
end

private

def user_research_recruitment_banner_title
"Help us improve GOV.UK Publishing"
end

def allowing_request_to_user_research_recruitment_google_form
yield
rescue ActionController::RoutingError
raise unless current_url == UserResearchRecruitmentController::USER_RESEARCH_RECRUITMENT_FORM_URL
end
end

0 comments on commit bf4af43

Please sign in to comment.