2016-06-17 04:01:03 -04:00
|
|
|
require('spec_helper')
|
|
|
|
|
|
|
|
describe Projects::TodosController do
|
2016-06-17 04:13:21 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-06-17 04:13:21 -04:00
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project) }
|
|
|
|
|
|
|
|
context 'Issues' do
|
2016-06-17 13:31:37 -04:00
|
|
|
describe 'POST create' do
|
2016-07-11 02:10:04 -04:00
|
|
|
def go
|
|
|
|
post :create,
|
2017-02-23 18:55:01 -05:00
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2016-07-11 02:10:04 -04:00
|
|
|
issuable_id: issue.id,
|
|
|
|
issuable_type: 'issue',
|
|
|
|
format: 'html'
|
|
|
|
end
|
|
|
|
|
2016-06-17 13:31:37 -04:00
|
|
|
context 'when authorized' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.team << [user, :developer]
|
|
|
|
end
|
|
|
|
|
2016-07-11 02:10:04 -04:00
|
|
|
it 'creates todo for issue' do
|
2016-06-17 13:31:37 -04:00
|
|
|
expect do
|
2016-07-11 02:10:04 -04:00
|
|
|
go
|
2016-06-17 13:31:37 -04:00
|
|
|
end.to change { user.todos.count }.by(1)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-06-17 13:31:37 -04:00
|
|
|
end
|
2016-07-11 02:10:04 -04:00
|
|
|
|
|
|
|
it 'returns todo path and pending count' do
|
|
|
|
go
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-07-11 02:10:04 -04:00
|
|
|
expect(json_response['count']).to eq 1
|
|
|
|
expect(json_response['delete_path']).to match(/\/dashboard\/todos\/\d{1}/)
|
|
|
|
end
|
2016-06-17 04:13:21 -04:00
|
|
|
end
|
|
|
|
|
2016-11-18 08:51:52 -05:00
|
|
|
context 'when not authorized for project' do
|
2016-07-11 02:10:04 -04:00
|
|
|
it 'does not create todo for issue that user has no access to' do
|
2016-06-17 13:31:37 -04:00
|
|
|
sign_in(user)
|
|
|
|
expect do
|
2016-07-11 02:10:04 -04:00
|
|
|
go
|
2016-06-17 13:31:37 -04:00
|
|
|
end.to change { user.todos.count }.by(0)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-06-17 13:31:37 -04:00
|
|
|
end
|
|
|
|
|
2016-07-11 02:10:04 -04:00
|
|
|
it 'does not create todo for issue when user not logged in' do
|
2016-06-17 13:31:37 -04:00
|
|
|
expect do
|
2016-07-11 02:10:04 -04:00
|
|
|
go
|
2016-06-17 13:31:37 -04:00
|
|
|
end.to change { user.todos.count }.by(0)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
2016-06-17 13:31:37 -04:00
|
|
|
end
|
2016-06-17 04:13:21 -04:00
|
|
|
end
|
2016-11-18 08:51:52 -05:00
|
|
|
|
|
|
|
context 'when not authorized for issue' do
|
|
|
|
before do
|
|
|
|
project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
project.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE)
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't create todo" do
|
2017-08-09 05:52:22 -04:00
|
|
|
expect { go }.not_to change { user.todos.count }
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-11-18 08:51:52 -05:00
|
|
|
end
|
|
|
|
end
|
2016-06-17 04:01:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-17 04:13:21 -04:00
|
|
|
context 'Merge Requests' do
|
2016-06-17 13:31:37 -04:00
|
|
|
describe 'POST create' do
|
2016-07-11 02:10:04 -04:00
|
|
|
def go
|
|
|
|
post :create,
|
2017-02-23 18:55:01 -05:00
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
2016-07-11 02:10:04 -04:00
|
|
|
issuable_id: merge_request.id,
|
|
|
|
issuable_type: 'merge_request',
|
|
|
|
format: 'html'
|
|
|
|
end
|
|
|
|
|
2016-06-17 13:31:37 -04:00
|
|
|
context 'when authorized' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.team << [user, :developer]
|
|
|
|
end
|
|
|
|
|
2016-07-11 02:10:04 -04:00
|
|
|
it 'creates todo for merge request' do
|
2016-06-17 13:31:37 -04:00
|
|
|
expect do
|
2016-07-11 02:10:04 -04:00
|
|
|
go
|
2016-06-17 13:31:37 -04:00
|
|
|
end.to change { user.todos.count }.by(1)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-06-17 13:31:37 -04:00
|
|
|
end
|
2016-07-11 02:10:04 -04:00
|
|
|
|
|
|
|
it 'returns todo path and pending count' do
|
|
|
|
go
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-07-11 02:10:04 -04:00
|
|
|
expect(json_response['count']).to eq 1
|
|
|
|
expect(json_response['delete_path']).to match(/\/dashboard\/todos\/\d{1}/)
|
|
|
|
end
|
2016-06-17 04:13:21 -04:00
|
|
|
end
|
|
|
|
|
2016-11-29 08:47:43 -05:00
|
|
|
context 'when not authorized for project' do
|
2016-07-11 02:10:04 -04:00
|
|
|
it 'does not create todo for merge request user has no access to' do
|
2016-06-17 13:31:37 -04:00
|
|
|
sign_in(user)
|
|
|
|
expect do
|
2016-07-11 02:10:04 -04:00
|
|
|
go
|
2016-06-17 13:31:37 -04:00
|
|
|
end.to change { user.todos.count }.by(0)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-06-17 13:31:37 -04:00
|
|
|
end
|
|
|
|
|
2016-07-11 02:10:04 -04:00
|
|
|
it 'does not create todo for merge request user has no access to' do
|
2016-06-17 13:31:37 -04:00
|
|
|
expect do
|
2016-07-11 02:10:04 -04:00
|
|
|
go
|
2016-06-17 13:31:37 -04:00
|
|
|
end.to change { user.todos.count }.by(0)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
2016-06-17 13:31:37 -04:00
|
|
|
end
|
2016-06-17 04:13:21 -04:00
|
|
|
end
|
2016-11-29 08:47:43 -05:00
|
|
|
|
|
|
|
context 'when not authorized for merge_request' do
|
|
|
|
before do
|
|
|
|
project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
project.project_feature.update!(merge_requests_access_level: ProjectFeature::PRIVATE)
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't create todo" do
|
2017-08-09 05:52:22 -04:00
|
|
|
expect { go }.not_to change { user.todos.count }
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-11-29 08:47:43 -05:00
|
|
|
end
|
|
|
|
end
|
2016-06-17 04:06:00 -04:00
|
|
|
end
|
|
|
|
end
|
2016-06-17 04:01:03 -04:00
|
|
|
end
|