1
- RSpec . describe ProtipsController , type : :controller , skip : true do
1
+ RSpec . describe ProtipsController , type : :controller do
2
2
let ( :current_user ) { Fabricate ( :user ) }
3
3
4
4
before { controller . send :sign_in , current_user }
@@ -7,23 +7,19 @@ def valid_attributes
7
7
{
8
8
title : 'hello world' ,
9
9
body : "somethings that's meaningful and nice" ,
10
- topics : %w( java javascript ) ,
10
+ topic_list : " java, javascript" ,
11
11
user_id : current_user . id
12
12
}
13
13
end
14
14
15
- def valid_session
16
- { }
17
- end
18
-
19
15
describe 'GET user' do
20
16
describe 'banned' do
21
17
it 'should assign user @protips for page, despite not being in search index' do
22
18
current_user . update_attribute ( :banned_at , Time . now )
23
19
expect ( current_user . banned? ) . to eq ( true )
24
20
Protip . rebuild_index
25
21
protip = Protip . create! valid_attributes
26
- get :user , { username : current_user . username } , valid_session
22
+ get :user , { username : current_user . username }
27
23
expect ( assigns ( :protips ) . first . title ) . to eq ( protip . title )
28
24
end
29
25
end
@@ -32,28 +28,33 @@ def valid_session
32
28
it 'should assign user @protips for page' do
33
29
Protip . rebuild_index
34
30
protip = Protip . create! valid_attributes
35
- get :user , { username : current_user . username } , valid_session
31
+ get :user , { username : current_user . username }
36
32
expect ( assigns ( :protips ) . results . first . title ) . to eq ( protip . title )
37
33
end
38
-
39
34
end
40
-
41
35
end
42
36
43
37
# describe "GET topic" do
44
38
# it "assigns all protips as @protips" do
45
39
# Protip.rebuild_index
46
40
# protip = Protip.create! valid_attributes
47
- # get :topic, {tags: "java"}, valid_session
41
+ # get :topic, {tags: "java"}
48
42
# expect(assigns(:protips).results.first.title).to eq(protip.title)
49
43
# end
50
44
# end
51
45
52
46
describe 'GET show using public_id' do
53
- it 'redirects to GET show using slug' do
47
+ it 'redirects to GET show if slug is empty' do
48
+ protip = Protip . create! valid_attributes
49
+ protip . save
50
+ get :show , { id : protip . to_param }
51
+ expect ( response ) . to redirect_to slug_protips_path ( protip , protip . friendly_id )
52
+ end
53
+
54
+ it 'redirects to GET show if slug is invalid' do
54
55
protip = Protip . create! valid_attributes
55
56
protip . save
56
- get :show , { id : protip . to_param } , valid_session
57
+ get :show , { id : protip . to_param , slug : "an_invalid_slug" }
57
58
expect ( response ) . to redirect_to slug_protips_path ( protip , protip . friendly_id )
58
59
end
59
60
end
@@ -62,7 +63,7 @@ def valid_session
62
63
it 'assigns the requested protip as @protip' do
63
64
protip = Protip . create! valid_attributes
64
65
protip . save
65
- get :show , { id : protip . public_id , slug : protip . friendly_id } , valid_session
66
+ get :show , { id : protip . public_id , slug : protip . friendly_id }
66
67
expect ( assigns ( :protip ) ) . to eq ( protip )
67
68
end
68
69
end
@@ -71,26 +72,26 @@ def valid_session
71
72
before { allow_any_instance_of ( User ) . to receive ( :skills ) . and_return ( [ 'skill' ] ) } # User must have a skill to create protips
72
73
73
74
it 'assigns a new protip as @protip' do
74
- get :new , { } , valid_session
75
+ get :new , { }
75
76
expect ( assigns ( :protip ) ) . to be_a_new ( Protip )
76
77
end
77
78
78
79
it 'allows viewing the page when you have a skill' do
79
- get :new , { } , valid_session
80
+ get :new , { }
80
81
expect ( response ) . to render_template ( 'new' )
81
82
end
82
83
83
84
it "prevents viewing the page when you don't have a skill" do
84
85
allow_any_instance_of ( User ) . to receive ( :skills ) . and_return ( [ ] )
85
- get :new , { } , valid_session
86
+ get :new , { }
86
87
expect ( response ) . to redirect_to badge_path ( username : current_user . username , anchor : 'add-skill' )
87
88
end
88
89
end
89
90
90
91
describe 'GET edit' do
91
92
it 'assigns the requested protip as @protip' do
92
93
protip = Protip . create! valid_attributes
93
- get :edit , { id : protip . to_param } , valid_session
94
+ get :edit , { id : protip . to_param }
94
95
expect ( assigns ( :protip ) ) . to eq ( protip )
95
96
end
96
97
end
@@ -101,18 +102,18 @@ def valid_session
101
102
describe 'with valid params' do
102
103
it 'creates a new Protip' do
103
104
expect do
104
- post :create , { protip : valid_attributes } , valid_session
105
+ post :create , { protip : valid_attributes }
105
106
end . to change ( Protip , :count ) . by ( 1 )
106
107
end
107
108
108
109
it 'assigns a newly created protip as @protip' do
109
- post :create , { protip : valid_attributes } , valid_session
110
+ post :create , { protip : valid_attributes }
110
111
expect ( assigns ( :protip ) ) . to be_a ( Protip )
111
112
expect ( assigns ( :protip ) ) . to be_persisted
112
113
end
113
114
114
115
it 'redirects to the created protip' do
115
- post :create , { protip : valid_attributes } , valid_session
116
+ post :create , { protip : valid_attributes }
116
117
expect ( response ) . to redirect_to ( Protip . last )
117
118
end
118
119
end
@@ -121,21 +122,21 @@ def valid_session
121
122
it 'assigns a newly created but unsaved protip as @protip' do
122
123
# Trigger the behavior that occurs when invalid params are submitted
123
124
allow_any_instance_of ( Protip ) . to receive ( :save ) . and_return ( false )
124
- post :create , { protip : { } } , valid_session
125
+ post :create , { protip : { } }
125
126
expect ( assigns ( :protip ) ) . to be_a_new ( Protip )
126
127
end
127
128
128
129
it "re-renders the 'new' template" do
129
130
# Trigger the behavior that occurs when invalid params are submitted
130
131
allow_any_instance_of ( Protip ) . to receive ( :save ) . and_return ( false )
131
- post :create , { protip : { } } , valid_session
132
+ post :create , { protip : { } }
132
133
expect ( response ) . to render_template ( 'new' )
133
134
end
134
135
end
135
136
136
137
it "prevents creating when you don't have a skill" do
137
138
allow_any_instance_of ( User ) . to receive ( :skills ) . and_return ( [ ] )
138
- post :create , { protip : valid_attributes } , valid_session
139
+ post :create , { protip : valid_attributes }
139
140
expect ( response ) . to redirect_to badge_path ( username : current_user . username , anchor : 'add-skill' )
140
141
end
141
142
end
@@ -149,18 +150,18 @@ def valid_session
149
150
# receives the :update_attributes message with whatever params are
150
151
# submitted in the request.
151
152
expect_any_instance_of ( Protip ) . to receive ( :update_attributes ) . with ( 'body' => 'params' )
152
- put :update , { id : protip . to_param , protip : { 'body' => 'params' } } , valid_session
153
+ put :update , { id : protip . to_param , protip : { 'body' => 'params' } }
153
154
end
154
155
155
156
it 'assigns the requested protip as @protip' do
156
157
protip = Protip . create! valid_attributes
157
- put :update , { id : protip . to_param , protip : valid_attributes } , valid_session
158
+ put :update , { id : protip . to_param , protip : valid_attributes }
158
159
expect ( assigns ( :protip ) ) . to eq ( protip )
159
160
end
160
161
161
162
it 'redirects to the protip' do
162
163
protip = Protip . create! valid_attributes
163
- put :update , { id : protip . to_param , protip : valid_attributes } , valid_session
164
+ put :update , { id : protip . to_param , protip : valid_attributes }
164
165
expect ( response ) . to redirect_to ( protip )
165
166
end
166
167
end
@@ -170,7 +171,7 @@ def valid_session
170
171
protip = Protip . create! valid_attributes
171
172
# Trigger the behavior that occurs when invalid params are submitted
172
173
allow_any_instance_of ( Protip ) . to receive ( :save ) . and_return ( false )
173
- put :update , { id : protip . to_param , protip : { } } , valid_session
174
+ put :update , { id : protip . to_param , protip : { } }
174
175
expect ( assigns ( :protip ) ) . to eq ( protip )
175
176
end
176
177
@@ -180,7 +181,7 @@ def valid_session
180
181
# Trigger the behavior that occurs when invalid params are submitted
181
182
allow_any_instance_of ( Protip ) . to receive ( :save ) . and_return ( false )
182
183
183
- put :update , { id : protip . to_param , protip : { } } , valid_session
184
+ put :update , { id : protip . to_param , protip : { } }
184
185
expect ( response ) . to render_template ( 'edit' )
185
186
end
186
187
end
@@ -191,20 +192,20 @@ def valid_session
191
192
attributes = valid_attributes
192
193
attributes [ :user_id ] = Fabricate ( :user ) . id
193
194
protip = Protip . create! attributes
194
- delete :destroy , { id : protip . to_param } , valid_session
195
+ delete :destroy , { id : protip . to_param }
195
196
expect { protip . reload } . not_to raise_error
196
197
end
197
198
198
199
it 'destroys the requested protip' do
199
200
protip = Protip . create! valid_attributes
200
201
expect {
201
- delete :destroy , { id : protip . to_param } , valid_session
202
+ delete :destroy , { id : protip . to_param }
202
203
} . to change ( Protip , :count ) . by ( -1 )
203
204
end
204
205
205
206
it 'redirects to the protips list' do
206
207
protip = Protip . create! ( valid_attributes )
207
- delete :destroy , { id : protip . to_param } , valid_session
208
+ delete :destroy , { id : protip . to_param }
208
209
expect ( response ) . to redirect_to ( protips_url )
209
210
end
210
211
end
0 commit comments