mongoid_time_field 0.2.2 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7180a86b7f2a54f680b0da5bb2388896749519b8
4
- data.tar.gz: 7ade24dc09af27c8f37f5df045f13eef2fa14fb2
3
+ metadata.gz: 16e4a3ef8e112fe1e01003ef243967c0a31146cd
4
+ data.tar.gz: 1e3348992eb14c4ad2b3450b30eee9b354bcd918
5
5
  SHA512:
6
- metadata.gz: 820f40c21a377b967fad550d1664562d3ceceb1ac5d8dc19dcdc4098929fd08f78c1fd45e26941343aad08db2c367c2188918ce0a8dd1c5dc73888f99ffaf9cc
7
- data.tar.gz: 6e009f5bb2d6ac3fa56836cfdd21806585955094a045ef9cb2dc1946eaf214a5e51b055d6959aaf3035577f0019f241b79761bc71aad230637c336f8ca7a9d0a
6
+ metadata.gz: f4f9f7bab1adef22a450867915a1f3745c590dc77487ade1ac0cdee9dc27e21822fe6d0573c97c48794b4ef3ff3f2a13730b8da56871f577ab3406c8575b2d02
7
+ data.tar.gz: 90abaa8ef9a927e4c72a682133f6d2248cf5d8f253e88d0ef1718d3d28e4caf0556306758e3b564fe7dc4a7e5fb777a1f0fa17c99c167f4d2a7426abbd2fd2e3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid_time_field (0.2.2)
4
+ mongoid_time_field (0.2.3)
5
5
  mongoid (>= 3.0.0)
6
6
 
7
7
  GEM
data/README.rdoc CHANGED
@@ -10,13 +10,13 @@ Include the gem in your Gemfile
10
10
 
11
11
  == Usage
12
12
 
13
- class DummyTime
14
- include Mongoid::Document
13
+ class DummyTime
14
+ include Mongoid::Document
15
15
 
16
- field :worktime, type: TimeField.new(format: 'HH:MM')
17
- field :time_of_day, type: TimeField.new(format: 'HH:MM:SS')
18
- field :duration, type: TimeField.new(format: 'mm:SS')
19
- end
16
+ field :worktime, type: TimeField.new(format: 'HH:MM')
17
+ field :time_of_day, type: TimeField.new(format: 'HH:MM:SS')
18
+ field :duration, type: TimeField.new(format: 'mm:SS')
19
+ end
20
20
 
21
21
  == Format tokens:
22
22
 
@@ -31,11 +31,11 @@ Include the gem in your Gemfile
31
31
 
32
32
  Leftmost value in format is of arbitrary length (i.e. format 'HH:MM' is not limited to 24 hours, 'mm:SS' is not limited to 60 minutes and should not overflow)
33
33
 
34
+ All time values are converted and stored in mongodb as seconds (integer field).
35
+
34
36
  == changes since v.0.1.0
35
37
  Default format for deprecated time_field syntax is 'mm:SS' for compatibility (If you stored HH:MM with 0.1.0 it should still just keep working with 'mm:SS' format, with seconds stored in DB, but if you change to new syntax and use 'HH:MM' format, you need to multiply all stored values by 60)
36
38
 
37
- All time values are converted and stored in mongodb as seconds.
38
-
39
39
  == Contributing to mongoid_time_field
40
40
 
41
41
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
@@ -26,14 +26,18 @@ class TimeField
26
26
  nil
27
27
  else
28
28
  match = @options[:regexp].match(value)
29
- seconds = 0
30
- names = match.names
29
+ if match.nil?
30
+ nil
31
+ else
32
+ seconds = 0
33
+ names = match.names
31
34
 
32
- seconds += match['s'].to_i if names.include?('s')
33
- seconds += match['m'].to_i * 60 if names.include?('m')
34
- seconds += match['h'].to_i * 3600 if names.include?('h')
35
+ seconds += match['s'].to_i if names.include?('s')
36
+ seconds += match['m'].to_i * 60 if names.include?('m')
37
+ seconds += match['h'].to_i * 3600 if names.include?('h')
35
38
 
36
- Mongoid::TimeField::Value.new(seconds, @options)
39
+ Mongoid::TimeField::Value.new(seconds, @options)
40
+ end
37
41
  end
38
42
  end
39
43
 
@@ -1,3 +1,3 @@
1
1
  module MongoidTimeField
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -0,0 +1,7 @@
1
+ class DummyValidate
2
+ include Mongoid::Document
3
+
4
+ field :def, type: TimeField.new()
5
+
6
+ validates_presence_of :def
7
+ end
data/spec/v2_spec.rb CHANGED
@@ -186,4 +186,25 @@ describe Mongoid::TimeField do
186
186
  dummy.def.should eq '2:03'
187
187
  end
188
188
  end
189
+
190
+ describe 'validation' do
191
+ it 'validates presence' do
192
+ dummy = DummyValidate.new
193
+ dummy.should_not be_valid
194
+ dummy.errors.count.should eq 1
195
+ dummy.errors.messages[:def][0].should eq "can't be blank"
196
+ dummy.save.should eq false
197
+ end
198
+
199
+ it 'validates numericality' do
200
+ dummy = DummyValidate.new
201
+ dummy.should_not be_valid
202
+ dummy.errors.count.should eq 1
203
+ dummy.errors.messages[:def][0].should eq "can't be blank"
204
+ dummy.def = '10:00'
205
+ dummy.should be_valid
206
+ dummy.errors.count.should eq 0
207
+ dummy.save.should eq true
208
+ end
209
+ end
189
210
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_time_field
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebtv
@@ -120,6 +120,7 @@ files:
120
120
  - spec/support/dummy_duration.rb
121
121
  - spec/support/dummy_time.rb
122
122
  - spec/support/dummy_v2.rb
123
+ - spec/support/dummy_validate.rb
123
124
  - spec/support/mongoid.yml
124
125
  - spec/v1_spec.rb
125
126
  - spec/v2_spec.rb
@@ -152,6 +153,7 @@ test_files:
152
153
  - spec/support/dummy_duration.rb
153
154
  - spec/support/dummy_time.rb
154
155
  - spec/support/dummy_v2.rb
156
+ - spec/support/dummy_validate.rb
155
157
  - spec/support/mongoid.yml
156
158
  - spec/v1_spec.rb
157
159
  - spec/v2_spec.rb