validates_timeliness 3.0.15 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +21 -0
  3. data/CHANGELOG.rdoc +0 -5
  4. data/README.rdoc +5 -5
  5. data/gemfiles/rails_4_0.gemfile +19 -0
  6. data/gemfiles/rails_4_1.gemfile +19 -0
  7. data/gemfiles/rails_4_2.gemfile +19 -0
  8. data/lib/generators/validates_timeliness/templates/validates_timeliness.rb +2 -2
  9. data/lib/validates_timeliness.rb +1 -1
  10. data/lib/validates_timeliness/attribute_methods.rb +36 -36
  11. data/lib/validates_timeliness/extensions.rb +3 -4
  12. data/lib/validates_timeliness/extensions/date_time_select.rb +2 -9
  13. data/lib/validates_timeliness/extensions/multiparameter_handler.rb +59 -65
  14. data/lib/validates_timeliness/helper_methods.rb +8 -2
  15. data/lib/validates_timeliness/orm/active_record.rb +59 -13
  16. data/lib/validates_timeliness/validator.rb +13 -5
  17. data/lib/validates_timeliness/version.rb +1 -1
  18. data/spec/spec_helper.rb +3 -2
  19. data/spec/support/model_helpers.rb +4 -4
  20. data/spec/support/tag_matcher.rb +35 -0
  21. data/spec/support/test_model.rb +0 -1
  22. data/spec/validates_timeliness/attribute_methods_spec.rb +10 -10
  23. data/spec/validates_timeliness/conversion_spec.rb +41 -41
  24. data/spec/validates_timeliness/extensions/date_time_select_spec.rb +5 -4
  25. data/spec/validates_timeliness/extensions/multiparameter_handler_spec.rb +8 -7
  26. data/spec/validates_timeliness/helper_methods_spec.rb +8 -8
  27. data/spec/validates_timeliness/orm/active_record_spec.rb +37 -37
  28. data/spec/validates_timeliness/validator/after_spec.rb +3 -3
  29. data/spec/validates_timeliness/validator/before_spec.rb +3 -3
  30. data/spec/validates_timeliness/validator/is_at_spec.rb +4 -4
  31. data/spec/validates_timeliness/validator/on_or_after_spec.rb +3 -3
  32. data/spec/validates_timeliness/validator/on_or_before_spec.rb +3 -3
  33. data/spec/validates_timeliness/validator_spec.rb +26 -26
  34. data/spec/validates_timeliness_spec.rb +8 -8
  35. metadata +7 -11
  36. data/gemfiles/mongoid_2_1.gemfile +0 -16
  37. data/gemfiles/mongoid_2_2.gemfile +0 -16
  38. data/gemfiles/mongoid_2_3.gemfile +0 -16
  39. data/gemfiles/mongoid_2_4.gemfile +0 -16
  40. data/gemfiles/rails_3_0.gemfile +0 -15
  41. data/gemfiles/rails_3_1.gemfile +0 -15
  42. data/gemfiles/rails_3_2.gemfile +0 -15
  43. data/lib/validates_timeliness/orm/mongoid.rb +0 -49
  44. data/spec/validates_timeliness/orm/mongoid_spec.rb +0 -223
