activerecord-time 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/Gemfile +0 -6
- data/README.md +52 -3
- data/activerecord-time.gemspec +1 -0
- data/gemfiles/ar32.gemfile.lock +17 -15
- data/gemfiles/ar40.gemfile.lock +17 -15
- data/gemfiles/ar41.gemfile.lock +16 -15
- data/gemfiles/ar42.gemfile.lock +18 -17
- data/gemfiles/common.gemfile +2 -3
- data/lib/activerecord-time/version.rb +1 -1
- data/lib/time_of_day.rb +16 -0
- data/matrix_test.rb +1 -1
- data/test/test_helper.rb +3 -0
- data/test/time_of_day_test.rb +130 -9
- metadata +32 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dabe685f8ccbf24d8508ebaac1638b4d544a4199
|
4
|
+
data.tar.gz: bb73addeaac1bcec334d5e26c2d9eb78a39e163f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43236b8cc04aa36186110e88efb5e214063fa58b56fb273fbc8d3855717f400509a5afd61b8435104302e586f5445809162797c473583f31d0fda1cda9699b42
|
7
|
+
data.tar.gz: cbba40060ba4e41068afbddd4709a1451251ec82094555b16df087cf4523845c9e5180ee0f90f920fbd6ceab522b25fde63c4b59bc1d6a91cf4c07567f50c2ce
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -6,9 +6,3 @@ gemspec
|
|
6
6
|
if ENV['AR_VERSION']
|
7
7
|
gem 'activerecord', ENV['AR_VERSION']
|
8
8
|
end
|
9
|
-
|
10
|
-
# TODO(uwe): Remove when ARJDBC 1.4.0 is out
|
11
|
-
if RUBY_ENGINE == 'jruby'
|
12
|
-
gem 'activerecord-jdbc-adapter', '>= 1.3.17', github: 'jruby/activerecord-jdbc-adapter', branch: '1-3-stable'
|
13
|
-
end
|
14
|
-
# ODOT
|
data/README.md
CHANGED
@@ -7,7 +7,13 @@ A handler for storing TimeOfDay objects in ActiveRecord objects as SQL time valu
|
|
7
7
|
Also adds load/dump of TimeOfDay objects to and from YAML streams, so you can use
|
8
8
|
them in fixtures.
|
9
9
|
|
10
|
-
|
10
|
+
Also adds JSON encode/decode.
|
11
|
+
|
12
|
+
The gem supports MRI and JRuby at Ruby language level 1.9.3 and later. Other
|
13
|
+
Ruby implementations may work.
|
14
|
+
|
15
|
+
ActiveRecord 3.2 and later supported.
|
16
|
+
|
11
17
|
|
12
18
|
## Installation
|
13
19
|
|
@@ -25,8 +31,8 @@ Or install it yourself as:
|
|
25
31
|
|
26
32
|
## Usage
|
27
33
|
|
28
|
-
Create your tables with fields with type :time and you will be able to access
|
29
|
-
TimeOfDay objects.
|
34
|
+
Create your tables with fields with type :time and you will be able to access
|
35
|
+
them as TimeOfDay objects.
|
30
36
|
|
31
37
|
```Ruby
|
32
38
|
create_table :schedules do |t|
|
@@ -66,6 +72,37 @@ schedule = Schedule.new
|
|
66
72
|
schedule.start_time = '08:34'
|
67
73
|
```
|
68
74
|
|
75
|
+
## TimeOfDay Kernel extension
|
76
|
+
|
77
|
+
Kernel is extended with a TimeOfDay constructor that takes either a parseable
|
78
|
+
String or one or more integers.
|
79
|
+
|
80
|
+
```Ruby
|
81
|
+
party_starts_at = TimeOfDay('17:59')
|
82
|
+
dancing_starts_at = TimeOfDay(20, 02)
|
83
|
+
```
|
84
|
+
|
85
|
+
## TimeOfDay Date extension
|
86
|
+
|
87
|
+
Ruby Date objects are extended with the `at` method that takes a TimeOfDay
|
88
|
+
argument to produce a Ruby Time object. As a shortcut, a String that is
|
89
|
+
parseable by TimeOfDay can be given.
|
90
|
+
|
91
|
+
```Ruby
|
92
|
+
halloween = Date.parse('2015-10-31')
|
93
|
+
trick_or_treat = halloween.at(TimeOfDay.parse('18:00'))
|
94
|
+
halloween_dinner = halloween.at('20:00')
|
95
|
+
```
|
96
|
+
|
97
|
+
## TimeOfDay Time extension
|
98
|
+
|
99
|
+
Ruby Time objects are extended with the `time_of_day` method that returns a
|
100
|
+
TimeOfDay object corresponding to the time of day of the Time object.
|
101
|
+
|
102
|
+
```Ruby
|
103
|
+
Time.parse('2015-10-31 20:00').time_of_day # returns TimeOfDay(20, 0)
|
104
|
+
```
|
105
|
+
|
69
106
|
|
70
107
|
|
71
108
|
## Contributing
|
@@ -75,3 +112,15 @@ schedule.start_time = '08:34'
|
|
75
112
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
76
113
|
4. Push to the branch (`git push origin my-new-feature`)
|
77
114
|
5. Create new Pull Request
|
115
|
+
|
116
|
+
## Testing
|
117
|
+
|
118
|
+
Run tests using
|
119
|
+
|
120
|
+
rake
|
121
|
+
|
122
|
+
### Matrix test
|
123
|
+
|
124
|
+
./matrix_test.rb
|
125
|
+
|
126
|
+
This will run the tests for the same environments as travis-ci.
|
data/activerecord-time.gemspec
CHANGED
data/gemfiles/ar32.gemfile.lock
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/jruby/activerecord-jdbc-adapter.git
|
3
|
-
revision: 16446e752f07e03eaa6386184039addb42fc3e60
|
4
|
-
branch: 1-3-stable
|
5
|
-
specs:
|
6
|
-
activerecord-jdbc-adapter (1.3.17)
|
7
|
-
activerecord (>= 2.2)
|
8
|
-
activerecord-jdbcpostgresql-adapter (1.3.17)
|
9
|
-
activerecord-jdbc-adapter (~> 1.3.17)
|
10
|
-
jdbc-postgres (>= 9.1)
|
11
|
-
activerecord-jdbcsqlite3-adapter (1.3.17)
|
12
|
-
activerecord-jdbc-adapter (~> 1.3.17)
|
13
|
-
jdbc-sqlite3 (>= 3.7.2, < 3.9)
|
14
|
-
|
15
1
|
GEM
|
16
2
|
remote: https://rubygems.org/
|
17
3
|
specs:
|
@@ -23,15 +9,25 @@ GEM
|
|
23
9
|
activesupport (= 3.2.22)
|
24
10
|
arel (~> 3.0.2)
|
25
11
|
tzinfo (~> 0.3.29)
|
12
|
+
activerecord-jdbc-adapter (1.3.18)
|
13
|
+
activerecord (>= 2.2)
|
14
|
+
activerecord-jdbcpostgresql-adapter (1.3.18)
|
15
|
+
activerecord-jdbc-adapter (~> 1.3.18)
|
16
|
+
jdbc-postgres (>= 9.1)
|
17
|
+
activerecord-jdbcsqlite3-adapter (1.3.18)
|
18
|
+
activerecord-jdbc-adapter (~> 1.3.18)
|
19
|
+
jdbc-sqlite3 (>= 3.7.2, < 3.9)
|
26
20
|
activesupport (3.2.22)
|
27
21
|
i18n (~> 0.6, >= 0.6.4)
|
28
22
|
multi_json (~> 1.0)
|
29
23
|
ansi (1.5.0)
|
30
24
|
arel (3.0.3)
|
31
25
|
builder (3.0.4)
|
26
|
+
docile (1.1.5)
|
32
27
|
i18n (0.7.0)
|
33
28
|
jdbc-postgres (9.4.1200)
|
34
29
|
jdbc-sqlite3 (3.8.10.1)
|
30
|
+
json (1.8.3-java)
|
35
31
|
minitest (5.8.0)
|
36
32
|
minitest-reporters (1.0.19)
|
37
33
|
ansi
|
@@ -42,6 +38,11 @@ GEM
|
|
42
38
|
pg (0.18.2)
|
43
39
|
rake (10.4.2)
|
44
40
|
ruby-progressbar (1.7.5)
|
41
|
+
simplecov (0.10.0)
|
42
|
+
docile (~> 1.1.0)
|
43
|
+
json (~> 1.8)
|
44
|
+
simplecov-html (~> 0.10.0)
|
45
|
+
simplecov-html (0.10.0)
|
45
46
|
sqlite3 (1.3.10)
|
46
47
|
tzinfo (0.3.44)
|
47
48
|
|
@@ -51,12 +52,13 @@ PLATFORMS
|
|
51
52
|
|
52
53
|
DEPENDENCIES
|
53
54
|
activerecord (~> 3.2.22)
|
54
|
-
activerecord-jdbc-adapter
|
55
|
+
activerecord-jdbc-adapter
|
55
56
|
activerecord-jdbcpostgresql-adapter
|
56
57
|
activerecord-jdbcsqlite3-adapter
|
57
58
|
minitest-reporters
|
58
59
|
pg
|
59
60
|
rake
|
61
|
+
simplecov
|
60
62
|
sqlite3
|
61
63
|
|
62
64
|
BUNDLED WITH
|
data/gemfiles/ar40.gemfile.lock
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/jruby/activerecord-jdbc-adapter.git
|
3
|
-
revision: 16446e752f07e03eaa6386184039addb42fc3e60
|
4
|
-
branch: 1-3-stable
|
5
|
-
specs:
|
6
|
-
activerecord-jdbc-adapter (1.3.17)
|
7
|
-
activerecord (>= 2.2)
|
8
|
-
activerecord-jdbcpostgresql-adapter (1.3.17)
|
9
|
-
activerecord-jdbc-adapter (~> 1.3.17)
|
10
|
-
jdbc-postgres (>= 9.1)
|
11
|
-
activerecord-jdbcsqlite3-adapter (1.3.17)
|
12
|
-
activerecord-jdbc-adapter (~> 1.3.17)
|
13
|
-
jdbc-sqlite3 (>= 3.7.2, < 3.9)
|
14
|
-
|
15
1
|
GEM
|
16
2
|
remote: https://rubygems.org/
|
17
3
|
specs:
|
@@ -24,6 +10,14 @@ GEM
|
|
24
10
|
activesupport (= 4.0.13)
|
25
11
|
arel (~> 4.0.0)
|
26
12
|
activerecord-deprecated_finders (1.0.4)
|
13
|
+
activerecord-jdbc-adapter (1.3.18)
|
14
|
+
activerecord (>= 2.2)
|
15
|
+
activerecord-jdbcpostgresql-adapter (1.3.18)
|
16
|
+
activerecord-jdbc-adapter (~> 1.3.18)
|
17
|
+
jdbc-postgres (>= 9.1)
|
18
|
+
activerecord-jdbcsqlite3-adapter (1.3.18)
|
19
|
+
activerecord-jdbc-adapter (~> 1.3.18)
|
20
|
+
jdbc-sqlite3 (>= 3.7.2, < 3.9)
|
27
21
|
activesupport (4.0.13)
|
28
22
|
i18n (~> 0.6, >= 0.6.9)
|
29
23
|
minitest (~> 4.2)
|
@@ -33,10 +27,12 @@ GEM
|
|
33
27
|
ansi (1.5.0)
|
34
28
|
arel (4.0.2)
|
35
29
|
builder (3.1.4)
|
30
|
+
docile (1.1.5)
|
36
31
|
hashie (3.4.2)
|
37
32
|
i18n (0.7.0)
|
38
33
|
jdbc-postgres (9.4.1200)
|
39
34
|
jdbc-sqlite3 (3.8.10.1)
|
35
|
+
json (1.8.3-java)
|
40
36
|
minitest (4.7.5)
|
41
37
|
minitest-reporters (0.14.24)
|
42
38
|
ansi
|
@@ -49,6 +45,11 @@ GEM
|
|
49
45
|
ansi (~> 1.5.0)
|
50
46
|
hashie (>= 1.1.0)
|
51
47
|
rake (10.4.2)
|
48
|
+
simplecov (0.10.0)
|
49
|
+
docile (~> 1.1.0)
|
50
|
+
json (~> 1.8)
|
51
|
+
simplecov-html (~> 0.10.0)
|
52
|
+
simplecov-html (0.10.0)
|
52
53
|
sqlite3 (1.3.10)
|
53
54
|
thread_safe (0.3.5)
|
54
55
|
thread_safe (0.3.5-java)
|
@@ -60,12 +61,13 @@ PLATFORMS
|
|
60
61
|
|
61
62
|
DEPENDENCIES
|
62
63
|
activerecord (~> 4.0.13)
|
63
|
-
activerecord-jdbc-adapter
|
64
|
+
activerecord-jdbc-adapter
|
64
65
|
activerecord-jdbcpostgresql-adapter
|
65
66
|
activerecord-jdbcsqlite3-adapter
|
66
67
|
minitest-reporters
|
67
68
|
pg
|
68
69
|
rake
|
70
|
+
simplecov
|
69
71
|
sqlite3
|
70
72
|
|
71
73
|
BUNDLED WITH
|
data/gemfiles/ar41.gemfile.lock
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/jruby/activerecord-jdbc-adapter.git
|
3
|
-
revision: 16446e752f07e03eaa6386184039addb42fc3e60
|
4
|
-
branch: 1-3-stable
|
5
|
-
specs:
|
6
|
-
activerecord-jdbc-adapter (1.3.17)
|
7
|
-
activerecord (>= 2.2)
|
8
|
-
activerecord-jdbcpostgresql-adapter (1.3.17)
|
9
|
-
activerecord-jdbc-adapter (~> 1.3.17)
|
10
|
-
jdbc-postgres (>= 9.1)
|
11
|
-
activerecord-jdbcsqlite3-adapter (1.3.17)
|
12
|
-
activerecord-jdbc-adapter (~> 1.3.17)
|
13
|
-
jdbc-sqlite3 (>= 3.7.2, < 3.9)
|
14
|
-
|
15
1
|
GEM
|
16
2
|
remote: https://rubygems.org/
|
17
3
|
specs:
|
@@ -22,6 +8,14 @@ GEM
|
|
22
8
|
activemodel (= 4.1.12)
|
23
9
|
activesupport (= 4.1.12)
|
24
10
|
arel (~> 5.0.0)
|
11
|
+
activerecord-jdbc-adapter (1.3.18)
|
12
|
+
activerecord (>= 2.2)
|
13
|
+
activerecord-jdbcpostgresql-adapter (1.3.18)
|
14
|
+
activerecord-jdbc-adapter (~> 1.3.18)
|
15
|
+
jdbc-postgres (>= 9.1)
|
16
|
+
activerecord-jdbcsqlite3-adapter (1.3.18)
|
17
|
+
activerecord-jdbc-adapter (~> 1.3.18)
|
18
|
+
jdbc-sqlite3 (>= 3.7.2, < 3.9)
|
25
19
|
activesupport (4.1.12)
|
26
20
|
i18n (~> 0.6, >= 0.6.9)
|
27
21
|
json (~> 1.7, >= 1.7.7)
|
@@ -31,6 +25,7 @@ GEM
|
|
31
25
|
ansi (1.5.0)
|
32
26
|
arel (5.0.1.20140414130214)
|
33
27
|
builder (3.2.2)
|
28
|
+
docile (1.1.5)
|
34
29
|
i18n (0.7.0)
|
35
30
|
jdbc-postgres (9.4.1200)
|
36
31
|
jdbc-sqlite3 (3.8.10.1)
|
@@ -45,6 +40,11 @@ GEM
|
|
45
40
|
pg (0.18.2)
|
46
41
|
rake (10.4.2)
|
47
42
|
ruby-progressbar (1.7.5)
|
43
|
+
simplecov (0.10.0)
|
44
|
+
docile (~> 1.1.0)
|
45
|
+
json (~> 1.8)
|
46
|
+
simplecov-html (~> 0.10.0)
|
47
|
+
simplecov-html (0.10.0)
|
48
48
|
sqlite3 (1.3.10)
|
49
49
|
thread_safe (0.3.5)
|
50
50
|
thread_safe (0.3.5-java)
|
@@ -57,12 +57,13 @@ PLATFORMS
|
|
57
57
|
|
58
58
|
DEPENDENCIES
|
59
59
|
activerecord (~> 4.1.12)
|
60
|
-
activerecord-jdbc-adapter
|
60
|
+
activerecord-jdbc-adapter
|
61
61
|
activerecord-jdbcpostgresql-adapter
|
62
62
|
activerecord-jdbcsqlite3-adapter
|
63
63
|
minitest-reporters
|
64
64
|
pg
|
65
65
|
rake
|
66
|
+
simplecov
|
66
67
|
sqlite3
|
67
68
|
|
68
69
|
BUNDLED WITH
|
data/gemfiles/ar42.gemfile.lock
CHANGED
@@ -1,19 +1,3 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/jruby/activerecord-jdbc-adapter.git
|
3
|
-
revision: 16446e752f07e03eaa6386184039addb42fc3e60
|
4
|
-
branch: 1-3-stable
|
5
|
-
specs:
|
6
|
-
activerecord-jdbc-adapter (1.3.17)
|
7
|
-
activerecord (>= 2.2)
|
8
|
-
activerecord-jdbcpostgresql-adapter (1.3.17)
|
9
|
-
activerecord-jdbc-adapter (~> 1.3.17)
|
10
|
-
jdbc-postgres (>= 9.1)
|
11
|
-
activerecord-jdbcsqlite3-adapter (1.3.17)
|
12
|
-
activerecord-jdbc-adapter (~> 1.3.17)
|
13
|
-
jdbc-sqlite3 (>= 3.7.2, < 3.9)
|
14
|
-
jdbc-postgres (9.3.1102)
|
15
|
-
jdbc-sqlite3 (3.7.2.1)
|
16
|
-
|
17
1
|
GEM
|
18
2
|
remote: https://rubygems.org/
|
19
3
|
specs:
|
@@ -24,6 +8,14 @@ GEM
|
|
24
8
|
activemodel (= 4.2.3)
|
25
9
|
activesupport (= 4.2.3)
|
26
10
|
arel (~> 6.0)
|
11
|
+
activerecord-jdbc-adapter (1.3.18)
|
12
|
+
activerecord (>= 2.2)
|
13
|
+
activerecord-jdbcpostgresql-adapter (1.3.18)
|
14
|
+
activerecord-jdbc-adapter (~> 1.3.18)
|
15
|
+
jdbc-postgres (>= 9.1)
|
16
|
+
activerecord-jdbcsqlite3-adapter (1.3.18)
|
17
|
+
activerecord-jdbc-adapter (~> 1.3.18)
|
18
|
+
jdbc-sqlite3 (>= 3.7.2, < 3.9)
|
27
19
|
activesupport (4.2.3)
|
28
20
|
i18n (~> 0.7)
|
29
21
|
json (~> 1.7, >= 1.7.7)
|
@@ -33,7 +25,10 @@ GEM
|
|
33
25
|
ansi (1.5.0)
|
34
26
|
arel (6.0.3)
|
35
27
|
builder (3.2.2)
|
28
|
+
docile (1.1.5)
|
36
29
|
i18n (0.7.0)
|
30
|
+
jdbc-postgres (9.4.1200)
|
31
|
+
jdbc-sqlite3 (3.8.10.1)
|
37
32
|
json (1.8.3)
|
38
33
|
json (1.8.3-java)
|
39
34
|
minitest (5.8.0)
|
@@ -45,6 +40,11 @@ GEM
|
|
45
40
|
pg (0.18.2)
|
46
41
|
rake (10.4.2)
|
47
42
|
ruby-progressbar (1.7.5)
|
43
|
+
simplecov (0.10.0)
|
44
|
+
docile (~> 1.1.0)
|
45
|
+
json (~> 1.8)
|
46
|
+
simplecov-html (~> 0.10.0)
|
47
|
+
simplecov-html (0.10.0)
|
48
48
|
sqlite3 (1.3.10)
|
49
49
|
thread_safe (0.3.5)
|
50
50
|
thread_safe (0.3.5-java)
|
@@ -57,12 +57,13 @@ PLATFORMS
|
|
57
57
|
|
58
58
|
DEPENDENCIES
|
59
59
|
activerecord (~> 4.2.3)
|
60
|
-
activerecord-jdbc-adapter
|
60
|
+
activerecord-jdbc-adapter
|
61
61
|
activerecord-jdbcpostgresql-adapter
|
62
62
|
activerecord-jdbcsqlite3-adapter
|
63
63
|
minitest-reporters
|
64
64
|
pg
|
65
65
|
rake
|
66
|
+
simplecov
|
66
67
|
sqlite3
|
67
68
|
|
68
69
|
BUNDLED WITH
|
data/gemfiles/common.gemfile
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
platform :jruby do
|
4
|
-
gem 'activerecord-jdbc-adapter'
|
5
|
-
github: 'jruby/activerecord-jdbc-adapter',
|
6
|
-
branch: '1-3-stable'
|
4
|
+
gem 'activerecord-jdbc-adapter'
|
7
5
|
gem 'activerecord-jdbcpostgresql-adapter'
|
8
6
|
gem 'activerecord-jdbcsqlite3-adapter'
|
9
7
|
end
|
@@ -15,3 +13,4 @@ end
|
|
15
13
|
|
16
14
|
gem 'minitest-reporters'
|
17
15
|
gem 'rake'
|
16
|
+
gem 'simplecov'
|
data/lib/time_of_day.rb
CHANGED
@@ -95,6 +95,10 @@ class TimeOfDay
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
+
def to_json(*)
|
99
|
+
%{"#{to_s}"}
|
100
|
+
end
|
101
|
+
|
98
102
|
end
|
99
103
|
|
100
104
|
class Time
|
@@ -106,9 +110,21 @@ end
|
|
106
110
|
|
107
111
|
class Date
|
108
112
|
def at(time_of_day)
|
113
|
+
time_of_day = TimeOfDay.parse(time_of_day) if time_of_day.is_a?(String)
|
109
114
|
Time.local(year, month, day, time_of_day.hour, time_of_day.minute, time_of_day.second)
|
110
115
|
end
|
111
116
|
|
112
117
|
end
|
113
118
|
|
119
|
+
module Kernel
|
120
|
+
def TimeOfDay(string_or_int, *ints)
|
121
|
+
if string_or_int.is_a? String
|
122
|
+
raise(ArgumentError, 'TimeOfDay() takes a string or multiple integers as arguments') unless ints.empty?
|
123
|
+
TimeOfDay.parse(string_or_int)
|
124
|
+
else
|
125
|
+
TimeOfDay.new(string_or_int, *ints)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
114
130
|
YAML.add_tag 'tag:yaml.org,2002:time', TimeOfDay
|
data/matrix_test.rb
CHANGED
@@ -9,7 +9,7 @@ travis['rvm'].each do |ruby|
|
|
9
9
|
puts
|
10
10
|
system "rvm install #{ruby}"
|
11
11
|
exit $? unless $? == 0
|
12
|
-
system "rvm #{ruby} do gem install bundler"
|
12
|
+
system "rvm #{ruby} do gem query -i -n bundler >/dev/null || gem install bundler"
|
13
13
|
exit $? unless $? == 0
|
14
14
|
travis['gemfile'].each do |gemfile|
|
15
15
|
puts '$' * 80
|
data/test/test_helper.rb
CHANGED
@@ -13,6 +13,9 @@ require 'logger'
|
|
13
13
|
require 'fileutils'
|
14
14
|
require 'yaml'
|
15
15
|
|
16
|
+
require 'simplecov'
|
17
|
+
SimpleCov.start
|
18
|
+
|
16
19
|
FileUtils.rm_rf File.expand_path(':memory:', File.dirname(__FILE__))
|
17
20
|
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
18
21
|
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/test.log')
|
data/test/time_of_day_test.rb
CHANGED
@@ -16,6 +16,44 @@ class TimeOfDayTest < Minitest::Test
|
|
16
16
|
@twelve_o_clock = nil
|
17
17
|
end
|
18
18
|
|
19
|
+
def test_initialize
|
20
|
+
tod = TimeOfDay.new(1, 2, 3)
|
21
|
+
assert_equal 1, tod.hour
|
22
|
+
assert_equal 2, tod.minute
|
23
|
+
assert_equal 3, tod.second
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_kernel_initialize
|
27
|
+
tod = TimeOfDay(1, 2, 3)
|
28
|
+
assert_equal 1, tod.hour
|
29
|
+
assert_equal 2, tod.minute
|
30
|
+
assert_equal 3, tod.second
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_kernel_initialize_string
|
34
|
+
tod = TimeOfDay('01:02:03')
|
35
|
+
assert_equal 1, tod.hour
|
36
|
+
assert_equal 2, tod.minute
|
37
|
+
assert_equal 3, tod.second
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_now
|
41
|
+
tod = TimeOfDay.now
|
42
|
+
assert tod.hour
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_parse
|
46
|
+
tod = TimeOfDay.parse('10:01')
|
47
|
+
assert_equal 10, tod.hour
|
48
|
+
assert_equal 1, tod.minute
|
49
|
+
assert_equal 0, tod.second
|
50
|
+
|
51
|
+
tod = TimeOfDay.parse('23:59:59')
|
52
|
+
assert_equal 23, tod.hour
|
53
|
+
assert_equal 59, tod.minute
|
54
|
+
assert_equal 59, tod.second
|
55
|
+
end
|
56
|
+
|
19
57
|
def test_parse_full
|
20
58
|
assert_equal @twelve_o_clock, TimeOfDay.parse('12:00:00')
|
21
59
|
end
|
@@ -43,10 +81,10 @@ class TimeOfDayTest < Minitest::Test
|
|
43
81
|
end
|
44
82
|
|
45
83
|
def test_activerecord
|
46
|
-
Event.create! name
|
47
|
-
t = Event.where(start_at
|
84
|
+
Event.create! :name => 'Bored meeting', :start_at => @twelve_o_clock
|
85
|
+
t = Event.where(:start_at => '12:00:00').first
|
48
86
|
assert_equal TimeOfDay, t.start_at.class
|
49
|
-
assert_equal t, Event.where(start_at
|
87
|
+
assert_equal t, Event.where(:start_at => @twelve_o_clock).first
|
50
88
|
assert_equal t, Event.where('start_at = ?', @twelve_o_clock).first
|
51
89
|
assert_equal t, Event.where('start_at >= ?', @twelve_o_clock).first
|
52
90
|
assert_equal t, Event.where('start_at <= ?', @twelve_o_clock).first
|
@@ -56,9 +94,9 @@ class TimeOfDayTest < Minitest::Test
|
|
56
94
|
|
57
95
|
# TODO(uwe): Simplify when we stop supporting ActiveRecord 3
|
58
96
|
if ActiveRecord::VERSION::MAJOR >= 4
|
59
|
-
t.update! start_at
|
97
|
+
t.update! :start_at => TimeOfDay.new(13)
|
60
98
|
else
|
61
|
-
t.update_attributes! start_at
|
99
|
+
t.update_attributes! :start_at => TimeOfDay.new(13)
|
62
100
|
end
|
63
101
|
# ODOT
|
64
102
|
|
@@ -67,17 +105,100 @@ class TimeOfDayTest < Minitest::Test
|
|
67
105
|
|
68
106
|
def test_activerecord_binary_column
|
69
107
|
text = 'Some binary content'
|
70
|
-
Event.create! content
|
71
|
-
e = Event.where(content
|
108
|
+
Event.create! :content => text
|
109
|
+
e = Event.where(:content => text).first
|
72
110
|
assert_equal text, e.content
|
73
111
|
|
74
112
|
# TODO(uwe): Simplify when we stop supporting ActiveRecord 3
|
75
113
|
if ActiveRecord::VERSION::MAJOR >= 4
|
76
|
-
e.update! content
|
114
|
+
e.update! :content => 'Other binary content'
|
77
115
|
else
|
78
|
-
e.update_attributes! content
|
116
|
+
e.update_attributes! :content => 'Other binary content'
|
79
117
|
end
|
80
118
|
# ODOT
|
81
119
|
end
|
82
120
|
|
121
|
+
def test_on
|
122
|
+
tod = TimeOfDay.new(12, 59)
|
123
|
+
assert_equal 12, tod.hour
|
124
|
+
assert_equal 59, tod.minute
|
125
|
+
|
126
|
+
t = tod.on(Date.new(2000, 12, 31))
|
127
|
+
assert_equal 12, t.hour
|
128
|
+
assert_equal 59, t.min
|
129
|
+
assert_equal 0, t.sec
|
130
|
+
assert_equal 2000, t.year
|
131
|
+
assert_equal 12, t.month
|
132
|
+
assert_equal 31, t.day
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_minus
|
136
|
+
tod = TimeOfDay.new(12, 0, 59)
|
137
|
+
tod -= 60
|
138
|
+
|
139
|
+
assert_equal 11, tod.hour
|
140
|
+
assert_equal 59, tod.minute
|
141
|
+
assert_equal 59, tod.second
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_equality
|
145
|
+
tod1 = TimeOfDay.new(12, 0, 5)
|
146
|
+
tod2 = TimeOfDay.new(12, 0, 5)
|
147
|
+
assert tod1 == tod2
|
148
|
+
tod2 -= 1
|
149
|
+
assert_equal false, tod1 == tod2
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_spaceship
|
153
|
+
tod1 = TimeOfDay.new(12, 0)
|
154
|
+
tod2 = TimeOfDay.new(13, 0)
|
155
|
+
assert_equal -1, tod1 <=> tod2
|
156
|
+
assert_equal 1, tod2 <=> tod1
|
157
|
+
assert_equal 0, tod1 <=> tod1
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_strftime
|
161
|
+
tod = TimeOfDay.new(6, 20, 59)
|
162
|
+
assert_equal '06:20:59', tod.strftime('%H:%M:%S')
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_to_s
|
166
|
+
tod = TimeOfDay.new(12, 13, 14)
|
167
|
+
assert_equal '12:13', tod.to_s(false)
|
168
|
+
assert_equal '12:13:14', tod.to_s(true)
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_to_yaml
|
172
|
+
tod = TimeOfDay.new(12, 13, 14)
|
173
|
+
assert_match /--- !!time '?12:13:14'?\n/, tod.to_yaml
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_date_at
|
177
|
+
tod = TimeOfDay.new(12, 13, 14)
|
178
|
+
d = Date.new(2000, 12, 31)
|
179
|
+
t = d.at(tod)
|
180
|
+
assert_equal 12, t.hour
|
181
|
+
assert_equal 13, t.min
|
182
|
+
assert_equal 14, t.sec
|
183
|
+
assert_equal 2000, t.year
|
184
|
+
assert_equal 12, t.month
|
185
|
+
assert_equal 31, t.day
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_date_at_string
|
189
|
+
tod = '12:13:14'
|
190
|
+
d = Date.new(2000, 12, 31)
|
191
|
+
t = d.at(tod)
|
192
|
+
assert_equal 12, t.hour
|
193
|
+
assert_equal 13, t.min
|
194
|
+
assert_equal 14, t.sec
|
195
|
+
assert_equal 2000, t.year
|
196
|
+
assert_equal 12, t.month
|
197
|
+
assert_equal 31, t.day
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_to_json
|
201
|
+
tod = TimeOfDay.new(12, 13)
|
202
|
+
assert_equal "\"12:13:00\"", tod.to_json('foo')
|
203
|
+
end
|
83
204
|
end
|
metadata
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uwe Kubosch
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: activerecord
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - ">="
|
@@ -20,8 +19,9 @@ dependencies:
|
|
20
19
|
- - "<"
|
21
20
|
- !ruby/object:Gem::Version
|
22
21
|
version: 5.0.0
|
23
|
-
|
22
|
+
name: activerecord
|
24
23
|
prerelease: false
|
24
|
+
type: :runtime
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
@@ -31,63 +31,76 @@ dependencies:
|
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 5.0.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name: pg
|
35
34
|
requirement: !ruby/object:Gem::Requirement
|
36
35
|
requirements:
|
37
36
|
- - ">="
|
38
37
|
- !ruby/object:Gem::Version
|
39
38
|
version: '0'
|
40
|
-
|
39
|
+
name: activerecord-jdbcpostgresql-adapter
|
41
40
|
prerelease: false
|
41
|
+
type: :development
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name: sqlite3
|
49
48
|
requirement: !ruby/object:Gem::Requirement
|
50
49
|
requirements:
|
51
50
|
- - ">="
|
52
51
|
- !ruby/object:Gem::Version
|
53
52
|
version: '0'
|
54
|
-
|
53
|
+
name: activerecord-jdbcsqlite3-adapter
|
55
54
|
prerelease: false
|
55
|
+
type: :development
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name: minitest-reporters
|
63
62
|
requirement: !ruby/object:Gem::Requirement
|
64
63
|
requirements:
|
65
64
|
- - ">="
|
66
65
|
- !ruby/object:Gem::Version
|
67
66
|
version: '0'
|
68
|
-
|
67
|
+
name: minitest-reporters
|
69
68
|
prerelease: false
|
69
|
+
type: :development
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name: rake
|
77
76
|
requirement: !ruby/object:Gem::Requirement
|
78
77
|
requirements:
|
79
78
|
- - ">="
|
80
79
|
- !ruby/object:Gem::Version
|
81
80
|
version: '0'
|
81
|
+
name: rake
|
82
|
+
prerelease: false
|
82
83
|
type: :development
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
name: simplecov
|
83
96
|
prerelease: false
|
97
|
+
type: :development
|
84
98
|
version_requirements: !ruby/object:Gem::Requirement
|
85
99
|
requirements:
|
86
100
|
- - ">="
|
87
101
|
- !ruby/object:Gem::Version
|
88
102
|
version: '0'
|
89
|
-
description: A handler for storing TimeOfDay objects in ActiveRecord objects as sql
|
90
|
-
time values.
|
103
|
+
description: A handler for storing TimeOfDay objects in ActiveRecord objects as sql time values.
|
91
104
|
email:
|
92
105
|
- uwe@kubosch.no
|
93
106
|
executables: []
|
@@ -125,7 +138,7 @@ homepage: https://github.com/donv/activerecord-time
|
|
125
138
|
licenses:
|
126
139
|
- MIT
|
127
140
|
metadata: {}
|
128
|
-
post_install_message:
|
141
|
+
post_install_message:
|
129
142
|
rdoc_options: []
|
130
143
|
require_paths:
|
131
144
|
- lib
|
@@ -140,12 +153,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
153
|
- !ruby/object:Gem::Version
|
141
154
|
version: '0'
|
142
155
|
requirements: []
|
143
|
-
rubyforge_project:
|
144
|
-
rubygems_version: 2.4.
|
145
|
-
signing_key:
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 2.4.8
|
158
|
+
signing_key:
|
146
159
|
specification_version: 4
|
147
|
-
summary: A handler for storing TimeOfDay objects in ActiveRecord objects as sql time
|
148
|
-
values.
|
160
|
+
summary: A handler for storing TimeOfDay objects in ActiveRecord objects as sql time values.
|
149
161
|
test_files:
|
150
162
|
- test/database.yml
|
151
163
|
- test/schema.rb
|