[rspec-users] Rspec and acl_system2 plugin

Franck D'agostini franck.dagostini at gmail.com
Sat Aug 11 12:34:42 EDT 2007


Hello,

I'm trying to spec a Rails application using the couple
restful_authentication/acl_system2 plugins.

In my admin layout, I put the following code :

<% restrict_to "admin" do -%>
<ul id="admin-tabs">
  <li> /users Users management </li>
</ul>
<% end -%>

Then in my spec file 'spec/views/layout/admin.rhtml_spec.rb' :

describe "Layout Admin if admin user" do
  include UserMockViewHelper
  
  it "should display the admin tabs" do
    login_as :admin
    render 'layouts/admin'
    response.should have_tag("ul#admin-tabs")
  end
end

the UserMockViewHelper module handle the mocking of the current user :

module UserMockViewHelper
  def login_as(user)
    @current_user = mock_model(User)
    @role = mock_model(Role)

    case user
    when :admin
      @role.stub!(:map).and_return(["admin", "cms"])
    when :cms_admin
      @role.stub!(:map).and_return(["cms", "cms_admin"])
    when :cms
      @role.stub!(:map).and_return(["cms"])
    else
      @role.stub!(:map).and_return([])
    end

    @current_user.stub!(:roles).and_return(@role)
    @current_user.stub!(:login).and_return(user)
   
User.should_receive(:find_by_id).any_number_of_times.and_return(@current_user)
    request.session[:user] = @current_user
   
@controller.template.should_receive(:current_user).and_return(@current_user)    
  end  
end

When I run 'ruby script/spec spec/views/layouts/admin.rhtml_spec.rb', I've
got the following error message :

ActionView::TemplateError in 'Layout Admin if admin user should display the
admin tabs'
undefined local variable or method `current_user' for
#<Spec::Rails::DSL::ViewExampleController:0x3076d88>
On line #28 of app/views/layouts/admin.rhtml

    25:     <ul>
    26:       <li> /articles Publications </li>
    27:     </ul>
    28:     <% restrict_to "admin" do -%>
    29:     <ul id="admin-tabs">
    30:       <li> /users Utilisateurs </li>
    31:     </ul>

   
#{RAILS_ROOT}/vendor/plugins/acl_system2/lib/caboose/access_control.rb:75:in
`restrict_to'
    (eval):2:in `send'
    (eval):2:in `restrict_to'
    #{RAILS_ROOT}/app/views/layouts/admin.rhtml:28:in
`_run_rhtml_47app47views47layouts47admin46rhtml'
   
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:326:in
`send'
   
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:326:in
`compile_and_render_template'
   
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:301:in
`render_template'
   
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:260:in
`render_file'


In the acl_system2 plugin, we have the following code :

# restrict_to "admin | moderator" do
#   link_to "foo"
# end   
def restrict_to(logicstring, context = {})
  return false if current_user.nil?
  result = ''    
  if permit?(logicstring, context) 
    result = yield if block_given?
  end 
  result
end


I'm just starting with rspec and I believe I'm missing something ...

Did someone run into this error before ?
-- 
View this message in context: http://www.nabble.com/Rspec-and-acl_system2-plugin-tf4254003.html#a12106932
Sent from the rspec-users mailing list archive at Nabble.com.



More information about the rspec-users mailing list