Skip to content

Commit

Permalink
Support rails 8.0.0 (#260)
Browse files Browse the repository at this point in the history
* Support rails 8.0.0

* fix rubocop warning

```
lib/activerecord-multi-tenant/model_extensions.rb:69:37: C: [Corrected] Style/KeywordArgumentsMerging: Provide additional arguments directly rather than using merge.
          belongs_to tenant_name, **options.slice(:class_name, :inverse_of, :optional) ...
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
  • Loading branch information
alpaca-tc authored Nov 11, 2024
1 parent 0ac43aa commit 3b21347
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/active-record-multi-tenant-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ jobs:
- rails-7.0
- rails-7.1
- rails-7.2
- rails-8.0
- active-record-6.0
- active-record-6.1
- active-record-7.0
- active-record-7.1
- active-record-7.2
- active-record-8.0
citus_version:
- '10'
- '11'
Expand Down
8 changes: 8 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ appraise 'rails-7.2' do
gem 'rails', '~> 7.2.0'
end

appraise 'rails-8.0' do
gem 'rails', '~> 8.0.0'
end

appraise 'active-record-6.0' do
gem 'activerecord', '~> 6.0.3'
end
Expand All @@ -39,3 +43,7 @@ end
appraise 'active-record-7.2' do
gem 'activerecord', '~> 7.2.0'
end

appraise 'active-record-8.0' do
gem 'activerecord', '~> 8.0.0'
end
7 changes: 5 additions & 2 deletions lib/activerecord-multi-tenant/model_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ def inherited(subclass)

# Create an implicit belongs_to association only if tenant class exists
if MultiTenant.tenant_klass_defined?(tenant_name, options)
belongs_to tenant_name, **options.slice(:class_name, :inverse_of, :optional)
.merge(foreign_key: options[:partition_key])
belongs_to(
tenant_name,
**options.slice(:class_name, :inverse_of, :optional),
foreign_key: options[:partition_key]
)
end

# New instances should have the tenant set
Expand Down
2 changes: 1 addition & 1 deletion lib/activerecord-multi-tenant/query_rewriter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def relations_from_node_join(node_join)
ActiveRecord::QueryMethods.prepend(MultiTenant::QueryMethodsExtensions)

module MultiTenantFindBy
if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 2
if ActiveRecord.gem_version >= Gem::Version.create('7.2.0')
def cached_find_by_statement(connection, key, &block)
return super unless respond_to?(:scoped_by_tenant?) && scoped_by_tenant?

Expand Down
4 changes: 2 additions & 2 deletions lib/activerecord-multi-tenant/relation_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def update_all(updates)

stmt = Arel::UpdateManager.new
stmt.table(table)
stmt.set Arel.sql(@klass.send(:sanitize_sql_for_assignment, updates))
stmt.set Arel.sql(klass.send(:sanitize_sql_for_assignment, updates))
stmt.wheres = [generate_in_condition_subquery]

klass.connection.update(stmt, "#{klass} Update All").tap { reset }
Expand All @@ -39,7 +39,7 @@ def generate_in_condition_subquery
# Build an Arel query
arel = if eager_loading?
apply_join_dependency.arel
elsif ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 2
elsif ActiveRecord.gem_version >= Gem::Version.create('7.2.0')
build_arel(klass.connection)
else
build_arel
Expand Down
2 changes: 1 addition & 1 deletion spec/activerecord-multi-tenant/model_extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def self.name
end

describe 'inspect method filters senstive column values' do
if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 2
if ActiveRecord.gem_version >= Gem::Version.create('7.2.0')
# related: https://github.com/rails/rails/pull/49765
around do |example|
prev = Account.attributes_for_inspect
Expand Down

0 comments on commit 3b21347

Please sign in to comment.