diff --git a/spec/ransack/adapters/active_record/base_spec.rb b/spec/ransack/adapters/active_record/base_spec.rb index 4a0d5e7..bfa444e 100644 --- a/spec/ransack/adapters/active_record/base_spec.rb +++ b/spec/ransack/adapters/active_record/base_spec.rb @@ -18,6 +18,13 @@ module Ransack expect(subject.object).to be_an ::ActiveRecord::Relation end + context "multiple database connection" do + it "does not raise error" do + expect { Person.ransack(name_cont: "test") }.not_to raise_error + expect { SubDB::OperationHistory.ransack(people_id_eq: 1) }.not_to raise_error + end + end + context 'with scopes' do before do allow(Person) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ebedf2a..ab3b430 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -37,6 +37,7 @@ RSpec.configure do |config| line = '=' * message.length puts line, message, line Schema.create + SubDB::Schema.create end config.before(:all) { Sham.reset(:before_all) } diff --git a/spec/support/schema.rb b/spec/support/schema.rb index 88363d2..48f22ca 100644 --- a/spec/support/schema.rb +++ b/spec/support/schema.rb @@ -261,3 +261,30 @@ module Schema ) end end + +module SubDB + class Base < ActiveRecord::Base + self.abstract_class = true + establish_connection( + adapter: 'sqlite3', + database: ':memory:' + ) + end + + class OperationHistory < Base + end + + module Schema + def self.create + s = ::ActiveRecord::Schema.new + s.instance_variable_set(:@connection, SubDB::Base.connection) + s.verbose = false + s.define({}) do + create_table :operation_histories, force: true do |t| + t.string :operation_type + t.integer :people_id + end + end + end + end +end