Skip to content

Commit 97478f7

Browse files
committed
Update Active Record and Ruby requirements
1 parent 12b04af commit 97478f7

File tree

6 files changed

+51
-176
lines changed

6 files changed

+51
-176
lines changed

.travis.yml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,33 @@
1+
sudo: false
12
language: ruby
3+
cache: bundler
24

35
before_install:
46
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
57
- gem install bundler -v '< 2'
68

79
rvm:
8-
- 2.3.8
9-
- 2.4.6
10-
- 2.5.5
11-
- 2.6.2
10+
- "2.5"
11+
- "2.6"
1212
gemfile:
13-
- gemfiles/Gemfile.ar-4.2
14-
- gemfiles/Gemfile.ar-5.0
15-
- gemfiles/Gemfile.ar-5.1
1613
- gemfiles/Gemfile.ar-5.2
14+
- gemfiles/Gemfile.ar-6.0
1715
- gemfiles/Gemfile.ar-master
1816

1917
env:
20-
- TIMEZONE_AWARE=1 POSTGRES=1 MYSQL=1
21-
- TIMEZONE_AWARE=0 POSTGRES=1 MYSQL=1
22-
- TIMEZONE_AWARE=1 POSTGRES=1 POSTGRES_JSON=1
23-
- TIMEZONE_AWARE=0 POSTGRES=1 POSTGRES_JSON=1
18+
- TIMEZONE_AWARE=1 POSTGRES=1 MYSQL=1 POSTGRES_JSON=1
19+
- TIMEZONE_AWARE=0 POSTGRES=1 MYSQL=1 POSTGRES_JSON=1
2420

2521
matrix:
2622
exclude:
27-
- rvm: 2.3.8
28-
gemfile: 'gemfiles/Gemfile.ar-master'
29-
- rvm: 2.4.6
23+
- rvm: "2.6"
24+
gemfile: 'gemfiles/Gemfile.6-0'
25+
- rvm: "2.6"
3026
gemfile: 'gemfiles/Gemfile.ar-master'
3127

32-
addons:
33-
postgresql: 9.3
34-
35-
sudo: false
36-
cache: bundler
28+
services:
29+
- mysql
30+
- postgresql
3731

3832
before_script:
3933
- mysql -e 'create database typed_store_test;'

activerecord-typedstore.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
1818
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
1919
spec.require_paths = ['lib']
2020

21-
spec.add_dependency 'activerecord', '>= 4.2'
21+
spec.add_dependency 'activerecord', '>= 5.2'
2222

2323
spec.add_development_dependency 'bundler'
2424
spec.add_development_dependency 'rake', '~> 10'

gemfiles/Gemfile.ar-4.2

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
22

33
gemspec path: '..'
44

5-
gem 'activerecord', '~> 5.1.0'
5+
gem 'activerecord', '~> 6.0.0'

spec/active_record/typed_store_spec.rb

Lines changed: 29 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,11 @@
7070
}.to change { !!model.age_changed? }.from(true).to(false)
7171
end
7272

73-
if AR_VERSION >= AR_4_2
74-
it 'can be restored individually' do
75-
model.age = 24
76-
expect {
77-
model.restore_age!
78-
}.to change { model.age }.from(24).to(12)
79-
end
80-
else
81-
it 'can be reset individually' do
82-
model.age = 24
83-
expect {
84-
model.reset_age!
85-
}.to change { model.age }.from(24).to(12)
86-
end
73+
it 'can be restored individually' do
74+
model.age = 24
75+
expect {
76+
model.restore_age!
77+
}.to change { model.age }.from(24).to(12)
8778
end
8879

8980
it 'does not dirty track assigning the same boolean' do
@@ -432,48 +423,26 @@
432423
let(:time) { time_string.respond_to?(:in_time_zone) ? time_string.in_time_zone : Time.parse(time_string) }
433424

434425
context "with ActiveRecord #{ActiveRecord::VERSION::STRING}" do
435-
if AR_VERSION < AR_4_0
436-
it 'has the defined default as initial value' do
437-
model.save
438-
expect(model.published_at).to be == time
439-
end
426+
it 'has the defined default as initial value' do
427+
model.save
428+
expect(model.reload.published_at).to be == time
429+
end
440430

