Commit 60b40492 authored by Phil Hughes's avatar Phil Hughes

Added todo controller tests for merge requests

parent 7c95dc41
require('spec_helper') require('spec_helper')
describe Projects::TodosController do describe Projects::TodosController do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, source_project: project) }
describe 'POST #create' do
before do context 'Issues' do
sign_in(user) describe 'POST #create' do
project.team << [user, :developer] before do
sign_in(user)
project.team << [user, :developer]
end
it 'should create todo for issue' do
expect do
post(:create, namespace_id: project.namespace.path,
project_id: project.path,
issuable_id: issue.id,
issuable_type: "issue")
end.to change { user.todos.count }.by(1)
expect(response.status).to eq(200)
end
end end
it 'should create todo for issue' do describe 'POST #create when not authorized' do
expect do before do
post(:create, namespace_id: project.namespace.path, sign_in(user)
project_id: project.path, end
issuable_id: issue.id,
issuable_type: "issue")
end.to change { user.todos.count }.by(1)
expect(response.status).to eq(200) it 'should create todo for issue' do
expect do
post(:create, namespace_id: project.namespace.path,
project_id: project.path,
issuable_id: issue.id,
issuable_type: "issue")
end.to change { user.todos.count }.by(0)
expect(response.status).to eq(404)
end
end
describe 'POST #create when not logged in' do
it 'should create todo for issue' do
expect do
post(:create, namespace_id: project.namespace.path,
project_id: project.path,
issuable_id: issue.id,
issuable_type: "issue")
end.to change { user.todos.count }.by(0)
expect(response.status).to eq(302)
end
end end
end end
describe 'POST #create when not authorized' do context 'Merge Requests' do
before do describe 'POST #create' do
sign_in(user) before do
sign_in(user)
project.team << [user, :developer]
end
it 'should create todo for issue' do
expect do
post(:create, namespace_id: project.namespace.path,
project_id: project.path,
issuable_id: merge_request.id,
issuable_type: "merge_request")
end.to change { user.todos.count }.by(1)
expect(response.status).to eq(200)
end
end end
it 'should create todo for issue' do describe 'POST #create when not authorized' do
expect do before do
post(:create, namespace_id: project.namespace.path, sign_in(user)
project_id: project.path, end
issuable_id: issue.id,
issuable_type: "issue")
end.to change { user.todos.count }.by(0)
expect(response.status).to eq(404) it 'should create todo for issue' do
expect do
post(:create, namespace_id: project.namespace.path,
project_id: project.path,
issuable_id: merge_request.id,
issuable_type: "merge_request")
end.to change { user.todos.count }.by(0)
expect(response.status).to eq(404)
end
end end
end
describe 'POST #create when not logged in' do describe 'POST #create when not logged in' do
it 'should create todo for issue' do it 'should create todo for issue' do
expect do expect do
post(:create, namespace_id: project.namespace.path, post(:create, namespace_id: project.namespace.path,
project_id: project.path, project_id: project.path,
issuable_id: issue.id, issuable_id: merge_request.id,
issuable_type: "issue") issuable_type: "merge_request")
end.to change { user.todos.count }.by(0) end.to change { user.todos.count }.by(0)
expect(response.status).to eq(302) expect(response.status).to eq(302)
end
end end
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