spec/validator_spec.rb in validates_timeliness-2.3.1 vs spec/validator_spec.rb in validates_timeliness-2.3.2

- old
+ new

@@ -1,10 +1,18 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe ValidatesTimeliness::Validator do attr_accessor :person, :validator + if ValidatesTimeliness::I18N_LATEST + I18N_REGEXP = /\%\{\w*\}/ + I18N_INTERPOLATION = '%{%s}' + else + I18N_REGEXP = /\{\{\w*\}\}/ + I18N_INTERPOLATION = '{{%s}}' + end + before :all do # freezes time using time_travel plugin Time.now = Time.utc(2000, 1, 1, 0, 0, 0) end @@ -511,12 +519,13 @@ if defined?(I18n) describe "localized error messages" do before(:all) do + message = "retfa #{I18N_INTERPOLATION}" % 'restriction' translations = { - :activerecord => {:errors => {:messages => { :after => 'retfa {{restriction}}' }}}, + :activerecord => {:errors => {:messages => { :after => message }}}, :validates_timeliness => {:error_value_formats => {}} } I18n.backend.store_translations 'zz', translations I18n.locale = :zz end @@ -614,11 +623,12 @@ if defined?(I18n) describe "I18n" do it "should use global default if locale format missing" do - I18n.backend.store_translations 'zz', :activerecord => {:errors => {:messages => { :after => 'after {{restriction}}' }}} + message = "after #{I18N_INTERPOLATION}" % 'restriction' + I18n.backend.store_translations 'zz', :activerecord => {:errors => {:messages => { :after => message }}} I18n.locale = :zz configure_validator(:type => :datetime, :after => 1.day.from_now) validate_with(:birth_date_and_time, Time.now) person.errors.on(:birth_date_and_time).should match(/after \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\Z/) end @@ -706,8 +716,8 @@ end def error_messages return @error_messages if defined?(@error_messages) messages = defined?(I18n) ? I18n.t('activerecord.errors.messages') : validator.send(:error_messages) - @error_messages = messages.inject({}) {|h, (k, v)| h[k] = v.sub(/ (\%s|\{\{\w*\}\}).*/, ''); h } + @error_messages = messages.inject({}) {|h, (k, v)| h[k] = v.sub(/ (\%s|#{I18N_REGEXP}).*/, ''); h } end end