From 0ec573f4c5705ecce51ebe637750301fa57e3d1f Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 13 Mar 2014 17:43:33 +0000 Subject: Rename spec files so they're run by rake spec. --- spec/lib/i18n_interpolation_spec.rb | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 spec/lib/i18n_interpolation_spec.rb (limited to 'spec/lib/i18n_interpolation_spec.rb') diff --git a/spec/lib/i18n_interpolation_spec.rb b/spec/lib/i18n_interpolation_spec.rb new file mode 100644 index 000000000..b07cf1e9a --- /dev/null +++ b/spec/lib/i18n_interpolation_spec.rb @@ -0,0 +1,78 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe "when using i18n" do + + it "should not complain if we're missing variables from the string" do + result = _('Hello', :dip => 'hummus') + result.should == 'Hello' + result = _('Hello {{dip}}', :dip => 'hummus') + result.should == 'Hello hummus' + end + + it "should assume that simple translations are always html safe" do + _("Hello").should be_html_safe + end +end + +describe "n_" do + it "should return the translated singular" do + FastGettext.should_receive(:n_).with("Apple", "Apples", 1).and_return("Apfel") + n_("Apple", "Apples", 1).should == "Apfel" + end + + it "should return the translated plural" do + FastGettext.should_receive(:n_).with("Apple", "Apples", 3).and_return("Äpfel") + n_("Apple", "Apples", 3).should == "Äpfel" + end + + it "should return the translated singular interpolated" do + FastGettext.should_receive(:n_).with("I eat {{count}} apple", "I eat {{count}} apples", 1). + and_return("Ich esse {{count}} Apfel") + n_("I eat {{count}} apple", "I eat {{count}} apples", 1, :count => 1).should == "Ich esse 1 Apfel" + end + + it "should return the translated plural interpolated" do + FastGettext.should_receive(:n_).with("I eat {{count}} apple", "I eat {{count}} apples", 3). + and_return("Ich esse {{count}} Äpfel") + n_("I eat {{count}} apple", "I eat {{count}} apples", 3, :count => 3).should == "Ich esse 3 Äpfel" + end + + it "should always be html safe when there is no interpolation" do + FastGettext.should_receive(:n_).with("Apple", "Apples", 1).and_return("Apfel") + n_("Apple", "Apples", 1).should be_html_safe + end +end + +describe "gettext_interpolate" do + context "html unsafe string" do + let(:string) { "Hello {{a}}" } + + it "should give an unsafe result" do + result = gettext_interpolate(string, :a => "foo") + result.should == "Hello foo" + result.should_not be_html_safe + end + + it "should give an unsafe result" do + result = gettext_interpolate(string, :a => "foo".html_safe) + result.should == "Hello foo" + result.should_not be_html_safe + end + end + + context "html safe string" do + let(:string) { "Hello {{a}}".html_safe } + + it "should quote the input if it's unsafe" do + result = gettext_interpolate(string, :a => "foo&") + result.should == "Hello foo&" + result.should be_html_safe + end + + it "should not quote the input if it's safe" do + result = gettext_interpolate(string, :a => "foo&".html_safe) + result.should == "Hello foo&" + result.should be_html_safe + end + end +end -- cgit v1.2.3 From fa01a70f38f387ead23c23489b064d35567a1742 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Fri, 14 Mar 2014 09:03:01 +0000 Subject: Add encoding line --- spec/lib/i18n_interpolation_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/lib/i18n_interpolation_spec.rb') diff --git a/spec/lib/i18n_interpolation_spec.rb b/spec/lib/i18n_interpolation_spec.rb index b07cf1e9a..47037ecdb 100644 --- a/spec/lib/i18n_interpolation_spec.rb +++ b/spec/lib/i18n_interpolation_spec.rb @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "when using i18n" do -- cgit v1.2.3