From 011ea070dbb31c1458f3efd1b738aa80ba5ba4a0 Mon Sep 17 00:00:00 2001 From: Adam Meehan Date: Mon, 12 Jan 2009 13:03:21 +1100 Subject: [PATCH] fix interpolation_values examples for rails version without i18n --- .../rails/matchers/validate_timeliness.rb | 3 ++- spec/validator_spec.rb | 26 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb b/lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb index c7b30b3..ad65f74 100644 --- a/lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb +++ b/lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb @@ -123,7 +123,8 @@ module Spec restriction = [restriction] unless restriction.is_a?(Array) restriction.map! {|r| @validator.send(:type_cast_value, r) } interpolate = @validator.send(:interpolation_values, option, restriction ) - if defined?(I18n) + # get I18n message if defined and has interpolation keys in msg + if defined?(I18n) && msg.match(/\{\{/) msg = @record.errors.generate_message(@expected, option, interpolate) else msg = msg % interpolate diff --git a/spec/validator_spec.rb b/spec/validator_spec.rb index 4f47b00..bb73942 100644 --- a/spec/validator_spec.rb +++ b/spec/validator_spec.rb @@ -376,16 +376,24 @@ describe ValidatesTimeliness::Validator do end describe "interpolation_values" do - it "should return hash of interpolation keys with restriction values" do - before = '1900-01-01' - configure_validator(:type => :date, :before => before) - validator.send(:interpolation_values, :before, before.to_date).should == {:restriction => before} - end + if defined?(I18n) + it "should return hash of interpolation keys with restriction values" do + before = '1900-01-01' + configure_validator(:type => :date, :before => before) + validator.send(:interpolation_values, :before, before.to_date).should == {:restriction => before} + end - it "should return empty hash if no interpolation keys are in message" do - before = '1900-01-01' - configure_validator(:type => :date, :before => before, :before_message => 'too late') - validator.send(:interpolation_values, :before, before.to_date).should be_empty + it "should return empty hash if no interpolation keys are in message" do + before = '1900-01-01' + configure_validator(:type => :date, :before => before, :before_message => 'too late') + validator.send(:interpolation_values, :before, before.to_date).should be_empty + end + else + it "should return array of interpolation values" do + before = '1900-01-01' + configure_validator(:type => :date, :before => before) + validator.send(:interpolation_values, :before, before.to_date).should == [before] + end end end