Add spec for multiple database connection
This commit is contained in:
parent
1faf48b328
commit
3247d09a7b
|
@ -18,6 +18,13 @@ module Ransack
|
||||||
expect(subject.object).to be_an ::ActiveRecord::Relation
|
expect(subject.object).to be_an ::ActiveRecord::Relation
|
||||||
end
|
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
|
context 'with scopes' do
|
||||||
before do
|
before do
|
||||||
allow(Person)
|
allow(Person)
|
||||||
|
|
|
@ -37,6 +37,7 @@ RSpec.configure do |config|
|
||||||
line = '=' * message.length
|
line = '=' * message.length
|
||||||
puts line, message, line
|
puts line, message, line
|
||||||
Schema.create
|
Schema.create
|
||||||
|
SubDB::Schema.create
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:all) { Sham.reset(:before_all) }
|
config.before(:all) { Sham.reset(:before_all) }
|
||||||
|
|
|
@ -261,3 +261,30 @@ module Schema
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue