Skip to content
Newer
Older
100644 564 lines (459 sloc) 15.5 KB
d4fa068 @dchelimsky Add controller DSL for spec'ing behaviour of subclasses of
dchelimsky authored Jul 23, 2010
1 Feature: anonymous controller
2
9311099 @cupakromer Update cuke feature with style changes.
cupakromer authored May 13, 2014
3 Use the `controller` method to define an anonymous controller that will
4 inherit from the described class. This is useful for specifying behavior like
5 global error handling.
6
7 To specify a different base class you can pass the class explicitly to the
8 controller method:
9
10 ```ruby
11 controller(BaseController)
12 ```
13
14 You can also disable base type inference, in which case anonymous controllers
15 will inherit from `ApplicationController` instead of the described class by
16 default:
17
18 ```ruby
c0d72d7 @cupakromer Fix formatting for feature description.
cupakromer authored May 24, 2014
19 RSpec.configure do |c|
9311099 @cupakromer Update cuke feature with style changes.
cupakromer authored May 13, 2014
20 c.infer_base_class_for_anonymous_controllers = false
21 end
22
31fe4d0 @JonRowe manually tag type examples
JonRowe authored Oct 16, 2014
23 RSpec.describe BaseController, :type => :controller do
c0d72d7 @cupakromer Fix formatting for feature description.
cupakromer authored May 24, 2014
24 controller do
25 def index; end
26
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
27 # this normally creates an anonymous `BaseController` subclass,
28 # however since `infer_base_class_for_anonymous_controllers` is
29 # disabled, it creates a subclass of `ApplicationController`
c0d72d7 @cupakromer Fix formatting for feature description.
cupakromer authored May 24, 2014
30 end
31 end
9311099 @cupakromer Update cuke feature with style changes.
cupakromer authored May 13, 2014
32 ```
33
80637fc @pixeltrix Fix empty template rendering for Rails 4.2.5.1
pixeltrix authored Jan 26, 2016
34 Scenario: Specify error handling in `ApplicationController` with redirect
d4fa068 @dchelimsky Add controller DSL for spec'ing behaviour of subclasses of
dchelimsky authored Jul 24, 2010
35 Given a file named "spec/controllers/application_controller_spec.rb" with:
78b151a @vanstee Identify ruby code for syntax highlighting
vanstee authored Oct 12, 2012
36 """ruby
d3065c0 @cupakromer Move spec_helper to rails_helper.
cupakromer authored May 29, 2014
37 require "rails_helper"
d4fa068 @dchelimsky Add controller DSL for spec'ing behaviour of subclasses of
dchelimsky authored Jul 24, 2010
38
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
39 class ApplicationController < ActionController::Base
40 class AccessDenied < StandardError; end
d4fa068 @dchelimsky Add controller DSL for spec'ing behaviour of subclasses of
dchelimsky authored Jul 24, 2010
41
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
42 rescue_from AccessDenied, :with => :access_denied
d4fa068 @dchelimsky Add controller DSL for spec'ing behaviour of subclasses of
dchelimsky authored Jul 24, 2010
43
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
44 private
48a231e Allow testing of ApplicationController subclasses with controller()
Mike Gehard authored Aug 5, 2010
45
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
46 def access_denied
47 redirect_to "/401.html"
48 end
48a231e Allow testing of ApplicationController subclasses with controller()
Mike Gehard authored Aug 6, 2010
49 end
d4fa068 @dchelimsky Add controller DSL for spec'ing behaviour of subclasses of
dchelimsky authored Jul 24, 2010
50
31fe4d0 @JonRowe manually tag type examples
JonRowe authored Oct 16, 2014
51 RSpec.describe ApplicationController, :type => :controller do
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
52 controller do
53 def index
54 raise ApplicationController::AccessDenied
55 end
d4fa068 @dchelimsky Add controller DSL for spec'ing behaviour of subclasses of
dchelimsky authored Jul 24, 2010
56 end
57
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
58 describe "handling AccessDenied exceptions" do
59 it "redirects to the /401.html page" do
60 get :index
a65ff6e @alindeman Features use new expect() syntax
alindeman authored Aug 6, 2012
61 expect(response).to redirect_to("/401.html")
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
62 end
d4fa068 @dchelimsky Add controller DSL for spec'ing behaviour of subclasses of
dchelimsky authored Jul 24, 2010
63 end
48a231e Allow testing of ApplicationController subclasses with controller()
Mike Gehard authored Aug 6, 2010
64 end
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
65 """
2a0c0d7 @dchelimsky upgrade cucumber and aruba
dchelimsky authored Mar 24, 2011
66 When I run `rspec spec`
78a3307 @dchelimsky cukes
dchelimsky authored Jan 16, 2011
67 Then the examples should all pass
48a231e Allow testing of ApplicationController subclasses with controller()
Mike Gehard authored Aug 6, 2010
68
80637fc @pixeltrix Fix empty template rendering for Rails 4.2.5.1
pixeltrix authored Jan 26, 2016
69 Scenario: Specify error handling in `ApplicationController` with render
70 Given a file named "spec/controllers/application_controller_spec.rb" with:
71 """ruby
72 require "rails_helper"
73
74 class ApplicationController < ActionController::Base
75 class AccessDenied < StandardError; end
76
77 rescue_from AccessDenied, :with => :access_denied
78
79 private
80
81 def access_denied
82 render "errors/401"
83 end
84 end
85
86 RSpec.describe ApplicationController, :type => :controller do
87 controller do
88 def index
89 raise ApplicationController::AccessDenied
90 end
91 end
92
93 describe "handling AccessDenied exceptions" do
94 it "renders the errors/401 template" do
95 get :index
96 expect(response).to render_template("errors/401")
97 end
98 end
99 end
100 """
101 When I run `rspec spec`
102 Then the examples should all pass
103
104 Scenario: Specify error handling in `ApplicationController` with render :file
105 Given a file named "spec/controllers/application_controller_spec.rb" with:
106 """ruby
107 require "rails_helper"
108
109 class ApplicationController < ActionController::Base
110 class AccessDenied < StandardError; end
111
112 rescue_from AccessDenied, :with => :access_denied
113
114 private
115
116 def access_denied
117 render :file => "errors/401"
118 end
119 end
120
121 RSpec.describe ApplicationController, :type => :controller do
122 controller do
123 def index
124 raise ApplicationController::AccessDenied
125 end
126 end
127
128 describe "handling AccessDenied exceptions" do
129 it "renders the errors/401 template" do
130 get :index
131 expect(response).to render_template("errors/401")
132 end
133 end
134 end
135 """
136 When I run `rspec spec`
137 Then the examples should all pass
138
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
139 Scenario: Specify error handling in a subclass
48a231e Allow testing of ApplicationController subclasses with controller()
Mike Gehard authored Aug 6, 2010
140 Given a file named "spec/controllers/application_controller_subclass_spec.rb" with:
78b151a @vanstee Identify ruby code for syntax highlighting
vanstee authored Oct 12, 2012
141 """ruby
d3065c0 @cupakromer Move spec_helper to rails_helper.
cupakromer authored May 30, 2014
142 require "rails_helper"
48a231e Allow testing of ApplicationController subclasses with controller()
Mike Gehard authored Aug 6, 2010
143
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
144 class ApplicationController < ActionController::Base
145 class AccessDenied < StandardError; end
146 end
48a231e Allow testing of ApplicationController subclasses with controller()
Mike Gehard authored Aug 6, 2010
147
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
148 class FoosController < ApplicationController
48a231e Allow testing of ApplicationController subclasses with controller()
Mike Gehard authored Aug 6, 2010
149
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
150 rescue_from ApplicationController::AccessDenied,
151 :with => :access_denied
48a231e Allow testing of ApplicationController subclasses with controller()
Mike Gehard authored Aug 6, 2010
152
153 private
154
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
155 def access_denied
156 redirect_to "/401.html"
157 end
48a231e Allow testing of ApplicationController subclasses with controller()
Mike Gehard authored Aug 6, 2010
158 end
159
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
160 RSpec.describe FoosController, :type => :controller do
161 controller(FoosController) do
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
162 def index
163 raise ApplicationController::AccessDenied
164 end
48a231e Allow testing of ApplicationController subclasses with controller()
Mike Gehard authored Aug 6, 2010
165 end
d4fa068 @dchelimsky Add controller DSL for spec'ing behaviour of subclasses of
dchelimsky authored Jul 24, 2010
166
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
167 describe "handling AccessDenied exceptions" do
168 it "redirects to the /401.html page" do
169 get :index
a65ff6e @alindeman Features use new expect() syntax
alindeman authored Aug 7, 2012
170 expect(response).to redirect_to("/401.html")
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
171 end
d4fa068 @dchelimsky Add controller DSL for spec'ing behaviour of subclasses of
dchelimsky authored Jul 24, 2010
172 end
173 end
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
174 """
2a0c0d7 @dchelimsky upgrade cucumber and aruba
dchelimsky authored Mar 25, 2011
175 When I run `rspec spec`
78a3307 @dchelimsky cukes
dchelimsky authored Jan 16, 2011
176 Then the examples should all pass
631e889 @alindeman Add failing cuke to demonstrate regression with around_filter
alindeman authored May 12, 2011
177
9311099 @cupakromer Update cuke feature with style changes.
cupakromer authored May 13, 2014
178 Scenario: Infer base class from the described class
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
179 Given a file named "spec/controllers/base_class_can_be_inferred_spec.rb" with:
78b151a @vanstee Identify ruby code for syntax highlighting
vanstee authored Oct 12, 2012
180 """ruby
d3065c0 @cupakromer Move spec_helper to rails_helper.
cupakromer authored May 30, 2014
181 require "rails_helper"
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
182
183 class ApplicationController < ActionController::Base; end
184
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
185 class FoosController < ApplicationController; end
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
186
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
187 RSpec.describe FoosController, :type => :controller do
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
188 controller do
189 def index
190 render :text => "Hello World"
191 end
192 end
193
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
194 it "creates anonymous controller derived from FoosController" do
195 expect(controller).to be_a_kind_of(FoosController)
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
196 end
a2caa56 @alindeman Infer base class of anonymous controllers
alindeman authored Aug 17, 2011
197 end
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
198 """
a2caa56 @alindeman Infer base class of anonymous controllers
alindeman authored Aug 17, 2011
199 When I run `rspec spec`
200 Then the examples should all pass
201
9311099 @cupakromer Update cuke feature with style changes.
cupakromer authored May 13, 2014
202 Scenario: Use `name` and `controller_name` from the described class
4b74b1f @billychan spec and cucumber passed
billychan authored Dec 24, 2013
203 Given a file named "spec/controllers/get_name_and_controller_name_from_described_class_spec.rb" with:
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
204 """ruby
d3065c0 @cupakromer Move spec_helper to rails_helper.
cupakromer authored May 30, 2014
205 require "rails_helper"
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
206
207 class ApplicationController < ActionController::Base; end
208 class FoosController < ApplicationController; end
209
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
210 RSpec.describe "Access controller names", :type => :controller do
9311099 @cupakromer Update cuke feature with style changes.
cupakromer authored May 13, 2014
211 controller FoosController do
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
212 def index
213 @name = self.class.name
214 @controller_name = controller_name
215 render :text => "Hello World"
216 end
4b74b1f @billychan spec and cucumber passed
billychan authored Dec 24, 2013
217 end
218
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
219 before do
220 get :index
221 end
4b74b1f @billychan spec and cucumber passed
billychan authored Dec 24, 2013
222
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
223 it "gets the class name as described" do
224 expect(assigns[:name]).to eq('FoosController')
225 end
4b74b1f @billychan spec and cucumber passed
billychan authored Dec 24, 2013
226
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
227 it "gets the controller_name as described" do
228 expect(assigns[:controller_name]).to eq('foos')
229 end
43de9d1 @billychan some improvements and ws removal
billychan authored Dec 24, 2013
230 end
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
231 """
4b74b1f @billychan spec and cucumber passed
billychan authored Dec 24, 2013
232 When I run `rspec spec`
233 Then the examples should all pass
234
9311099 @cupakromer Update cuke feature with style changes.
cupakromer authored May 13, 2014
235 Scenario: Invoke `around_filter` and `around_action` in base class
631e889 @alindeman Add failing cuke to demonstrate regression with around_filter
alindeman authored May 12, 2011
236 Given a file named "spec/controllers/application_controller_around_filter_spec.rb" with:
78b151a @vanstee Identify ruby code for syntax highlighting
vanstee authored Oct 12, 2012
237 """ruby
d3065c0 @cupakromer Move spec_helper to rails_helper.
cupakromer authored May 30, 2014
238 require "rails_helper"
631e889 @alindeman Add failing cuke to demonstrate regression with around_filter
alindeman authored May 12, 2011
239
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
240 class ApplicationController < ActionController::Base
241 around_filter :an_around_filter
631e889 @alindeman Add failing cuke to demonstrate regression with around_filter
alindeman authored May 12, 2011
242
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
243 def an_around_filter
244 @callback_invoked = true
245 yield
246 end
631e889 @alindeman Add failing cuke to demonstrate regression with around_filter
alindeman authored May 12, 2011
247 end
248
31fe4d0 @JonRowe manually tag type examples
JonRowe authored Oct 16, 2014
249 RSpec.describe ApplicationController, :type => :controller do
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
250 controller do
251 def index
252 render :nothing => true
253 end
631e889 @alindeman Add failing cuke to demonstrate regression with around_filter
alindeman authored May 12, 2011
254 end
255
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
256 it "invokes the callback" do
257 get :index
631e889 @alindeman Add failing cuke to demonstrate regression with around_filter
alindeman authored May 12, 2011
258
263b953 @alindeman be_true -> be_truthy, be_false -> be_falsey
alindeman authored Jul 22, 2013
259 expect(assigns[:callback_invoked]).to be_truthy
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
260 end
631e889 @alindeman Add failing cuke to demonstrate regression with around_filter
alindeman authored May 12, 2011
261 end
58e89df @dchelimsky beef up anonymous controller doc
dchelimsky authored Aug 17, 2011
262 """
631e889 @alindeman Add failing cuke to demonstrate regression with around_filter
alindeman authored May 12, 2011
263 When I run `rspec spec`
264 Then the examples should all pass
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
265
9311099 @cupakromer Update cuke feature with style changes.
cupakromer authored May 13, 2014
266 Scenario: Anonymous controllers only create resource routes
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
267 Given a file named "spec/controllers/application_controller_spec.rb" with:
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
268 """ruby
d3065c0 @cupakromer Move spec_helper to rails_helper.
cupakromer authored May 30, 2014
269 require "rails_helper"
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
270
18e40b9 @cupakromer Verify that the newer `UrlGenerationError` exists.
cupakromer authored Nov 16, 2014
271 if defined?(ActionController::UrlGenerationError)
272 ExpectedRoutingError = ActionController::UrlGenerationError
273 else
274 ExpectedRoutingError = ActionController::RoutingError
275 end
276
31fe4d0 @JonRowe manually tag type examples
JonRowe authored Oct 16, 2014
277 RSpec.describe ApplicationController, :type => :controller do
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
278 controller do
279 def index
280 render :text => "index called"
281 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
282
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
283 def create
284 render :text => "create called"
285 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
286
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
287 def new
288 render :text => "new called"
289 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
290
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
291 def show
292 render :text => "show called"
293 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
294
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
295 def edit
296 render :text => "edit called"
297 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
298
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
299 def update
300 render :text => "update called"
301 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
302
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
303 def destroy
304 render :text => "destroy called"
305 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
306
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
307 def willerror
308 render :text => "will not render"
309 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
310 end
311
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
312 describe "#index" do
313 it "responds to GET" do
314 get :index
315 expect(response.body).to eq "index called"
316 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
317
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
318 it "also responds to POST" do
319 post :index
320 expect(response.body).to eq "index called"
321 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
322
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
323 it "also responds to PUT" do
324 put :index
325 expect(response.body).to eq "index called"
326 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
327
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
328 it "also responds to DELETE" do
329 delete :index
330 expect(response.body).to eq "index called"
331 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
332 end
333
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
334 describe "#create" do
335 it "responds to POST" do
336 post :create
a65ff6e @alindeman Features use new expect() syntax
alindeman authored Aug 7, 2012
337 expect(response.body).to eq "create called"
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
338 end
339
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
340 # And the rest...
341 %w{get post put delete}.each do |calltype|
342 it "responds to #{calltype}" do
343 send(calltype, :create)
344 expect(response.body).to eq "create called"
345 end
346 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
347 end
348
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
349 describe "#new" do
350 it "responds to GET" do
351 get :new
a65ff6e @alindeman Features use new expect() syntax
alindeman authored Aug 7, 2012
352 expect(response.body).to eq "new called"
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
353 end
354
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
355 # And the rest...
356 %w{get post put delete}.each do |calltype|
357 it "responds to #{calltype}" do
358 send(calltype, :new)
359 expect(response.body).to eq "new called"
360 end
361 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
362 end
363
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
364 describe "#edit" do
365 it "responds to GET" do
366 get :edit, :id => "anyid"
a65ff6e @alindeman Features use new expect() syntax
alindeman authored Aug 7, 2012
367 expect(response.body).to eq "edit called"
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
368 end
369
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
370 it "requires the :id parameter" do
18e40b9 @cupakromer Verify that the newer `UrlGenerationError` exists.
cupakromer authored Nov 16, 2014
371 expect { get :edit }.to raise_error(ExpectedRoutingError)
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
372 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
373
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
374 # And the rest...
375 %w{get post put delete}.each do |calltype|
376 it "responds to #{calltype}" do
377 send(calltype, :edit, {:id => "anyid"})
378 expect(response.body).to eq "edit called"
379 end
380 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
381 end
382
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
383 describe "#show" do
384 it "responds to GET" do
385 get :show, :id => "anyid"
a65ff6e @alindeman Features use new expect() syntax
alindeman authored Aug 7, 2012
386 expect(response.body).to eq "show called"
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
387 end
388
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
389 it "requires the :id parameter" do
18e40b9 @cupakromer Verify that the newer `UrlGenerationError` exists.
cupakromer authored Nov 16, 2014
390 expect { get :show }.to raise_error(ExpectedRoutingError)
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
391 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
392
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
393 # And the rest...
394 %w{get post put delete}.each do |calltype|
395 it "responds to #{calltype}" do
396 send(calltype, :show, {:id => "anyid"})
397 expect(response.body).to eq "show called"
398 end
399 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
400 end
401
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
402 describe "#update" do
403 it "responds to PUT" do
404 put :update, :id => "anyid"
a65ff6e @alindeman Features use new expect() syntax
alindeman authored Aug 7, 2012
405 expect(response.body).to eq "update called"
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
406 end
407
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
408 it "requires the :id parameter" do
18e40b9 @cupakromer Verify that the newer `UrlGenerationError` exists.
cupakromer authored Nov 16, 2014
409 expect { put :update }.to raise_error(ExpectedRoutingError)
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
410 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
411
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
412 # And the rest...
413 %w{get post put delete}.each do |calltype|
414 it "responds to #{calltype}" do
415 send(calltype, :update, {:id => "anyid"})
416 expect(response.body).to eq "update called"
417 end
418 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
419 end
420
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
421 describe "#destroy" do
422 it "responds to DELETE" do
423 delete :destroy, :id => "anyid"
a65ff6e @alindeman Features use new expect() syntax
alindeman authored Aug 7, 2012
424 expect(response.body).to eq "destroy called"
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
425 end
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
426
427 it "requires the :id parameter" do
18e40b9 @cupakromer Verify that the newer `UrlGenerationError` exists.
cupakromer authored Nov 16, 2014
428 expect { delete :destroy }.to raise_error(ExpectedRoutingError)
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
429 end
430
431 # And the rest...
432 %w{get post put delete}.each do |calltype|
433 it "responds to #{calltype}" do
434 send(calltype, :destroy, {:id => "anyid"})
435 expect(response.body).to eq "destroy called"
436 end
437 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
438 end
439
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
440 describe "#willerror" do
441 it "cannot be called" do
18e40b9 @cupakromer Verify that the newer `UrlGenerationError` exists.
cupakromer authored Nov 16, 2014
442 expect { get :willerror }.to raise_error(ExpectedRoutingError)
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
443 end
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
444 end
445 end
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
446 """
c8523df @alanshields Document what actions are made available in an anonymous controller
alanshields authored Jul 14, 2011
447 When I run `rspec spec`
448 Then the examples should all pass
4469230 @pcasaretto Add cuke feature explaining custom routes
pcasaretto authored Dec 7, 2012
449
9311099 @cupakromer Update cuke feature with style changes.
cupakromer authored May 13, 2014
450 Scenario: Draw custom routes for anonymous controllers
4469230 @pcasaretto Add cuke feature explaining custom routes
pcasaretto authored Dec 7, 2012
451 Given a file named "spec/controllers/application_controller_spec.rb" with:
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
452 """ruby
d3065c0 @cupakromer Move spec_helper to rails_helper.
cupakromer authored May 30, 2014
453 require "rails_helper"
4469230 @pcasaretto Add cuke feature explaining custom routes
pcasaretto authored Dec 7, 2012
454
31fe4d0 @JonRowe manually tag type examples
JonRowe authored Oct 16, 2014
455 RSpec.describe ApplicationController, :type => :controller do
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
456 controller do
457 def custom
458 render :text => "custom called"
459 end
4469230 @pcasaretto Add cuke feature explaining custom routes
pcasaretto authored Dec 7, 2012
460 end
461
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
462 specify "manually draw the route to request a custom action" do
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
463 routes.draw { get "custom" => "anonymous#custom" }
4469230 @pcasaretto Add cuke feature explaining custom routes
pcasaretto authored Dec 7, 2012
464
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
465 get :custom
466 expect(response.body).to eq "custom called"
467 end
4469230 @pcasaretto Add cuke feature explaining custom routes
pcasaretto authored Dec 7, 2012
468 end
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
469 """
4469230 @pcasaretto Add cuke feature explaining custom routes
pcasaretto authored Dec 7, 2012
470 When I run `rspec spec`
471 Then the examples should all pass
49572e4 @alindeman Adds regression feature for referring to application routes within an…
alindeman authored Jan 12, 2013
472
9311099 @cupakromer Update cuke feature with style changes.
cupakromer authored May 13, 2014
473 Scenario: Draw custom routes for defined controllers
c41c984 @billychan cucumber: add example on named controller route
billychan authored Dec 24, 2013
474 Given a file named "spec/controllers/application_controller_spec.rb" with:
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
475 """ruby
d3065c0 @cupakromer Move spec_helper to rails_helper.
cupakromer authored May 30, 2014
476 require "rails_helper"
c41c984 @billychan cucumber: add example on named controller route
billychan authored Dec 24, 2013
477
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
478 class FoosController < ApplicationController; end
c41c984 @billychan cucumber: add example on named controller route
billychan authored Dec 24, 2013
479
31fe4d0 @JonRowe manually tag type examples
JonRowe authored Oct 16, 2014
480 RSpec.describe ApplicationController, :type => :controller do
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
481 controller FoosController do
482 def custom
483 render :text => "custom called"
484 end
c41c984 @billychan cucumber: add example on named controller route
billychan authored Dec 24, 2013
485 end
486
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
487 specify "manually draw the route to request a custom action" do
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
488 routes.draw { get "custom" => "foos#custom" }
c41c984 @billychan cucumber: add example on named controller route
billychan authored Dec 24, 2013
489
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
490 get :custom
491 expect(response.body).to eq "custom called"
492 end
c41c984 @billychan cucumber: add example on named controller route
billychan authored Dec 24, 2013
493 end
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
494 """
c41c984 @billychan cucumber: add example on named controller route
billychan authored Dec 24, 2013
495 When I run `rspec spec`
496 Then the examples should all pass
497
d827f3e @cupakromer Cuke scenario describing failing behavior.
cupakromer authored May 14, 2014
498 Scenario: Works with namespaced controllers
499 Given a file named "spec/controllers/namespaced_controller_spec.rb" with:
500 """ruby
d3065c0 @cupakromer Move spec_helper to rails_helper.
cupakromer authored May 30, 2014
501 require "rails_helper"
d827f3e @cupakromer Cuke scenario describing failing behavior.
cupakromer authored May 14, 2014
502
503 class ApplicationController < ActionController::Base; end
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
504
505 module Outer
506 module Inner
d827f3e @cupakromer Cuke scenario describing failing behavior.
cupakromer authored May 14, 2014
507 class FoosController < ApplicationController; end
508 end
509 end
510
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
511 RSpec.describe Outer::Inner::FoosController, :type => :controller do
d827f3e @cupakromer Cuke scenario describing failing behavior.
cupakromer authored May 14, 2014
512 controller do
513 def index
514 @name = self.class.name
515 @controller_name = controller_name
516 render :text => "Hello World"
517 end
518 end
519
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
520 it "creates anonymous controller derived from the namespace" do
521 expect(controller).to be_a_kind_of(Outer::Inner::FoosController)
d827f3e @cupakromer Cuke scenario describing failing behavior.
cupakromer authored May 14, 2014
522 end
523
524 it "gets the class name as described" do
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
525 expect{ get :index }.to change{
526 assigns[:name]
527 }.to eq('Outer::Inner::FoosController')
d827f3e @cupakromer Cuke scenario describing failing behavior.
cupakromer authored May 14, 2014
528 end
529
530 it "gets the controller_name as described" do
c034b86 @cupakromer Eliminate scrolling in cuke examples.
cupakromer authored Nov 16, 2014
531 expect{ get :index }.to change{
532 assigns[:controller_name]
533 }.to eq('foos')
d827f3e @cupakromer Cuke scenario describing failing behavior.
cupakromer authored May 14, 2014
534 end
535 end
536 """
537 When I run `rspec spec`
538 Then the examples should all pass
539
9311099 @cupakromer Update cuke feature with style changes.
cupakromer authored May 13, 2014
540 Scenario: Refer to application routes in the controller under test
49572e4 @alindeman Adds regression feature for referring to application routes within an…
alindeman authored Jan 12, 2013
541 Given a file named "spec/controllers/application_controller_spec.rb" with:
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
542 """ruby
d3065c0 @cupakromer Move spec_helper to rails_helper.
cupakromer authored May 30, 2014
543 require "rails_helper"
49572e4 @alindeman Adds regression feature for referring to application routes within an…
alindeman authored Jan 12, 2013
544
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
545 Rails.application.routes.draw do
546 match "/login" => "sessions#new", :as => "login", :via => "get"
547 end
49572e4 @alindeman Adds regression feature for referring to application routes within an…
alindeman authored Jan 12, 2013
548
31fe4d0 @JonRowe manually tag type examples
JonRowe authored Oct 16, 2014
549 RSpec.describe ApplicationController, :type => :controller do
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
550 controller do
551 def index
552 redirect_to login_url
553 end
49572e4 @alindeman Adds regression feature for referring to application routes within an…
alindeman authored Jan 12, 2013
554 end
555
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
556 it "redirects to the login page" do
557 get :index
558 expect(response).to redirect_to("/login")
559 end
49572e4 @alindeman Adds regression feature for referring to application routes within an…
alindeman authored Jan 12, 2013
560 end
143e3cd @JonRowe cleanup after #891
JonRowe authored Dec 25, 2013
561 """
49572e4 @alindeman Adds regression feature for referring to application routes within an…
alindeman authored Jan 12, 2013
562 When I run `rspec spec`
563 Then the examples should all pass
Something went wrong with that request. Please try again.