Skip to content

Commit

Permalink
Add spec for multiple database connection
Browse files Browse the repository at this point in the history
  • Loading branch information
yujideveloper committed Mar 15, 2018
1 parent 1faf48b commit 3247d09
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spec/ransack/adapters/active_record/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ module ActiveRecord
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)
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
line = '=' * message.length
puts line, message, line
Schema.create
SubDB::Schema.create
end

config.before(:all) { Sham.reset(:before_all) }
Expand Down
27 changes: 27 additions & 0 deletions spec/support/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,30 @@ def self.create
)
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

0 comments on commit 3247d09

Please sign in to comment.