Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix abstract class descendants not inheriting custom connection #2

Merged
merged 1 commit into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/octopus/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ def hijack_methods
around_save :run_on_shard, :unless => -> { self.class.custom_octopus_connection }
after_initialize :set_current_shard

cattr_accessor :custom_octopus_connection

class << self
attr_accessor :custom_octopus_connection
attr_accessor :custom_octopus_table_name

alias_method_chain :connection, :octopus
Expand Down
6 changes: 6 additions & 0 deletions spec/octopus/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@
expect(CustomConnection.connection.current_database).to eq('octopus_shard_2')
end

it 'reuses parent model connection' do
klass = Class.new(CustomConnection)

expect(klass.connection).to be klass.connection
end

it 'should not mess with custom connection table names' do
expect(Advert.connection.current_database).to eq('octopus_shard_1')
Advert.create!(:name => 'Teste')
Expand Down