mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
Move timeliness defined methods to a module so they can be overwritten.
This commit is contained in:
parent
0e3f56e26d
commit
889b5a9b07
@ -42,7 +42,7 @@ module ValidatesTimeliness
|
|||||||
super
|
super
|
||||||
end
|
end
|
||||||
EOV
|
EOV
|
||||||
class_eval(method_body, __FILE__, line)
|
generated_timeliness_methods.module_eval(method_body, __FILE__, line)
|
||||||
end
|
end
|
||||||
|
|
||||||
def define_timeliness_before_type_cast_method(attr_name)
|
def define_timeliness_before_type_cast_method(attr_name)
|
||||||
@ -51,7 +51,11 @@ module ValidatesTimeliness
|
|||||||
_timeliness_raw_value_for('#{attr_name}')
|
_timeliness_raw_value_for('#{attr_name}')
|
||||||
end
|
end
|
||||||
EOV
|
EOV
|
||||||
class_eval(method_body, __FILE__, line)
|
generated_timeliness_methods.module_eval(method_body, __FILE__, line)
|
||||||
|
end
|
||||||
|
|
||||||
|
def generated_timeliness_methods
|
||||||
|
@generated_timeliness_methods ||= Module.new.tap { |m| include(m) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -75,6 +75,13 @@ class Employee < ActiveRecord::Base
|
|||||||
validates_time :birth_time
|
validates_time :birth_time
|
||||||
validates_datetime :birth_datetime
|
validates_datetime :birth_datetime
|
||||||
define_attribute_methods
|
define_attribute_methods
|
||||||
|
|
||||||
|
attr_accessor :redefined_birth_date_called
|
||||||
|
|
||||||
|
def birth_date=(value)
|
||||||
|
self.redefined_birth_date_called = true
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Rspec.configure do |c|
|
Rspec.configure do |c|
|
||||||
|
|||||||
@ -34,6 +34,12 @@ describe ValidatesTimeliness::AttributeMethods do
|
|||||||
r._timeliness_raw_value_for(:birth_datetime).should == date_string
|
r._timeliness_raw_value_for(:birth_datetime).should == date_string
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should not overwrite user defined methods' do
|
||||||
|
e = Employee.new
|
||||||
|
e.birth_date = '2010-01-01'
|
||||||
|
e.redefined_birth_date_called.should be_true
|
||||||
|
end
|
||||||
|
|
||||||
context "with plugin parser" do
|
context "with plugin parser" do
|
||||||
class PersonWithParser
|
class PersonWithParser
|
||||||
include TestModel
|
include TestModel
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user