aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/plugins/gettext_i18n_rails/spec
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2011-03-09 14:58:30 +0000
committerSeb Bacon <seb.bacon@gmail.com>2011-03-09 14:58:30 +0000
commitb4585af18e9c3a033f6cfe27213f0575af795a66 (patch)
tree996efa1487ac0d8cb7e4f53ee6478ad625b9d27d /vendor/plugins/gettext_i18n_rails/spec
parent224b8a4ba3a24af91068505c7907724448a4096d (diff)
parent4cc2cf2a6d935adfd263ea4fd7791a6d84f704da (diff)
merge from master (post-CSRF changes)
Diffstat (limited to 'vendor/plugins/gettext_i18n_rails/spec')
-rw-r--r--vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/action_controller_spec.rb40
-rw-r--r--vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb83
-rw-r--r--vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/backend_spec.rb46
-rw-r--r--vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/string_interpolate_fix_spec.rb32
-rw-r--r--vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails_spec.rb84
-rw-r--r--vendor/plugins/gettext_i18n_rails/spec/spec_helper.rb17
6 files changed, 302 insertions, 0 deletions
diff --git a/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/action_controller_spec.rb b/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/action_controller_spec.rb
new file mode 100644
index 000000000..9b12c9fa8
--- /dev/null
+++ b/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/action_controller_spec.rb
@@ -0,0 +1,40 @@
+require File.expand_path("../spec_helper", File.dirname(__FILE__))
+
+FastGettext.silence_errors
+
+describe ActionController::Base do
+ before do
+ #controller
+ @c = ActionController::Base.new
+ fake_session = {}
+ @c.stub!(:session).and_return fake_session
+ fake_cookies = {}
+ @c.stub!(:cookies).and_return fake_cookies
+ @c.params = {}
+ @c.request = stub(:env => {})
+
+ #locale
+ FastGettext.available_locales = nil
+ FastGettext.locale = 'fr'
+ FastGettext.available_locales = ['fr','en']
+ end
+
+ it "changes the locale" do
+ @c.params = {:locale=>'en'}
+ @c.set_gettext_locale
+ @c.session[:locale].should == 'en'
+ FastGettext.locale.should == 'en'
+ end
+
+ it "stays with default locale when none was found" do
+ @c.set_gettext_locale
+ @c.session[:locale].should == 'fr'
+ FastGettext.locale.should == 'fr'
+ end
+
+ it "reads the locale from the HTTP_ACCEPT_LANGUAGE" do
+ @c.request.stub!(:env).and_return 'HTTP_ACCEPT_LANGUAGE'=>'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'
+ @c.set_gettext_locale
+ FastGettext.locale.should == 'en'
+ end
+end \ No newline at end of file
diff --git a/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb b/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
new file mode 100644
index 000000000..aad5aaf42
--- /dev/null
+++ b/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
@@ -0,0 +1,83 @@
+# coding: utf-8
+require File.expand_path("../spec_helper", File.dirname(__FILE__))
+
+FastGettext.silence_errors
+
+ActiveRecord::Base.establish_connection({
+ :adapter => "sqlite3",
+ :database => ":memory:",
+})
+
+ActiveRecord::Schema.define(:version => 1) do
+ create_table :car_seats, :force=>true do |t|
+ t.string :seat_color
+ end
+
+ create_table :parts, :force=>true do |t|
+ t.string :name
+ t.references :car_seat
+ end
+end
+
+class CarSeat < ActiveRecord::Base
+ validates_presence_of :seat_color, :message=>"translate me"
+ has_many :parts
+ accepts_nested_attributes_for :parts
+end
+
+class Part < ActiveRecord::Base
+ belongs_to :car_seat
+end
+
+describe ActiveRecord::Base do
+ before do
+ FastGettext.current_cache = {}
+ end
+
+ describe :human_name do
+ it "is translated through FastGettext" do
+ CarSeat.should_receive(:_).with('car seat').and_return('Autositz')
+ CarSeat.human_name.should == 'Autositz'
+ end
+ end
+
+ describe :human_attribute_name do
+ it "translates attributes through FastGettext" do
+ CarSeat.should_receive(:s_).with('CarSeat|Seat color').and_return('Sitz farbe')
+ CarSeat.human_attribute_name(:seat_color).should == 'Sitz farbe'
+ end
+
+ it "translates nested attributes through FastGettext" do
+ CarSeat.should_receive(:s_).with('CarSeat|Parts|Name').and_return('Handle')
+ CarSeat.human_attribute_name(:"parts.name").should == 'Handle'
+ end
+ end
+
+ describe 'error messages' do
+ let(:model){
+ c = CarSeat.new
+ c.valid?
+ c
+ }
+
+ it "translates error messages" do
+ FastGettext.stub!(:current_repository).and_return('translate me'=>"Übersetz mich!")
+ FastGettext._('translate me').should == "Übersetz mich!"
+ model.errors.on(:seat_color).should == "Übersetz mich!"
+ end
+
+ it "translates scoped error messages" do
+ pending 'scope is no longer added in 3.x' if ActiveRecord::VERSION::MAJOR >= 3
+ FastGettext.stub!(:current_repository).and_return('activerecord.errors.translate me'=>"Übersetz mich!")
+ FastGettext._('activerecord.errors.translate me').should == "Übersetz mich!"
+ model.errors.on(:seat_color).should == "Übersetz mich!"
+ end
+
+ it "translates error messages with %{fn}" do
+ pending
+ FastGettext.stub!(:current_repository).and_return('translate me'=>"Übersetz %{fn} mich!")
+ FastGettext._('translate me').should == "Übersetz %{fn} mich!"
+ model.errors.on(:seat_color).should == "Übersetz car_seat mich!"
+ end
+ end
+end
diff --git a/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/backend_spec.rb b/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/backend_spec.rb
new file mode 100644
index 000000000..e0df1e725
--- /dev/null
+++ b/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/backend_spec.rb
@@ -0,0 +1,46 @@
+require File.expand_path("../spec_helper", File.dirname(__FILE__))
+
+describe GettextI18nRails::Backend do
+ it "redirects calls to another I18n backend" do
+ subject.backend.should_receive(:xxx).with(1,2)
+ subject.xxx(1,2)
+ end
+
+ describe :available_locales do
+ it "maps them to FastGettext" do
+ FastGettext.should_receive(:available_locales).and_return [:xxx]
+ subject.available_locales.should == [:xxx]
+ end
+
+ it "and returns an empty array when FastGettext.available_locales is nil" do
+ FastGettext.should_receive(:available_locales).and_return nil
+ subject.available_locales.should == []
+ end
+ end
+
+ describe :translate do
+ it "uses gettext when the key is translatable" do
+ FastGettext.stub(:current_repository).and_return 'xy.z.u'=>'a'
+ subject.translate('xx','u',:scope=>['xy','z']).should == 'a'
+ end
+
+ it "interpolates options" do
+ FastGettext.stub(:current_repository).and_return 'ab.c'=>'a%{a}b'
+ subject.translate('xx','c',:scope=>['ab'], :a => 'X').should == 'aXb'
+ end
+
+ it "can translate with gettext using symbols" do
+ FastGettext.stub(:current_repository).and_return 'xy.z.v'=>'a'
+ subject.translate('xx',:v ,:scope=>['xy','z']).should == 'a'
+ end
+
+ it "can translate with gettext using a flat scope" do
+ FastGettext.stub(:current_repository).and_return 'xy.z.x'=>'a'
+ subject.translate('xx',:x ,:scope=>'xy.z').should == 'a'
+ end
+
+ it "uses the super when the key is not translatable" do
+ lambda{subject.translate('xx','y',:scope=>['xy','z'])}.should raise_error(I18n::MissingTranslationData)
+ end
+ end
+end \ No newline at end of file
diff --git a/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/string_interpolate_fix_spec.rb b/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/string_interpolate_fix_spec.rb
new file mode 100644
index 000000000..c437699e7
--- /dev/null
+++ b/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/string_interpolate_fix_spec.rb
@@ -0,0 +1,32 @@
+require File.expand_path("../spec_helper", File.dirname(__FILE__))
+require 'gettext_i18n_rails/string_interpolate_fix'
+
+describe "String#%" do
+ it "is not safe if it was not safe" do
+ result = ("<br/>%{x}" % {:x => 'a'})
+ result.should == '<br/>a'
+ result.html_safe?.should == false
+ end
+
+ it "stays safe if it was safe" do
+ result = ("<br/>%{x}".html_safe % {:x => 'a'})
+ result.should == '<br/>a'
+ result.html_safe?.should == true
+ end
+
+ it "escapes unsafe added to safe" do
+ result = ("<br/>%{x}".html_safe % {:x => '<br/>'})
+ result.should == '<br/>&lt;br/&gt;'
+ result.html_safe?.should == true
+ end
+
+ it "does not escape unsafe if it was unsafe" do
+ result = ("<br/>%{x}" % {:x => '<br/>'})
+ result.should == '<br/><br/>'
+ result.html_safe?.should == false
+ end
+
+ it "does not break array replacement" do
+ "%ssd" % ['a'].should == "asd"
+ end
+end \ No newline at end of file
diff --git a/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails_spec.rb b/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails_spec.rb
new file mode 100644
index 000000000..3688d8b10
--- /dev/null
+++ b/vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails_spec.rb
@@ -0,0 +1,84 @@
+require File.expand_path("spec_helper", File.dirname(__FILE__))
+
+FastGettext.silence_errors
+
+describe GettextI18nRails do
+ before do
+ GettextI18nRails.translations_are_html_safe = nil
+ end
+
+ it "extends all classes with fast_gettext" do
+ _('test')
+ end
+
+ describe 'translations_are_html_safe' do
+ before do
+ GettextI18nRails.translations_are_html_safe = nil
+ end
+
+ it "makes translations not html_safe by default" do
+ _('x').html_safe?.should == false
+ s_('x').html_safe?.should == false
+ n_('x','y',2).html_safe?.should == false
+ String._('x').html_safe?.should == false
+ String.s_('x').html_safe?.should == false
+ String.n_('x','y',2).html_safe?.should == false
+ end
+
+ it "makes instance translations html_safe when wanted" do
+ GettextI18nRails.translations_are_html_safe = true
+ _('x').html_safe?.should == true
+ s_('x').html_safe?.should == true
+ n_('x','y',2).html_safe?.should == true
+ end
+
+ it "makes class translations html_safe when wanted" do
+ GettextI18nRails.translations_are_html_safe = true
+ String._('x').html_safe?.should == true
+ String.s_('x').html_safe?.should == true
+ String.n_('x','y',2).html_safe?.should == true
+ end
+
+ it "does not make everything html_safe" do
+ 'x'.html_safe?.should == false
+ end
+ end
+
+ it "sets up out backend" do
+ I18n.backend.is_a?(GettextI18nRails::Backend).should be_true
+ end
+
+ it "has a VERSION" do
+ GettextI18nRails::VERSION.should =~ /^\d+\.\d+\.\d+$/
+ end
+
+ describe 'FastGettext I18n interaction' do
+ before do
+ FastGettext.available_locales = nil
+ FastGettext.locale = 'de'
+ end
+
+ it "links FastGettext with I18n locale" do
+ FastGettext.locale = 'xx'
+ I18n.locale.should == :xx
+ end
+
+ it "does not set an not-accepted locale to I18n.locale" do
+ FastGettext.available_locales = ['de']
+ FastGettext.locale = 'xx'
+ I18n.locale.should == :de
+ end
+
+ it "links I18n.locale and FastGettext.locale" do
+ I18n.locale = :yy
+ FastGettext.locale.should == 'yy'
+ end
+
+ it "does not set a non-available locale though I18n.locale" do
+ FastGettext.available_locales = ['de']
+ I18n.locale = :xx
+ FastGettext.locale.should == 'de'
+ I18n.locale.should == :de
+ end
+ end
+end \ No newline at end of file
diff --git a/vendor/plugins/gettext_i18n_rails/spec/spec_helper.rb b/vendor/plugins/gettext_i18n_rails/spec/spec_helper.rb
new file mode 100644
index 000000000..f8002b766
--- /dev/null
+++ b/vendor/plugins/gettext_i18n_rails/spec/spec_helper.rb
@@ -0,0 +1,17 @@
+require 'rubygems'
+if ENV['VERSION']
+ puts "running VERSION #{ENV['VERSION']}"
+ gem 'actionpack', ENV['VERSION']
+ gem 'activerecord', ENV['VERSION']
+ gem 'activesupport', ENV['VERSION']
+ gem 'actionmailer', ENV['VERSION']
+end
+
+$LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
+
+require 'active_support'
+require 'active_record'
+require 'action_controller'
+require 'action_mailer'
+require 'fast_gettext'
+require 'gettext_i18n_rails' \ No newline at end of file