mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-23 06:16:44 +00:00
use I18n default value when missing value for error value format
This commit is contained in:
parent
cd62163152
commit
ea082b5258
@ -14,6 +14,12 @@ module ValidatesTimeliness
|
||||
:on_or_after => :>=,
|
||||
}.freeze
|
||||
|
||||
DEFAULT_ERROR_VALUE_FORMATS = {
|
||||
:date => '%Y-%m-%d',
|
||||
:time => '%H:%M:%S',
|
||||
:datetime => '%Y-%m-%d %H:%M:%S'
|
||||
}.freeze
|
||||
|
||||
def self.kind
|
||||
:timeliness
|
||||
end
|
||||
@ -56,7 +62,7 @@ module ValidatesTimeliness
|
||||
end
|
||||
|
||||
def format_error_value(value)
|
||||
format = I18n.t(@type, :scope => 'validates_timeliness.error_value_formats')
|
||||
format = I18n.t(@type, :default => DEFAULT_ERROR_VALUE_FORMATS[@type], :scope => 'validates_timeliness.error_value_formats')
|
||||
value.strftime(format)
|
||||
end
|
||||
|
||||
|
||||
@ -171,6 +171,21 @@ describe ValidatesTimeliness::Validator do
|
||||
validator.format_error_value(Time.mktime(2010,1,1,12,34,56)).should == '2010-01-01 12:34:56'
|
||||
end
|
||||
end
|
||||
|
||||
describe "with missing translation" do
|
||||
before :all do
|
||||
I18n.locale = :es
|
||||
end
|
||||
|
||||
it 'should use the default format for the type' do
|
||||
validator = ValidatesTimeliness::Validator.new(:attributes => [:birth_date], :type => :date)
|
||||
validator.format_error_value(Date.new(2010,1,1)).should == '2010-01-01'
|
||||
end
|
||||
|
||||
after :all do
|
||||
I18n.locale = :en
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "custom error message" do
|
||||
|
||||
Loading…
Reference in New Issue
Block a user