Topic: login_as not assigning the proper role in my functional test
I'm looking at adding some authentication to my application - since I've never really worked with it before, and want to take advantage of the Rails community, I'm using the restful_authentication plugin, and following the tutorial posted here on the forum: http://www.railsforum.com/viewtopic.php?id=14216
Since I also want to start experimenting with unit tests (I have never really used them in my prior 'life' as a .NET developer), I'm making sure my tests run before I add my own functionality. However, the first functional test fails with the following error:
method test_should_get_index in roles_controller_test.rb at line 15
method run in default.rb at line 7
Expected response to be a <:success>, but was <302>
Now, in my RolesController I specify a before_filter requiring the logged-in user to be a member of the administrators group (this was taken verbatim from the Tutorial).
has_many :roles, :through => :permissions
has_many :users, :through => :permissions
My roles.yml file looks like this:
and my permissions.yml file looks like this:
user: quentin # quentin is the first user provided by restful_authentication in users.yml
Finally, in test/functional/roles_controller_test.rb
class RolesControllerTest < ActionController::TestCase
fixtures :users, :roles, :permissions
@controller = RolesController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
I have verified that the user 'quentin' has the administrator permission, but for some reason login_as isn't doing something properly, as it's still redirecting (302 is a redirect, right?) instead of getting the proper page. Interestingly enough, if I put login_as :quentin inside of the method itself, ActiveRecord fails with the error that it can't find a User without an ID - I thought that a yml fixture didn't need an explicit ID as of Rails 2.0. It fails if I explicitly say id: 1, as well. I'm really at a loss for why it's failing.
Could anyone point me in the right direction? I'm not really used to Rails and Ruby yet, but I want to learn - it's much more pleasant than using C#, if I do say so myself.
Last edited by wayne.m (2008-03-17 22:23:08)