validates_timeliness 3.0.8 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +21 -0
  3. data/CHANGELOG.rdoc +21 -1
  4. data/README.rdoc +20 -22
  5. data/Rakefile +5 -1
  6. data/gemfiles/rails_4_0.gemfile +19 -0
  7. data/gemfiles/rails_4_1.gemfile +19 -0
  8. data/gemfiles/rails_4_2.gemfile +19 -0
  9. data/lib/generators/validates_timeliness/install_generator.rb +0 -1
  10. data/lib/generators/validates_timeliness/templates/validates_timeliness.rb +3 -3
  11. data/lib/validates_timeliness/attribute_methods.rb +42 -26
  12. data/lib/validates_timeliness/extensions/date_time_select.rb +2 -9
  13. data/lib/validates_timeliness/extensions/multiparameter_handler.rb +59 -54
  14. data/lib/validates_timeliness/extensions.rb +3 -4
  15. data/lib/validates_timeliness/helper_methods.rb +7 -6
  16. data/lib/validates_timeliness/orm/active_record.rb +70 -15
  17. data/lib/validates_timeliness/railtie.rb +2 -1
  18. data/lib/validates_timeliness/validator.rb +29 -4
  19. data/lib/validates_timeliness/version.rb +1 -1
  20. data/lib/validates_timeliness.rb +13 -13
  21. data/spec/spec_helper.rb +10 -5
  22. data/spec/support/config_helper.rb +10 -0
  23. data/spec/support/model_helpers.rb +4 -4
  24. data/spec/support/tag_matcher.rb +35 -0
  25. data/spec/support/test_model.rb +0 -1
  26. data/spec/validates_timeliness/attribute_methods_spec.rb +22 -7
  27. data/spec/validates_timeliness/conversion_spec.rb +41 -41
  28. data/spec/validates_timeliness/extensions/date_time_select_spec.rb +5 -4
  29. data/spec/validates_timeliness/extensions/multiparameter_handler_spec.rb +28 -16
  30. data/spec/validates_timeliness/helper_methods_spec.rb +12 -12
  31. data/spec/validates_timeliness/orm/active_record_spec.rb +178 -44
  32. data/spec/validates_timeliness/validator/after_spec.rb +3 -3
  33. data/spec/validates_timeliness/validator/before_spec.rb +3 -3
  34. data/spec/validates_timeliness/validator/is_at_spec.rb +4 -4
  35. data/spec/validates_timeliness/validator/on_or_after_spec.rb +3 -3
  36. data/spec/validates_timeliness/validator/on_or_before_spec.rb +3 -3
  37. data/spec/validates_timeliness/validator_spec.rb +66 -25
  38. data/spec/validates_timeliness_spec.rb +8 -8
  39. data/validates_timeliness.gemspec +2 -2
  40. metadata +41 -60
  41. data/lib/validates_timeliness/orm/mongoid.rb +0 -54
  42. data/spec/validates_timeliness/orm/mongoid_spec.rb +0 -113
@@ -3,108 +3,242 @@ require 'spec_helper'
3
3
  describe ValidatesTimeliness, 'ActiveRecord' do
4
4
 
5
5
  context "validation methods" do
6
+ let(:record) { Employee.new }
7
+
6
8
  it 'should be defined for the class' do
7
- ActiveRecord::Base.should respond_to(:validates_date)
8
- ActiveRecord::Base.should respond_to(:validates_time)
9
- ActiveRecord::Base.should respond_to(:validates_datetime)
9
+ expect(ActiveRecord::Base).to respond_to(:validates_date)
10
+ expect(ActiveRecord::Base).to respond_to(:validates_time)
11
+ expect(ActiveRecord::Base).to respond_to(:validates_datetime)
10
12
  end
11
13
 
12
14
  it 'should defines for the instance' do
13
- Employee.new.should respond_to(:validates_date)
14
- Employee.new.should respond_to(:validates_time)
15
- Employee.new.should respond_to(:validates_datetime)
15
+ expect(record).to respond_to(:validates_date)
16
+ expect(record).to respond_to(:validates_time)
17
+ expect(record).to respond_to(:validates_datetime)
18
+ end
19
+
20
+ it "should validate a valid value string" do
21
+ record.birth_date = '2012-01-01'
22
+
23
+ record.valid?
24
+ expect(record.errors[:birth_date]).to be_empty
25
+ end
26
+
27
+ it "should validate a invalid value string" do
28
+ record.birth_date = 'not a date'
29
+
30
+ record.valid?
31
+ expect(record.errors[:birth_date]).not_to be_empty
32
+ end
33
+
34
+ it "should validate a nil value" do
35
+ record.birth_date = nil
36
+
37
+ record.valid?
38
+ expect(record.errors[:birth_date]).to be_empty
16
39
  end
