include timezone awareness option for attribute parsing

This commit is contained in:
Adam Meehan 2010-09-21 18:27:12 +10:00
parent c8ad4cd525
commit bf57efaaa6
2 changed files with 8 additions and 5 deletions

View File

@ -19,7 +19,7 @@ module ValidatesTimeliness
def #{attr_name}=(value)
@attributes_cache ||= {}
@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
end
EOV
@ -35,6 +35,8 @@ module ValidatesTimeliness
class_eval(method_body, __FILE__, line)
end
public
def timeliness_attribute_timezone_aware?(attr_name)
false
end

View File

@ -20,7 +20,8 @@ describe ValidatesTimeliness::AttributeMethods do
context "with plugin parser" do
class EmployeeWithParser < ActiveRecord::Base
set_table_name 'employees'
validates_datetime :birth_date
validates_date :birth_date
validates_datetime :birth_datetime
end
before :all do
@ -33,10 +34,10 @@ describe ValidatesTimeliness::AttributeMethods do
r.birth_date = '2010-01-01'
end
it 'should be strict on day values' do
it 'should parse string as current timezone' do
r = EmployeeWithParser.new
r.birth_date = '2010-02-31'
r.birth_date.should be_nil
r.birth_datetime = '2010-01-01 12:00'
r.birth_datetime.zone == Time.zone.name
end
after :all do