Hi there, I just started writing tests today after some months of using rails (slap wrists). I seem to be getting the hang of things, but I''m hitting a wall when it comes to functional_testing pages protected by login_engine/user_engine. all my assertions come back with: Expected response to be a <:success>, but was <302> Is there a way I can login from within a test? thanks dorian -- I do things for love or money
The simplest way to ''login'' when you are testing a protected
controller is to put a user in the session as part of your setup
method, i.e.
class PithyCartoonTest < Test::Unit::TestCase
def setup
@controller = SuperRobotMonkeyTeamHyperForceGoController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
session[:user] = users(:chiro)
end
def test_should_be_able_to_summon_the_power_primate
get ''team_member'', :name =>
''antauri''
assert_response :success
# and so on....
end
Another good idea is defining a login method in your test_helper.rb
which does a similar thing.
HTH
- james
On 4/28/06, Dorian Mcfarland <loaf@isness.org>
wrote:> Hi there,
> I just started writing tests today after some months of using rails (slap
wrists).
> I seem to be getting the hang of things, but I''m hitting a wall
when it comes to functional_testing pages protected by login_engine/user_engine.
>
> all my assertions come back with:
> Expected response to be a <:success>, but was <302>
>
> Is there a way I can login from within a test?
>
> thanks
>
> dorian
>
> --
> I do things for love or money
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
* J *
~
Dorian Mcfarland <loaf@...> writes:> > Hi there, > I just started writing tests today after some months of using rails(slap wrists).> I seem to be getting the hang of things, but I''m hitting a wallwhen it comes to functional_testing pages> protected by login_engine/user_engine. > > all my assertions come back with: > Expected response to be a <:success>, but was <302> > > Is there a way I can login from within a test? > > thanks > > dorian > > -- > I do things for love or money >Hi Dorian, What I did (not staying entirely DRY) was to copy all of the *.yml-files from /vendor/plugins/user_engine/test/fixtures to /test/fixtures and then add fixtures :users, :roles, :users_roles (and other fixtures you need) to the test cases that need authentication. This ensures that user data is loaded for each test, and makes you able to add: def setup ... @request.session[:user] = User.find(1) end - to each test case, which will "authenticate" you as the administrator (with id=1) for all your tests. Best regards, Casper Fabricius