17
40
  end
18
41
 
19
42
  it 'should determine type for attribute' do
20
- Employee.timeliness_attribute_type(:birth_date).should == :date
43
+ expect(Employee.timeliness_attribute_type(:birth_date)).to eq :date
44
+ end
45
+
46
+ context 'attribute timezone awareness' do
47
+ let(:klass) {
48
+ Class.new(ActiveRecord::Base) do
49
+ self.table_name = 'employees'
50
+ attr_accessor :some_date
51
+ attr_accessor :some_time
52
+ attr_accessor :some_datetime
53
+ validates_date :some_date
54
+ validates_time :some_time
55
+ validates_datetime :some_datetime
56
+ end
57
+ }
58
+
59
+ context 'for column attribute' do
60
+ it 'should be detected from column type' do
61
+ expect(klass.timeliness_attribute_timezone_aware?(:birth_date)).to be_falsey
62
+ expect(klass.timeliness_attribute_timezone_aware?(:birth_time)).to be_falsey
63
+ expect(klass.timeliness_attribute_timezone_aware?(:birth_datetime)).to be_truthy
64
+ end
65
+ end
66
+
67
+ context 'for non-column attribute' do
68
+ it 'should be detected from the validation type' do
69
+ expect(klass.timeliness_attribute_timezone_aware?(:some_date)).to be_falsey
70
+ expect(klass.timeliness_attribute_timezone_aware?(:some_time)).to be_falsey
71
+ expect(klass.timeliness_attribute_timezone_aware?(:some_datetime)).to be_truthy
72
+ end
73
+ end
21
74
  end
22
75
 
23
76
  context "attribute write method" do
24
77
  class EmployeeWithCache < ActiveRecord::Base
25
- set_table_name 'employees'
26
- validates_datetime :birth_datetime
78
+ self.table_name = 'employees'
79
+ validates_date :birth_date, :allow_blank => true
80
+ validates_time :birth_time, :allow_blank => true
81
+ validates_datetime :birth_datetime, :allow_blank => true
27
82
  end
28
83
 
29
- it 'should cache attribute raw value' do
30
- r = EmployeeWithCache.new
31
- r.birth_datetime = date_string = '2010-01-01'
32
- r._timeliness_raw_value_for(:birth_datetime).should == date_string
84
+ context 'value cache' do
85
+ let(:record) { EmployeeWithCache.new }
86
+
87
+ context 'for datetime column' do
88
+ it 'should store raw value' do
89
+ record.birth_datetime = datetime_string = '2010-01-01 12:30'
90
+
91
+ expect(record.read_timeliness_attribute_before_type_cast('birth_datetime')).to eq datetime_string
92
+ end
93
+ end
94
+
95
+ context 'for date column' do
96
+ it 'should store raw value' do
97
+ record.birth_date = date_string = '2010-01-01'
98
+
99
+ expect(record.read_timeliness_attribute_before_type_cast('birth_date')).to eq date_string
100
+ end
101
+ end
102
+
103
+ context 'for time column' do
104
+ it 'should store raw value' do
105
+ record.birth_time = time_string = '12:12'
106
+
107
+ expect(record.read_timeliness_attribute_before_type_cast('birth_time')).to eq time_string
108
+ end
109
+ end
33
110
  end
34
111
 
35
112
  context "with plugin parser" do
36
113
  with_config(:use_plugin_parser, true)
114
+ let(:record) { EmployeeWithParser.new }
37
115
 
38
116
  class EmployeeWithParser < ActiveRecord::Base
39
- set_table_name 'employees'
40
- validates_date :birth_date
41
- validates_datetime :birth_datetime
117
+ self.table_name = 'employees'
118
+ validates_date :birth_date, :allow_blank => true
119
+ validates_time :birth_time, :allow_blank => true
120
+ validates_datetime :birth_datetime, :allow_blank => true
42
121
  end
43
122
 
