I'm not sure that you can send requests to 'other' controllers in
Rails' functional testing at the moment (I believe that the upcoming
integration testing is going to cover that).

If you want to test the user login controller, you would need to set
the @controller instance variable to be a UserController object.

In most cases like this, it is sufficient to simply place a User
object in the test session directly, rather than log in via an actual
controller. There have been quite a few posts about this to the mail
Rails list over the past month or so; a trip to Google should find
them fairly quickly.

HTH

- james

On 3/3/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>  I am developing an application for RAILS that includes the login and user
> engines.  I am now trying to write functional tests for that application.
> Of course the first thing that happens when I get or post any action is a
> redirection to user/login.  So I created a login test to proceed all of my
> others.  I have created user fixtures that are based on real users that I
> have logged in successfully many times via the browser.  I simply created
> YAML directly from them.  I also noticed that it was necessary to config the
> salt which I have done, matching the salt from my environment.rb.
>
>  I cannot get past the user/login screen.  Here is the code that calls the
> login test:
>
>  require File.dirname(__FILE__) + '/../test_helper'
>  require 'of_controller'
>
>  # Re-raise errors caught by the controller.
>  class OfController; def rescue_action(e) raise e end; end
>
>  class OfControllerTest < Test::Unit::TestCase
>   fixtures  :permissions, :users, :roles
>
>   def setup
>     LoginEngine::CONFIG[:salt] = "whatever"
>     @controller = OfController.new
>     @request    = ActionController::TestRequest.new
>     @response   = ActionController::TestResponse.new
>
>     @request.host = "localhost"
>   end
>
>   # Replace this with your real tests.
>   def test_takeOrder
>     login
>     get :action => 'takeOrder', :context => '11111'
>     assert_response :success
>    end
>  end
>
>  And here is the login code:
>
>  def login(name='some_user', password='some_password')
>     post :controller => 'user', :action => 'login', :user => {:login =>
> name, :password => password}
>     assert_session_has :user
>     assert_response :redirect
>     assert_redirected_to :controller => 'user', :action => "home"
>  end
>
>  The assert_redirected_to always fails.  I get redirected to user/login
> again.  It appears that the login is invalid but the salt, username, and
> password are identical to my development environment where they work.
> Please forgive me if I am doing something stupid -- I am a bit of a newbie
> to RAILS testing.  I'd appreciate any help.
>
>  Thanks!No virus found in this incoming message.
>  Checked by AVG Free Edition.
>  Version: 7.1.371 / Virus Database: 268.1.1/271 - Release Date: 2/28/2006
>
> _______________________________________________
> engine-users mailing list
> [email protected]
> http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org
>
>
>


--
* J *
  ~
_______________________________________________
engine-users mailing list
[email protected]
http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org

Reply via email to