activerecord-time 0.3.14 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf7bd87897ba45fafd55442761573cbbf5c5ad12
4
- data.tar.gz: 2e432fb8826089f68847933383c00ec298d4cbca
3
+ metadata.gz: b1430418d53117b880e0f6f9ee19f76f11c79cfe
4
+ data.tar.gz: 738201de8e6cd4ca6e3c4b11213867df2cd9c91d
5
5
  SHA512:
6
- metadata.gz: 89ca7c611a9372e71d8f4ac65130a1d842d1a304b28afc2f942557cf6e73cfd92846cdd4aa416c13efe9c481936c42778a0fe6439dff30508fcb0f3cf59bcb81
7
- data.tar.gz: 711db65a5a4f5c75a8be62229a74251030054a65b5647230d0779077f867d10377dcf50a7b1a333f165eb7802c670dd1e70347716c918853c8a734a24eb33a29
6
+ metadata.gz: 8993938930022bbfbe9bc2fb388fafe090bd91113e7b7d34abe090c6419e1cdbc3db0264833701e291bd4ff32cec953653bfef8009fcdafb2c8d8d702ecf4a02
7
+ data.tar.gz: 887959d0d52c63ebc6d77500482dd9abc343892ea8ef57969a66cbc76e00b7bb89e92b63c4b4fff8197d066b1787a989e2bdd8c6b990830ab44374528e5770fe
data/.travis.yml CHANGED
@@ -1,8 +1,15 @@
1
1
  language: ruby
2
+ sudo: false
2
3
  rvm:
3
- - "1.9.3"
4
- - "2.0.0"
5
- - "2.1.5"
4
+ - jruby-head
6
5
  - ruby-head
6
+ - "2.2"
7
7
  - jruby-19mode
8
- - jruby-head
8
+ - "2.1"
9
+ - "2.0.0"
10
+ - "1.9.3"
11
+ env:
12
+ - AR_VERSION="~>4.2.1"
13
+ - AR_VERSION="~>4.1.10"
14
+ - AR_VERSION="~>4.0.13"
15
+ - AR_VERSION="~>3.2.21"
data/Gemfile CHANGED
@@ -2,3 +2,13 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in activerecord-time.gemspec
4
4
  gemspec
5
+
6
+ if ENV['AR_VERSION']
7
+ gem 'activerecord', ENV['AR_VERSION']
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.4.0.dev', github: 'jruby/activerecord-jdbc-adapter'
13
+ end
14
+ # ODOT
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
+ require 'bundler/setup'
2
3
  require 'bundler/gem_tasks'
3
4
  require 'rake/testtask'
4
5
 
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
20
  gem.require_paths = %w(lib)
21
21
 
22
- gem.add_runtime_dependency 'activerecord'
22
+ gem.add_runtime_dependency 'activerecord', '>=3.2.21', '<5.0.0'
23
23
 
24
24
  if defined? JRUBY_VERSION
25
25
  gem.add_development_dependency 'activerecord-jdbcpostgresql-adapter'
@@ -1,17 +1,14 @@
1
1
  require 'activerecord-time/version'
2
+ require 'active_record/version'
2
3
  require 'time_of_day'
3
- if defined?(JRUBY_VERSION)
4
- require 'activerecord-time/extension_arjdbc'
5
- else
6
- require 'activerecord-time/extension_mri'
7
- end
8
-
9
- module Arel
10
- module Visitors
11
- class Arel::Visitors::Visitor
12
- def visit_TimeOfDay o, a
13
- "'#{o.to_s(:db)}'"
14
- end
15
- end
16
- end
4
+ # TODO(uwe): Simplify when we stop supporing ActiveRecord 3.2
5
+ if ActiveRecord::VERSION::MAJOR < 3 ||
6
+ (ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR < 2)
7
+ raise 'activerecord-time only supports ActiveRecord 3.2.21 or later'
8
+ # TODO(uwe): Simplify when we stop supporing ActiveRecord 4.0 and 4.1
9
+ elsif ActiveRecord::VERSION::MAJOR == 3 ||
10
+ (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR <= 1)
11
+ require 'activerecord-time/extension_until_4_1'
12
+ elsif ActiveRecord.gem_version >= Gem::Version.new('4.2.0')
13
+ require 'activerecord-time/extension_4_2'
17
14
  end
