validates_timeliness 2.3.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
= 2.3.1 [2010-03-19]
|
2
|
+
- Fixed bug where custom attribute writer method for date/times were being overriden
|
3
|
+
|
1
4
|
= 2.3.0 [2010-02-04]
|
2
5
|
- Backwards incompatible change to :equal_to option. Fixed error message clash with :equal_to option which exists in Rails already. Option is now :is_at.
|
3
6
|
- Fixed I18n support so it returns missing translation message instead of error
|
@@ -24,7 +24,6 @@ module ValidatesTimeliness
|
|
24
24
|
|
25
25
|
def write_date_time_attribute(attr_name, value, type, time_zone_aware)
|
26
26
|
@attributes_cache["_#{attr_name}_before_type_cast"] = value
|
27
|
-
|
28
27
|
value = ValidatesTimeliness::Parser.parse(value, type)
|
29
28
|
|
30
29
|
if value && type != :date
|
@@ -49,16 +48,22 @@ module ValidatesTimeliness
|
|
49
48
|
|
50
49
|
columns_hash.each do |name, column|
|
51
50
|
if [:date, :time, :datetime].include?(column.type)
|
52
|
-
time_zone_aware = create_time_zone_conversion_attribute?(name, column) rescue false
|
53
|
-
|
54
51
|
method_name = "#{name}="
|
52
|
+
next if instance_method_already_implemented?(method_name)
|
53
|
+
|
54
|
+
time_zone_aware = create_time_zone_conversion_attribute?(name, column) rescue false
|
55
55
|
define_method(method_name) do |value|
|
56
|
-
|
56
|
+
write_date_time_attribute(name, value, column.type, time_zone_aware)
|
57
57
|
end
|
58
58
|
timeliness_methods << method_name
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
# Hack to get around instance_method_already_implemented? caching the
|
63
|
+
# methods in the ivar. It then appears to subsequent calls that the
|
64
|
+
# methods defined here, have not been and get defined again.
|
65
|
+
@_defined_class_methods = nil
|
66
|
+
|
62
67
|
define_attribute_methods_without_timeliness
|
63
68
|
# add generated methods which is a Set object hence no += method
|
64
69
|
timeliness_methods.each {|attr| generated_methods << attr }
|
@@ -6,10 +6,11 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should define and call write method on first assign" do
|
9
|
-
Person.class_eval { @generated_methods = Set.new }
|
10
|
-
Person.send(:undef_method, :birth_date=)
|
11
|
-
|
12
|
-
|
9
|
+
Person.class_eval { @generated_methods = Set.new; @_defined_class_methods = nil }
|
10
|
+
Person.send(:undef_method, :birth_date=) if Person.instance_methods.include?('birth_date=')
|
11
|
+
person = Person.new
|
12
|
+
person.should_receive(:write_date_time_attribute)
|
13
|
+
person.birth_date = "2000-01-01"
|
13
14
|
end
|
14
15
|
|
15
16
|
it "should call write_date_time_attribute when time attribute assigned value" do
|
@@ -80,7 +81,6 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
|
|
80
81
|
|
81
82
|
it "should not save invalid date value to database" do
|
82
83
|
time_string = "2000-01-32 02:03:04"
|
83
|
-
@person = Person.new
|
84
84
|
@person.birth_date_and_time = time_string
|
85
85
|
@person.save
|
86
86
|
@person.reload
|
@@ -92,7 +92,6 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
|
|
92
92
|
it "should return time object from database in default timezone" do
|
93
93
|
ActiveRecord::Base.default_timezone = :utc
|
94
94
|
time_string = "2000-01-01 09:00:00"
|
95
|
-
@person = Person.new
|
96
95
|
@person.birth_date_and_time = time_string
|
97
96
|
@person.save
|
98
97
|
@person.reload
|
@@ -111,7 +110,6 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
|
|
111
110
|
it "should return time object from database in correct timezone" do
|
112
111
|
Time.zone = 'Melbourne'
|
113
112
|
time_string = "2000-06-01 09:00:00"
|
114
|
-
@person = Person.new
|
115
113
|
@person.birth_date_and_time = time_string
|
116
114
|
@person.save
|
117
115
|
@person.reload
|
@@ -123,7 +121,6 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
|
|
123
121
|
it "should return correct date value after new value assigned" do
|
124
122
|
today = Date.today
|
125
123
|
tomorrow = Date.today + 1.day
|
126
|
-
@person = Person.new
|
127
124
|
@person.birth_date = today
|
128
125
|
@person.birth_date.should == today
|
129
126
|
@person.birth_date = tomorrow
|
@@ -133,11 +130,28 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
|
|
133
130
|
it "should update date attribute on existing object" do
|
134
131
|
today = Date.today
|
135
132
|
tomorrow = Date.today + 1.day
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
133
|
+
person = Person.create(:birth_date => today)
|
134
|
+
person.birth_date = tomorrow
|
135
|
+
person.save!
|
136
|
+
person.reload
|
137
|
+
person.birth_date.should == tomorrow
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "attribute writer" do
|
141
|
+
|
142
|
+
it "should be able to be overridden in class" do
|
143
|
+
Person.class_eval { attr_accessor :birth_date }
|
144
|
+
person = Person.new
|
145
|
+
person.birth_date = 'overriden'
|
146
|
+
person.birth_date.should == 'overriden'
|
147
|
+
end
|
148
|
+
|
149
|
+
after do
|
150
|
+
Person.class_eval do
|
151
|
+
undef_method(:birth_date)
|
152
|
+
undef_method(:birth_date=)
|
153
|
+
end
|
154
|
+
end
|
141
155
|
end
|
142
156
|
|
143
157
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_timeliness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Meehan
|
@@ -9,7 +9,7 @@ autorequire: validates_timeliness
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-19 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|