Commit 483a28a4 authored by Rémy Coutable's avatar Rémy Coutable

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
parents 12cc675c f1235491
require 'rails_helper' require 'rails_helper'
feature 'Issues > User uses slash commands', feature: true, js: true do feature 'Issues > User uses slash commands', feature: true, js: true do
include SlashCommandsHelpers
include WaitForAjax include WaitForAjax
it_behaves_like 'issuable record that supports slash commands in its description and notes', :issue do 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 ...@@ -17,14 +18,15 @@ feature 'Issues > User uses slash commands', feature: true, js: true do
visit namespace_project_issue_path(project.namespace, project, issue) visit namespace_project_issue_path(project.namespace, project, issue)
end end
after do
wait_for_ajax
end
describe 'adding a due date from note' do describe 'adding a due date from note' do
let(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
it 'does not create a note, and sets the due date accordingly' do it 'does not create a note, and sets the due date accordingly' do
page.within('.js-main-target-form') do write_note("/due 2016-08-28")
fill_in 'note[note]', with: "/due 2016-08-28"
click_button 'Comment'
end
expect(page).not_to have_content '/due 2016-08-28' expect(page).not_to have_content '/due 2016-08-28'
expect(page).to have_content 'Your commands have been executed!' 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 ...@@ -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 it 'does not create a note, and removes the due date accordingly' do
expect(issue.due_date).to eq Date.new(2016, 8, 28) expect(issue.due_date).to eq Date.new(2016, 8, 28)
page.within('.js-main-target-form') do write_note("/remove_due_date")
fill_in 'note[note]', with: "/remove_due_date"
click_button 'Comment'
end
expect(page).not_to have_content '/remove_due_date' expect(page).not_to have_content '/remove_due_date'
expect(page).to have_content 'Your commands have been executed!' expect(page).to have_content 'Your commands have been executed!'
......
require 'rails_helper' require 'rails_helper'
feature 'Merge Requests > User uses slash commands', feature: true, js: true do feature 'Merge Requests > User uses slash commands', feature: true, js: true do
include SlashCommandsHelpers
include WaitForAjax include WaitForAjax
let(:user) { create(:user) } let(:user) { create(:user) }
...@@ -20,12 +21,13 @@ feature 'Merge Requests > User uses slash commands', feature: true, js: true do ...@@ -20,12 +21,13 @@ feature 'Merge Requests > User uses slash commands', feature: true, js: true do
visit namespace_project_merge_request_path(project.namespace, project, merge_request) visit namespace_project_merge_request_path(project.namespace, project, merge_request)
end end
it 'does not recognize the command nor create a note' do after do
page.within('.js-main-target-form') do wait_for_ajax
fill_in 'note[note]', with: "/due 2016-08-28"
click_button 'Comment'
end end
it 'does not recognize the command nor create a note' do
write_note("/due 2016-08-28")
expect(page).not_to have_content '/due 2016-08-28' expect(page).not_to have_content '/due 2016-08-28'
end end
end end
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
# It takes a `issuable_type`, and expect an `issuable`. # 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| 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(:master) { create(:user) }
let(:assignee) { create(:user, username: 'bob') } let(:assignee) { create(:user, username: 'bob') }
let(:guest) { create(:user) } let(:guest) { create(:user) }
...@@ -18,6 +21,11 @@ shared_examples 'issuable record that supports slash commands in its description ...@@ -18,6 +21,11 @@ shared_examples 'issuable record that supports slash commands in its description
login_with(master) login_with(master)
end end
after do
# Ensure all outstanding Ajax requests are complete to avoid database deadlocks
wait_for_ajax
end
describe "new #{issuable_type}" do describe "new #{issuable_type}" do
context 'with commands in the description' do context 'with commands in the description' do
it "creates the #{issuable_type} and interpret commands accordingly" 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 ...@@ -44,10 +52,7 @@ shared_examples 'issuable record that supports slash commands in its description
context 'with a note containing commands' do context 'with a note containing commands' do
it 'creates a note without the commands and interpret the commands accordingly' do it 'creates a note without the commands and interpret the commands accordingly' do
page.within('.js-main-target-form') do write_note("Awesome!\n/assign @bob\n/label ~bug\n/milestone %\"ASAP\"")
fill_in 'note[note]', with: "Awesome!\n/assign @bob\n/label ~bug\n/milestone %\"ASAP\""
click_button 'Comment'
end
expect(page).to have_content 'Awesome!' expect(page).to have_content 'Awesome!'
expect(page).not_to have_content '/assign @bob' expect(page).not_to have_content '/assign @bob'
...@@ -66,10 +71,7 @@ shared_examples 'issuable record that supports slash commands in its description ...@@ -66,10 +71,7 @@ shared_examples 'issuable record that supports slash commands in its description
context 'with a note containing only commands' do context 'with a note containing only commands' do
it 'does not create a note but interpret the commands accordingly' do it 'does not create a note but interpret the commands accordingly' do
page.within('.js-main-target-form') do write_note("/assign @bob\n/label ~bug\n/milestone %\"ASAP\"")
fill_in 'note[note]', with: "/assign @bob\n/label ~bug\n/milestone %\"ASAP\""
click_button 'Comment'
end
expect(page).not_to have_content '/assign @bob' expect(page).not_to have_content '/assign @bob'
expect(page).not_to have_content '/label ~bug' expect(page).not_to have_content '/label ~bug'
...@@ -92,10 +94,7 @@ shared_examples 'issuable record that supports slash commands in its description ...@@ -92,10 +94,7 @@ shared_examples 'issuable record that supports slash commands in its description
context "when current user can close #{issuable_type}" do context "when current user can close #{issuable_type}" do
it "closes the #{issuable_type}" do it "closes the #{issuable_type}" do
page.within('.js-main-target-form') do write_note("/close")
fill_in 'note[note]', with: "/close"
click_button 'Comment'
end
expect(page).not_to have_content '/close' expect(page).not_to have_content '/close'
expect(page).to have_content 'Your commands have been executed!' 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 ...@@ -112,10 +111,7 @@ shared_examples 'issuable record that supports slash commands in its description
end end
it "does not close the #{issuable_type}" do it "does not close the #{issuable_type}" do
page.within('.js-main-target-form') do write_note("/close")
fill_in 'note[note]', with: "/close"
click_button 'Comment'
end
expect(page).not_to have_content '/close' expect(page).not_to have_content '/close'
expect(page).not_to have_content 'Your commands have been executed!' 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 ...@@ -133,10 +129,7 @@ shared_examples 'issuable record that supports slash commands in its description
context "when current user can reopen #{issuable_type}" do context "when current user can reopen #{issuable_type}" do
it "reopens the #{issuable_type}" do it "reopens the #{issuable_type}" do
page.within('.js-main-target-form') do write_note("/reopen")
fill_in 'note[note]', with: "/reopen"
click_button 'Comment'
end
expect(page).not_to have_content '/reopen' expect(page).not_to have_content '/reopen'
expect(page).to have_content 'Your commands have been executed!' 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 ...@@ -153,10 +146,7 @@ shared_examples 'issuable record that supports slash commands in its description
end end
it "does not reopen the #{issuable_type}" do it "does not reopen the #{issuable_type}" do
page.within('.js-main-target-form') do write_note("/reopen")
fill_in 'note[note]', with: "/reopen"
click_button 'Comment'
end
expect(page).not_to have_content '/reopen' expect(page).not_to have_content '/reopen'
expect(page).not_to have_content 'Your commands have been executed!' 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 ...@@ -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 "with a note changing the #{issuable_type}'s title" do
context "when current user can change title of #{issuable_type}" do context "when current user can change title of #{issuable_type}" do
it "reopens the #{issuable_type}" do it "reopens the #{issuable_type}" do
page.within('.js-main-target-form') do write_note("/title Awesome new title")
fill_in 'note[note]', with: "/title Awesome new title"
click_button 'Comment'
end
expect(page).not_to have_content '/title' expect(page).not_to have_content '/title'
expect(page).to have_content 'Your commands have been executed!' 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 ...@@ -189,10 +176,7 @@ shared_examples 'issuable record that supports slash commands in its description
end end
it "does not reopen the #{issuable_type}" do it "does not reopen the #{issuable_type}" do
page.within('.js-main-target-form') do write_note("/title Awesome new title")
fill_in 'note[note]', with: "/title Awesome new title"
click_button 'Comment'
end
expect(page).not_to have_content '/title' expect(page).not_to have_content '/title'
expect(page).not_to have_content 'Your commands have been executed!' 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 ...@@ -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 context "with a note marking the #{issuable_type} as todo" do
it "creates a new todo for the #{issuable_type}" do it "creates a new todo for the #{issuable_type}" do
page.within('.js-main-target-form') do write_note("/todo")
fill_in 'note[note]', with: "/todo"
click_button 'Comment'
end
expect(page).not_to have_content '/todo' expect(page).not_to have_content '/todo'
expect(page).to have_content 'Your commands have been executed!' 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 ...@@ -238,10 +219,7 @@ shared_examples 'issuable record that supports slash commands in its description
expect(todo.author).to eq master expect(todo.author).to eq master
expect(todo.user).to eq master expect(todo.user).to eq master
page.within('.js-main-target-form') do write_note("/done")
fill_in 'note[note]', with: "/done"
click_button 'Comment'
end
expect(page).not_to have_content '/done' expect(page).not_to have_content '/done'
expect(page).to have_content 'Your commands have been executed!' 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 ...@@ -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 it "creates a new todo for the #{issuable_type}" do
expect(issuable.subscribed?(master)).to be_falsy expect(issuable.subscribed?(master)).to be_falsy
page.within('.js-main-target-form') do write_note("/subscribe")
fill_in 'note[note]', with: "/subscribe"
click_button 'Comment'
end
expect(page).not_to have_content '/subscribe' expect(page).not_to have_content '/subscribe'
expect(page).to have_content 'Your commands have been executed!' 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 ...@@ -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 it "creates a new todo for the #{issuable_type}" do
expect(issuable.subscribed?(master)).to be_truthy expect(issuable.subscribed?(master)).to be_truthy
page.within('.js-main-target-form') do write_note("/unsubscribe")
fill_in 'note[note]', with: "/unsubscribe"
click_button 'Comment'
end
expect(page).not_to have_content '/unsubscribe' expect(page).not_to have_content '/unsubscribe'
expect(page).to have_content 'Your commands have been executed!' expect(page).to have_content 'Your commands have been executed!'
......
...@@ -75,6 +75,7 @@ module LoginHelpers ...@@ -75,6 +75,7 @@ module LoginHelpers
def logout def logout
find(".header-user-dropdown-toggle").click find(".header-user-dropdown-toggle").click
click_link "Sign out" click_link "Sign out"
expect(page).to have_content('Signed out successfully')
end end
# Logout without JavaScript driver # Logout without JavaScript driver
......
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
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