activerecord-time 0.10.1 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +23 -14
- data/.rubocop_todo.yml +81 -14
- data/.travis.yml +17 -31
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/activerecord-time.gemspec +10 -2
- data/gemfiles/ar51.gemfile +0 -1
- data/gemfiles/ar51.gemfile.lock +35 -43
- data/gemfiles/ar52.gemfile +0 -2
- data/gemfiles/ar52.gemfile.lock +36 -19
- data/gemfiles/{ar42.gemfile → ar60.gemfile} +1 -1
- data/gemfiles/{ar50.gemfile.lock → ar60.gemfile.lock} +31 -32
- data/gemfiles/{ar50.gemfile → ar61.gemfile} +1 -1
- data/gemfiles/common.gemfile +1 -1
- data/lib/activerecord-time.rb +3 -16
- data/lib/activerecord-time/{extension_5_0.rb → extension.rb} +5 -0
- data/lib/activerecord-time/version.rb +3 -1
- data/lib/time_of_day.rb +45 -2
- data/lib/time_of_day/core_ext.rb +9 -0
- data/matrix_test.rb +19 -5
- data/test/database.yml +0 -17
- data/test/schema.rb +2 -0
- data/test/test_helper.rb +6 -2
- data/test/time_of_day_test.rb +23 -22
- metadata +57 -19
- data/gemfiles/ar42.gemfile.lock +0 -77
- data/lib/activerecord-time/extension_4_2.rb +0 -31
- data/lib/activerecord-time/extension_until_4_1.rb +0 -71
data/test/database.yml
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
sqlite:
|
2
|
-
:adapter: sqlite
|
3
|
-
:dbfile: plugin.sqlite.db
|
4
1
|
sqlite3:
|
5
2
|
:adapter: sqlite3
|
6
3
|
:dbfile: ":memory:"
|
@@ -12,17 +9,3 @@ postgresql:
|
|
12
9
|
:password:
|
13
10
|
:database: activerecord-time_test
|
14
11
|
:min_messages: ERROR
|
15
|
-
mysql:
|
16
|
-
:adapter: mysql
|
17
|
-
:host: localhost
|
18
|
-
:username: rails
|
19
|
-
:password:
|
20
|
-
:database: activerecord-time_test
|
21
|
-
derby:
|
22
|
-
:adapter: derby
|
23
|
-
:driver: org.apache.derby.jdbc.EmbeddedDriver
|
24
|
-
:url: jdbc:derby:activerecord-time_test-derby;user=derby;create=true",
|
25
|
-
:username: derby
|
26
|
-
:pool: 50
|
27
|
-
:transaction_isolation: false
|
28
|
-
:database: activerecord-time_test-derby
|
data/test/schema.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
2
4
|
RAILS_ROOT = File.dirname(__FILE__)
|
3
5
|
|
@@ -13,8 +15,10 @@ require 'logger'
|
|
13
15
|
require 'fileutils'
|
14
16
|
require 'yaml'
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
+
if defined?(Rake) && (RUBY_ENGINE != 'jruby' || org.jruby.RubyInstanceConfig.FULL_TRACE_ENABLED)
|
19
|
+
require 'simplecov'
|
20
|
+
SimpleCov.start
|
21
|
+
end
|
18
22
|
|
19
23
|
FileUtils.rm_rf File.expand_path(':memory:', File.dirname(__FILE__))
|
20
24
|
config = YAML.load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
data/test/time_of_day_test.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
4
|
|
3
5
|
class ApplicationRecord < ActiveRecord::Base
|
4
6
|
self.abstract_class = true
|
5
7
|
end
|
8
|
+
|
6
9
|
class Event < ApplicationRecord
|
7
10
|
end
|
8
11
|
|
9
|
-
# TODO(uwe): Remove when we stop testing ActiveRecord 4.0
|
10
|
-
Minitest::Test = Minitest::Unit unless defined? Minitest::Test
|
11
|
-
# ODOT
|
12
|
-
|
13
12
|
class TimeOfDayTest < Minitest::Test
|
14
13
|
def setup
|
15
14
|
@twelve_o_clock = TimeOfDay.parse '12:00:00'
|
@@ -58,12 +57,12 @@ class TimeOfDayTest < Minitest::Test
|
|
58
57
|
end
|
59
58
|
|
60
59
|
def test_parse_immutable_string
|
61
|
-
tod = TimeOfDay.parse('10:01'
|
60
|
+
tod = TimeOfDay.parse('10:01')
|
62
61
|
assert_equal 10, tod.hour
|
63
62
|
assert_equal 1, tod.minute
|
64
63
|
assert_equal 0, tod.second
|
65
64
|
|
66
|
-
tod = TimeOfDay.parse('23:59:59'
|
65
|
+
tod = TimeOfDay.parse('23:59:59')
|
67
66
|
assert_equal 23, tod.hour
|
68
67
|
assert_equal 59, tod.minute
|
69
68
|
assert_equal 59, tod.second
|
@@ -107,14 +106,7 @@ class TimeOfDayTest < Minitest::Test
|
|
107
106
|
assert_nil Event.where('start_at < ?', @twelve_o_clock).first
|
108
107
|
assert_nil Event.where('start_at > ?', @twelve_o_clock).first
|
109
108
|
|
110
|
-
|
111
|
-
if ActiveRecord::VERSION::MAJOR >= 4
|
112
|
-
t.update! start_at: TimeOfDay.new(13)
|
113
|
-
else
|
114
|
-
t.update_attributes! start_at: TimeOfDay.new(13)
|
115
|
-
end
|
116
|
-
# ODOT
|
117
|
-
|
109
|
+
t.update! start_at: TimeOfDay.new(13)
|
118
110
|
t.destroy
|
119
111
|
end
|
120
112
|
|
@@ -124,13 +116,7 @@ class TimeOfDayTest < Minitest::Test
|
|
124
116
|
e = Event.where(content: text).first
|
125
117
|
assert_equal text, e.content
|
126
118
|
|
127
|
-
|
128
|
-
if ActiveRecord::VERSION::MAJOR >= 4
|
129
|
-
e.update! content: 'Other binary content'
|
130
|
-
else
|
131
|
-
e.update_attributes! content: 'Other binary content'
|
132
|
-
end
|
133
|
-
# ODOT
|
119
|
+
e.update! content: 'Other binary content'
|
134
120
|
end
|
135
121
|
|
136
122
|
def test_on
|
@@ -169,7 +155,7 @@ class TimeOfDayTest < Minitest::Test
|
|
169
155
|
tod2 = TimeOfDay.new(13, 0)
|
170
156
|
assert_equal(-1, tod1 <=> tod2)
|
171
157
|
assert_equal 1, tod2 <=> tod1
|
172
|
-
assert_equal 0, tod1 <=> tod1
|
158
|
+
assert_equal 0, tod1 <=> tod1
|
173
159
|
end
|
174
160
|
|
175
161
|
def test_strftime
|
@@ -216,4 +202,19 @@ class TimeOfDayTest < Minitest::Test
|
|
216
202
|
tod = TimeOfDay.new(12, 13)
|
217
203
|
assert_equal '"12:13:00"', tod.to_json('foo')
|
218
204
|
end
|
205
|
+
|
206
|
+
def test_eql?
|
207
|
+
a = TimeOfDay.new(10, 11, 12)
|
208
|
+
b = TimeOfDay.new(10, 11, 12)
|
209
|
+
assert a.eql?(b)
|
210
|
+
assert_equal a.hash, b.hash
|
211
|
+
hashmap = {}
|
212
|
+
hashmap[a] = 'foo'
|
213
|
+
hashmap[b] = 'bar'
|
214
|
+
assert_equal hashmap, TimeOfDay.new(10, 11, 12) => 'bar'
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_inspect
|
218
|
+
assert_equal '#<TimeOfDay hour=10, minute=11, second=12>', TimeOfDay.new(10, 11, 12).inspect
|
219
|
+
end
|
219
220
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.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:
|
11
|
+
date: 2021-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.1'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '7'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '5.1'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '7'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: pg
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,6 +100,48 @@ dependencies:
|
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rubocop-performance
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: rubocop-rails
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: rubocop-rake
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
103
145
|
- !ruby/object:Gem::Dependency
|
104
146
|
name: simplecov
|
105
147
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,19 +174,16 @@ files:
|
|
132
174
|
- README.md
|
133
175
|
- Rakefile
|
134
176
|
- activerecord-time.gemspec
|
135
|
-
- gemfiles/ar42.gemfile
|
136
|
-
- gemfiles/ar42.gemfile.lock
|
137
|
-
- gemfiles/ar50.gemfile
|
138
|
-
- gemfiles/ar50.gemfile.lock
|
139
177
|
- gemfiles/ar51.gemfile
|
140
178
|
- gemfiles/ar51.gemfile.lock
|
141
179
|
- gemfiles/ar52.gemfile
|
142
180
|
- gemfiles/ar52.gemfile.lock
|
181
|
+
- gemfiles/ar60.gemfile
|
182
|
+
- gemfiles/ar60.gemfile.lock
|
183
|
+
- gemfiles/ar61.gemfile
|
143
184
|
- gemfiles/common.gemfile
|
144
185
|
- lib/activerecord-time.rb
|
145
|
-
- lib/activerecord-time/
|
146
|
-
- lib/activerecord-time/extension_5_0.rb
|
147
|
-
- lib/activerecord-time/extension_until_4_1.rb
|
186
|
+
- lib/activerecord-time/extension.rb
|
148
187
|
- lib/activerecord-time/version.rb
|
149
188
|
- lib/time_of_day.rb
|
150
189
|
- lib/time_of_day/core_ext.rb
|
@@ -157,7 +196,7 @@ homepage: https://github.com/donv/activerecord-time
|
|
157
196
|
licenses:
|
158
197
|
- MIT
|
159
198
|
metadata: {}
|
160
|
-
post_install_message:
|
199
|
+
post_install_message:
|
161
200
|
rdoc_options: []
|
162
201
|
require_paths:
|
163
202
|
- lib
|
@@ -165,16 +204,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
204
|
requirements:
|
166
205
|
- - ">="
|
167
206
|
- !ruby/object:Gem::Version
|
168
|
-
version: '2.
|
207
|
+
version: '2.5'
|
169
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
209
|
requirements:
|
171
210
|
- - ">="
|
172
211
|
- !ruby/object:Gem::Version
|
173
212
|
version: '0'
|
174
213
|
requirements: []
|
175
|
-
|
176
|
-
|
177
|
-
signing_key:
|
214
|
+
rubygems_version: 3.2.3
|
215
|
+
signing_key:
|
178
216
|
specification_version: 4
|
179
217
|
summary: A handler for storing TimeOfDay objects in ActiveRecord objects as sql time
|
180
218
|
values.
|
data/gemfiles/ar42.gemfile.lock
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
activemodel (4.2.10)
|
5
|
-
activesupport (= 4.2.10)
|
6
|
-
builder (~> 3.1)
|
7
|
-
activerecord (4.2.10)
|
8
|
-
activemodel (= 4.2.10)
|
9
|
-
activesupport (= 4.2.10)
|
10
|
-
arel (~> 6.0)
|
11
|
-
activerecord-jdbc-adapter (50.0)
|
12
|
-
activerecord (>= 2.2)
|
13
|
-
activerecord-jdbcderby-adapter (0.8.2)
|
14
|
-
activerecord-jdbc-adapter (>= 0.8.2)
|
15
|
-
jdbc-derby (>= 10.3.2.1)
|
16
|
-
activerecord-jdbcpostgresql-adapter (50.0)
|
17
|
-
activerecord-jdbc-adapter (~> 50.0)
|
18
|
-
jdbc-postgres (>= 9.4, < 43)
|
19
|
-
activerecord-jdbcsqlite3-adapter (50.0)
|
20
|
-
activerecord-jdbc-adapter (~> 50.0)
|
21
|
-
jdbc-sqlite3 (~> 3.8, < 3.30)
|
22
|
-
activesupport (4.2.10)
|
23
|
-
i18n (~> 0.7)
|
24
|
-
minitest (~> 5.1)
|
25
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
26
|
-
tzinfo (~> 1.1)
|
27
|
-
ansi (1.5.0)
|
28
|
-
arel (6.0.4)
|
29
|
-
builder (3.2.3)
|
30
|
-
concurrent-ruby (1.0.5)
|
31
|
-
concurrent-ruby (1.0.5-java)
|
32
|
-
docile (1.3.0)
|
33
|
-
i18n (0.9.5)
|
34
|
-
concurrent-ruby (~> 1.0)
|
35
|
-
jdbc-derby (10.12.1.1)
|
36
|
-
jdbc-postgres (42.1.4)
|
37
|
-
jdbc-sqlite3 (3.20.1)
|
38
|
-
json (2.1.0)
|
39
|
-
json (2.1.0-java)
|
40
|
-
minitest (5.10.3)
|
41
|
-
minitest-reporters (1.2.0)
|
42
|
-
ansi
|
43
|
-
builder
|
44
|
-
minitest (>= 5.0)
|
45
|
-
ruby-progressbar
|
46
|
-
pg (0.21.0)
|
47
|
-
rake (12.3.1)
|
48
|
-
ruby-progressbar (1.9.0)
|
49
|
-
simplecov (0.16.1)
|
50
|
-
docile (~> 1.1)
|
51
|
-
json (>= 1.8, < 3)
|
52
|
-
simplecov-html (~> 0.10.0)
|
53
|
-
simplecov-html (0.10.2)
|
54
|
-
sqlite3 (1.3.13)
|
55
|
-
thread_safe (0.3.6)
|
56
|
-
thread_safe (0.3.6-java)
|
57
|
-
tzinfo (1.2.5)
|
58
|
-
thread_safe (~> 0.1)
|
59
|
-
|
60
|
-
PLATFORMS
|
61
|
-
java
|
62
|
-
ruby
|
63
|
-
|
64
|
-
DEPENDENCIES
|
65
|
-
activerecord (~> 4.2.3)
|
66
|
-
activerecord-jdbc-adapter
|
67
|
-
activerecord-jdbcderby-adapter
|
68
|
-
activerecord-jdbcpostgresql-adapter
|
69
|
-
activerecord-jdbcsqlite3-adapter
|
70
|
-
minitest-reporters
|
71
|
-
pg (< 1)
|
72
|
-
rake
|
73
|
-
simplecov
|
74
|
-
sqlite3
|
75
|
-
|
76
|
-
BUNDLED WITH
|
77
|
-
1.16.1
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters
|
3
|
-
module Quoting
|
4
|
-
def _quote_with_time_of_day(value)
|
5
|
-
return "'#{value}'" if value.is_a?(TimeOfDay)
|
6
|
-
_quote_without_time_of_day(value)
|
7
|
-
end
|
8
|
-
alias_method_chain :_quote, :time_of_day
|
9
|
-
def _type_cast_with_time_of_day(value)
|
10
|
-
return value.to_s if value.is_a?(TimeOfDay)
|
11
|
-
_type_cast_without_time_of_day(value)
|
12
|
-
end
|
13
|
-
alias_method_chain :_type_cast, :time_of_day
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
module Activerecord
|
18
|
-
module Time
|
19
|
-
module TypeCast
|
20
|
-
private
|
21
|
-
|
22
|
-
def cast_value(value)
|
23
|
-
return value.time_of_day if value.is_a?(::DateTime) || value.is_a?(::Time)
|
24
|
-
return value unless value.is_a?(::String)
|
25
|
-
return if value.empty?
|
26
|
-
TimeOfDay.parse value
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
ActiveRecord::Type::Time.prepend Activerecord::Time::TypeCast
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'active_record/connection_adapters/abstract/quoting'
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module ConnectionAdapters
|
5
|
-
module Quoting
|
6
|
-
def quote_with_time_of_day(value, column = nil)
|
7
|
-
if column && column.type == :time && value.is_a?(Integer)
|
8
|
-
value = TimeOfDay.new(value / 3600, (value % 3600) / 60, value % 60)
|
9
|
-
end
|
10
|
-
return "'#{value.to_s(:db)}'" if value.is_a?(TimeOfDay)
|
11
|
-
quote_without_time_of_day(value, column)
|
12
|
-
end
|
13
|
-
|
14
|
-
alias_method_chain :quote, :time_of_day
|
15
|
-
|
16
|
-
def type_cast_with_time_of_day(value, column)
|
17
|
-
return value.to_s if value.is_a?(TimeOfDay)
|
18
|
-
type_cast_without_time_of_day(value, column)
|
19
|
-
end
|
20
|
-
|
21
|
-
alias_method_chain :type_cast, :time_of_day
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
module Activerecord
|
27
|
-
module Time
|
28
|
-
module DummyTime
|
29
|
-
def klass
|
30
|
-
return TimeOfDay if type == :time
|
31
|
-
super
|
32
|
-
end
|
33
|
-
|
34
|
-
module ClassMethods
|
35
|
-
def string_to_dummy_time(value)
|
36
|
-
return value if value.is_a? TimeOfDay
|
37
|
-
return value.time_of_day if value.is_a? ::Time
|
38
|
-
return nil if value.empty?
|
39
|
-
TimeOfDay.parse(value)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.prepended(base)
|
44
|
-
class << base
|
45
|
-
prepend ClassMethods
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
ActiveRecord::ConnectionAdapters::Column.prepend Activerecord::Time::DummyTime
|
53
|
-
|
54
|
-
module Arel
|
55
|
-
module Visitors
|
56
|
-
class Visitor
|
57
|
-
# rubocop: disable Naming/MethodName
|
58
|
-
# TODO(uwe): Simplify when we stop support for AR < 5
|
59
|
-
if Gem::Version.new(Arel::VERSION) >= Gem::Version.new('5.0.0')
|
60
|
-
def visit_TimeOfDay(object, _collector)
|
61
|
-
"'#{object.to_s(:db)}'"
|
62
|
-
end
|
63
|
-
else
|
64
|
-
def visit_TimeOfDay(object)
|
65
|
-
"'#{object.to_s(:db)}'"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
# rubocop: enable Naming/MethodName
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|