Following Railscast #385 & #386 I have added authorization to my Rails 4 application (rails 4.2.6, rspec-rails 3.4.2). After adding authorization, all of my controller specs fail.
My feature specs still pass because in the spec I login as admin to perform actions that are not allowed visitors (:edit, :update...). If I make all actions allowed to a visitor my controller specs pass. However, any action that only the admin can perform will fail in the controller spec.
The scaffold generator creates an empty
let(:valid_session) { { } }
that it says in the comments:
# This should return the minimal set of values that should be in the session in order to pass any filters (e.g. authentication) defined in MyController.
However, I don't know how to configure this :valid_session to allow authentication to pass.
When I try the solution posted in this question:
def valid_session
controller.stub!(:signed_in?).and_return(true)
end
I get this error:
NoMethodError:
undefined method `stub' for #<MyController
Since, all of the many branching paths of logic should be tested at a lower level (ie the controller spec) rather than the feature spec, how do I get the controller specs to pass?
How do I configure valid_session or what other method can I use to pass authorization in my controller specs?