From f9e0dc83c01e247eb2e15ca2571ded459f395b5e Mon Sep 17 00:00:00 2001 From: Kevin Pheasey Date: Tue, 12 Apr 2022 12:08:09 -0400 Subject: [PATCH 1/4] chore(gemspec): allow for rails 6.1 --- .travis.yml | 13 ++++++++++++- apartment.gemspec | 2 +- gemfiles/rails_6_1.gemfile | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 gemfiles/rails_6_1.gemfile diff --git a/.travis.yml b/.travis.yml index 78067b58..b21d2693 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ gemfile: - gemfiles/rails_5_1.gemfile - gemfiles/rails_5_2.gemfile - gemfiles/rails_6_0.gemfile + - gemfiles/rails_6_1.gemfile - gemfiles/rails_master.gemfile bundler_args: --without local before_install: @@ -44,20 +45,30 @@ matrix: gemfile: gemfiles/rails_5_2.gemfile - rvm: 2.1.9 gemfile: gemfiles/rails_6_0.gemfile + - rvm: 2.1.9 + gemfile: gemfiles/rails_6_1.gemfile - rvm: 2.1.9 gemfile: gemfiles/rails_master.gemfile - - rvm: 2.2.9 + - rvm: 2.2.9 gemfile: gemfiles/rails_6_0.gemfile + - rvm: 2.2.9 + gemfile: gemfiles/rails_6_1.gemfile - rvm: 2.3.6 gemfile: gemfiles/rails_6_0.gemfile + - rvm: 2.3.6 + gemfile: gemfiles/rails_6_1.gemfile - rvm: 2.4.3 gemfile: gemfiles/rails_6_0.gemfile + - rvm: 2.4.3 + gemfile: gemfiles/rails_6_1.gemfile - rvm: jruby-9.1.15.0 gemfile: gemfiles/rails_5_1.gemfile - rvm: jruby-9.1.15.0 gemfile: gemfiles/rails_5_2.gemfile - rvm: jruby-9.1.15.0 gemfile: gemfiles/rails_6_0.gemfile + - rvm: jruby-9.1.15.0 + gemfile: gemfiles/rails_6_1.gemfile - rvm: jruby-9.1.15.0 gemfile: gemfiles/rails_master.gemfile fast_finish: true diff --git a/apartment.gemspec b/apartment.gemspec index eb59070f..02702001 100644 --- a/apartment.gemspec +++ b/apartment.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.licenses = ["MIT"] # must be >= 3.1.2 due to bug in prepared_statements - s.add_dependency 'activerecord', '>= 3.1.2', '< 6.1' + s.add_dependency 'activerecord', '>= 3.1.2', '< 7' s.add_dependency 'rack', '>= 1.3.6' s.add_dependency 'public_suffix', '>= 2' s.add_dependency 'parallel', '>= 0.7.1' diff --git a/gemfiles/rails_6_1.gemfile b/gemfiles/rails_6_1.gemfile new file mode 100644 index 00000000..c74b95e0 --- /dev/null +++ b/gemfiles/rails_6_1.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "rails", "~> 6.1" + +group :local do + gem "pry" + gem "guard-rspec", "~> 4.2" +end + +platforms :ruby do + gem "sqlite3", "~> 1.4" +end + +platforms :jruby do + gem "activerecord-jdbc-adapter", "~> 61.1" + gem "activerecord-jdbcpostgresql-adapter", "~> 61.1" + gem "activerecord-jdbcmysql-adapter", "~> 61.1" +end + +gemspec path: "../" From 3a4553194ae79a469cb0dd40a76466beb146688f Mon Sep 17 00:00:00 2001 From: Kevin Pheasey Date: Tue, 12 Apr 2022 12:26:15 -0400 Subject: [PATCH 2/4] chore(gemspec): allow for rails 7 --- .travis.yml | 11 +++++++++++ apartment.gemspec | 2 +- gemfiles/rails_7_0.gemfile | 22 ++++++++++++++++++++++ lib/apartment.rb | 10 +++++++++- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 gemfiles/rails_7_0.gemfile diff --git a/.travis.yml b/.travis.yml index b21d2693..2469a812 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ gemfile: - gemfiles/rails_5_2.gemfile - gemfiles/rails_6_0.gemfile - gemfiles/rails_6_1.gemfile + - gemfiles/rails_7_0.gemfile - gemfiles/rails_master.gemfile bundler_args: --without local before_install: @@ -47,20 +48,28 @@ matrix: gemfile: gemfiles/rails_6_0.gemfile - rvm: 2.1.9 gemfile: gemfiles/rails_6_1.gemfile + - rvm: 2.1.9 + gemfile: gemfiles/rails_7_0.gemfile - rvm: 2.1.9 gemfile: gemfiles/rails_master.gemfile - rvm: 2.2.9 gemfile: gemfiles/rails_6_0.gemfile - rvm: 2.2.9 gemfile: gemfiles/rails_6_1.gemfile + - rvm: 2.2.9 + gemfile: gemfiles/rails_7_0.gemfile - rvm: 2.3.6 gemfile: gemfiles/rails_6_0.gemfile - rvm: 2.3.6 gemfile: gemfiles/rails_6_1.gemfile + - rvm: 2.3.6 + gemfile: gemfiles/rails_7_0.gemfile - rvm: 2.4.3 gemfile: gemfiles/rails_6_0.gemfile - rvm: 2.4.3 gemfile: gemfiles/rails_6_1.gemfile + - rvm: 2.4.3 + gemfile: gemfiles/rails_7_0.gemfile - rvm: jruby-9.1.15.0 gemfile: gemfiles/rails_5_1.gemfile - rvm: jruby-9.1.15.0 @@ -69,6 +78,8 @@ matrix: gemfile: gemfiles/rails_6_0.gemfile - rvm: jruby-9.1.15.0 gemfile: gemfiles/rails_6_1.gemfile + - rvm: jruby-9.1.15.0 + gemfile: gemfiles/rails_7_0.gemfile - rvm: jruby-9.1.15.0 gemfile: gemfiles/rails_master.gemfile fast_finish: true diff --git a/apartment.gemspec b/apartment.gemspec index 02702001..579781a5 100644 --- a/apartment.gemspec +++ b/apartment.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.licenses = ["MIT"] # must be >= 3.1.2 due to bug in prepared_statements - s.add_dependency 'activerecord', '>= 3.1.2', '< 7' + s.add_dependency 'activerecord', '>= 3.1.2', '< 8' s.add_dependency 'rack', '>= 1.3.6' s.add_dependency 'public_suffix', '>= 2' s.add_dependency 'parallel', '>= 0.7.1' diff --git a/gemfiles/rails_7_0.gemfile b/gemfiles/rails_7_0.gemfile new file mode 100644 index 00000000..ef5398bc --- /dev/null +++ b/gemfiles/rails_7_0.gemfile @@ -0,0 +1,22 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "rails", "~> 7.0" + +group :local do + gem "pry" + gem "guard-rspec", "~> 4.2" +end + +platforms :ruby do + gem "sqlite3", "~> 1.4" +end + +platforms :jruby do + gem "activerecord-jdbc-adapter", "~> 61.1" + gem "activerecord-jdbcpostgresql-adapter", "~> 61.1" + gem "activerecord-jdbcmysql-adapter", "~> 61.1" +end + +gemspec path: "../" diff --git a/lib/apartment.rb b/lib/apartment.rb index b20a7728..5bdc5aa0 100644 --- a/lib/apartment.rb +++ b/lib/apartment.rb @@ -16,7 +16,15 @@ class << self attr_accessor(*ACCESSOR_METHODS) attr_writer(*WRITER_METHODS) - def_delegators :connection_class, :connection, :connection_config, :establish_connection + def_delegators :connection_class, :connection, :establish_connection + + def connection_config + if ::ActiveRecord::Base.respond_to?(:connection_db_config) + ::ActiveRecord::Base.connection_db_config.configuration_hash + else + ::ActiveRecord::Base.connection_config + end + end # configure apartment with available options def configure From f7b3b106e793e2114fa8ef6460fa9734f486bde3 Mon Sep 17 00:00:00 2001 From: Kevin Pheasey Date: Wed, 12 Jun 2024 10:27:42 -0400 Subject: [PATCH 3/4] feat(app): use File.exist? in place of File.exists? to support ruby 3.2 --- Rakefile | 4 ++-- lib/apartment/adapters/abstract_adapter.rb | 2 +- lib/apartment/adapters/sqlite3_adapter.rb | 6 +++--- spec/adapters/sqlite3_adapter_spec.rb | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Rakefile b/Rakefile index df67edc6..59c589eb 100644 --- a/Rakefile +++ b/Rakefile @@ -40,8 +40,8 @@ namespace :db do apartment_db_file = 'spec/config/database.yml' rails_db_file = 'spec/dummy/config/database.yml' - FileUtils.copy(apartment_db_file + '.sample', apartment_db_file, :verbose => true) unless File.exists?(apartment_db_file) - FileUtils.copy(rails_db_file + '.sample', rails_db_file, :verbose => true) unless File.exists?(rails_db_file) + FileUtils.copy(apartment_db_file + '.sample', apartment_db_file, :verbose => true) unless File.exist?(apartment_db_file) + FileUtils.copy(rails_db_file + '.sample', rails_db_file, :verbose => true) unless File.exist?(rails_db_file) end end diff --git a/lib/apartment/adapters/abstract_adapter.rb b/lib/apartment/adapters/abstract_adapter.rb index 78b844b9..c7e2f0d0 100644 --- a/lib/apartment/adapters/abstract_adapter.rb +++ b/lib/apartment/adapters/abstract_adapter.rb @@ -209,7 +209,7 @@ def multi_tenantify_with_tenant_db_name(config, tenant) # Load a file or raise error if it doesn't exists # def load_or_raise(file) - if File.exists?(file) + if File.exist?(file) load(file) else raise FileNotFound, "#{file} doesn't exist yet" diff --git a/lib/apartment/adapters/sqlite3_adapter.rb b/lib/apartment/adapters/sqlite3_adapter.rb index dff5a21b..eb0469b0 100644 --- a/lib/apartment/adapters/sqlite3_adapter.rb +++ b/lib/apartment/adapters/sqlite3_adapter.rb @@ -17,7 +17,7 @@ def initialize(config) def drop(tenant) raise TenantNotFound, - "The tenant #{environmentify(tenant)} cannot be found." unless File.exists?(database_file(tenant)) + "The tenant #{environmentify(tenant)} cannot be found." unless File.exist?(database_file(tenant)) File.delete(database_file(tenant)) end @@ -30,14 +30,14 @@ def current def connect_to_new(tenant) raise TenantNotFound, - "The tenant #{environmentify(tenant)} cannot be found." unless File.exists?(database_file(tenant)) + "The tenant #{environmentify(tenant)} cannot be found." unless File.exist?(database_file(tenant)) super database_file(tenant) end def create_tenant(tenant) raise TenantExists, - "The tenant #{environmentify(tenant)} already exists." if File.exists?(database_file(tenant)) + "The tenant #{environmentify(tenant)} already exists." if File.exist?(database_file(tenant)) begin f = File.new(database_file(tenant), File::CREAT) diff --git a/spec/adapters/sqlite3_adapter_spec.rb b/spec/adapters/sqlite3_adapter_spec.rb index 55004952..fcb6198b 100644 --- a/spec/adapters/sqlite3_adapter_spec.rb +++ b/spec/adapters/sqlite3_adapter_spec.rb @@ -40,7 +40,7 @@ def tenant_names it "should create a new database" do subject.create db_name - expect(File.exists?("#{default_dir}/#{Rails.env}_#{db_name}.sqlite3")).to eq true + expect(File.exist?("#{default_dir}/#{Rails.env}_#{db_name}.sqlite3")).to eq true end end @@ -55,7 +55,7 @@ def tenant_names it "should create a new database" do subject.create db_name - expect(File.exists?("#{default_dir}/#{db_name}.sqlite3")).to eq true + expect(File.exist?("#{default_dir}/#{db_name}.sqlite3")).to eq true end end @@ -73,7 +73,7 @@ def tenant_names it "should create a new database" do subject.create db_name - expect(File.exists?("#{default_dir}/#{db_name}_#{Rails.env}.sqlite3")).to eq true + expect(File.exist?("#{default_dir}/#{db_name}_#{Rails.env}.sqlite3")).to eq true end end From 6b91a322e04491eb0bb64474f0285d00249db275 Mon Sep 17 00:00:00 2001 From: Kevin Pheasey Date: Wed, 12 Jun 2024 11:18:30 -0400 Subject: [PATCH 4/4] chore(app): increment version --- HISTORY.md | 6 ++++++ lib/apartment/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index c6e1398f..7ee1b325 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,9 @@ +# 2.3.0 + * June 12, 2024 + +## Added + - Support for Ruby 3.2 + # 2.2.1 * June 19, 2019 diff --git a/lib/apartment/version.rb b/lib/apartment/version.rb index 40b2f751..25f180b1 100644 --- a/lib/apartment/version.rb +++ b/lib/apartment/version.rb @@ -1,3 +1,3 @@ module Apartment - VERSION = "2.2.1" + VERSION = "2.3.0" end