Skip to content

Commit c8523df

Browse files
committed
Document what actions are made available in an anonymous controller
It's a somewhat long test, but it shows what calls you can make and what calls you cannot make on an anonymous controller. I ran into this issue myself when I thought that all actions were routed. They weren't. Written on time paid for by onetotheworld.net
1 parent 95dac95 commit c8523df

File tree

1 file changed

+178
-0
lines changed

1 file changed

+178
-0
lines changed

features/controller_specs/anonymous_controller.feature

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,181 @@ Feature: anonymous controller
107107
"""
108108
When I run `rspec spec`
109109
Then the examples should all pass
110+
111+
Scenario: anonymous controllers only create resource routes
112+
Given a file named "spec/controllers/application_controller_spec.rb" with:
113+
"""
114+
require "spec_helper"
115+
116+
describe ApplicationController do
117+
controller do
118+
def index
119+
render :text => "index called"
120+
end
121+
122+
def create
123+
render :text => "create called"
124+
end
125+
126+
def new
127+
render :text => "new called"
128+
end
129+
130+
def show
131+
render :text => "show called"
132+
end
133+
134+
def edit
135+
render :text => "edit called"
136+
end
137+
138+
def update
139+
render :text => "update called"
140+
end
141+
142+
def destroy
143+
render :text => "destroy called"
144+
end
145+
146+
def willerror
147+
render :text => "will not render"
148+
end
149+
end
150+
151+
describe "#index" do
152+
it "responds to GET" do
153+
get :index
154+
response.body.should == "index called"
155+
end
156+
157+
it "also responds to POST" do
158+
post :index
159+
response.body.should == "index called"
160+
end
161+
162+
it "also responds to PUT" do
163+
put :index
164+
response.body.should == "index called"
165+
end
166+
167+
it "also responds to DELETE" do
168+
delete :index
169+
response.body.should == "index called"
170+
end
171+
end
172+
173+
describe "#create" do
174+
it "responds to POST" do
175+
post :create
176+
response.body.should == "create called"
177+
end
178+
179+
# And the rest...
180+
%w{get post put delete}.each do |calltype|
181+
it "responds to #{calltype}" do
182+
send(calltype.intern, :create)
183+
response.body.should == "create called"
184+
end
185+
end
186+
end
187+
188+
describe "#new" do
189+
it "responds to GET" do
190+
get :new
191+
response.body.should == "new called"
192+
end
193+
194+
# And the rest...
195+
%w{get post put delete}.each do |calltype|
196+
it "responds to #{calltype}" do
197+
send(calltype.intern, :new)
198+
response.body.should == "new called"
199+
end
200+
end
201+
end
202+
203+
describe "#edit" do
204+
it "responds to GET" do
205+
get :edit, :id => "anyid"
206+
response.body.should == "edit called"
207+
end
208+
209+
it "requires the :id parameter" do
210+
expect { get :edit }.to raise_error(ActionController::RoutingError)
211+
end
212+
213+
# And the rest...
214+
%w{get post put delete}.each do |calltype|
215+
it "responds to #{calltype}" do
216+
send(calltype.intern, :edit, {:id => "anyid"})
217+
response.body.should == "edit called"
218+
end
219+
end
220+
end
221+
222+
describe "#show" do
223+
it "responds to GET" do
224+
get :show, :id => "anyid"
225+
response.body.should == "show called"
226+
end
227+
228+
it "requires the :id parameter" do
229+
expect { get :show }.to raise_error(ActionController::RoutingError)
230+
end
231+
232+
# And the rest...
233+
%w{get post put delete}.each do |calltype|
234+
it "responds to #{calltype}" do
235+
send(calltype.intern, :show, {:id => "anyid"})
236+
response.body.should == "show called"
237+
end
238+
end
239+
end
240+
241+
describe "#update" do
242+
it "responds to PUT" do
243+
put :update, :id => "anyid"
244+
response.body.should == "update called"
245+
end
246+
247+
it "requires the :id parameter" do
248+
expect { put :update }.to raise_error(ActionController::RoutingError)
249+
end
250+
251+
# And the rest...
252+
%w{get post put delete}.each do |calltype|
253+
it "responds to #{calltype}" do
254+
send(calltype.intern, :update, {:id => "anyid"})
255+
response.body.should == "update called"
256+
end
257+
end
258+
end
259+
260+
describe "#destroy" do
261+
it "responds to DELETE" do
262+
delete :destroy, :id => "anyid"
263+
response.body.should == "destroy called"
264+
end
265+
266+
it "requires the :id parameter" do
267+
expect { delete :destroy }.to raise_error(ActionController::RoutingError)
268+
end
269+
270+
# And the rest...
271+
%w{get post put delete}.each do |calltype|
272+
it "responds to #{calltype}" do
273+
send(calltype.intern, :destroy, {:id => "anyid"})
274+
response.body.should == "destroy called"
275+
end
276+
end
277+
end
278+
279+
describe "#willerror" do
280+
it "cannot be called" do
281+
expect { get :willerror }.to raise_error(ActionController::RoutingError)
282+
end
283+
end
284+
end
285+
"""
286+
When I run `rspec spec`
287+
Then the examples should all pass

0 commit comments

Comments
 (0)