2016-06-30 11:34:19 -04:00
|
|
|
# Specifications for behavior common to all objects with executable attributes.
|
|
|
|
# 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|
|
2016-08-09 11:51:40 -04:00
|
|
|
let(:master) { create(:user) }
|
2016-06-30 11:34:19 -04:00
|
|
|
let(:assignee) { create(:user, username: 'bob') }
|
2016-08-09 11:51:40 -04:00
|
|
|
let(:guest) { create(:user) }
|
2016-06-30 11:34:19 -04:00
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let!(:milestone) { create(:milestone, project: project, title: 'ASAP') }
|
|
|
|
let!(:label_bug) { create(:label, project: project, title: 'bug') }
|
|
|
|
let!(:label_feature) { create(:label, project: project, title: 'feature') }
|
|
|
|
let(:new_url_opts) { {} }
|
|
|
|
|
|
|
|
before do
|
2016-08-09 11:51:40 -04:00
|
|
|
project.team << [master, :master]
|
2016-06-30 11:34:19 -04:00
|
|
|
project.team << [assignee, :developer]
|
2016-08-09 11:51:40 -04:00
|
|
|
project.team << [guest, :guest]
|
|
|
|
login_with(master)
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "new #{issuable_type}" do
|
|
|
|
context 'with commands in the description' do
|
|
|
|
it "creates the #{issuable_type} and interpret commands accordingly" do
|
|
|
|
visit public_send("new_namespace_project_#{issuable_type}_path", project.namespace, project, new_url_opts)
|
|
|
|
fill_in "#{issuable_type}_title", with: 'bug 345'
|
|
|
|
fill_in "#{issuable_type}_description", with: "bug description\n/label ~bug\n/milestone %\"ASAP\""
|
|
|
|
click_button "Submit #{issuable_type}".humanize
|
|
|
|
|
|
|
|
issuable = project.public_send(issuable_type.to_s.pluralize).first
|
|
|
|
|
2016-08-16 20:59:55 -04:00
|
|
|
expect(issuable.description).to eq "bug description"
|
2016-06-30 11:34:19 -04:00
|
|
|
expect(issuable.labels).to eq [label_bug]
|
|
|
|
expect(issuable.milestone).to eq milestone
|
|
|
|
expect(page).to have_content 'bug 345'
|
|
|
|
expect(page).to have_content 'bug description'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "note on #{issuable_type}" do
|
|
|
|
before do
|
|
|
|
visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
expect(page).to have_content 'Awesome!'
|
|
|
|
expect(page).not_to have_content '/assign @bob'
|
|
|
|
expect(page).not_to have_content '/label ~bug'
|
|
|
|
expect(page).not_to have_content '/milestone %"ASAP"'
|
|
|
|
|
|
|
|
issuable.reload
|
|
|
|
note = issuable.notes.user.first
|
|
|
|
|
2016-08-16 20:59:55 -04:00
|
|
|
expect(note.note).to eq "Awesome!"
|
2016-06-30 11:34:19 -04:00
|
|
|
expect(issuable.assignee).to eq assignee
|
|
|
|
expect(issuable.labels).to eq [label_bug]
|
|
|
|
expect(issuable.milestone).to eq milestone
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/assign @bob'
|
|
|
|
expect(page).not_to have_content '/label ~bug'
|
|
|
|
expect(page).not_to have_content '/milestone %"ASAP"'
|
2016-08-12 21:20:51 -04:00
|
|
|
expect(page).to have_content 'Your commands have been executed!'
|
2016-06-30 11:34:19 -04:00
|
|
|
|
|
|
|
issuable.reload
|
|
|
|
|
|
|
|
expect(issuable.notes.user).to be_empty
|
|
|
|
expect(issuable.assignee).to eq assignee
|
|
|
|
expect(issuable.labels).to eq [label_bug]
|
|
|
|
expect(issuable.milestone).to eq milestone
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-09 11:51:40 -04:00
|
|
|
context "with a note closing the #{issuable_type}" do
|
|
|
|
before do
|
|
|
|
expect(issuable).to be_open
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/close'
|
2016-08-12 21:20:51 -04:00
|
|
|
expect(page).to have_content 'Your commands have been executed!'
|
2016-08-09 11:51:40 -04:00
|
|
|
|
|
|
|
expect(issuable.reload).to be_closed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when current user cannot close #{issuable_type}" do
|
|
|
|
before do
|
|
|
|
logout
|
|
|
|
login_with(guest)
|
|
|
|
visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
|
|
|
|
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
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/close'
|
2016-08-12 21:20:51 -04:00
|
|
|
expect(page).not_to have_content 'Your commands have been executed!'
|
2016-08-09 11:51:40 -04:00
|
|
|
|
|
|
|
expect(issuable).to be_open
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a note reopening the #{issuable_type}" do
|
|
|
|
before do
|
|
|
|
issuable.close
|
|
|
|
expect(issuable).to be_closed
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/reopen'
|
2016-08-12 21:20:51 -04:00
|
|
|
expect(page).to have_content 'Your commands have been executed!'
|
2016-08-09 11:51:40 -04:00
|
|
|
|
|
|
|
expect(issuable.reload).to be_open
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when current user cannot reopen #{issuable_type}" do
|
|
|
|
before do
|
|
|
|
logout
|
|
|
|
login_with(guest)
|
|
|
|
visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
|
|
|
|
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
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/reopen'
|
2016-08-12 21:20:51 -04:00
|
|
|
expect(page).not_to have_content 'Your commands have been executed!'
|
2016-08-09 11:51:40 -04:00
|
|
|
|
|
|
|
expect(issuable).to be_closed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-09 14:54:18 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/title'
|
2016-08-12 21:20:51 -04:00
|
|
|
expect(page).to have_content 'Your commands have been executed!'
|
2016-08-09 14:54:18 -04:00
|
|
|
|
|
|
|
expect(issuable.reload.title).to eq 'Awesome new title'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when current user cannot change title of #{issuable_type}" do
|
|
|
|
before do
|
|
|
|
logout
|
|
|
|
login_with(guest)
|
|
|
|
visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
|
|
|
|
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
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/title'
|
2016-08-12 21:20:51 -04:00
|
|
|
expect(page).not_to have_content 'Your commands have been executed!'
|
2016-08-09 14:54:18 -04:00
|
|
|
|
|
|
|
expect(issuable.reload.title).not_to eq 'Awesome new title'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-30 11:34:19 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/todo'
|
2016-08-12 21:20:51 -04:00
|
|
|
expect(page).to have_content 'Your commands have been executed!'
|
2016-06-30 11:34:19 -04:00
|
|
|
|
2016-08-09 11:51:40 -04:00
|
|
|
todos = TodosFinder.new(master).execute
|
2016-06-30 11:34:19 -04:00
|
|
|
todo = todos.first
|
|
|
|
|
|
|
|
expect(todos.size).to eq 1
|
|
|
|
expect(todo).to be_pending
|
|
|
|
expect(todo.target).to eq issuable
|
2016-08-09 11:51:40 -04:00
|
|
|
expect(todo.author).to eq master
|
|
|
|
expect(todo.user).to eq master
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a note marking the #{issuable_type} as done" do
|
|
|
|
before do
|
2016-08-09 11:51:40 -04:00
|
|
|
TodoService.new.mark_todo(issuable, master)
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a new todo for the #{issuable_type}" do
|
2016-08-09 11:51:40 -04:00
|
|
|
todos = TodosFinder.new(master).execute
|
2016-06-30 11:34:19 -04:00
|
|
|
todo = todos.first
|
|
|
|
|
|
|
|
expect(todos.size).to eq 1
|
|
|
|
expect(todos.first).to be_pending
|
|
|
|
expect(todo.target).to eq issuable
|
2016-08-09 11:51:40 -04:00
|
|
|
expect(todo.author).to eq master
|
|
|
|
expect(todo.user).to eq master
|
2016-06-30 11:34:19 -04:00
|
|
|
|
|
|
|
page.within('.js-main-target-form') do
|
|
|
|
fill_in 'note[note]', with: "/done"
|
|
|
|
click_button 'Comment'
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/done'
|
2016-08-12 21:20:51 -04:00
|
|
|
expect(page).to have_content 'Your commands have been executed!'
|
2016-06-30 11:34:19 -04:00
|
|
|
|
|
|
|
expect(todo.reload).to be_done
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a note subscribing to the #{issuable_type}" do
|
|
|
|
it "creates a new todo for the #{issuable_type}" do
|
2016-08-09 11:51:40 -04:00
|
|
|
expect(issuable.subscribed?(master)).to be_falsy
|
2016-06-30 11:34:19 -04:00
|
|
|
|
|
|
|
page.within('.js-main-target-form') do
|
|
|
|
fill_in 'note[note]', with: "/subscribe"
|
|
|
|
click_button 'Comment'
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/subscribe'
|
2016-08-12 21:20:51 -04:00
|
|
|
expect(page).to have_content 'Your commands have been executed!'
|
2016-06-30 11:34:19 -04:00
|
|
|
|
2016-08-09 11:51:40 -04:00
|
|
|
expect(issuable.subscribed?(master)).to be_truthy
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a note unsubscribing to the #{issuable_type} as done" do
|
|
|
|
before do
|
2016-08-09 11:51:40 -04:00
|
|
|
issuable.subscribe(master)
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a new todo for the #{issuable_type}" do
|
2016-08-09 11:51:40 -04:00
|
|
|
expect(issuable.subscribed?(master)).to be_truthy
|
2016-06-30 11:34:19 -04:00
|
|
|
|
|
|
|
page.within('.js-main-target-form') do
|
|
|
|
fill_in 'note[note]', with: "/unsubscribe"
|
|
|
|
click_button 'Comment'
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).not_to have_content '/unsubscribe'
|
2016-08-12 21:20:51 -04:00
|
|
|
expect(page).to have_content 'Your commands have been executed!'
|
2016-06-30 11:34:19 -04:00
|
|
|
|
2016-08-09 11:51:40 -04:00
|
|
|
expect(issuable.subscribed?(master)).to be_falsy
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|