This is apparently not related to Shoulda... This test also fails
using Test::Unit by itself:

  test 'A guest on GET to #show' do
    get :show, { :id => users(:alexander).id }

    assert flash.empty?
    assert_not_nil assigns(:user)
    assert_response :success
  end

Failure:
 1) Failure:
  test_A_guest_on_GET_to_#show(UsersControllerTest) [test/functional/
users_controller_test.rb:44]:
  <false> is not true.

Line 44 is the flash being empty, it is, once again set to:
{:error=>"Sorry! You need to log in before visiting that page."}

Am I missing something obvious? Why is this filter always running? Is
this related to Rails3?

Thanks in advance.

-John Postlethwait

On May 27, 1:07 pm, John Postlethwait <john.postlethw...@gmail.com>
wrote:
> I'm using Shoulda and restful_authentication on Rails3 and whenever I
> run my tests a before filter for login_required is always triggered,
> despite my filter being set up as:
>
>   before_filter :login_required, :only =>
> [:update, :edit, :suspend, :unsuspend, :destroy, :purge]
>
> My test is this:
>
>   context 'A guest to the site' do
>     context 'on GET to :show' do
>       setup { get :show, { :id => users(:alexander).id } }
>
>       should_not_set_the_flash
>       should_assign_to :user
>       should_respond_with :success
>     end
>   end
>
> The test fails though:
>
>   3) Failure:
>   test: A guest to the site on GET to :show should assign @user.
> (UsersControllerTest)
>     []:
>   Expected action to assign a value for @user
>
>   4) Failure:
>   test: A guest to the site on GET to :show should not set the flash.
> (UsersControllerTest)
>     []:
>   Did not expect the flash to be set, but was {:error=>"Sorry! You
> need to log in before visiting that page."}
>
>   5) Failure:
>   test: A guest to the site on GET to :show should respond with
> success. (UsersControllerTest)
>     []:
>   Expected response to be a 200, but was 302
>
> Here is the code for my before_filter that is actually making this
> test fail:
>
>   def login_required
>     authorized? || access_denied
>   end
>
>   def access_denied
>     session[:return_to] = request.fullpath
>     flash[:error] = t('application.flash.error.login_required')
>
>     redirect_to(new_sessions_path)
>   end
>
> This code, as far as my understanding goes, should NOT ever be called
> from this test though... I have the :only => [] in the controller to
> not do it on show. Can anyone lend any insight as to why it is being
> triggered? Another strange thing is this DOES NOT happen in production
> or development modes using the browser. I can be logged out and visit
> this page just fine without this before_filter being called.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to