diff --git a/.travis.yml b/.travis.yml index 78067b58..2469a812 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,8 @@ 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 - gemfiles/rails_master.gemfile bundler_args: --without local before_install: @@ -44,20 +46,40 @@ 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_7_0.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.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 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_7_0.gemfile - rvm: jruby-9.1.15.0 gemfile: gemfiles/rails_master.gemfile fast_finish: true 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/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/apartment.gemspec b/apartment.gemspec index eb59070f..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', '< 6.1' + 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_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: "../" 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 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/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 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