1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
require('spec_helper')
describe Projects::TodosController do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, source_project: project) }
context 'Issues' do
describe 'POST create' do
context 'when authorized' do
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).to have_http_status(200)
end
end
context 'when not authorized' do
it 'should not create todo for issue that user has no access to' do
sign_in(user)
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).to have_http_status(404)
end
it 'should not create todo for issue when user not logged in' 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).to have_http_status(302)
end
end
end
end
context 'Merge Requests' do
describe 'POST create' do
context 'when authorized' do
before do
sign_in(user)
project.team << [user, :developer]
end
it 'should create todo for merge request' 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).to have_http_status(200)
end
end
context 'when not authorized' do
it 'should not create todo for merge request user has no access to' do
sign_in(user)
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).to have_http_status(404)
end
it 'should not create todo for merge request user has no access to' 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).to have_http_status(302)
end
end
end
end
end