Permalink
Browse files

add space in multiword model in I18n unauthorized message - closes #292

  • Loading branch information...
1 parent 951d70e commit ba999970b17f3c277103ccbd7dcd00ddad0dcba8 @ryanb committed Mar 8, 2011
Showing with 2 additions and 1 deletion.
  1. +1 −1 lib/cancan/ability.rb
  2. +1 −0 spec/cancan/ability_spec.rb
View
2 lib/cancan/ability.rb
@@ -206,7 +206,7 @@ def authorize!(action, subject, *args)
def unauthorized_message(action, subject)
keys = unauthorized_message_keys(action, subject)
variables = {:action => action.to_s}
- variables[:subject] = (subject.class == Class ? subject : subject.class).to_s.downcase
+ variables[:subject] = (subject.class == Class ? subject : subject.class).to_s.underscore.humanize.downcase
message = I18n.translate(nil, variables.merge(:scope => :unauthorized, :default => keys + [""]))
message.blank? ? nil : message
end
View
1 spec/cancan/ability_spec.rb
@@ -395,6 +395,7 @@ class Container < Hash; end
it "should have variables for action and subject" do
I18n.backend.store_translations :en, :unauthorized => {:manage => {:all => "%{action} %{subject}"}} # old syntax for now in case testing with old I18n
@ability.unauthorized_message(:update, Array).should == "update array"
+ @ability.unauthorized_message(:update, ArgumentError).should == "update argument error"
@ability.unauthorized_message(:edit, 1..3).should == "edit range"
end
end

0 comments on commit ba99997

Please sign in to comment.