udo.eisenbarth
unread,Feb 26, 2012, 7:35:25 AM2/26/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to declarative_authorization
Hi,
I tried to test my application using rspec but ran in some trouble
with "Permission denied" errors although the resource should have been
accessible even with the :guest role. In the real application (in
development env) everything works as expected.
The test logfile shows the error message:
Processing by PagesController#start as HTML
Permission denied: No matching rules found for start for
#<Authorization::AnonymousUser:0xb7739a8 @role_symbols=[:guest]>
(roles [:guest], privileges [:start], context :pages).
Rendered text template (0.0ms)
Completed 403 Forbidden in 333ms (Views: 325.4ms | ActiveRecord:
0.0ms)
Of course the test failes.... If I uncomment the
Authorization.ignore_access_control(true) then everything works of
course....
BTW: I'm using Rails 3.1.3, declarative_authorization 0.5.5, rspec
2.8.0
Here is the (somewhat abbreviated) code:
-------
pages_controller_spec.rb
require 'spec_helper'
describe PagesController do
render_views
before (:each) do
activate_authlogic
# Authorization.ignore_access_control(true)
end
describe "GET 'start'" do
it "should be successful" do
get :start
response.should be_success
end
end
-------
pages_controller.rb
class PagesController < ApplicationController
filter_access_to :all
def start
@pageTitle=""
end
-------
authorization_rules.rb
authorization do
role :admin do
has_omnipotence
includes :operator
end
role :operator do
has_permission_on :experiments, :to => :manage
has_permission_on :statistics, :to => [:overview, :calendar]
includes :guest
end
role :guest do
has_permission_on :pages, :to => [:start,:about,:changelog]
end
end
Best regards,
Udo