Skip to content

Commit

Permalink
removed condition and updating/fixing spec
Browse files Browse the repository at this point in the history
  • Loading branch information
tahir-khalid committed Oct 15, 2024
1 parent 476f98e commit 2bc161b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
8 changes: 2 additions & 6 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@
<%= javascript_include_tag "application", type: "module", nonce: true %>
<%= stylesheet_link_tag "application" %>
<%= csrf_meta_tags %>
<% if Rails.env.production? && analytics_cookies_accepted? %>
<%= render "shared/ga_head" %>
<% end %>
<%= render "shared/ga_head" %>
</head>
<body class="govuk-template__body app-body-class">
<% if Rails.env.production? && analytics_cookies_accepted? %>
<%= render "shared/ga_body" %>
<% end %>
<%= render "shared/ga_body" %>
<%= javascript_tag nonce: true do -%>
document.body.className += ' js-enabled' + ('noModule' in HTMLScriptElement.prototype ? ' govuk-frontend-supported' : '');
<% end -%>
Expand Down
6 changes: 0 additions & 6 deletions spec/features/cookie_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@
We’d also like to use analytics cookies so we can understand how you use the service and make improvements."
end

# before(:each) do
# Capybara.current_session.driver.browser.manage.delete_all_cookies
# end

scenario "when the user accepts analytics cookies and changes their mind" do
visit("/")
expect(page).to have_text(cookie_banner_text)

byebug

click_button("Accept analytics cookies")
expect(page).to have_text("You’ve accepted additional cookies.")

Expand Down
17 changes: 17 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,21 @@
config.infer_spec_type_from_file_location!

config.filter_rails_from_backtrace!

config.before(:each, type: :feature) do
clear_cookies
end
end

def clear_cookies
browser = Capybara.current_session.driver.browser
if browser.respond_to?(:clear_cookies)
# Rack::Test
browser.clear_cookies
elsif browser.respond_to?(:manage) && browser.manage.respond_to?(:delete_all_cookies)
# Selenium::WebDriver
browser.manage.delete_all_cookies
else
raise "Unsupported driver: #{Capybara.current_driver.inspect}"
end
end

0 comments on commit 2bc161b

Please sign in to comment.