On Thu, Dec 10, 2009 at 2:32 AM, Amit Kulkarni <[email protected]> wrote:
> Hello,
> I am writing controller specs.I want to know how can i write specs which
> invlove before filters in controllers.
Generally, before filters are part of the internal implementation and
don't warrant specification that knows about their existence. For
example, consider a controller action that should only be invoked by
an admin. The spec might look like this:
describe WidgetController do
describe "POST create" do
context "with an anonymous visitor" do
it "redirects to login" do
post :create, :widget => valid_widget_attributes
response.should redirect_to(login_path)
end
end
context "with an 'admin'" do
it "redirects to the widget list" do
login_as :admin
post :create, :widget => valid_widget_attributes
response.should redirect_to(widgets_path)
end
end
end
end
Typically this authorization would be implemented in a before filter,
but, as you can see, there is no mention of before filters in the
spec.
HTH,
David
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users