44
- it 'should parse a string value' do
45
- Timeliness::Parser.should_receive(:parse)
46
- r = EmployeeWithParser.new
47
- r.birth_date = '2010-01-01'
123
+ context "for a date column" do
124
+ it 'should parse a string value' do
125
+ expect(Timeliness::Parser).to receive(:parse)
126
+
127
+ record.birth_date = '2010-01-01'
128
+ end
129
+
130
+ it 'should parse a invalid string value as nil' do
131
+ expect(Timeliness::Parser).to receive(:parse)
132
+
133
+ record.birth_date = 'not valid'
134
+ end
135
+
136
+ it 'should store a Date value after parsing string' do
137
+ record.birth_date = '2010-01-01'
138
+
139
+ expect(record.birth_date).to be_kind_of(Date)
140
+ expect(record.birth_date).to eq Date.new(2010, 1, 1)
141
+ end
48
142
  end
49
143
 
50
- context "for a date column" do
51
- it 'should store a date value after parsing string' do
52
- r = EmployeeWithParser.new
53
- r.birth_date = '2010-01-01'
144
+ context "for a time column" do
145
+ it 'should parse a string value' do
146
+ expect(Timeliness::Parser).to receive(:parse)
54
147
 
55
- r.birth_date.should be_kind_of(Date)
56
- r.birth_date.should == Date.new(2010, 1, 1)
148
+ record.birth_time = '12:30'
149
+ end
150
+
151
+ it 'should parse a invalid string value as nil' do
152
+ expect(Timeliness::Parser).to receive(:parse)
153
+
154
+ record.birth_time = 'not valid'
155
+ end
156
+
157
+ it 'should store a Time value after parsing string' do
158
+ record.birth_time = '12:30'
159
+
160
+ expect(record.birth_time).to be_kind_of(Time)
161
+ expect(record.birth_time).to eq Time.utc(2000, 1, 1, 12, 30)
57
162
  end
58
163
  end
59
164
 
60
165
  context "for a datetime column" do
61
166
  with_config(:default_timezone, 'Australia/Melbourne')
62
167
 
168
+ it 'should parse a string value' do
169
+ expect(Timeliness::Parser).to receive(:parse)
170
+
171
+ record.birth_datetime = '2010-01-01 12:00'
172
+ end
173
+
174
+ it 'should parse a invalid string value as nil' do
175
+ expect(Timeliness::Parser).to receive(:parse)
176
+
177
+ record.birth_datetime = 'not valid'
178
+ end
179
+
63
180
  it 'should parse string into Time value' do
64
- r = EmployeeWithParser.new
65
- r.birth_datetime = '2010-01-01 12:00'
181
+ record.birth_datetime = '2010-01-01 12:00'
66
182
 
67
- r.birth_datetime.should be_kind_of(Time)
183
+ expect(record.birth_datetime).to be_kind_of(Time)
68
184
  end
69
185
 
70
186
  it 'should parse string as current timezone' do
71
- r = EmployeeWithParser.new
72
- r.birth_datetime = '2010-06-01 12:00'
187
+ record.birth_datetime = '2010-06-01 12:00'
73
188
 
74
- r.birth_datetime.utc_offset.should == Time.zone.utc_offset
189
+ expect(record.birth_datetime.utc_offset).to eq Time.zone.utc_offset
75
190
  end
76
191
  end
77
192
  end
78
193
  end
79
194
 
80
- context "cached value" do
81
- it 'should be cleared on reload' do
82
- r = Employee.create!
83
- r.birth_date = '2010-01-01'
84
- r.reload
195
+ context "reload" do
196
+ it 'should clear cache value' do
197
+ record = Employee.create!
198
+ record.birth_date = '2010-01-01'
199
+
200
+ record.reload
85
201
 
86
- r._timeliness_raw_value_for(:birth_date).should be_nil
202
+ expect(record.read_timeliness_attribute_before_type_cast('birth_date')).to be_nil
87
203
  end
88
204
  end
89
205
 
90
206
  context "before_type_cast method" do
207
+ let(:record) { Employee.new }
208
+
91
209
  it 'should be defined on class if ORM supports it' do
92
- Employee.new.should respond_to(:birth_datetime_before_type_cast)
210
+ expect(record).to respond_to(:birth_datetime_before_type_cast)
93
211
  end
94
212
 
95
213
  it 'should return original value' do
