mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-24 14:56:43 +00:00
include timezone awareness option for attribute parsing
This commit is contained in:
parent
c8ad4cd525
commit
bf57efaaa6
@ -19,7 +19,7 @@ module ValidatesTimeliness
|
|||||||
def #{attr_name}=(value)
|
def #{attr_name}=(value)
|
||||||
@attributes_cache ||= {}
|
@attributes_cache ||= {}
|
||||||
@attributes_cache["_#{attr_name}_before_type_cast"] = value
|
@attributes_cache["_#{attr_name}_before_type_cast"] = value
|
||||||
#{ "value = ValidatesTimeliness::Parser.parse(value, :#{type}) if value.is_a?(String)" if ValidatesTimeliness.use_plugin_parser }
|
#{ "value = ValidatesTimeliness::Parser.parse(value, :#{type}, :timezone_aware => #{timezone_aware}) if value.is_a?(String)" if ValidatesTimeliness.use_plugin_parser }
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
EOV
|
EOV
|
||||||
@ -35,6 +35,8 @@ module ValidatesTimeliness
|
|||||||
class_eval(method_body, __FILE__, line)
|
class_eval(method_body, __FILE__, line)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
public
|
||||||
|
|
||||||
def timeliness_attribute_timezone_aware?(attr_name)
|
def timeliness_attribute_timezone_aware?(attr_name)
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|||||||
@ -20,7 +20,8 @@ describe ValidatesTimeliness::AttributeMethods do
|
|||||||
context "with plugin parser" do
|
context "with plugin parser" do
|
||||||
class EmployeeWithParser < ActiveRecord::Base
|
class EmployeeWithParser < ActiveRecord::Base
|
||||||
set_table_name 'employees'
|
set_table_name 'employees'
|
||||||
validates_datetime :birth_date
|
validates_date :birth_date
|
||||||
|
validates_datetime :birth_datetime
|
||||||
end
|
end
|
||||||
|
|
||||||
before :all do
|
before :all do
|
||||||
@ -33,10 +34,10 @@ describe ValidatesTimeliness::AttributeMethods do
|
|||||||
r.birth_date = '2010-01-01'
|
r.birth_date = '2010-01-01'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be strict on day values' do
|
it 'should parse string as current timezone' do
|
||||||
r = EmployeeWithParser.new
|
r = EmployeeWithParser.new
|
||||||
r.birth_date = '2010-02-31'
|
r.birth_datetime = '2010-01-01 12:00'
|
||||||
r.birth_date.should be_nil
|
r.birth_datetime.zone == Time.zone.name
|
||||||
end
|
end
|
||||||
|
|
||||||
after :all do
|
after :all do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user