Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Saner warning and accessor for logger

  • Loading branch information...
commit 2df8258cab19e34bfbc0d60cae5008a6cc449bdc 1 parent bb474ff
Nathan Long authored
View
2  README.markdown
@@ -398,7 +398,7 @@ You can define your own `authority_forbidden` method:
```ruby
# Send 'em back where they came from with a slap on the wrist
def authority_forbidden(exception)
- Authority.configuration.logger.warn(error.message)
+ Authority.logger.warn(error.message)
redirect_to request.referrer.presence || root_path, :alert => 'You are not authorized to complete that action.'
end
```
View
4 lib/authority.rb
@@ -57,6 +57,10 @@ def self.configure
configuration
end
+ def self.logger
+ @logger ||= configuration.logger
+ end
+
private
def self.require_authority_internals!
View
2  lib/authority/controller.rb
@@ -77,7 +77,7 @@ def authorize_action_for(authority_resource, *options)
#
# @param [Exception] error, an error that indicates the user tried to perform a forbidden action.
def authority_forbidden(error)
- Authority.configuration.logger.warn(error.message)
+ Authority.logger.warn(error.message)
render :file => Rails.root.join('public', '403.html'), :status => 403, :layout => false
end
View
4 lib/authority/user_abilities.rb
@@ -27,7 +27,9 @@ def can?(action, options = {})
begin
# For backwards compatibility
response = ApplicationAuthorizer.send("can_#{action}?", self, options)
- puts "DEPRECATION WARNING: Please rename `ApplicationAuthorizer.can_#{action}?` to `authorizes_to_#{action}?`"
+ Authority.logger.warn(
+ "DEPRECATION WARNING: Please rename `ApplicationAuthorizer.can_#{action}?` to `authorizes_to_#{action}?`"
+ )
response
rescue NoMethodError => new_exception
raise original_exception
View
2  spec/authority/configuration_spec.rb
@@ -19,7 +19,7 @@
logger = Logger.new(null)
Logger.should_receive(:new).with(STDERR).and_return(logger)
Authority.configure
- Authority.configuration.logger
+ Authority.logger
end
end
View
4 spec/authority/controller_spec.rb
@@ -191,14 +191,14 @@ def self.before_filter(*args) ; end
let(:mock_error) { mock(:message => 'oh noes! an error!') }
it "logs an error" do
- Authority.configuration.logger.should_receive(:warn)
+ Authority.logger.should_receive(:warn)
controller_instance.stub(:render)
controller_instance.send(:authority_forbidden, mock_error)
end
it "renders the public/403.html file" do
forbidden_page = Rails.root.join('public/403.html')
- Authority.configuration.logger.stub(:warn)
+ Authority.logger.stub(:warn)
controller_instance.should_receive(:render).with(:file => forbidden_page, :status => 403, :layout => false)
controller_instance.send(:authority_forbidden, mock_error)
end
View
7 spec/authority/user_abilities_spec.rb
@@ -61,16 +61,15 @@
before :each do
ApplicationAuthorizer.stub(:can_mimic_lemurs?).and_return('thumbs up!')
- # NOTE - prevents annoying output during these tests, but don't try to use `puts` below... ;)
- $stdout.stub(:puts)
+ Authority.logger.stub(:warn)
end
it "uses the `can` return value (for backwards compatibility)" do
expect(user.can?(:mimic_lemurs)).to eq('thumbs up!')
end
- it "puts a deprecation warning" do
- $stdout.should_receive(:puts).with(
+ it "sends a deprecation warning" do
+ Authority.logger.should_receive(:warn).with(
"DEPRECATION WARNING: Please rename `ApplicationAuthorizer.can_mimic_lemurs?` to `authorizes_to_mimic_lemurs?`"
)
user.can?(:mimic_lemurs)
Please sign in to comment.
Something went wrong with that request. Please try again.