SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problems on book's functional test

    Have you got any problem on test "test_should_redirect_after_login_with_return_url" on page 271?
    I have a redirect error

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code please

  3. #3
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is the code for the test in the account_controller_test.rb functional test file:

    Code:
    def test_should_redirect_after_login_with_return_url
        post :login, { :login => 'skyblaze', :password => 'prova' }, :return_to => '/story/new'
        assert_redirected_to '/story/new'
      end
    ...and this is the before-filter code in application.rb that relates to that test:

    Code:
    def login_required
        return true if logged_in?
        session[:return_to] = request.request_uri
        redirect_to :controller => "/account", :action => "login" and return false
      end
    rake test:functionals output is:

    skyblaze@skyblaze:~/shovell$ rake test:functionals
    (in /home/skyblaze/shovell)
    /usr/bin/ruby1.8 -Ilib:test "/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb" "test/functional/story_controller_test.rb" "test/functional/account_controller_test.rb"
    Loaded suite /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader
    Started
    ...F.F
    Finished in 0.146309 seconds.

    1) Failure:
    test_should_redirect_after_login_with_return_url(AccountControllerTest)
    [/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/assertions/response_assertions.rb:86:in `assert_redirected_to'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/assertions/response_assertions.rb:35:in `assert_redirected_to'
    ./test/functional/account_controller_test.rb:38:in `test_should_redirect_after_login_with_return_url']:
    response is not a redirection to all of the options supplied (redirection is <{"controller"=>"story"}>), difference: <{"action"=>"new"}>

    2) Failure:
    default_test(StoryControllerTest) [/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb:5]:
    No tests were specified.

    6 tests, 18 assertions, 2 failures, 0 errors
    rake aborted!
    Command failed with status (1): [/usr/bin/ruby1.8 -Ilib:test "/usr/lib/ruby...]

    (See full trace by running task with --trace)
    skyblaze@skyblaze:~/shovell$

  4. #4
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think this is the code we need. There should be a login action that has code like this:

    Code:
    def login
      // ...
      // log  the user in
      if params[:return_to]
        redirect_to params[:return_to]
      else
        // render the page or redirect to :action => 'new' ??
      end
    end

  5. #5
    SitePoint Member skrolikowski's Avatar
    Join Date
    Nov 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Similar problem I'm still stuck on here.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •