debian-mirror-gitlab/spec/controllers/projects/todos_controller_spec.rb

145 lines
4 KiB
Ruby
Raw Normal View History

2016-06-22 15:30:34 +05:30
require('spec_helper')
describe Projects::TodosController do
let(:user) { create(:user) }
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2016-06-22 15:30:34 +05:30
let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, source_project: project) }
context 'Issues' do
describe 'POST create' do
2016-08-24 12:49:21 +05:30
def go
post :create,
2017-08-17 22:00:37 +05:30
namespace_id: project.namespace,
project_id: project,
2016-08-24 12:49:21 +05:30
issuable_id: issue.id,
issuable_type: 'issue',
format: 'html'
end
2016-06-22 15:30:34 +05:30
context 'when authorized' do
before do
sign_in(user)
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2016-06-22 15:30:34 +05:30
end
2016-08-24 12:49:21 +05:30
it 'creates todo for issue' do
2016-06-22 15:30:34 +05:30
expect do
2016-08-24 12:49:21 +05:30
go
2016-06-22 15:30:34 +05:30
end.to change { user.todos.count }.by(1)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-08-24 12:49:21 +05:30
end
it 'returns todo path and pending count' do
go
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-08-24 12:49:21 +05:30
expect(json_response['count']).to eq 1
2018-03-17 18:26:18 +05:30
expect(json_response['delete_path']).to match(%r{/dashboard/todos/\d{1}})
2016-06-22 15:30:34 +05:30
end
end
2017-01-15 13:20:01 +05:30
context 'when not authorized for project' do
2016-08-24 12:49:21 +05:30
it 'does not create todo for issue that user has no access to' do
2016-06-22 15:30:34 +05:30
sign_in(user)
expect do
2016-08-24 12:49:21 +05:30
go
2016-06-22 15:30:34 +05:30
end.to change { user.todos.count }.by(0)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2016-06-22 15:30:34 +05:30
end
2016-08-24 12:49:21 +05:30
it 'does not create todo for issue when user not logged in' do
2016-06-22 15:30:34 +05:30
expect do
2016-08-24 12:49:21 +05:30
go
2016-06-22 15:30:34 +05:30
end.to change { user.todos.count }.by(0)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(302)
2016-06-22 15:30:34 +05:30
end
end
2017-01-15 13:20:01 +05:30
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
2018-03-17 18:26:18 +05:30
expect { go }.not_to change { user.todos.count }
expect(response).to have_gitlab_http_status(404)
2017-01-15 13:20:01 +05:30
end
end
2016-06-22 15:30:34 +05:30
end
end
context 'Merge Requests' do
describe 'POST create' do
2016-08-24 12:49:21 +05:30
def go
post :create,
2017-08-17 22:00:37 +05:30
namespace_id: project.namespace,
project_id: project,
2016-08-24 12:49:21 +05:30
issuable_id: merge_request.id,
issuable_type: 'merge_request',
format: 'html'
end
2016-06-22 15:30:34 +05:30
context 'when authorized' do
before do
sign_in(user)
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2016-06-22 15:30:34 +05:30
end
2016-08-24 12:49:21 +05:30
it 'creates todo for merge request' do
2016-06-22 15:30:34 +05:30
expect do
2016-08-24 12:49:21 +05:30
go
2016-06-22 15:30:34 +05:30
end.to change { user.todos.count }.by(1)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-08-24 12:49:21 +05:30
end
it 'returns todo path and pending count' do
go
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-08-24 12:49:21 +05:30
expect(json_response['count']).to eq 1
2018-03-17 18:26:18 +05:30
expect(json_response['delete_path']).to match(%r{/dashboard/todos/\d{1}})
2016-06-22 15:30:34 +05:30
end
end
2017-01-15 13:20:01 +05:30
context 'when not authorized for project' do
2016-08-24 12:49:21 +05:30
it 'does not create todo for merge request user has no access to' do
2016-06-22 15:30:34 +05:30
sign_in(user)
expect do
2016-08-24 12:49:21 +05:30
go
2016-06-22 15:30:34 +05:30
end.to change { user.todos.count }.by(0)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(404)
2016-06-22 15:30:34 +05:30
end
2016-08-24 12:49:21 +05:30
it 'does not create todo for merge request user has no access to' do
2016-06-22 15:30:34 +05:30
expect do
2016-08-24 12:49:21 +05:30
go
2016-06-22 15:30:34 +05:30
end.to change { user.todos.count }.by(0)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(302)
2016-06-22 15:30:34 +05:30
end
end
2017-01-15 13:20:01 +05:30
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
2018-03-17 18:26:18 +05:30
expect { go }.not_to change { user.todos.count }
expect(response).to have_gitlab_http_status(404)
2017-01-15 13:20:01 +05:30
end
end
2016-06-22 15:30:34 +05:30
end
end
end