Skip to content

Commit 7b6a511

Browse files
committed
Changes for Rails 7 compatibility
1 parent 6adb04b commit 7b6a511

10 files changed

+36
-83
lines changed

Appraisals

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
#-*- ruby -*-
2-
3-
appraise 'rails50' do
4-
gem 'rails', '~> 5.0.0'
5-
gem 'jquery-rails'
6-
end
7-
8-
appraise 'rails51' do
9-
gem 'rails', '~> 5.1.0'
10-
gem 'jquery-rails'
11-
end
12-
13-
appraise 'rails52' do
14-
gem 'rails', '~> 5.2.0'
15-
gem 'jquery-rails'
16-
end
17-
18-
appraise 'rails60' do
19-
gem 'rails', '~> 6'
2+
appraise 'rails70' do
3+
gem 'rails', '~> 7.0'
204
gem 'jquery-rails'
215
end

activerecord-tablefree.gemspec

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ Gem::Specification.new do |gem|
2525

2626
gem.add_runtime_dependency('activerecord', '>= 6.0.0')
2727

28-
gem.add_development_dependency('bundler', '~> 1')
29-
gem.add_development_dependency('rake', '~> 12', '> 0')
28+
gem.add_development_dependency('bundler', '~> 2')
29+
gem.add_development_dependency('rake', '~> 13', '> 0')
3030

3131
# gem.add_development_dependency("rails") # This is in the appraisal gemfiles
3232
gem.add_development_dependency('sqlite3', '~> 1')
3333

34-
gem.add_development_dependency('appraisal', '~> 1')
34+
gem.add_development_dependency('appraisal', '~> 2')
3535
gem.add_development_dependency('aruba', '~> 0')
3636
gem.add_development_dependency('cucumber', '~> 3')
3737
gem.add_development_dependency('rspec', '~> 3')
@@ -42,7 +42,7 @@ Gem::Specification.new do |gem|
4242
gem.add_development_dependency('gem-release', '~> 2')
4343
gem.add_development_dependency('listen', '~> 3')
4444
gem.add_development_dependency('nokogiri', '~> 1.0')
45-
gem.add_development_dependency('rails', '~> 6')
45+
gem.add_development_dependency('rails', '~> 7.0')
4646
gem.add_development_dependency('wwtd', '~> 1')
4747

4848
# gem.add_development_dependency('launchy', '~> 2.1')

gemfiles/.DS_Store

6 KB
Binary file not shown.

gemfiles/rails50.gemfile

-9
This file was deleted.

gemfiles/rails51.gemfile

-9
This file was deleted.

gemfiles/rails52.gemfile

-9
This file was deleted.

gemfiles/rails60.gemfile gemfiles/rails70.gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
source "https://rubygems.org"
44

55
gem "byebug", platform: :mri
6-
gem "rails", "~> 6"
6+
gem "rails", "~> 7.0"
77
gem "jquery-rails"
88

9-
gemspec :path => "../"
9+
gemspec path: "../"

lib/activerecord/tablefree.rb

+18-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,24 @@ def column(name, sql_type = nil, default = nil, null = true, cast_class_params =
9292
else
9393
"ActiveRecord::Type::#{sql_type.to_s.camelize}".constantize rescue nil
9494
end
95-
raise InvalidColumnType, "sql_type is #{sql_type} (#{sql_type.class}), which is not supported" unless cast_class.respond_to?(:new)
95+
unless cast_class.respond_to?(:new)
96+
raise InvalidColumnType, "sql_type is #{sql_type} (#{sql_type.class}), which is not supported"
97+
end
98+
9699
cast_type = cast_class.new(*cast_class_params)
97-
tablefree_options[:columns_hash][name.to_s] = ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, cast_type, null)
100+
sql_type_metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(
101+
sql_type: cast_type.type.to_s,
102+
type: cast_type.type,
103+
limit: cast_type.limit,
104+
precision: cast_type.precision,
105+
scale: cast_type.scale
106+
)
107+
tablefree_options[:columns_hash][name.to_s] = ActiveRecord::ConnectionAdapters::Column.new(
108+
name.to_s,
109+
default,
110+
sql_type_metadata,
111+
null
112+
)
98113
end
99114

