From 71f60bc4acadc0d8dda2a93f4805d4ddff66ff0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicola=CC=81s=20Hock=20Isaza?= Date: Thu, 30 Jun 2011 18:16:47 -0500 Subject: [PATCH] Adding tests for i18n translation for default messages --- spec/cancan/exceptions_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/cancan/exceptions_spec.rb b/spec/cancan/exceptions_spec.rb index 1c98832..f646ff5 100644 --- a/spec/cancan/exceptions_spec.rb +++ b/spec/cancan/exceptions_spec.rb @@ -32,4 +32,27 @@ describe CanCan::AccessDenied do @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, :cancan => {:default_message => "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