@@ -0,0 +1,29 @@
1
+ require 'active_record/type/time'
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ module Quoting
6
+ def _quote_with_time_of_day(value)
7
+ return "'#{value}'" if TimeOfDay === value
8
+ _quote_without_time_of_day(value)
9
+ end
10
+ alias_method_chain :_quote, :time_of_day
11
+ def _type_cast_with_time_of_day(value)
12
+ return value.to_s if TimeOfDay === value
13
+ _type_cast_without_time_of_day(value)
14
+ end
15
+ alias_method_chain :_type_cast, :time_of_day
16
+ end
17
+ end
18
+ module Type
19
+ class Time < Value # :nodoc:
20
+ private
21
+ def cast_value(value)
22
+ return value.time_of_day if value.is_a?(::DateTime) || value.is_a?(::Time)
23
+ return value unless value.is_a?(::String)
24
+ return if value.empty?
25
+ TimeOfDay.parse value
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,53 @@
1
+ require 'active_record/connection_adapters/abstract/quoting'
2
+ require 'active_record/connection_adapters/sqlite3_adapter'
3
+
4
+ module ActiveRecord
5
+ module ConnectionAdapters
6
+ class Column
7
+ def klass_with_time_of_day
8
+ return TimeOfDay if :time === type
9
+ klass_without_time_of_day
10
+ end
11
+
12
+ alias_method_chain :klass, :time_of_day
13
+
14
+ def self.string_to_dummy_time(string)
15
+ return string if string.is_a? TimeOfDay
16
+ return string.time_of_day if string.is_a? ::Time
17
+ return nil if string.empty?
18
+ TimeOfDay.parse(string)
19
+ end
20
+ end
21
+ module Quoting
22
+ def quote_with_time_of_day(value, column = nil)
23
+ if column && column.type == :time && Integer === value
24
+ value = TimeOfDay.new(value / 3600, (value % 3600) / 60, value % 60)
25
+ end
26
+ return "'#{value.to_s(:db)}'" if TimeOfDay === value
27
+ quote_without_time_of_day(value, column)
28
+ end
29
+ alias_method_chain :quote, :time_of_day
30
+ def type_cast_with_time_of_day(value, column)
31
+ return value.to_s if TimeOfDay === value
32
+ type_cast_without_time_of_day(value, column)
33
+ end
34
+ alias_method_chain :type_cast, :time_of_day
35
+ end
36
+ end
37
+ end
38
+
39
+ module Arel
40
+ module Visitors
41
+ class Arel::Visitors::Visitor
42
+ if Gem::Version.new(Arel::VERSION) >= Gem::Version.new('5.0.0')
43
+ def visit_TimeOfDay o, a
44
+ "'#{o.to_s(:db)}'"
45
+ end
46
+ else
47
+ def visit_TimeOfDay o
48
+ "'#{o.to_s(:db)}'"
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,5 +1,5 @@
1
1
  module Activerecord
2
2
  module Time
3
- VERSION = '0.3.14'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
data/matrix_test.sh CHANGED
@@ -1,12 +1,19 @@
1
1
  #!/bin/bash -el
2
2
 
3
- echo
4
- rvm use ruby
5
- rake
6
-
7
- echo
8
- rvm use jruby
9
- rake
3
+ for rb in ruby jruby-head ; do
4
+ rvm use $rb
5
+ for AR_VERSION in "~>4.2.1" "~>4.1.10" "~>4.0.13" "~>3.2.21" ; do
6
+ export AR_VERSION
7
+ bundle update
8
+ for DB in postgresql sqlite3 ; do
9
+ export DB
10
+ echo
11
+ echo Testing $rb $DB $AR_VERSION
12
+ echo
13
+ bundle exec rake
14
+ done
15
+ done
16
+ done
10
17
 
11
18
  echo -e "\033[0;32m"
12
19
  echo -e " TESTS PASSED OK!"
data/test/database.yml CHANGED
@@ -7,13 +7,14 @@ sqlite3:
7
7
  :database: ":memory:"
8
8
  postgresql:
9
9
  :adapter: postgresql
10
+ :host: localhost
10
11
  :username: postgres
11
- :password: postgres
12
- :database: plugin_test
12
+ :password:
13
+ :database: activerecord-time_test
13
14
  :min_messages: ERROR
14
15
  mysql:
15
16
  :adapter: mysql
16
17
  :host: localhost
17
18
  :username: rails
18
19
  :password:
19
- :database: plugin_test
20
+ :database: activerecord-time_test
data/test/test_helper.rb CHANGED
@@ -15,5 +15,19 @@ require 'fileutils'
15
15
  FileUtils.rm_rf File.expand_path(':memory:', File.dirname(__FILE__))
16
16
  config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
17
17
  ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/test.log')