431+
it 'retreive a time instance' do
432+
model.update(published_at: time)
433+
expect(model.reload.published_at).to be == time
434+
end
435+
436+
if ActiveRecord::Base.time_zone_aware_attributes
441437
it 'properly cast assigned value to time' do
442438
model.remind_at = time_string
443439
expect(model.remind_at).to be == time
444440
end
445-
it 'properly cast assigned value to time on save' do
441+
else
442+
it 'properly cast assigned value to time' do
446443
model.remind_at = time_string
447-
model.save
448-
model.reload
449444
expect(model.remind_at).to be == time
450445
end
451-
it 'retreive a Time instance' do
452-
model.update(published_at: time)
453-
expect(model.reload.published_at).to be == time
454-
end
455-
else
456-
it 'has the defined default as initial value' do
457-
model.save
458-
expect(model.reload.published_at).to be == time
459-
end
460-
461-
it 'retreive a time instance' do
462-
model.update(published_at: time)
463-
expect(model.reload.published_at).to be == time
464-
end
465-
466-
if ActiveRecord::Base.time_zone_aware_attributes
467-
it 'properly cast assigned value to time' do
468-
model.remind_at = time_string
469-
expect(model.remind_at).to be == time
470-
end
471-
else
472-
it 'properly cast assigned value to time' do
473-
model.remind_at = time_string
474-
expect(model.remind_at).to be == time
475-
end
476-
end
477446
end
478447
end
479448
end
@@ -485,61 +454,27 @@
485454
let(:time) { datetime_string.respond_to?(:in_time_zone) ? datetime_string.in_time_zone : Time.parse(datetime_string) }
486455

487456
context "with ActiveRecord #{ActiveRecord::VERSION::STRING}" do
457+
it 'has the defined default as initial value' do
458+
model.save
459+
expect(model.reload.published_at).to be == datetime
460+
end
488461

489-
if AR_VERSION < AR_4_0
490-
491-
it 'has the defined default as initial value' do
492-
model.save
493-
expect(model.published_at).to be == time
494-
end
462+
it 'retreive a DateTime instance' do
463+
model.update(published_at: datetime)
464+
expect(model.reload.published_at).to be == datetime
465+
end
495466

467+
if ActiveRecord::Base.time_zone_aware_attributes
496468
it 'properly cast assigned value to time' do
497469
model.remind_at = datetime_string
498470
expect(model.remind_at).to be == time
499471
end
500-
501-
it 'properly cast assigned value to time on save' do
502-
model.remind_at = datetime_string
503-
model.save
504-
model.reload
505-
expect(model.remind_at).to be == time
506-
end
507-
508-
it 'retreive a Time instance' do
509-
model.update(published_at: datetime)
510-
expect(model.reload.published_at).to be == time
511-
end
512-
513472
else
514-
515-
it 'has the defined default as initial value' do
516-
model.save
517-
expect(model.reload.published_at).to be == datetime
518-
end
519-
520-
it 'retreive a DateTime instance' do
521-
model.update(published_at: datetime)
522-
expect(model.reload.published_at).to be == datetime
523-
end
524-
525-
if ActiveRecord::Base.time_zone_aware_attributes
526-
527-
it 'properly cast assigned value to time' do
528-
model.remind_at = datetime_string
529-
expect(model.remind_at).to be == time
530-
end
531-
532-
else
533-
534-
it 'properly cast assigned value to datetime' do
535-
model.remind_at = datetime_string
536-
expect(model.remind_at).to be == datetime
537-
end
538-
473+
it 'properly cast assigned value to datetime' do
474+
model.remind_at = datetime_string
475+
expect(model.remind_at).to be == datetime
539476
end
540-
541477
end
542-
543478
end
544479

545480
it 'nillify unparsable datetimes' do
@@ -896,15 +831,6 @@
896831
it_should_behave_like 'a model supporting arrays', true
897832
end if defined?(PostgresqlRegularARModel)
898833

899-
describe PostgresHstoreTypedStoreModel do
900-
if AR_VERSION >= AR_4_1
901-
pending('TODO: Rails edge HStore compatibiliy')
902-
else
903-
it_should_behave_like 'any model'
904-
it_should_behave_like 'a store', false
905-
end
906-
end if defined?(PostgresHstoreTypedStoreModel)
907-
908834
describe PostgresJsonTypedStoreModel do
909835
it_should_behave_like 'any model'
910836
it_should_behave_like 'a store', true, :json

spec/support/models.rb

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
require 'json'
33
require 'yaml'
44

