# This examples can only be run if the plugin is installed in a Rails app
# Requires RSpec plugin or gem
require File.dirname(__FILE__) + '/helpers/spec_helper'
include ActionView::Helpers::DateHelper
include ActionView::Helpers::NumberHelper
include ActionView::Helpers::FormOptionsHelper
describe "when Rails is loaded" do
before(:each) do
Globalite.current_locale = 'en-US'
end
it "should have loaded fr" do
Globalite.locales.should include(:"fr-FR")
end
it "should have loaded the rails localization file in English and French" do
:error_message_inclusion.l.should == "is not included in the list"
Globalite.locale = :"fr-FR"
Globalite.locales.should include(:"fr-FR")
Globalite.locale.should == :"fr-FR"
Globalite.localizations.keys.should include(:error_message_inclusion)
Globalite.localizations[:error_message_inclusion].should_not be(nil)
:error_message_inclusion.l.should == "n'est pas inclus dans la liste."
end
it "ActiveRecord error messages should be localized in English" do
ActiveRecord::Errors.default_error_messages[:confirmation].should include("doesn't match confirmation")
Globalite.current_language = :fr
ActiveRecord::Errors.default_error_messages[:confirmation].should include("ne correspond pas à la confirmation")
end
it "distance_of_time_in_words should be localized properly" do
from = Time.mktime(2004, 3, 6, 21, 41, 18)
distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 41, 25)).should == "less than a minute"
distance_of_time_in_words(Time.mktime(2004, 3, 7, 1, 20), from).should == "about 4 hours"
Globalite.language = :fr
distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 41, 25)).should == "moins d'une minute"
distance_of_time_in_words(Time.mktime(2004, 3, 7, 1, 20), from).should == "environ 4 heures"
end
it "currency should be localized" do
number_to_currency(123).should == "$123.00"
Globalite.current_language = :fr
number_to_currency(123).should == "123,00 €"
end
it "should support different locales" do
Globalite.current_locale = :"en-US"
number_to_currency(123).should == "$123.00"
Globalite.current_locale = :"en-UK"
number_to_currency(123).should == "£123.00"
end
it "date_select should be localized" do
select_day(Time.mktime(2003, 8, 16)).should == %Q(\n)
select_day(Time.mktime(2003, 8, 16), :include_blank => true).should == %Q(\n)
select_day(16, :include_blank => true).should == %Q(\n)
Globalite.current_language = :fr
select_day(Time.mktime(2003, 8, 16)).should == %Q(\n)
end
it "datetime_select should be localized" do
select_datetime(nil, :prefix => "date[first]").should include('January')
Globalite.language = :fr
select_datetime(nil, :prefix => "date[first]").should include('Janvier')
end
it "the months names and their abbreviations should be localized" do
select_month(Time.mktime(2003, 8, 16)).should == %Q(\n)
Globalite.language = :fr
select_month(Time.mktime(2003, 8, 16)).should == %Q(\n)
end
it "the country list should be localized" do
expected_en = %Q(\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n)
country_options_for_select.should include(expected_fr)
end
it 'time should be localized' do
t = Time.parse('2006-12-25 13:55')
t.to_formatted_s(:long).should == 'December 25, 2006 13:55'
Globalite.language = :fr
t.l(:long).should == '25 Décembre, 2006 13:55'
t.l(:short).should == '25 Déc, 13:55'
# custom format
t.l('%a, %A, %d %b %B %Y %H:%M:%S %p').should == "Lun, Lundi, 25 Déc Décembre 2006 13:55:00 pm"
end
it 'date should be localized' do
d = Date.new(2007,05,13)
d.l.should == '2007-05-13'
Globalite.current_language = :fr
d.l(:short).should == '13 Mai'
end
it 'an array to sentence should be localized' do
us = ['Heidi', 'Matt']
us.to_sentence.should == 'Heidi and Matt'
Globalite.current_language = :fr
us.to_sentence.should == 'Heidi et Matt'
end
end