18
- ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
18
+ db = ENV['DB'] || 'sqlite3'
19
+ if db != 'sqlite3'
20
+ ActiveRecord::Base.establish_connection config[db].merge(database: nil)
21
+ begin
22
+ ActiveRecord::Base.connection.drop_database config[db][:database]
23
+ rescue
24
+ puts $!
25
+ end
26
+ begin
27
+ ActiveRecord::Base.connection.create_database config[db][:database], charset: 'utf8'
28
+ rescue
29
+ puts $!
30
+ end
31
+ end
32
+ ActiveRecord::Base.establish_connection config[db]
19
33
  load(File.dirname(__FILE__) + '/schema.rb') if File.exist?(File.dirname(__FILE__) + '/schema.rb')
@@ -3,6 +3,10 @@ require File.expand_path('test_helper', File.dirname(__FILE__))
3
3
  class Event < ActiveRecord::Base
4
4
  end
5
5
 
6
+ # TODO(uwe): Remove when we stop testing ActiveRecord 4.0
7
+ MiniTest::Test = Minitest::Unit unless defined? Minitest::Test
8
+ # ODOT
9
+
6
10
  class TimeOfDayTest < Minitest::Test
7
11
  def setup
8
12
  @twelve_o_clock = TimeOfDay.parse '12:00:00'
@@ -34,9 +38,14 @@ class TimeOfDayTest < Minitest::Test
34
38
  assert_match /---\nstart_at: !!time '?12:34:56'?\n/, string
35
39
  end
36
40
 
41
+ def test_column_type
42
+ assert_equal [:integer, :string, :time], Event.columns.map(&:type)
43
+ end
44
+
37
45
  def test_activerecord
38
46
  Event.create! name: 'Bored meeting', start_at: @twelve_o_clock
39
47
  t = Event.where(start_at: '12:00:00').first
48
+ assert_equal TimeOfDay, t.start_at.class
40
49
  assert_equal t, Event.where(start_at: @twelve_o_clock).first
41
50
  assert_equal t, Event.where('start_at = ?', @twelve_o_clock).first
42
51
  assert_equal t, Event.where('start_at >= ?', @twelve_o_clock).first
@@ -45,7 +54,14 @@ class TimeOfDayTest < Minitest::Test
45
54
  assert_nil Event.where('start_at < ?', @twelve_o_clock).first
46
55
  assert_nil Event.where('start_at > ?', @twelve_o_clock).first
47
56
 
48
- t.update! start_at: TimeOfDay.new(13)
57
+ # TODO(uwe): Simplify when we stop supporting ActiveRecord 3
58
+ if ActiveRecord::VERSION::MAJOR >= 4
59
+ t.update! start_at: TimeOfDay.new(13)
60
+ else
61
+ t.update_attributes! start_at: TimeOfDay.new(13)
62
+ end
63
+ # ODOT
64
+
49
65
  t.destroy
50
66
  end
51
67
 
metadata CHANGED
@@ -1,94 +1,101 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-time
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.4.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: 2014-12-11 00:00:00.000000000 Z
11
+ date: 2015-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: activerecord
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
- - - '>='
17
+ - - ">="
17
18
  - !ruby/object:Gem::Version
18
- version: '0'
19
- name: activerecord
20
- prerelease: false
19
+ version: 3.2.21
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 5.0.0
21
23
  type: :runtime
24
+ prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - '>='
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '0'
29
+ version: 3.2.21
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 5.0.0
27
33
  - !ruby/object:Gem::Dependency
34
+ name: pg
28
35
  requirement: !ruby/object:Gem::Requirement
29
36
  requirements:
30
- - - '>='
37
+ - - ">="
31
38
  - !ruby/object:Gem::Version
32
39
  version: '0'
33
- name: activerecord-jdbcpostgresql-adapter
34
- prerelease: false
35
40
  type: :development
41
+ prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - '>='
44
+ - - ">="
39
45
  - !ruby/object:Gem::Version
40
46
  version: '0'
41
47
  - !ruby/object:Gem::Dependency
48
+ name: sqlite3
42
49
  requirement: !ruby/object:Gem::Requirement
43
50
  requirements:
44
- - - '>='
51
+ - - ">="
45
52
  - !ruby/object:Gem::Version
46
53
  version: '0'
47
- name: activerecord-jdbcsqlite3-adapter
48
- prerelease: false
49
54
  type: :development
55
+ prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - '>='
58
+ - - ">="
53
59
  - !ruby/object:Gem::Version
54
60
  version: '0'
55
61
  - !ruby/object:Gem::Dependency
62
+ name: minitest-reporters
56
63
  requirement: !ruby/object:Gem::Requirement
57
64
  requirements:
58
- - - '>='
65
+ - - ">="
59
66
  - !ruby/object:Gem::Version
60
67
  version: '0'
61
- name: minitest-reporters
62
- prerelease: false
63
68
  type: :development
69
+ prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
- - - '>='
72
+ - - ">="
67
73
  - !ruby/object:Gem::Version
