diff --git a/cancan.gemspec b/cancan.gemspec index 8dbb135..2fdff9c 100644 --- a/cancan.gemspec +++ b/cancan.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "cancan" - s.version = "1.3.4" + s.version = "1.4.0.beta1" s.author = "Ryan Bates" s.email = "ryan@railscasts.com" s.homepage = "http://github.com/ryanb/cancan" diff --git a/lib/cancan/ability.rb b/lib/cancan/ability.rb index 118c827..ebf4414 100644 --- a/lib/cancan/ability.rb +++ b/lib/cancan/ability.rb @@ -207,7 +207,9 @@ module CanCan def unauthorized_message(action, subject) keys = unauthorized_message_keys(action, subject) - message = I18n.translate(nil, :scope => :unauthorized, :default => keys + [""]) + variables = {:action => action.to_s} + variables[:subject] = (subject.class == Class ? subject : subject.class).to_s.downcase + message = I18n.translate(nil, variables.merge(:scope => :unauthorized, :default => keys + [""])) message.blank? ? nil : message end diff --git a/spec/cancan/ability_spec.rb b/spec/cancan/ability_spec.rb index a07b56e..42bc618 100644 --- a/spec/cancan/ability_spec.rb +++ b/spec/cancan/ability_spec.rb @@ -327,5 +327,11 @@ describe CanCan::Ability do @ability.unauthorized_message(:update, Array).should == "modify array" @ability.unauthorized_message(:edit, Array).should == "modify array" 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(:edit, 1..3).should == "edit range" + end end end