5-
AR_VERSION = Gem::Version.new(ActiveRecord::VERSION::STRING)
6-
AR_4_0 = Gem::Version.new('4.0')
7-
AR_4_1 = Gem::Version.new('4.1.0.beta')
8-
AR_4_2 = Gem::Version.new('4.2.0-rc1')
9-
AR_5_0 = Gem::Version.new('5.0.0')
10-
115
ActiveRecord::Base.time_zone_aware_attributes = ENV['TIMEZONE_AWARE'] != '0'
126
ActiveRecord::Base.configurations = {
137
'test_sqlite3' => { 'adapter' => 'sqlite3', 'database' => '/tmp/typed_store.db' },
@@ -80,7 +74,7 @@ def define_store_with_attributes(**options)
8074
end
8175
end
8276

83-
MigrationClass = AR_VERSION >= AR_5_0 ? ActiveRecord::Migration["5.0"] : ActiveRecord::Migration
77+
MigrationClass = ActiveRecord::Migration["5.0"]
8478
class CreateAllTables < MigrationClass
8579

8680
def self.recreate_table(name, *args, &block)
@@ -98,13 +92,11 @@ def self.up
9892
ActiveRecord::Base.establish_connection(ENV['POSTGRES_URL'] || :test_postgresql)
9993
recreate_table(:postgresql_regular_ar_models) { |t| define_columns(t); t.text :untyped_settings }
10094

101-
if AR_VERSION >= AR_4_0
102-
execute "create extension if not exists hstore"
103-
recreate_table(:postgres_hstore_typed_store_models) { |t| t.hstore :settings; t.text :untyped_settings }
95+
execute "create extension if not exists hstore"
96+
recreate_table(:postgres_hstore_typed_store_models) { |t| t.hstore :settings; t.text :untyped_settings }
10497

105-
if ENV['POSTGRES_JSON']
106-
recreate_table(:postgres_json_typed_store_models) { |t| t.json :settings; t.text :explicit_settings; t.text :partial_settings; t.text :untyped_settings }
107-
end
98+
if ENV['POSTGRES_JSON']
99+
recreate_table(:postgres_json_typed_store_models) { |t| t.json :settings; t.text :explicit_settings; t.text :partial_settings; t.text :untyped_settings }
108100
end
109101
end
110102

@@ -163,45 +155,15 @@ class PostgresqlRegularARModel < ActiveRecord::Base
163155
store :untyped_settings, accessors: [:title]
164156
end
165157

166-
if AR_VERSION >= AR_4_0
167-
168-
class PostgresHstoreTypedStoreModel < ActiveRecord::Base
158+
if ENV['POSTGRES_JSON']
159+
class PostgresJsonTypedStoreModel < ActiveRecord::Base
169160
establish_connection ENV['POSTGRES_URL'] || :test_postgresql
170161
store :untyped_settings, accessors: [:title]
171162

172163
define_store_with_attributes(coder: ColumnCoder.new(AsJson))
173164
define_store_with_no_attributes(coder: ColumnCoder.new(AsJson))
174165
define_store_with_partial_attributes(coder: ColumnCoder.new(AsJson))
175166
end
176-
177-
if ENV['POSTGRES_JSON']
178-
179-
if AR_VERSION >= AR_4_2
180-
181-
class PostgresJsonTypedStoreModel < ActiveRecord::Base
182-
establish_connection ENV['POSTGRES_URL'] || :test_postgresql
183-
store :untyped_settings, accessors: [:title]
184-
185-
define_store_with_attributes(coder: ColumnCoder.new(AsJson))
186-
define_store_with_no_attributes(coder: ColumnCoder.new(AsJson))
187-
define_store_with_partial_attributes(coder: ColumnCoder.new(AsJson))
188-
end
189-
190-
else
191-
192-
class PostgresJsonTypedStoreModel < ActiveRecord::Base
193-
establish_connection ENV['POSTGRES_URL'] || :test_postgresql
194-
store :untyped_settings, accessors: [:title]
195-
196-
define_store_with_attributes(coder: ColumnCoder.new(AsJson))
197-
define_store_with_no_attributes(coder: ColumnCoder.new(AsJson))
198-
define_store_with_partial_attributes(coder: ColumnCoder.new(AsJson))
199-
end
200-
201-
end
202-
203-
end
204-
205167
end
206168
end
207169

@@ -267,5 +229,4 @@ class MarshalTypedStoreModel < ActiveRecord::Base
267229
]
268230
Models << MysqlRegularARModel if defined?(MysqlRegularARModel)
269231
Models << PostgresqlRegularARModel if defined?(PostgresqlRegularARModel)
270-
Models << PostgresHstoreTypedStoreModel if defined?(PostgresHstoreTypedStoreModel)
271232
Models << PostgresJsonTypedStoreModel if defined?(PostgresJsonTypedStoreModel)

0 commit comments

Comments
 (0)