Skip to content

Commit 7d38b42

Browse files
Merge pull request #2 from sparkapi/fix-abstract-classes
Fix abstract class descendants not inheriting custom connection
2 parents d117f27 + 8f56a3f commit 7d38b42

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/octopus/model.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ def hijack_methods
9898
around_save :run_on_shard, :unless => -> { self.class.custom_octopus_connection }
9999
after_initialize :set_current_shard
100100

101+
cattr_accessor :custom_octopus_connection
102+
101103
class << self
102-
attr_accessor :custom_octopus_connection
103104
attr_accessor :custom_octopus_table_name
104105

105106
alias_method_chain :connection, :octopus

spec/octopus/model_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@
263263
expect(CustomConnection.connection.current_database).to eq('octopus_shard_2')
264264
end
265265

266+
it 'reuses parent model connection' do
267+
klass = Class.new(CustomConnection)
268+
269+
expect(klass.connection).to be klass.connection
270+
end
271+
266272
it 'should not mess with custom connection table names' do
267273
expect(Advert.connection.current_database).to eq('octopus_shard_1')
268274
Advert.create!(:name => 'Teste')

0 commit comments

Comments
 (0)