@@ -1,223 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # Try loading mongoid and connecting. Otherwise, abort and skip spec.
4
- begin
5
-
6
- require 'mongoid'
7
- require 'validates_timeliness/orm/mongoid'
8
-
9
- Mongoid.configure do |config|
10
- config.connect_to('validates_timeliness_test')
11
- end
12
-
13
- describe ValidatesTimeliness, 'Mongoid' do
14
- after(:each) do
15
- Mongoid.purge!
16
- end
17
-
18
- class Article
19
- include Mongoid::Document
20
- field :publish_date, :type => Date
21
- field :publish_time, :type => Time
22
- field :publish_datetime, :type => DateTime
23
- validates_date :publish_date, :allow_nil => true
24
- validates_time :publish_time, :allow_nil => true
25
- validates_datetime :publish_datetime, :allow_nil => true
26
- end
27
-
28
- context "validation methods" do
29
- let(:record) { Article.new }
30
-
31
- it 'should be defined on the class' do
32
- Article.should respond_to(:validates_date)
33
- Article.should respond_to(:validates_time)
34
- Article.should respond_to(:validates_datetime)
35
- end
36
-
37
- it 'should be defined on the instance' do
38
- record.should respond_to(:validates_date)
39
- record.should respond_to(:validates_time)
40
- record.should respond_to(:validates_datetime)
41
- end
42
-
43
- it "should validate a valid value string" do
44
- record.publish_date = '2012-01-01'
45
-
46
- record.valid?
47
- record.errors[:publish_date].should be_empty
48
- end
49
-
50
- it "should validate a nil value" do
51
- record.publish_date = nil
52
-
53
- record.valid?
54
- record.errors[:publish_date].should be_empty
55
- end
56
- end
57
-
58
- it 'should determine type for attribute' do
59
- Article.timeliness_attribute_type(:publish_date).should == :date
60
- Article.timeliness_attribute_type(:publish_time).should == :time
61
- Article.timeliness_attribute_type(:publish_datetime).should == :datetime
62
- end
63
-
64
- context "attribute write method" do
65
- let(:record) { Article.new }
66
-
67
- it 'should cache attribute raw value' do
68
- record.publish_datetime = date_string = '2010-01-01'
69
-
70
- record._timeliness_raw_value_for('publish_datetime').should == date_string
71
- end
72
-
73
- context "with plugin parser" do
74
- let(:record) { ArticleWithParser.new }
75
-
76
- class ArticleWithParser
77
- include Mongoid::Document
78
- field :publish_date, :type => Date
79
- field :publish_time, :type => Time
80
- field :publish_datetime, :type => DateTime
81
-
82
- ValidatesTimeliness.use_plugin_parser = true
83
- validates_date :publish_date, :allow_nil => true
84
- validates_time :publish_time, :allow_nil => true
85
- validates_datetime :publish_datetime, :allow_nil => true
86
- ValidatesTimeliness.use_plugin_parser = false
87
- end
88
-
89
- context "for a date column" do
90
- it 'should parse a string value' do
91
- Timeliness::Parser.should_receive(:parse)
92
-
93
- record.publish_date = '2010-01-01'
94
- end
95
-
96
- it 'should parse a invalid string value as nil' do
97
- Timeliness::Parser.should_receive(:parse)
98
-
99
- record.publish_date = 'not valid'
100
- end
101
-
102
- it 'should store a Date value after parsing string' do
103
- record.publish_date = '2010-01-01'
104
-
105
- record.publish_date.should be_kind_of(Date)
106
- record.publish_date.should eq Date.new(2010, 1, 1)
107
- end
108
- end
109
-
110
- context "for a time column" do
111
- it 'should parse a string value' do
112
- Timeliness::Parser.should_receive(:parse)
113
-
114
- record.publish_time = '12:30'
115
- end
116
-
117
- it 'should parse a invalid string value as nil' do
118
- Timeliness::Parser.should_receive(:parse)
119
-
120
- record.publish_time = 'not valid'
121
- end
122
-
123
- it 'should store a Time value after parsing string' do
124
- record.publish_time = '12:30'
125
-
126
- record.publish_time.should be_kind_of(Time)
127
- record.publish_time.should eq Time.utc(2000, 1, 1, 12, 30)
128
- end
129
- end
130
-
131
- context "for a datetime column" do
132
- with_config(:default_timezone, 'Australia/Melbourne')
133
-
134
- it 'should parse a string value' do
135
- Timeliness::Parser.should_receive(:parse)
136
-
137
- record.publish_datetime = '2010-01-01 12:00'
138
- end
139
-
140
- it 'should parse a invalid string value as nil' do
141
- Timeliness::Parser.should_receive(:parse)
142
-
143
- record.publish_datetime = 'not valid'
144
- end
145
-
146
- it 'should parse string into DateTime value' do
147
- record.publish_datetime = '2010-01-01 12:00'
148
-
149
- record.publish_datetime.should be_kind_of(DateTime)
150
- end
151
-
152
- it 'should parse string as current timezone' do
153
- record.publish_datetime = '2010-06-01 12:00'
154
-
155
- record.publish_datetime.utc_offset.should eq Time.zone.utc_offset
156
- end
157
- end
158
- end
159
- end
160
-
161
- context "cached value" do
162
- it 'should be cleared on reload' do
163
- record = Article.create!
164
- record.publish_date = '2010-01-01'
165
- record.reload
166
- record._timeliness_raw_value_for('publish_date').should be_nil
167
- end
168
- end
169
-
170
- context "before_type_cast method" do
171
- let(:record){ Article.new }
172
-
173
- it 'should be defined on class if ORM supports it' do
174
- record.should respond_to(:publish_datetime_before_type_cast)
175
- end
176
-
177
- it 'should return original value' do
178
- record.publish_datetime = date_string = '2010-01-01'
179
-
180
- record.publish_datetime_before_type_cast.should eq date_string
181
- end
182
-
183
- it 'should return attribute if no attribute assignment has been made' do
184
- time = Time.zone.local(2010,01,01)
185
- Article.create(:publish_datetime => time)
186
- record = Article.last
187
- record.publish_datetime_before_type_cast.should eq time.to_datetime
188
- end
189
-
190
- context "with plugin parser" do
191
- with_config(:use_plugin_parser, true)
192
-
193
- it 'should return original value' do
194
- record.publish_datetime = date_string = '2010-01-31'
195
- record.publish_datetime_before_type_cast.should eq date_string
196
- end
197
- end
198
- end
199
-
200
- context "with aliased fields" do
201
- class ArticleWithAliasedFields
202
- include Mongoid::Document
203
- field :pd, as: :publish_date, :type => Date
204
- field :pt, as: :publish_time, :type => Time
205
- field :pdt, as: :publish_datetime, :type => DateTime
206
- validates_date :publish_date, :allow_nil => true
207
- validates_time :publish_time, :allow_nil => true
208
- validates_datetime :publish_datetime, :allow_nil => true
209
- end
210
-
211
- it 'should determine type for attribute' do
212
- ArticleWithAliasedFields.timeliness_attribute_type(:publish_date).should == :date
213
- ArticleWithAliasedFields.timeliness_attribute_type(:publish_time).should == :time
214
- ArticleWithAliasedFields.timeliness_attribute_type(:publish_datetime).should == :datetime
215
- end
216
- end
217
- end
218
-
219
- rescue LoadError
220
- puts "Mongoid specs skipped. Mongoid not installed"
221
- rescue StandardError => e
222
- puts "Mongoid specs skipped. MongoDB connection failed with error: #{e.message}"
223
- end