From 8f56a3f40059f03b77cab7603a4ab86e10476fe3 Mon Sep 17 00:00:00 2001 From: Gabriel Sobrinho Date: Sun, 4 Oct 2015 20:23:27 +0000 Subject: [PATCH] Fix abstract class descendants not inheriting custom connection Fix #219 --- lib/octopus/model.rb | 3 ++- spec/octopus/model_spec.rb | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/octopus/model.rb b/lib/octopus/model.rb index 29faf70a..11a46fe9 100644 --- a/lib/octopus/model.rb +++ b/lib/octopus/model.rb @@ -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 diff --git a/spec/octopus/model_spec.rb b/spec/octopus/model_spec.rb index d9881439..516c65b4 100644 --- a/spec/octopus/model_spec.rb +++ b/spec/octopus/model_spec.rb @@ -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')