Commit 7a8514c3 authored by Mike Greiling's avatar Mike Greiling

add set_cookie helper

parent 76de6327
require 'rails_helper' require 'rails_helper'
describe 'Issue Boards', js: true do describe 'Issue Boards', js: true do
include CookieHelper
include DragTo include DragTo
let(:group) { create(:group, :nested) } let(:group) { create(:group, :nested) }
...@@ -13,7 +14,7 @@ describe 'Issue Boards', js: true do ...@@ -13,7 +14,7 @@ describe 'Issue Boards', js: true do
project.team << [user, :master] project.team << [user, :master]
project.team << [user2, :master] project.team << [user2, :master]
page.driver.set_cookie('sidebar_collapsed', 'true') set_cookie('sidebar_collapsed', 'true')
sign_in(user) sign_in(user)
end end
......
require 'rails_helper' require 'rails_helper'
describe 'Visual tokens', js: true do describe 'Visual tokens', js: true do
include CookieHelper
include FilteredSearchHelpers include FilteredSearchHelpers
include WaitForRequests include WaitForRequests
...@@ -28,7 +29,7 @@ describe 'Visual tokens', js: true do ...@@ -28,7 +29,7 @@ describe 'Visual tokens', js: true do
sign_in(user) sign_in(user)
create(:issue, project: project) create(:issue, project: project)
page.driver.set_cookie('sidebar_collapsed', 'true') set_cookie('sidebar_collapsed', 'true')
visit project_issues_path(project) visit project_issues_path(project)
end end
......
require 'spec_helper' require 'spec_helper'
feature 'Diff note avatars', js: true do feature 'Diff note avatars', js: true do
include CookieHelper
include NoteInteractionHelpers include NoteInteractionHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
...@@ -22,7 +23,7 @@ feature 'Diff note avatars', js: true do ...@@ -22,7 +23,7 @@ feature 'Diff note avatars', js: true do
project.team << [user, :master] project.team << [user, :master]
sign_in user sign_in user
page.driver.set_cookie('sidebar_collapsed', 'true') set_cookie('sidebar_collapsed', 'true')
end end
context 'discussion tab' do context 'discussion tab' do
......
require 'spec_helper' require 'spec_helper'
feature 'Merge requests > User posts diff notes', :js do feature 'Merge requests > User posts diff notes', :js do
include CookieHelper
let(:user) { create(:user) } let(:user) { create(:user) }
let(:merge_request) { create(:merge_request) } let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.source_project } let(:project) { merge_request.source_project }
before do before do
visit '/' set_cookie('sidebar_collapsed', 'true')
page.driver.browser.manage.add_cookie(name: 'sidebar_collapsed', value: 'true')
project.add_developer(user) project.add_developer(user)
sign_in(user) sign_in(user)
......
# Helper for setting cookies in Selenium/WebDriver
#
module CookieHelper
def set_cookie(name, value, options = {})
# Selenium driver will not set cookies for a given domain when the browser is at `about:blank`.
# It also doesn't appear to allow overriding the cookie path. loading `/` is the most inclusive.
visit options.fetch(:path, '/') unless on_a_page?
page.driver.browser.manage.add_cookie(name: name, value: value, **options)
end
private
def on_a_page?
current_url = Capybara.current_session.driver.browser.current_url
current_url && current_url != '' && current_url != 'about:blank' && current_url != 'data:,'
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment