Forums » General Forum »
Running tests with lockdown
Added by Anonymous 207 days ago
So now I'm trying to run my tests and probably should have tried this before integrating to be tdd compliant. I'm having some serious problems logging in so my tests pass.
I don't think I saw a test_helper function similar to login_as :quentin in restful_authentication, and think one would be extremely helpful
I've tried creating my own login_as function and adding it to my test_helper.rb file (which could probably be added to a lib/lockdown/lockdown_test_helper.rb file)
to no avail.
def login_as(user)
user = users(user)
@request.session[:user_id] = user.id
@request.session[:user_name] = user.full_name
@request.session[:user_profile_id] = user.profile.id
end
I created an admin user in my users.yml fixture
and set user_groups: 'Administrators'
I've also tried adding another user_groups fixture but to no avail.
This is my last piece of the puzzle before I release any code changes and any help would be greatly appreciated.
Thanks
Replies
RE: Running tests with lockdown - Added by Andrew Stone 207 days ago
This is my original version of this (was for a much older and different version of Lockdown), I'm not sure if it will help, but wanted to give you an idea of what I had. I'll try to get to this this weekend.
If you figure this out before then and have some modifications/additions to make that I can add in to the generator, that would be great.
thanks,
andy
lockdown_test_helper.rb (1019 Bytes)
RE: Running tests with lockdown - Added by Andrew Stone 207 days ago
I just noticed the call to String.random...change that to random_string and you can use this code:
def random_string(len = 10)
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
Array.new(len){||chars[rand(chars.size)]}.join
end
RE: Running tests with lockdown - Added by Anonymous 207 days ago
Thanks for that. I wasn't setting session[:access_rights].
Here's what I have and I hope this helps in some way. I noticed you're not using fixtures and I know a lot of people aren't fans of them.
1) Throw the attached test_helper.rb in the lib/lockdown directory and include Lockdown::TestHelper in a test/test_helper.rb
2) Throw the fixture files in test/fixtures
3) In my functional tests, define my setup function like so
def setup
super
login_as_administrator
end
or to test varying permissions I can do
login_as :quentin, :group1, :group2
Anyway, I hope this helps you somehow and thanks for creating this neat gem.
Kevin Wu