-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathprojects_controller_spec.rb
More file actions
161 lines (134 loc) · 4.84 KB
/
projects_controller_spec.rb
File metadata and controls
161 lines (134 loc) · 4.84 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
# frozen_string_literal: true
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, params: { 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_successful
end
end
# 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
shared_context 'accessing_project' do |verb, action|
let(:a_project) { create(:project, host: 'github', full_name: 'test/test') }
context 'with existsing project' do
it 'via project id returns 302 status code' do
case verb
when :get
get(action, params: { id: a_project.id })
when :patch
patch(action, params: { 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, params: { service: 'github', repo: a_project.full_name })
when :patch
patch(action, params: { service: 'github', repo: a_project.full_name })
end
expect(response).to be_successful
end
end
context 'with non-existing project' do
it 'via project id returns 302 status code' do
case verb
when :get
get(action, params: { id: 999_999 })
when :patch
patch(action, params: { id: 999_999 })
end
expect(response).to be_redirect
end
it 'via project name returns 200 status code' do
case verb
when :get
get(action, params: { service: 'github', repo: 'no-such/project' })
when :patch
patch(action, params: { 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, params: { 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, params: { 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, params: { 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, params: { service: 'github', repo: 'test/test' })
expect(response).to be_redirect
end
end
end