100115
# Register a set of columns with the same SQL type
@@ -123,7 +138,7 @@ def destroy_all(*_args)
123138
end
124139

125140
case ActiveRecord::VERSION::MAJOR
126-
when 5, 6
141+
when 5, 6, 7
127142
def find_by_sql(*_args)
128143
case tablefree_options[:database]
129144
when :pretend_success

lib/activerecord/tablefree/connection.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def combine_bind_parameters(**_args)
5555
''
5656
end
5757

58-
def lookup_cast_type_from_column(*_args)
59-
@_cast_type ||= ActiveRecord::Tablefree::CastType.new
58+
def lookup_cast_type_from_column(column)
59+
@_cast_type = lookup_cast_type(column.type)
6060
end
6161

6262
def current_transaction

spec/activerecord/tablefree_spec.rb

+8-27
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def remove_models
5050
it { should respond_to :id= }
5151
it { should respond_to :name }
5252
it { should respond_to :name= }
53-
it { should respond_to :update_attributes }
53+
it { should respond_to :update }
5454
describe '#attributes=' do
5555
before(:example) { subject.attributes = ({ name: 'Jarl Friis' }) }
5656
it 'assign attributes' do
@@ -99,25 +99,6 @@ def remove_models
9999
end
100100

101101
shared_examples_for 'a tablefree model with fail_fast' do
102-
case ActiveRecord::VERSION::MAJOR
103-
when 3
104-
describe '#all' do
105-
it 'raises ActiveRecord::Tablefree::NoDatabase' do
106-
expect { subject.all }.to raise_exception(ActiveRecord::Tablefree::NoDatabase)
107-
end
108-
end
109-
when 4
110-
describe '#all' do
111-
it 'raises ActiveRecord::Tablefree::NoDatabase' do
112-
expect { subject.all }.to_not raise_exception
113-
end
114-
end
115-
describe '#all[]' do
116-
it 'raises ActiveRecord::Tablefree::NoDatabase' do
117-
expect { subject.all[0] }.to raise_exception(ActiveRecord::Tablefree::NoDatabase)
118-
end
119-
end
120-
end
121102
describe '#create' do
122103
it 'raises ActiveRecord::Tablefree::NoDatabase' do
123104
expect { subject.create(name: 'Jarl') }.to raise_exception(ActiveRecord::Tablefree::NoDatabase)
@@ -152,9 +133,9 @@ def remove_models
152133
expect { subject.reload }.to raise_exception(ActiveRecord::Tablefree::NoDatabase)
153134
end
154135
end
155-
describe '#update_attributes' do
136+
describe '#update' do
156137
it 'raises ActiveRecord::Tablefree::NoDatabase' do
157-
expect { subject.update_attributes(name: 'Jarl') }.to raise_exception(StandardError)
138+
expect { subject.update(name: 'Jarl') }.to raise_exception(StandardError)
158139
end
159140
end
160141
end
@@ -193,10 +174,10 @@ def remove_models
193174
subject { Chair.new(name: 'Jarl') }
194175
it_behaves_like 'a tablefree model instance with fail_fast'
195176
it_behaves_like 'a nested active record'
196-
describe '#update_attributes' do
177+
describe '#update' do
197178
it 'raises ActiveRecord::Tablefree::NoDatabase' do
198179
expect do
199-
subject.update_attributes(arm_rests: { name: 'nice arm_rest' })
180+
subject.update(arm_rests: { name: 'nice arm_rest' })
200181
end.to raise_exception(StandardError)
201182
end
202183
end
@@ -256,8 +237,8 @@ def remove_models
256237
before { subject.save! }
257238
specify { expect(subject.reload).to eq subject }
258239
end
259-
describe '#update_attributes' do
260-
specify { expect(subject.update_attributes(name: 'Jarl Friis')).to eq true }
240+
describe '#update' do
241+
specify { expect(subject.update(name: 'Jarl Friis')).to eq true }
261242
end
262243
end
263244

@@ -273,7 +254,7 @@ class Chair < ActiveRecord::Base
273254
end
274255
after(:context) do
275256
remove_models
276-
ActiveRecord::Base.clear_all_connections!
257+
ActiveRecord::Base.connection_handler.clear_all_connections!
277258
end
278259

279260
subject { Chair }

0 commit comments

Comments
 (0)