From ba999970b17f3c277103ccbd7dcd00ddad0dcba8 Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Tue, 8 Mar 2011 15:56:23 -0800 Subject: [PATCH] add space in multiword model in I18n unauthorized message - closes #292 --- lib/cancan/ability.rb | 2 +- spec/cancan/ability_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cancan/ability.rb b/lib/cancan/ability.rb index 039aa51..6dfa175 100644 --- a/lib/cancan/ability.rb +++ b/lib/cancan/ability.rb @@ -206,7 +206,7 @@ module CanCan 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 diff --git a/spec/cancan/ability_spec.rb b/spec/cancan/ability_spec.rb index abfaaea..5dd4e48 100644 --- a/spec/cancan/ability_spec.rb +++ b/spec/cancan/ability_spec.rb @@ -395,6 +395,7 @@ describe CanCan::Ability do 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