Created
September 19, 2011 18:26
-
-
Save yosemsweet/1227184 to your computer and use it in GitHub Desktop.
cancan ability caching issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def should_require_authorization_of(*args, &action) | |
defaults = {:role => :member, :not_authorized_status => 403}.merge(args.extract_options!) | |
options = defaults.merge(args.extract_options!) | |
authorize(options) | |
action.call | |
response.should_not return_status(options[:not_authorized_status]) | |
deauthorize(options) | |
debugger | |
action.call | |
response.should return_status(options[:not_authorized_status]) | |
end | |
def authorize(options) | |
user = Factory.build(:user) | |
user.stubs(:canvas_role?).with(instance_of(Canvas), options[:role]).returns(true) | |
user.stubs(:persisted?).returns(true) | |
controller.stubs(:current_user).returns(user) | |
end | |
def deauthorize(options) | |
user = Factory.build(:user) | |
user.stubs(:canvas_role?).with(instance_of(Canvas), options[:role]).returns(false) | |
user.stubs(:persisted?).returns(true) | |
controller.stubs(:current_user).returns(user) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def should_require_authorization_of(*args, &action) | |
defaults = {:action => :manage, :object => nil, :not_authorized_status => 403}.merge(args.extract_options!) | |
options = defaults.merge(args.extract_options!) | |
user = Factory.build(:user) | |
user.stubs(:persisted?).returns(true) | |
controller.stubs(:current_user).returns(user) | |
authorize(options) | |
action.call | |
response.should_not return_status(options[:not_authorized_status]) | |
deauthorize(options) | |
action.call | |
response.should return_status(options[:not_authorized_status]) | |
end | |
def authorize(options) | |
controller.current_ability.stubs(:can?).with(options[:action], options[:object]).returns(true) | |
end | |
def deauthorize(options) | |
controller.current_ability.stubs(:can?).with(options[:action], options[:object]).returns(false) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment