Skip to content

Commit

Permalink
Add rails 7 support and add ruby 3.1 to tests (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
will89 authored Mar 30, 2022
1 parent e0c7411 commit 8e28340
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 112 deletions.
35 changes: 14 additions & 21 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ version: 2.1
jobs:
lint:
docker:
- image: salsify/ruby_ci:2.5.8
- image: salsify/ruby_ci:2.7.5
working_directory: ~/rails-multitenant
steps:
- checkout
- restore_cache:
keys:
- v1-gems-ruby-2.5.8-{{ checksum "rails_multitenant.gemspec" }}-{{ checksum "Gemfile" }}
- v1-gems-ruby-2.5.8-
- v1-gems-ruby-2.7.5-{{ checksum "rails_multitenant.gemspec" }}-{{ checksum "Gemfile" }}
- v1-gems-ruby-2.7.5-
- run:
name: Install Gems
command: |
Expand All @@ -18,7 +18,7 @@ jobs:
bundle clean
fi
- save_cache:
key: v1-gems-ruby-2.5.8-{{ checksum "rails_multitenant.gemspec" }}-{{ checksum "Gemfile" }}
key: v1-gems-ruby-2.7.5-{{ checksum "rails_multitenant.gemspec" }}-{{ checksum "Gemfile" }}
paths:
- "vendor/bundle"
- "gemfiles/vendor/bundle"
Expand Down Expand Up @@ -69,27 +69,20 @@ workflows:
matrix:
parameters:
gemfile:
- "gemfiles/rails_4.2.gemfile"
- "gemfiles/rails_5.0.gemfile"
- "gemfiles/rails_5.1.gemfile"
- "gemfiles/rails_5.2.gemfile"
- "gemfiles/rails_6.0.gemfile"
- "gemfiles/rails_6.1.gemfile"
- "gemfiles/rails_7.0.gemfile"
ruby_version:
- "2.5.8"
- "2.6.6"
- "2.7.2"
- "3.0.0"
- "2.7.5"
- "3.0.3"
- "3.1.1"
exclude:
- gemfile: "gemfiles/rails_4.2.gemfile"
ruby_version: "2.7.2"
- gemfile: "gemfiles/rails_4.2.gemfile"
ruby_version: "3.0.0"
- gemfile: "gemfiles/rails_5.0.gemfile"
ruby_version: "3.0.0"
- gemfile: "gemfiles/rails_5.1.gemfile"
ruby_version: "3.0.0"
- gemfile: "gemfiles/rails_5.2.gemfile"
ruby_version: "3.0.0"
ruby_version: "3.0.3"
- gemfile: "gemfiles/rails_5.2.gemfile"
ruby_version: "3.1.1"
- gemfile: "gemfiles/rails_6.0.gemfile"
ruby_version: "3.0.3"
- gemfile: "gemfiles/rails_6.0.gemfile"
ruby_version: "3.0.0"
ruby_version: "3.1.1"
5 changes: 3 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ inherit_gem:
salsify_rubocop: conf/rubocop.yml

AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 2.7
Exclude:
- 'gemfiles/*'
- 'gemfiles/**/*'
- 'vendor/**/*'

Metrics/LineLength:
Enabled: true
Expand Down
30 changes: 9 additions & 21 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
# frozen_string_literal: true

appraise 'rails-4.2' do
gem 'sqlite3', '~> 1.3.6'
gem 'activerecord', '4.2.11.1'
gem 'activesupport', '4.2.11.1'
end

appraise 'rails-5.0' do
gem 'sqlite3', '~> 1.3.6'
gem 'activerecord', '5.0.7.2'
gem 'activesupport', '5.0.7.2'
end

appraise 'rails-5.1' do
gem 'activerecord', '5.1.7'
gem 'activesupport', '5.1.7'
end

appraise 'rails-5.2' do
gem 'activerecord', '5.2.4.4'
gem 'activesupport', '5.2.4.4'
end

appraise 'rails-6.0' do
gem 'activerecord', '6.0.3.4'
gem 'activesupport', '6.0.3.4'
gem 'activerecord', '~> 6.0.4'
gem 'activesupport', '~> 6.0.4'
end

appraise 'rails-6.1' do
gem 'activerecord', '6.1.0'
gem 'activesupport', '6.1.0'
gem 'activerecord', '~> 6.1.5'
gem 'activesupport', '~> 6.1.5'
end

appraise 'rails-7.0' do
gem 'activerecord', '~> 7.0.2'
gem 'activesupport', '~> 7.0.2'
end
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### 0.16.0
* Add support for Rails 7.0.
* Drop unsupported rails versions < 5.2
* Drop unsupported ruby versions < 2.7

### 0.15.0
* Add support for Rails 6.1.

Expand Down
9 changes: 0 additions & 9 deletions gemfiles/rails_4.2.gemfile

This file was deleted.

9 changes: 0 additions & 9 deletions gemfiles/rails_5.0.gemfile

This file was deleted.

4 changes: 2 additions & 2 deletions gemfiles/rails_6.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "activerecord", "6.0.3.4"
gem "activesupport", "6.0.3.4"
gem "activerecord", "~> 6.0.4"
gem "activesupport", "~> 6.0.4"

gemspec path: "../"
4 changes: 2 additions & 2 deletions gemfiles/rails_6.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "activerecord", "6.1.0"
gem "activesupport", "6.1.0"
gem "activerecord", "~> 6.1.5"
gem "activesupport", "~> 6.1.5"

gemspec path: "../"
4 changes: 2 additions & 2 deletions gemfiles/rails_5.1.gemfile → gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "activerecord", "5.1.7"
gem "activesupport", "5.1.7"
gem "activerecord", "~> 7.0.2"
gem "activesupport", "~> 7.0.2"

gemspec path: "../"
7 changes: 4 additions & 3 deletions lib/rails_multitenant/global_context_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def merge!(values)

# Duplicate the registry
def duplicate_registry
globals.each_with_object({}) do |(key, value), result|
result[key] = value.nil? || value.is_a?(Integer) ? value : value.dup
globals.transform_values do |value|
value.nil? || value.is_a?(Integer) ? value : value.dup
end
end

Expand Down Expand Up @@ -87,7 +87,8 @@ def replace_registry(registry)

# Run a block of code that disregards scoping during read queries
def with_unscoped_queries
with_merged_registry(__use_unscoped_queries: true) do
# disabling Style/ExplicitBlockArgument for performance reasons
with_merged_registry(__use_unscoped_queries: true) do # rubocop:disable Style/ExplicitBlockArgument
yield
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_multitenant/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module RailsMultitenant
VERSION = '0.15.0'
VERSION = '0.16.0'
end
8 changes: 4 additions & 4 deletions rails_multitenant.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ Gem::Specification.new do |spec|
spec.files = Dir['lib/**/*.rb', 'LICENSE.txt']
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 2.4.0'
spec.required_ruby_version = '>= 2.7.0'

spec.add_dependency 'activerecord', '>= 4.2', '< 6.2'
spec.add_dependency 'activesupport', '>= 4.2', '< 6.2'
spec.add_dependency 'activerecord', '>= 5.2', '< 7.1'
spec.add_dependency 'activesupport', '>= 5.2', '< 7.1'

spec.add_development_dependency 'appraisal'
spec.add_development_dependency 'coveralls'
spec.add_development_dependency 'database_cleaner', '>= 1.2'
spec.add_development_dependency 'rake', '>= 12.0'
spec.add_development_dependency 'rspec', '~> 3.8.0'
spec.add_development_dependency 'rspec_junit_formatter'
spec.add_development_dependency 'salsify_rubocop', '0.63.0'
spec.add_development_dependency 'salsify_rubocop', '~> 1.0.1'
spec.add_development_dependency 'simplecov', '~> 0.15.1'
spec.add_development_dependency 'sqlite3', '~> 1.4.0'
end
37 changes: 23 additions & 14 deletions spec/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
describe Item do

let!(:item1) { Item.create! }
let(:dependent_class) do
Class.new do
include RailsMultitenant::GlobalContextRegistry::Current
global_context_dependent_on Organization

def self.name
'DependentClass'
end
end
end

let(:sub_organization) do
Class.new(Organization) do
def self.name
'SubOrganization'
end
end
end

let!(:org2) { Organization.create! }
let!(:item2) { org2.as_current { Item.create! } }
Expand Down Expand Up @@ -46,15 +64,6 @@
end
end

class DependentClass
include RailsMultitenant::GlobalContextRegistry::Current
global_context_dependent_on Organization
end

class SubOrganization < Organization

end

describe ".as_current" do
it "returns the correct items with an org supplied" do
Organization.as_current(org2) do
Expand All @@ -77,18 +86,18 @@ class SubOrganization < Organization
DependentModel.current = DependentModel.create!
dependent = DependentModel.current

SubOrganization.create!.as_current do
sub_organization.create!.as_current do
expect(DependentModel.current).not_to equal(dependent)
end
end

it "invalidates dependent objects" do
dependent = DependentClass.current
dependent = dependent_class.new
dependent_class.current = dependent

SubOrganization.create!.as_current do
expect(DependentClass.current).not_to equal(dependent)
sub_organization.create!.as_current do
expect(dependent_class.current).not_to equal(dependent)
end
end
end

end
58 changes: 37 additions & 21 deletions spec/rails_multitenant/global_context_registry/current_spec.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,55 @@
# frozen_string_literal: true

describe RailsMultitenant::GlobalContextRegistry::Current do
class TestClass
include RailsMultitenant::GlobalContextRegistry::Current
provide_default :new

class TestClass
include RailsMultitenant::GlobalContextRegistry::Current
provide_default :new
attr_accessor :id

attr_accessor :id
def initialize(id: :default)
@id = id
end
end

def initialize(id: :default)
@id = id
describe RailsMultitenant::GlobalContextRegistry::Current do
let(:sub_class) do
Class.new(TestClass) do
def self.name
'SubClass'
end
end
end

class SubClass < TestClass
end
let(:dependent_class) do
Class.new do
include RailsMultitenant::GlobalContextRegistry::Current
provide_default { new }
global_context_dependent_on TestClass

class DependentClass
include RailsMultitenant::GlobalContextRegistry::Current
provide_default { new }
global_context_dependent_on TestClass
def self.name
'DependentClass'
end
end
end

class NoDefaultTestClass
include RailsMultitenant::GlobalContextRegistry::Current
let(:no_default_test_class) do
Class.new do
include RailsMultitenant::GlobalContextRegistry::Current

def self.name
'NoDefaultTestClass'
end
end
end

describe "current" do
it "returns default value when supplied" do
expect(TestClass.current.id).to eq(:default)
expect(SubClass.current.id).to eq(:default)
expect(sub_class.current.id).to eq(:default)
end

it "returns nil when no default supplied" do
expect(NoDefaultTestClass.current).to be_nil
expect(no_default_test_class.current).to be_nil
end
end

Expand All @@ -43,8 +59,8 @@ class NoDefaultTestClass
end

it "raises an error when current not set" do
NoDefaultTestClass.clear_current!
expect { NoDefaultTestClass.current! }.to raise_error('No current NoDefaultTestClass set')
no_default_test_class.clear_current!
expect { no_default_test_class.current! }.to raise_error('No current NoDefaultTestClass set')
end
end

Expand All @@ -56,9 +72,9 @@ class NoDefaultTestClass
end

it "clears dependencies" do
dependent = DependentClass.current
dependent = dependent_class.current
TestClass.current = TestClass.new
expect(DependentClass.current).not_to equal(dependent)
expect(dependent_class.current).not_to equal(dependent)
end
end

Expand Down
Loading

0 comments on commit 8e28340

Please sign in to comment.