summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/features/boards/boards_spec.rb3
-rw-r--r--spec/features/issues/filtered_search/visual_tokens_spec.rb3
-rw-r--r--spec/features/merge_requests/diff_notes_avatars_spec.rb3
-rw-r--r--spec/features/merge_requests/user_posts_diff_notes_spec.rb5
-rw-r--r--spec/support/cookie_helper.rb17
5 files changed, 26 insertions, 5 deletions
diff --git a/spec/features/boards/boards_spec.rb b/spec/features/boards/boards_spec.rb
index 33aca6cb527..cfff6025459 100644
--- a/spec/features/boards/boards_spec.rb
+++ b/spec/features/boards/boards_spec.rb
@@ -1,6 +1,7 @@
require 'rails_helper'
describe 'Issue Boards', js: true do
+ include CookieHelper
include DragTo
let(:group) { create(:group, :nested) }
@@ -13,7 +14,7 @@ describe 'Issue Boards', js: true do
project.team << [user, :master]
project.team << [user2, :master]
- page.driver.set_cookie('sidebar_collapsed', 'true')
+ set_cookie('sidebar_collapsed', 'true')
sign_in(user)
end
diff --git a/spec/features/issues/filtered_search/visual_tokens_spec.rb b/spec/features/issues/filtered_search/visual_tokens_spec.rb
index 2b624f4842d..949def43690 100644
--- a/spec/features/issues/filtered_search/visual_tokens_spec.rb
+++ b/spec/features/issues/filtered_search/visual_tokens_spec.rb
@@ -1,6 +1,7 @@
require 'rails_helper'
describe 'Visual tokens', js: true do
+ include CookieHelper
include FilteredSearchHelpers
include WaitForRequests
@@ -28,7 +29,7 @@ describe 'Visual tokens', js: true do
sign_in(user)
create(:issue, project: project)
- page.driver.set_cookie('sidebar_collapsed', 'true')
+ set_cookie('sidebar_collapsed', 'true')
visit project_issues_path(project)
end
diff --git a/spec/features/merge_requests/diff_notes_avatars_spec.rb b/spec/features/merge_requests/diff_notes_avatars_spec.rb
index ce82c5cd1dc..6f025fdc855 100644
--- a/spec/features/merge_requests/diff_notes_avatars_spec.rb
+++ b/spec/features/merge_requests/diff_notes_avatars_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
feature 'Diff note avatars', js: true do
+ include CookieHelper
include NoteInteractionHelpers
let(:user) { create(:user) }
@@ -22,7 +23,7 @@ feature 'Diff note avatars', js: true do
project.team << [user, :master]
sign_in user
- page.driver.set_cookie('sidebar_collapsed', 'true')
+ set_cookie('sidebar_collapsed', 'true')
end
context 'discussion tab' do
diff --git a/spec/features/merge_requests/user_posts_diff_notes_spec.rb b/spec/features/merge_requests/user_posts_diff_notes_spec.rb
index 0f31799f083..3b873d6f53c 100644
--- a/spec/features/merge_requests/user_posts_diff_notes_spec.rb
+++ b/spec/features/merge_requests/user_posts_diff_notes_spec.rb
@@ -1,13 +1,14 @@
require 'spec_helper'
feature 'Merge requests > User posts diff notes', :js do
+ include CookieHelper
+
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.source_project }
before do
- visit '/'
- page.driver.browser.manage.add_cookie(name: 'sidebar_collapsed', value: 'true')
+ set_cookie('sidebar_collapsed', 'true')
project.add_developer(user)
sign_in(user)
diff --git a/spec/support/cookie_helper.rb b/spec/support/cookie_helper.rb
new file mode 100644
index 00000000000..224619c899c
--- /dev/null
+++ b/spec/support/cookie_helper.rb
@@ -0,0 +1,17 @@
+# 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