68
74
  version: '0'
69
75
  - !ruby/object:Gem::Dependency
76
+ name: rake
70
77
  requirement: !ruby/object:Gem::Requirement
71
78
  requirements:
72
- - - '>='
79
+ - - ">="
73
80
  - !ruby/object:Gem::Version
74
81
  version: '0'
75
- name: rake
76
- prerelease: false
77
82
  type: :development
83
+ prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
- - - '>='
86
+ - - ">="
81
87
  - !ruby/object:Gem::Version
82
88
  version: '0'
83
- description: A handler for storing TimeOfDay objects in ActiveRecord objects as sql time values.
89
+ description: A handler for storing TimeOfDay objects in ActiveRecord objects as sql
90
+ time values.
84
91
  email:
85
92
  - uwe@kubosch.no
86
93
  executables: []
87
94
  extensions: []
88
95
  extra_rdoc_files: []
89
96
  files:
90
- - .gitignore
91
- - .travis.yml
97
+ - ".gitignore"
98
+ - ".travis.yml"
92
99
  - Gemfile
93
100
  - LICENSE
94
101
  - LICENSE.txt
@@ -96,8 +103,8 @@ files:
96
103
  - Rakefile
97
104
  - activerecord-time.gemspec
98
105
  - lib/activerecord-time.rb
99
- - lib/activerecord-time/extension_arjdbc.rb
100
- - lib/activerecord-time/extension_mri.rb
106
+ - lib/activerecord-time/extension_4_2.rb
107
+ - lib/activerecord-time/extension_until_4_1.rb
101
108
  - lib/activerecord-time/version.rb
102
109
  - lib/time_of_day.rb
103
110
  - matrix_test.sh
@@ -109,26 +116,27 @@ homepage: https://github.com/donv/activerecord-time
109
116
  licenses:
110
117
  - MIT
111
118
  metadata: {}
112
- post_install_message:
119
+ post_install_message:
113
120
  rdoc_options: []
114
121
  require_paths:
115
122
  - lib
116
123
  required_ruby_version: !ruby/object:Gem::Requirement
117
124
  requirements:
118
- - - '>='
125
+ - - ">="
119
126
  - !ruby/object:Gem::Version
120
127
  version: 1.9.3
121
128
  required_rubygems_version: !ruby/object:Gem::Requirement
122
129
  requirements:
123
- - - '>='
130
+ - - ">="
124
131
  - !ruby/object:Gem::Version
125
132
  version: '0'
126
133
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.1.9
129
- signing_key:
134
+ rubyforge_project:
135
+ rubygems_version: 2.4.6
136
+ signing_key:
130
137
  specification_version: 4
131
- summary: A handler for storing TimeOfDay objects in ActiveRecord objects as sql time values.
138
+ summary: A handler for storing TimeOfDay objects in ActiveRecord objects as sql time
139
+ values.
132
140
  test_files:
133
141
  - test/database.yml
134
142
  - test/schema.rb
@@ -1,30 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- class Column
4
- def klass_with_time_of_day
5
- return TimeOfDay if :time === type
6
- klass_without_time_of_day
7
- end
8
-
9
- alias_method_chain :klass, :time_of_day
10
-
11
- def self.string_to_dummy_time(string)
12
- return string if string.is_a? TimeOfDay
13
- return nil if string.empty?
14
- TimeOfDay.parse(string)
15
- end
16
- end
17
- module Quoting
18
- def quote_with_time_of_day(value, column = nil)
19
- return "'#{quoted_time(value)}'" if TimeOfDay === value
20
- quote_without_time_of_day(value, column)
21
- end
22
-
23
- alias_method_chain :quote, :time_of_day
24
-
25
- def quoted_time(value)
26
- value.to_s
27
- end
28
- end
29
- end
30
- end
@@ -1,25 +0,0 @@
1
- require 'active_record/connection_adapters/abstract/quoting'
2
-
3
- module ActiveRecord
4
- module ConnectionAdapters # :nodoc:
5
- module Quoting
6
- def type_cast_with_time_of_day(value, column)
7
- return value.to_s if TimeOfDay === value
8
- type_cast_without_time_of_day(value, column)
9
- end
10
-
11
- alias_method_chain :type_cast, :time_of_day
12
-
13
- def quote_with_time_of_day(value, column = nil)
14
- if column && column.type == :time && Integer === value
15
- value = TimeOfDay.new(value / 3600, (value % 3600) / 60, value % 60)
16
- end
17
- return "'#{value.to_s(:db)}'" if TimeOfDay === value
18
- quote_without_time_of_day(value, column)
19
- end
20
-
21
- alias_method_chain :quote, :time_of_day
22
-
23
- end
24
- end
25
- end