Has anyone successfully run the unit and functional tests that are
pre-generated with the ‘acts as authenticated’ plugin ?
I’m having huge amounts of problems and it’s not helped by the fact that
I’m a n00b to Rails and can’t tell if I’ve made some fundamental error
setting things up.
Sequence of events was
- Generate users scaffold
- Generate authenticate controller using plugin
- alter application.rb so that almost everything requires a logon
- Run rake
I quickly discovered that there was no way that
‘test_should_not_rehash_password’ would run successfully in the unit
tests, so I abandoned that (commented it out).
On a re-run I found so many errors in other parts of of the app (it’s a
team project) that I had to run just the ‘users’ functional test on its
own.
Virtually every test failed.
I thought my mods to application.rb might be the root of the problem,
but commenting them out got me no further, and replicating that
functionality within the ‘setup’ method of the functional test didn’t
help either. I also took a few guesses at things that might be missing
from the artificial test environment (I used a few includes in other
words) but again no luck.
I think there is probably something simple I’m missing that will make
these tests run out of the box, but I’m at a loss to know what it is.
Can anyone help ?
Cheers, Andy
Can you post up some of the actual errors you got? They will help
track the issue down…
Okay … here goes … I know that the redirects are happening because
of my changes to application.rb , but I don’t know how to modify the
test or test environment to replicate a logged on user.
D:\svn\DontBinIt\Application>ruby
test\functional\users_controller_test.rb
D:/svn/DontBinIt/Application/config/…/app/models/item.rb:38: warning:
found = in conditional, should be ==
Loaded suite test/functional/users_controller_test
Started
FFFFFFFF
Finished in 0.172 seconds.
-
Failure:
test_create(UsersControllerTest)
[test/functional/users_controller_test.rb:70]:
response is not a redirection to all of the options supplied
(redirection is <{:
controller=>"/authenticate", :action=>“login”}>)
-
Failure:
test_destroy(UsersControllerTest)
[test/functional/users_controller_test.rb:96]:
response is not a redirection to all of the options supplied
(redirection is <{:
controller=>"/authenticate", :action=>“login”}>)
-
Failure:
test_edit(UsersControllerTest)
[test/functional/users_controller_test.rb:78]:
Expected response to be a <:success>, but was <302>
-
Failure:
test_index(UsersControllerTest)
[test/functional/users_controller_test.rb:32]:
Expected response to be a <:success>, but was <302>
-
Failure:
test_list(UsersControllerTest)
[test/functional/users_controller_test.rb:39]:
Expected response to be a <:success>, but was <302>
-
Failure:
test_new(UsersControllerTest)
[test/functional/users_controller_test.rb:58]:
Expected response to be a <:success>, but was <302>
-
Failure:
test_show(UsersControllerTest)
[test/functional/users_controller_test.rb:48]:
Expected response to be a <:success>, but was <302>
-
Failure:
test_update(UsersControllerTest)
[test/functional/users_controller_test.rb:88]:
response is not a redirection to all of the options supplied
(redirection is <{:
controller=>"/authenticate", :action=>“login”}>)
8 tests, 15 assertions, 8 failures, 0 errors
On 11/28/05, rails nut [email protected] wrote:
And here are the mods to application.rb …
include AuthenticatedSystem
before_filter :login_required
before_filter :get_login_if_any
def get_login_if_any
current_user
end
By putting those lines in your controller, all your actions will
require a login for the tests. The generator generates a test helper
for this purpose in lib/authenticated_test_helper.rb:
http://techno-weenie.net/svn/projects/plugins/acts_as_authenticated/generators/authenticated/templates/authenticated_test_helper.rb
Be sure to include the helper in test/test_helper.rb
class Test::Unit::TestCase
include AuthenticatedTestHelper
self.use_transactional_fixtures = true
self.use_instantiated_fixtures = false
Now in your test:
login_as :bob # loads users(:bob) into the session
I apologize, I thought for sure I had better docs with this thing.
I’ll be sure to clarify this part. Do let me know if there are other
issues I missed
–
rick
http://techno-weenie.net
And here are the mods to application.rb …
include AuthenticatedSystem
before_filter :login_required
before_filter :get_login_if_any
def get_login_if_any
current_user
end
technoweenie wrote:
By putting those lines in your controller, …
Thanks for that… looks like just what I need.
Busy with something else right now, but I’ll be giving that a shot soon.
Cheers, Andy
technoweenie wrote:
By putting those lines in your controller, …
Yep, that DOES seem to have solved most of the problems. One or two
remain, though. Theres this one from the functional tests (with
associated code) …
- Failure:
test_create(UsersControllerTest)
[test/functional/users_controller_test.rb:101]:
Expected response to be a <:redirect>, but was <200>
def test_create
login_as(:quentin)
num_users = User.count
post :create, :user => {}
assert_response :redirect
assert_redirected_to :action => 'list'
assert_equal num_users + 1, User.count
end
I’m wondering if the test is correct in this case … it looks as though
the test is creating an ‘null’ user (no name etc) and (I guess) the
create action is rendering the form with an error message.
Any thoughts ?
Andy
end
Yup, I copied that from the scaffolding generator. Obviously the
scaffolding generator has no clue how your models work. Perhaps I
could the required login feilds by default though for
acts_as_authenticated. Good catch. I’m used to filling those fields
manually
In your case, just make the tweak yourself. No sense on waiting for
me to fix it so you can overwrite any changes you made.
–
rick
http://techno-weenie.net