96
- r = Employee.new
97
- r.birth_datetime = date_string = '2010-01-01'
214
+ record.birth_datetime = date_string = '2010-01-01'
98
215
 
99
- r.birth_datetime_before_type_cast.should == date_string
216
+ expect(record.birth_datetime_before_type_cast).to eq date_string
100
217
  end
101
218
 
102
219
  it 'should return attribute if no attribute assignment has been made' do
103
220
  datetime = Time.zone.local(2010,01,01)
104
221
  Employee.create(:birth_datetime => datetime)
105
222
 
106
- r = Employee.last
107
- r.birth_datetime_before_type_cast.should match(/2010-01-01 00:00:00/)
223
+ record = Employee.last
224
+ expect(record.birth_datetime_before_type_cast).to match(/#{datetime.utc.to_s[0...-4]}/)
225
+ end
226
+
227
+ context "with plugin parser" do
228
+ with_config(:use_plugin_parser, true)
229
+
230
+ it 'should return original value' do
231
+ record.birth_datetime = date_string = '2010-01-31'
232
+
233
+ expect(record.birth_datetime_before_type_cast).to eq date_string
234
+ end
235
+ end
236
+
237
+ end
238
+
239
+ context "define_attribute_methods" do
240
+ it "returns a falsy value if the attribute methods have already been generated" do
241
+ expect(Employee.define_attribute_methods).to be_falsey
108
242
  end
109
243
  end
110
244
  end
@@ -25,15 +25,15 @@ describe ValidatesTimeliness::Validator, ":after option" do
25
25
  end
26
26
 
27
27
  it "should not be valid for same time as restriction" do
28
- invalid!(:birth_time, Time.local_time(2000, 1, 1, 12, 0, 0), 'must be after 12:00:00')
28
+ invalid!(:birth_time, Time.local(2000, 1, 1, 12, 0, 0), 'must be after 12:00:00')
29
29
  end
30
30
 
31
31
  it "should not be valid for time before restriction" do
32
- invalid!(:birth_time, Time.local_time(2000, 1, 1, 11, 59, 59), 'must be after 12:00:00')
32
+ invalid!(:birth_time, Time.local(2000, 1, 1, 11, 59, 59), 'must be after 12:00:00')
33
33
  end
34
34
 
35
35
  it "should be valid for time after restriction" do
36
- valid!(:birth_time, Time.local_time(2000, 1, 1, 12, 00, 01))
36
+ valid!(:birth_time, Time.local(2000, 1, 1, 12, 00, 01))
37
37
  end
38
38
  end
39
39
 
@@ -25,15 +25,15 @@ describe ValidatesTimeliness::Validator, ":before option" do
25
25
  end
26
26
 
27
27
  it "should not be valid for time after restriction" do
28
- invalid!(:birth_time, Time.local_time(2000, 1, 1, 12, 00, 01), 'must be before 12:00:00')
28
+ invalid!(:birth_time, Time.local(2000, 1, 1, 12, 00, 01), 'must be before 12:00:00')
29
29
  end
30
30
 
31
31
  it "should not be valid for same time as restriction" do
32
- invalid!(:birth_time, Time.local_time(2000, 1, 1, 12, 0, 0), 'must be before 12:00:00')
32
+ invalid!(:birth_time, Time.local(2000, 1, 1, 12, 0, 0), 'must be before 12:00:00')
33
33
  end
34
34
 
35
35
  it "should be valid for time before restriction" do
36
- valid!(:birth_time, Time.local_time(2000, 1, 1, 11, 59, 59))
36
+ valid!(:birth_time, Time.local(2000, 1, 1, 11, 59, 59))
37
37
  end
38
38
  end
39
39
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe ValidatesTimeliness::Validator, ":is_at option" do
4
4
  before do
5
- Timecop.freeze(Time.local_time(2010, 1, 1, 0, 0, 0))
5
+ Timecop.freeze(Time.local(2010, 1, 1, 0, 0, 0))
6
6
  end
7
7
 
8
8
  describe "for date type" do
@@ -29,15 +29,15 @@ describe ValidatesTimeliness::Validator, ":is_at option" do
29
29
  end
30
30
 
31
31
  it "should not be valid for time before restriction" do
32
- invalid!(:birth_time, Time.local_time(2000, 1, 1, 11, 59, 59), 'must be at 12:00:00')
32
+ invalid!(:birth_time, Time.local(2000, 1, 1, 11, 59, 59), 'must be at 12:00:00')
33
33
  end
34
34
 
35
35
  it "should not be valid for time after restriction" do
36
- invalid!(:birth_time, Time.local_time(2000, 1, 1, 12, 00, 01), 'must be at 12:00:00')
36
+ invalid!(:birth_time, Time.local(2000, 1, 1, 12, 00, 01), 'must be at 12:00:00')
37
37
  end
38
38
 
39
39
  it "should be valid for same time as restriction" do
40
- valid!(:birth_time, Time.local_time(2000, 1, 1, 12, 0, 0))
40
+ valid!(:birth_time, Time.local(2000, 1, 1, 12, 0, 0))
41
41
  end
42
42
  end
43
43
 
@@ -25,15 +25,15 @@ describe ValidatesTimeliness::Validator, ":on_or_after option" do
25
25
  end
26
26
 
27
27
  it "should not be valid for time before restriction" do
28
- invalid!(:birth_time, Time.local_time(2000, 1, 1, 11, 59, 59), 'must be on or after 12:00:00')
28
+ invalid!(:birth_time, Time.local(2000, 1, 1, 11, 59, 59), 'must be on or after 12:00:00')
29
29
  end
30
30
 
31
31
  it "should be valid for time after restriction" do
32
- valid!(:birth_time, Time.local_time(2000, 1, 1, 12, 00, 01))
32
+ valid!(:birth_time, Time.local(2000, 1, 1, 12, 00, 01))
33
33
  end
34
34
 
35
35
  it "should be valid for same time as restriction" do
36
- valid!(:birth_time, Time.local_time(2000, 1, 1, 12, 0, 0))
36
+ valid!(:birth_time, Time.local(2000, 1, 1, 12, 0, 0))
37
37
  end
38
38
  end
39
39
 
@@ -25,15 +25,15 @@ describe ValidatesTimeliness::Validator, ":on_or_before option" do
25
25
  end
26
26
 
27
27
  it "should not be valid for time after restriction" do
28
- invalid!(:birth_time, Time.local_time(2000, 1, 1, 12, 00, 01), 'must be on or before 12:00:00')
28
+ invalid!(:birth_time, Time.local(2000, 1, 1, 12, 00, 01), 'must be on or before 12:00:00')
29
29
  end
30
30
 
31
31
  it "should be valid for time before restriction" do
32
- valid!(:birth_time, Time.local_time(2000, 1, 1, 11, 59, 59))
32
+ valid!(:birth_time, Time.local(2000, 1, 1, 11, 59, 59))
33
33
  end
34
34
 
35
35
  it "should be valid for same time as restriction" do
36
- valid!(:birth_time, Time.local_time(2000, 1, 1, 12, 0, 0))
36
+ valid!(:birth_time, Time.local(2000, 1, 1, 12, 0, 0))
37
37
  end
38
38
  end
39
39
 
@@ -1,23 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ValidatesTimeliness::Validator do
4
- NIL = [nil]
5
-
6
4
  before do
7
- Timecop.freeze(Time.local_time(2010, 1, 1, 0, 0, 0))
5
+ Timecop.freeze(Time.local(2010, 1, 1, 0, 0, 0))
8
6
  end
9
7
 
10
8
  describe "Model.validates with :timeliness option" do
11
9
  it 'should use plugin validator class' do
12
10
  Person.validates :birth_date, :timeliness => {:is_at => Date.new(2010,1,1), :type => :date}
13
- Person.validators.should have(1).kind_of(ActiveModel::Validations::TimelinessValidator)
11
+ expect(Person.validators.select { |v| v.is_a?(ActiveModel::Validations::TimelinessValidator) }.size).to eq(1)
14
12
  invalid!(:birth_date, Date.new(2010,1,2))
15
13
  valid!(:birth_date, Date.new(2010,1,1))
16
14
  end
17
15
 
18
16
  it 'should use default to :datetime type' do
19
17
  Person.validates :birth_datetime, :timeliness => {:is_at => Time.mktime(2010,1,1)}
20
- Person.validators.first.type.should == :datetime
18
+ expect(Person.validators.first.type).to eq(:datetime)
19
+ end
20
+
21
+ it 'should add attribute to timeliness attributes set' do
22
+ expect(PersonWithShim.timeliness_validated_attributes).not_to include(:birth_time)
23
+
24
+ PersonWithShim.validates :birth_time, :timeliness => {:is_at => "12:30"}
25
+
26
+ expect(PersonWithShim.timeliness_validated_attributes).to include(:birth_time)
21
27
  end
22
28
  end
23
29
 
@@ -29,22 +35,33 @@ describe ValidatesTimeliness::Validator do
29
35
  it 'should not be valid attribute is type cast to nil but raw value is non-nil invalid value' do
30
36
  Person.validates_date :birth_date, :allow_nil => true
31
37
  record = Person.new
32
- record.stub!(:birth_date).and_return(nil)
33
- record.stub!(:_timeliness_raw_value_for).and_return("Not a date")
34
- record.should_not be_valid
35
- record.errors[:birth_date].first.should == 'is not a valid date'
38
+ allow(record).to receive(:birth_date).and_return(nil)
39
+ allow(record).to receive(:read_timeliness_attribute_before_type_cast).and_return("Not a date")
40
+ expect(record).not_to be_valid
41
+ expect(record.errors[:birth_date].first).to eq('is not a valid date')
36
42
  end
37
43
 
38
44
  describe ":allow_nil option" do
39
45
  it 'should not allow nil by default' do
40
46
  Person.validates_date :birth_date
41
- invalid!(:birth_date, NIL, 'is not a valid date')
47
+ invalid!(:birth_date, [nil], 'is not a valid date')
42
48
  valid!(:birth_date, Date.today)
43
49
  end
44
50
 
45
51
  it 'should allow nil when true' do
46
52
  Person.validates_date :birth_date, :allow_nil => true
47
- valid!(:birth_date, NIL)
53
+ valid!(:birth_date, [nil])
54
+ end
55
+
56
+ context "with raw value cache" do
57
+ it "should not be valid with an invalid format" do
58
+ PersonWithShim.validates_date :birth_date, :allow_nil => true
59
+
60
+ p = PersonWithShim.new
61
+ p.birth_date = 'bogus'
62
+
63
+ expect(p).not_to be_valid
64
+ end
48
65
  end
49
66
  end
50
67
 
@@ -59,6 +76,17 @@ describe ValidatesTimeliness::Validator do
59
76
  Person.validates_date :birth_date, :allow_blank => true
60
77
  valid!(:birth_date, '')
61
78
  end
79
+
80
+ context "with raw value cache" do
81
+ it "should not be valid with an invalid format" do
82
+ PersonWithShim.validates_date :birth_date, :allow_blank => true
83
+
84
+ p = PersonWithShim.new
85
+ p.birth_date = 'bogus'
86
+
87
+ expect(p).not_to be_valid
88
+ end
89
+ end
62
90
  end
63
91
 
64
92
  describe ":between option" do
@@ -66,8 +94,8 @@ describe ValidatesTimeliness::Validator do
66
94
  it 'should be split option into :on_or_after and :on_or_before values' do
67
95
  on_or_after, on_or_before = Date.new(2010,1,1), Date.new(2010,1,2)
68
96
  Person.validates_date :birth_date, :between => [on_or_after, on_or_before]
69
- Person.validators.first.options[:on_or_after].should == on_or_after
70
- Person.validators.first.options[:on_or_before].should == on_or_before
97
+ expect(Person.validators.first.options[:on_or_after]).to eq(on_or_after)
98
+ expect(Person.validators.first.options[:on_or_before]).to eq(on_or_before)
71
99
  invalid!(:birth_date, on_or_after - 1, "must be on or after 2010-01-01")
72
100
  invalid!(:birth_date, on_or_before + 1, "must be on or before 2010-01-02")
73
101
  valid!(:birth_date, on_or_after)
@@ -79,14 +107,27 @@ describe ValidatesTimeliness::Validator do
79
107
  it 'should be split option into :on_or_after and :on_or_before values' do
80
108
  on_or_after, on_or_before = Date.new(2010,1,1), Date.new(2010,1,2)
81
109
  Person.validates_date :birth_date, :between => on_or_after..on_or_before
82
- Person.validators.first.options[:on_or_after].should == on_or_after
83
- Person.validators.first.options[:on_or_before].should == on_or_before
110
+ expect(Person.validators.first.options[:on_or_after]).to eq(on_or_after)
111
+ expect(Person.validators.first.options[:on_or_before]).to eq(on_or_before)
84
112
  invalid!(:birth_date, on_or_after - 1, "must be on or after 2010-01-01")
85
113
  invalid!(:birth_date, on_or_before + 1, "must be on or before 2010-01-02")
86
114
  valid!(:birth_date, on_or_after)
87
115
  valid!(:birth_date, on_or_before)
88
116
  end
89
117
  end
118
+
119
+ describe "range with excluded end value" do
120
+ it 'should be split option into :on_or_after and :before values' do
121
+ on_or_after, before = Date.new(2010,1,1), Date.new(2010,1,3)
122
+ Person.validates_date :birth_date, :between => on_or_after...before
123
+ expect(Person.validators.first.options[:on_or_after]).to eq(on_or_after)
124
+ expect(Person.validators.first.options[:before]).to eq(before)
125
+ invalid!(:birth_date, on_or_after - 1, "must be on or after 2010-01-01")
126
+ invalid!(:birth_date, before, "must be before 2010-01-03")
127
+ valid!(:birth_date, on_or_after)
128
+ valid!(:birth_date, before - 1)
129
+ end
130
+ end
90
131
  end
91
132
 
92
133
  describe ":ignore_usec option" do
@@ -118,13 +159,13 @@ describe ValidatesTimeliness::Validator do
118
159
  it "should be valid when value matches format" do
119
160
  person.birth_date = '11-12-1913'
120
161
  person.valid?
121
- person.errors[:birth_date].should be_empty
162
+ expect(person.errors[:birth_date]).to be_empty
122
163
  end
123
164
 
124
165
  it "should not be valid when value does not match format" do
125
166
  person.birth_date = '1913-12-11'
126
167
  person.valid?
127
- person.errors[:birth_date].should include('is not a valid date')
168
+ expect(person.errors[:birth_date]).to include('is not a valid date')
128
169
  end
129
170
  end
130
171
 
@@ -138,21 +179,21 @@ describe ValidatesTimeliness::Validator do
138
179
  it "should be added when ignore_restriction_errors is false" do
139
180
  with_config(:ignore_restriction_errors, false) do
140
181
  person.valid?
141
- person.errors[:birth_date].first.should match("Error occurred validating birth_date")
182
+ expect(person.errors[:birth_date].first).to match("Error occurred validating birth_date")
142
183
  end
143
184
  end
144
185
 
145
186
  it "should not be added when ignore_restriction_errors is true" do
146
187
  with_config(:ignore_restriction_errors, true) do
147
188
  person.valid?
148
- person.errors[:birth_date].should be_empty
189
+ expect(person.errors[:birth_date]).to be_empty
149
190
  end
150
191
  end
151
192
 
152
193
  it 'should exit on first error' do
153
194
  with_config(:ignore_restriction_errors, false) do
154
195
  person.valid?
155
- person.errors[:birth_date].should have(1).items
196
+ expect(person.errors[:birth_date].size).to eq(1)
156
197
  end
157
198
  end
158
199
  end
@@ -161,17 +202,17 @@ describe ValidatesTimeliness::Validator do
161
202
  describe "default" do
162
203
  it 'should format date error value as yyyy-mm-dd' do
163
204
  validator = ValidatesTimeliness::Validator.new(:attributes => [:birth_date], :type => :date)
164
- validator.format_error_value(Date.new(2010,1,1)).should == '2010-01-01'
205
+ expect(validator.format_error_value(Date.new(2010,1,1))).to eq('2010-01-01')
165
206
  end
166
207
 
167
208
  it 'should format time error value as hh:nn:ss' do
168
209
  validator = ValidatesTimeliness::Validator.new(:attributes => [:birth_time], :type => :time)
169
- validator.format_error_value(Time.mktime(2010,1,1,12,34,56)).should == '12:34:56'
210
+ expect(validator.format_error_value(Time.mktime(2010,1,1,12,34,56))).to eq('12:34:56')
170
211
  end
171
212
 
172
213
  it 'should format datetime error value as yyyy-mm-dd hh:nn:ss' do
173
214
  validator = ValidatesTimeliness::Validator.new(:attributes => [:birth_datetime], :type => :datetime)
174
- validator.format_error_value(Time.mktime(2010,1,1,12,34,56)).should == '2010-01-01 12:34:56'
215
+ expect(validator.format_error_value(Time.mktime(2010,1,1,12,34,56))).to eq('2010-01-01 12:34:56')
175
216
  end
176
217
  end
177
218
 
@@ -182,7 +223,7 @@ describe ValidatesTimeliness::Validator do
182
223
 
183
224
  it 'should use the default format for the type' do
184
225
  validator = ValidatesTimeliness::Validator.new(:attributes => [:birth_date], :type => :date)
185
- validator.format_error_value(Date.new(2010,1,1)).should == '2010-01-01'
226
+ expect(validator.format_error_value(Date.new(2010,1,1))).to eq('2010-01-01')
186
227
  end
187
228
 
188
229
  after :all do
@@ -196,7 +237,7 @@ describe ValidatesTimeliness::Validator do
196
237
  Person.validates_date :birth_date, :invalid_date_message => 'custom invalid message'
197
238
  invalid!(:birth_date, 'asdf', 'custom invalid message')
198
239
  end
199
-
240
+
200
241
  it 'should be used for invalid restriction' do
201
242
  Person.validates_date :birth_date, :before => Time.now, :before_message => 'custom before message'
202
243
  invalid!(:birth_date, Time.now, 'custom before message')
@@ -3,39 +3,39 @@ require 'spec_helper'
3
3
  describe ValidatesTimeliness do
4
4
 
5
5
  it 'should alias use_euro_formats to remove_us_formats on Timeliness gem' do
6
- Timeliness.should respond_to(:remove_us_formats)
6
+ expect(Timeliness).to respond_to(:remove_us_formats)
7
7
  end
8
8
 
9
9
  it 'should alias to date_for_time_type to dummy_date_for_time_type on Timeliness gem' do
10
- Timeliness.should respond_to(:dummy_date_for_time_type)
10
+ expect(Timeliness).to respond_to(:dummy_date_for_time_type)
11
11
  end
12
12
 
13
13
  describe "config" do
14
14
  it 'should delegate default_timezone to Timeliness gem' do
15
- Timeliness.should_receive(:default_timezone=)
15
+ expect(Timeliness).to receive(:default_timezone=)
16
16
  ValidatesTimeliness.default_timezone = :utc
17
17
  end
18
18
 
19
19
  it 'should delegate dummy_date_for_time_type to Timeliness gem' do
20
- Timeliness.should_receive(:dummy_date_for_time_type)
21
- Timeliness.should_receive(:dummy_date_for_time_type=)
20
+ expect(Timeliness).to receive(:dummy_date_for_time_type)
21
+ expect(Timeliness).to receive(:dummy_date_for_time_type=)
22
22
  array = ValidatesTimeliness.dummy_date_for_time_type
23
23
  ValidatesTimeliness.dummy_date_for_time_type = array
24
24
  end
25
25
 
26
26
  context "parser" do
27
27
  it 'should delegate add_formats to Timeliness gem' do
28
- Timeliness.should_receive(:add_formats)
28
+ expect(Timeliness).to receive(:add_formats)
29
29
  ValidatesTimeliness.parser.add_formats
30
30
  end
31
31
 
32
32
  it 'should delegate remove_formats to Timeliness gem' do
33
- Timeliness.should_receive(:remove_formats)
33
+ expect(Timeliness).to receive(:remove_formats)
34
34
  ValidatesTimeliness.parser.remove_formats
35
35
  end
36
36
 
37
37
  it 'should delegate remove_us_formats to Timeliness gem' do
38
- Timeliness.should_receive(:remove_us_formats)
38
+ expect(Timeliness).to receive(:remove_us_formats)
39
39
  ValidatesTimeliness.parser.remove_us_formats
40
40
  end
41
41
  end
@@ -12,9 +12,9 @@ Gem::Specification.new do |s|
12
12
  s.homepage = %q{http://github.com/adzap/validates_timeliness}
13
13
 
14
14
  s.require_paths = ["lib"]
15
- s.files = `git ls-files`.split("\n") - %w{ .gitignore .rspec Gemfile Gemfile.lock autotest/discover.rb }
15
+ s.files = `git ls-files`.split("\n") - %w{ .gitignore .rspec Gemfile Gemfile.lock autotest/discover.rb Appraisals Travis.yml } - Dir['gemsfiles/*']
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
18
18
 
19
- s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.4"])
19
+ s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.7"])
20
20
  end