Hey guys,
i have this before-filter in my application-controller:
def login_required
if !current_user
redirect_to join_welcome_path and return
end
end
This before-filter is prepended before all other before-filters in my
application_controller.rb like this
prepend_before_filter :login_required,
Now i want to test a controller which should only be accessible if
the user is logged in like that:
describe “new action” do
describe "before-filter requirements are not met" do
before(:each) do
activate_authlogic
end
it "should redirect to join_welcome_path if not logged in" do
controller.stub(:login_required).and_return(false)
get :new
response.should redirect_to(join_welcome_path)
end
The thing is, I would have expected this spec to pass - a call to
“new” invokes the login-required before-filter which redirects to the
join_welcome_path.
Instead i get:
NoMethodError in ‘Shopping::PaymentsController new action before-
filter requirements are not met should redirect to join_welcome_path
if not logged in’
undefined method `current_cart_size’ for nil:NilClass
which is from a before-filter which is triggered after the login-
required before-filter.
How do I even get there?
As far as I understood the docs, this line:
controller.stub(:login_required).and_return(false)
should cause a redirect, so how do i even get to subsequent before-
filters?
In a nutshell:
Why do I even reach subsequent before-filters?
What am I doing wrong here?