Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #409 from nhocki/patch-1
Browse files Browse the repository at this point in the history
Make CanCan Default Message a translatable text.
  • Loading branch information
ryanb committed Jul 1, 2011
2 parents 613ab1c + 1c3e617 commit 8f815c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cancan/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def initialize(message = nil, action = nil, subject = nil)
@message = message
@action = action
@subject = subject
@default_message = "You are not authorized to access this page."
@default_message = I18n.t(:"unauthorized.default", :default => "You are not authorized to access this page.")
end

def to_s
Expand Down
23 changes: 23 additions & 0 deletions spec/cancan/exceptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,27 @@
@exception.message.should == "Access denied!"
end
end

describe "i18n in the default message" do
after(:each) do
I18n.backend = nil
end

it "uses i18n for the default message" do
I18n.backend.store_translations :en, :unauthorized => {:default => "This is a different message"}
@exception = CanCan::AccessDenied.new
@exception.message.should == "This is a different message"
end

it "defaults to a nice message" do
@exception = CanCan::AccessDenied.new
@exception.message.should == "You are not authorized to access this page."
end

it "does not use translation if a message is given" do
@exception = CanCan::AccessDenied.new("Hey! You're not welcome here")
@exception.message.should == "Hey! You're not welcome here"
@exception.message.should_not == "You are not authorized to access this page."
end
end
end

0 comments on commit 8f815c4

Please sign in to comment.