forked from tip4commit/tip4commit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojects_controller_spec.rb
More file actions
258 lines (219 loc) · 8.31 KB
/
projects_controller_spec.rb
File metadata and controls
258 lines (219 loc) · 8.31 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
require 'spec_helper'
describe ProjectsController, type: :controller do
describe 'GET #index' do
let(:subject) { get :index }
before do
allow(Project).to receive(:order).with(available_amount_cache: :desc, watchers_count: :desc, full_name: :asc).and_return(Project)
allow(Project).to receive(:page).with(nil).and_return(Project)
allow(Project).to receive(:per).with(30).and_return(Project)
allow(Project).to receive(:to_a).and_return(Project)
allow(Project).to receive(:reject!).and_return(Project)
end
it 'renders index template' do
expect(subject).to render_template :index
end
it 'returns 200 status code' do
expect(subject.status).to eq 200
end
it 'Project calls order' do
expect(Project).to receive(:order).with(available_amount_cache: :desc, watchers_count: :desc, full_name: :asc).and_return(Project)
subject
end
it 'Project calls page' do
expect(Project).to receive(:page).with(nil).and_return(Project)
subject
end
it 'Project calls per' do
expect(Project).to receive(:per).with(30).and_return(Project)
subject
end
it 'assigns @projects' do
subject
expect(assigns[:projects].name).to eq 'Project'
end
end
describe 'GET #search' do
context 'with existing repo that has been blacklisted' do
let(:subject) { get :search, query: "https://github.com/mitsuhiko/flask" }
it 'renders blacklisted template' do
expect(subject).to render_template :blacklisted
end
end
end
describe 'POST #search' do
it 'returns 200 status code' do
post :search
expect(response).to be_success
end
end
=begin TODO: NFG - No route matches {:controller=>"projects", :action=>"update"}
describe 'PUT #update' do
it 'returns 200 status code' do
put :update
response.should be_success
end
end
=end
shared_context 'accessing_project' do |verb , action|
let(:a_project) { create :project , :host => 'github' , :full_name => "test/test" }
context 'existing_project' do
it 'via project id returns 302 status code' do
case verb
when :get ; get action , :id => a_project.id
when :patch ; patch action , :id => a_project.id
end
expect(response).to be_redirect
end
it 'via project name returns 200 status code' do
case verb
when :get ; get action , :service => 'github' , :repo => a_project.full_name
when :patch ; patch action , :service => 'github' , :repo => a_project.full_name
end
expect(response).to be_success
end
end
context 'nonexisting_project' do
it 'via project id returns 302 status code' do
case verb
when :get ; get action , :id => 999999
when :patch ; patch action , :id => 999999
end
expect(response).to be_redirect
end
it 'via project name returns 200 status code' do
case verb
when :get ; get action , :service => 'github' , :repo => 'no-such/project' ;
when :patch ; patch action , :service => 'github' , :repo => 'no-such/project' ;
end
expect(response).to be_redirect
end
end
end
describe 'GET #show' do
include_context 'accessing_project' , :get , :show
context 'with existing repo that has been blacklisted' do
let(:blacklisted_repo) { create(:project, host: "github", full_name: "mitsuhiko/flask") }
let(:subject) { get :show, service: "github", repo: blacklisted_repo.full_name }
it 'renders blacklisted template' do
expect(subject).to render_template :blacklisted
end
end
end
describe 'GET #edit' do
it 'returns 302 status code' do
# TODO: requires logged in user who is project collaborator
# include_context 'accessing_project' , :get , :edit
get :edit , :service => 'github' , :repo => 'test/test'
expect(response).to be_redirect
end
end
describe 'GET #decide_tip_amounts' do
# TODO: requires logged in user who is project collaborator and some tips
# include_context 'accessing_project' , :get , :decide_tip_amounts
it 'returns 302 status code' do
get :decide_tip_amounts , :service => 'github' , :repo => 'test/test'
expect(response).to be_redirect
end
end
describe 'PATCH #decide_tip_amounts' do
# TODO: requires logged in user who is project collaborator and some tips
# include_context 'accessing_project' , :patch , :decide_tip_amounts
it 'returns 302 status code' do
patch :decide_tip_amounts , :service => 'github' , :repo => 'test/test'
expect(response).to be_redirect
end
end
describe "routing" do
it "routes GET /projects to Project#index" do
expect({ :get => "/projects" }).to route_to(
:controller => "projects" ,
:action => "index" )
end
it "routes GET /projects/search?query= to Project#search" do
expect({ :get => "/projects/search?query=seldon&order=balance" }).to route_to(
:controller => "projects" ,
:action => "search" ,
:query => "seldon" ,
:order => "balance" )
end
it "routes GET /projects/1 to Project#show" do
expect({ :get => "/projects/1" }).to route_to(
:controller => "projects" ,
:action => "show" ,
:id => "1" )
end
it "routes GET /projects/1/edit to Project#edit" do
expect({ :get => "/projects/1/edit" }).to route_to(
:controller => "projects" ,
:action => "edit" ,
:id => "1" )
end
it "routes PUT /projects/1 to Project#update" do
expect({ :put => "/projects/1" }).to route_to(
:controller => "projects" ,
:action => "update" ,
:id => "1" )
end
it "routes GET /projects/1/decide_tip_amounts to Project#decide_tip_amounts" do
expect({ :get => "/projects/1/decide_tip_amounts" }).to route_to(
:controller => "projects" ,
:action => "decide_tip_amounts" ,
:id => "1" )
end
it "routes PATCH /projects/1/decide_tip_amounts to Project#decide_tip_amounts" do
expect({ :patch => "/projects/1/decide_tip_amounts" }).to route_to(
:controller => "projects" ,
:action => "decide_tip_amounts" ,
:id => "1" )
end
it "routes GET /projects/1/tips to Tips#index" do
expect({ :get => "/projects/1/tips" }).to route_to(
:controller => "tips" ,
:action => "index" ,
:project_id => "1" )
end
it "routes GET /projects/1/deposits to Deposits#index" do
expect({ :get => "/projects/1/deposits" }).to route_to(
:controller => "deposits" ,
:action => "index" ,
:project_id => "1" )
end
end
describe "Project pretty url routing" do
it "routes GET /:provider/:repo to Project#show" do
expect({ :get => "/github/test/test" }).to route_to(
:controller => "projects" ,
:action => "show" ,
:service => "github" ,
:repo => "test/test")
end
it "routes GET /:provider/:repo/edit to Project#edit" do
expect({ :get => "/github/test/test/edit" }).to route_to(
:controller => "projects" ,
:action => "edit" ,
:service => "github" ,
:repo => "test/test")
end
it "routes GET /:provider/:repo/decide_tip_amounts to Project#decide_tip_amounts" do
expect({ :get => "/github/test/test/decide_tip_amounts" }).to route_to(
:controller => "projects" ,
:action => "decide_tip_amounts" ,
:service => "github" ,
:repo => "test/test" )
end
it "routes GET /:provider/:repo/tips to Project#tips" do
expect({ :get => "/github/test/test/tips" }).to route_to(
:controller => "tips" ,
:action => "index" ,
:service => "github" ,
:repo => "test/test")
end
it "routes GET /:provider/:repo/deposits to Project#deposits" do
expect({ :get => "/github/test/test/deposits" }).to route_to(
:controller => "deposits" ,
:action => "index" ,
:service => "github" ,
:repo => "test/test")
end
end
end