diff options
author | Rémy Coutable <remy@rymai.me> | 2016-09-09 10:16:33 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-09-09 10:16:33 +0000 |
commit | 483a28a46bc3ad060749e36585912033440ae8c3 (patch) | |
tree | e97c0d8d5f6096f2845cac5728ca333d9ff7b057 /spec | |
parent | 12cc675ceb2c52b3f39260b807e48be91edb598c (diff) | |
parent | f12354916bf0531a1f2d7cffbc67d36fd425d088 (diff) | |
download | gitlab-ce-483a28a46bc3ad060749e36585912033440ae8c3.tar.gz |
Merge branch 'slash-commands-issuable-spec-fix' into 'master'
Fix intermittent spec failures with spec/features/issues/user_uses_slash_commands_spec.rb
This MR solves the intermittent spec failure:
```
1) Issues > User uses slash commands behaves like issuable record that supports slash commands in its description and notes note on issue with a note changing the issue's title when current user cannot change title of issue does not reopen the issue
Failure/Error: Gitlab::Routing.url_helpers.namespace_project_url(self.namespace, self)
ActionController::UrlGenerationError:
No route matches {:action=>"show", :controller=>"projects", :id=>#<Project id: 1, name: "project135", path: "gitlabhq", description: nil, created_at: "2016-08-31 20:45:48", updated_at: "2016-08-31 20:45:48", creator_id: 2, issues_enabled: true, merge_requests_enabled: true, wiki_enabled: true, namespace_id: 2, snippets_enabled: true, last_activity_at: "2016-08-31 20:45:48", import_url: nil, visibility_level: 20, archived: false, avatar: nil, import_status: "none", repository_size: 0.0, star_count: 0, import_type: nil, import_source: nil, commit_count: 0, import_error: nil, ci_id: nil, builds_enabled: true, shared_runners_enabled: true, runners_token: "_rNZHgsHzaDWGbyL3L2F", build_coverage_regex: nil, build_allow_git_fetch: true, build_timeout: 3600, pending_delete: false, public_builds: true, pushes_since_gc: 0, last_repository_check_failed: nil, last_repository_check_at: nil, container_registry_enabled: true, only_allow_merge_if_build_succeeds: false, has_external_issue_tracker: false, repository_storage: "default", request_access_enabled: true, has_external_wiki: false, lfs_enabled: nil>, :namespace_id=>nil} missing required keys: [:namespace_id]
Shared Example Group: "issuable record that supports slash commands in its description and notes" called from ./spec/features/issues/user_uses_slash_commands_spec.rb:6
# ./app/models/project.rb:611:in `web_url'
# ./app/models/project.rb:975:in `hook_attrs'
# ./lib/gitlab/data_builder/note.rb:58:in `build_base_data'
# ./lib/gitlab/data_builder/note.rb:38:in `build'
# ./app/services/notes/post_process_service.rb:19:in `hook_data'
# ./app/services/notes/post_process_service.rb:23:in `execute_note_hooks'
# ./app/services/notes/post_process_service.rb:14:in `execute'
# ./app/workers/new_note_worker.rb:10:in `perform'
# ./app/services/notes/create_service.rb:29:in `execute'
# ./app/controllers/projects/notes_controller.rb:26:in `create'
# ./lib/gitlab/request_profiler/middleware.rb:15:in `call'
# ./lib/gitlab/middleware/go.rb:16:in `call'
# ./lib/gitlab/middleware/static.rb:9:in `call'
```
There were a number of issues:
1. Sidekiq async tasks were being run after project namespaces were deleted. Use Sidekiq in fake mode to prevent this from Sidekiq tasks from being enqueued in the first place.
2. Some outstanding Ajax requests (e.g. autocomplete) were still being loaded while `DatabaseCleaner` ran
3. `logout` did not always wait for logout actually to complete
Closes #21723
See merge request !6271
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/issues/user_uses_slash_commands_spec.rb | 15 | ||||
-rw-r--r-- | spec/features/merge_requests/user_uses_slash_commands_spec.rb | 10 | ||||
-rw-r--r-- | spec/support/issuable_slash_commands_shared_examples.rb | 68 | ||||
-rw-r--r-- | spec/support/login_helpers.rb | 1 | ||||
-rw-r--r-- | spec/support/slash_commands_helpers.rb | 10 |
5 files changed, 44 insertions, 60 deletions
diff --git a/spec/features/issues/user_uses_slash_commands_spec.rb b/spec/features/issues/user_uses_slash_commands_spec.rb index 2883e392694..105629c485a 100644 --- a/spec/features/issues/user_uses_slash_commands_spec.rb +++ b/spec/features/issues/user_uses_slash_commands_spec.rb @@ -1,6 +1,7 @@ require 'rails_helper' feature 'Issues > User uses slash commands', feature: true, js: true do + include SlashCommandsHelpers include WaitForAjax it_behaves_like 'issuable record that supports slash commands in its description and notes', :issue do @@ -17,14 +18,15 @@ feature 'Issues > User uses slash commands', feature: true, js: true do visit namespace_project_issue_path(project.namespace, project, issue) end + after do + wait_for_ajax + end + describe 'adding a due date from note' do let(:issue) { create(:issue, project: project) } it 'does not create a note, and sets the due date accordingly' do - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "/due 2016-08-28" - click_button 'Comment' - end + write_note("/due 2016-08-28") expect(page).not_to have_content '/due 2016-08-28' expect(page).to have_content 'Your commands have been executed!' @@ -41,10 +43,7 @@ feature 'Issues > User uses slash commands', feature: true, js: true do it 'does not create a note, and removes the due date accordingly' do expect(issue.due_date).to eq Date.new(2016, 8, 28) - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "/remove_due_date" - click_button 'Comment' - end + write_note("/remove_due_date") expect(page).not_to have_content '/remove_due_date' expect(page).to have_content 'Your commands have been executed!' diff --git a/spec/features/merge_requests/user_uses_slash_commands_spec.rb b/spec/features/merge_requests/user_uses_slash_commands_spec.rb index d9ef0d18074..22d9d1b9fd5 100644 --- a/spec/features/merge_requests/user_uses_slash_commands_spec.rb +++ b/spec/features/merge_requests/user_uses_slash_commands_spec.rb @@ -1,6 +1,7 @@ require 'rails_helper' feature 'Merge Requests > User uses slash commands', feature: true, js: true do + include SlashCommandsHelpers include WaitForAjax let(:user) { create(:user) } @@ -20,11 +21,12 @@ feature 'Merge Requests > User uses slash commands', feature: true, js: true do visit namespace_project_merge_request_path(project.namespace, project, merge_request) end + after do + wait_for_ajax + end + it 'does not recognize the command nor create a note' do - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "/due 2016-08-28" - click_button 'Comment' - end + write_note("/due 2016-08-28") expect(page).not_to have_content '/due 2016-08-28' end diff --git a/spec/support/issuable_slash_commands_shared_examples.rb b/spec/support/issuable_slash_commands_shared_examples.rb index d2a49ea5c5e..5e3b8f2b23e 100644 --- a/spec/support/issuable_slash_commands_shared_examples.rb +++ b/spec/support/issuable_slash_commands_shared_examples.rb @@ -2,6 +2,9 @@ # It takes a `issuable_type`, and expect an `issuable`. shared_examples 'issuable record that supports slash commands in its description and notes' do |issuable_type| + include SlashCommandsHelpers + include WaitForAjax + let(:master) { create(:user) } let(:assignee) { create(:user, username: 'bob') } let(:guest) { create(:user) } @@ -18,6 +21,11 @@ shared_examples 'issuable record that supports slash commands in its description login_with(master) end + after do + # Ensure all outstanding Ajax requests are complete to avoid database deadlocks + wait_for_ajax + end + describe "new #{issuable_type}" do context 'with commands in the description' do it "creates the #{issuable_type} and interpret commands accordingly" do @@ -44,10 +52,7 @@ shared_examples 'issuable record that supports slash commands in its description context 'with a note containing commands' do it 'creates a note without the commands and interpret the commands accordingly' do - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "Awesome!\n/assign @bob\n/label ~bug\n/milestone %\"ASAP\"" - click_button 'Comment' - end + write_note("Awesome!\n/assign @bob\n/label ~bug\n/milestone %\"ASAP\"") expect(page).to have_content 'Awesome!' expect(page).not_to have_content '/assign @bob' @@ -66,10 +71,7 @@ shared_examples 'issuable record that supports slash commands in its description context 'with a note containing only commands' do it 'does not create a note but interpret the commands accordingly' do - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "/assign @bob\n/label ~bug\n/milestone %\"ASAP\"" - click_button 'Comment' - end + write_note("/assign @bob\n/label ~bug\n/milestone %\"ASAP\"") expect(page).not_to have_content '/assign @bob' expect(page).not_to have_content '/label ~bug' @@ -92,10 +94,7 @@ shared_examples 'issuable record that supports slash commands in its description context "when current user can close #{issuable_type}" do it "closes the #{issuable_type}" do - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "/close" - click_button 'Comment' - end + write_note("/close") expect(page).not_to have_content '/close' expect(page).to have_content 'Your commands have been executed!' @@ -112,10 +111,7 @@ shared_examples 'issuable record that supports slash commands in its description end it "does not close the #{issuable_type}" do - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "/close" - click_button 'Comment' - end + write_note("/close") expect(page).not_to have_content '/close' expect(page).not_to have_content 'Your commands have been executed!' @@ -133,10 +129,7 @@ shared_examples 'issuable record that supports slash commands in its description context "when current user can reopen #{issuable_type}" do it "reopens the #{issuable_type}" do - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "/reopen" - click_button 'Comment' - end + write_note("/reopen") expect(page).not_to have_content '/reopen' expect(page).to have_content 'Your commands have been executed!' @@ -153,10 +146,7 @@ shared_examples 'issuable record that supports slash commands in its description end it "does not reopen the #{issuable_type}" do - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "/reopen" - click_button 'Comment' - end + write_note("/reopen") expect(page).not_to have_content '/reopen' expect(page).not_to have_content 'Your commands have been executed!' @@ -169,10 +159,7 @@ shared_examples 'issuable record that supports slash commands in its description context "with a note changing the #{issuable_type}'s title" do context "when current user can change title of #{issuable_type}" do it "reopens the #{issuable_type}" do - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "/title Awesome new title" - click_button 'Comment' - end + write_note("/title Awesome new title") expect(page).not_to have_content '/title' expect(page).to have_content 'Your commands have been executed!' @@ -189,10 +176,7 @@ shared_examples 'issuable record that supports slash commands in its description end it "does not reopen the #{issuable_type}" do - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "/title Awesome new title" - click_button 'Comment' - end + write_note("/title Awesome new title") expect(page).not_to have_content '/title' expect(page).not_to have_content 'Your commands have been executed!' @@ -204,10 +188,7 @@ shared_examples 'issuable record that supports slash commands in its description context "with a note marking the #{issuable_type} as todo" do it "creates a new todo for the #{issuable_type}" do - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "/todo" - click_button 'Comment' - end + write_note("/todo") expect(page).not_to have_content '/todo' expect(page).to have_content 'Your commands have been executed!' @@ -238,10 +219,7 @@ shared_examples 'issuable record that supports slash commands in its description expect(todo.author).to eq master expect(todo.user).to eq master - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "/done" - click_button 'Comment' - end + write_note("/done") expect(page).not_to have_content '/done' expect(page).to have_content 'Your commands have been executed!' @@ -254,10 +232,7 @@ shared_examples 'issuable record that supports slash commands in its description it "creates a new todo for the #{issuable_type}" do expect(issuable.subscribed?(master)).to be_falsy - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "/subscribe" - click_button 'Comment' - end + write_note("/subscribe") expect(page).not_to have_content '/subscribe' expect(page).to have_content 'Your commands have been executed!' @@ -274,10 +249,7 @@ shared_examples 'issuable record that supports slash commands in its description it "creates a new todo for the #{issuable_type}" do expect(issuable.subscribed?(master)).to be_truthy - page.within('.js-main-target-form') do - fill_in 'note[note]', with: "/unsubscribe" - click_button 'Comment' - end + write_note("/unsubscribe") expect(page).not_to have_content '/unsubscribe' expect(page).to have_content 'Your commands have been executed!' diff --git a/spec/support/login_helpers.rb b/spec/support/login_helpers.rb index e5f76afbfc0..c0b3e83244d 100644 --- a/spec/support/login_helpers.rb +++ b/spec/support/login_helpers.rb @@ -75,6 +75,7 @@ module LoginHelpers def logout find(".header-user-dropdown-toggle").click click_link "Sign out" + expect(page).to have_content('Signed out successfully') end # Logout without JavaScript driver diff --git a/spec/support/slash_commands_helpers.rb b/spec/support/slash_commands_helpers.rb new file mode 100644 index 00000000000..df483afa0e3 --- /dev/null +++ b/spec/support/slash_commands_helpers.rb @@ -0,0 +1,10 @@ +module SlashCommandsHelpers + def write_note(text) + Sidekiq::Testing.fake! do + page.within('.js-main-target-form') do + fill_in 'note[note]', with: text + click_button 'Comment' + end + end + end +end |