spec/validator_spec.rb in validates_timeliness-1.1.1 vs spec/validator_spec.rb in validates_timeliness-1.1.2
- old
+ new
@@ -361,9 +361,43 @@
validate_with(:birth_time, "12:00")
should_have_no_error(:birth_time, :on_or_before)
end
end
+ describe "custom_error_messages" do
+ it "should return hash of custom error messages from configuration with _message truncated from keys" do
+ configure_validator(:type => :date, :invalid_date_message => 'thats no date')
+ validator.send(:custom_error_messages)[:invalid_date].should == 'thats no date'
+ end
+
+ it "should return empty hash if no custom error messages in configuration" do
+ configure_validator(:type => :date)
+ validator.send(:custom_error_messages).should be_empty
+ end
+ end
+
+ describe "interpolation_values" do
+ 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
+ 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
+
describe "restriction errors" do
before :each do
configure_validator(:type => :date, :before => lambda { raise })
end