View spec problem (RSpec 2)

230 views
Skip to first unread message

Kurt S.

unread,
Jan 13, 2011, 8:14:50 PM1/13/11
to declarative_...@googlegroups.com
Hi -- We're having problems with specs that ran great in Rails 2.3.8 and RSpec 1.3.x but are failing now that we have upgraded to Rails 3.0.3 and RSpec 2.4.  The problem occurs when we call permitted_to? in the view -- it can't find the method current_user, even though we have defined it in our ApplicationController per the documentation.  Note that this configuration and specs worked fine before, and we haven't changed anything except the Rails and RSpec versions.  We're on 0.5.2 of the gem.  Any suggestions appreciated. 

P.S.  This gem has worked great for our security needs...

Here is a dump of the error:

  19) /team_members/show manage team members should allow managers of team members to read zip
     Failure/Error: render
     ActionView::Template::Error:
       undefined local variable or method `current_user' for #<ActionView::TestCase::TestController:0x103822dd8>
     # /Users/kurtsnyder/.rvm/gems/ree-1.8.7-2010.02@rails3/gems/declarative_authorization-0.5.2/lib/declarative_authorization/in_controller.rb:81:in `has_role?'
     # /Users/kurtsnyder/.rvm/gems/ree-1.8.7-2010.02@rails3/gems/declarative_authorization-0.5.2/lib/declarative_authorization/helper.rb:52:in `has_role?'
     # ./app/views/team_members/show.html.haml:8:in `_app_views_team_members_show_html_haml___975676147_2176431740_0'

Wolfram Arnold, RubyFocus

unread,
Jan 13, 2011, 8:57:04 PM1/13/11
to declarative_authorization
It's most bizarre.

Even trying to attach a stub to the view object in a before block,
doesn't fix this, e.g.:

before do
view.stub!(:current_user).and_return(...)
end

same error.

I wonder how this worked under RSpec 1.3. My current best guess is
that RSpec 1.3 view testing mixed in the application controller
somehow, while RSpec 2.x is not doing this.

-Wolf

On Jan 13, 5:14 pm, "Kurt S." <k...@cissor.com> wrote:
> Hi -- We're having problems with specs that ran great in Rails 2.3.8 and
> RSpec 1.3.x but are failing now that we have upgraded to Rails 3.0.3 and
> RSpec 2.4.  The problem occurs when we call permitted_to? in the view -- it
> can't find the method current_user, even though we have defined it in our
> ApplicationController per the documentation.  Note that this configuration
> and specs worked fine before, and we haven't changed anything except the
> Rails and RSpec versions.  We're on 0.5.2 of the gem.  Any suggestions
> appreciated.  
>
> P.S.  This gem has worked great for our security needs...
>
> Here is a dump of the error:
>
>   19) /team_members/show manage team members should allow managers of team
> members to read zip
>      Failure/Error: render
>      ActionView::Template::Error:
>        undefined local variable or method `current_user' for
> #<ActionView::TestCase::TestController:0x103822dd8>
>      #
> /Users/kurtsnyder/.rvm/gems/ree-1.8.7-2010.02@rails3/gems/declarative_autho rization-0.5.2/lib/declarative_authorization/in_controller.rb:81:in
> `has_role?'
>      #
> /Users/kurtsnyder/.rvm/gems/ree-1.8.7-2010.02@rails3/gems/declarative_autho rization-0.5.2/lib/declarative_authorization/helper.rb:52:in

Edward Rudd

unread,
Jun 12, 2012, 10:57:30 PM6/12/12
to declarative_...@googlegroups.com
instead try controller.stub(:current_user).and_return(user)  that works for me.

I created this test helper method

def render_with user, options = {}, local_assigns = {}, &block
  Authorization::Maintenance.with_user(user) do
    controller.stub(:current_user).and_return(user)
    render options, local_assigns, &block
  end
end
Reply all
Reply to author
Forward
0 new messages