Skip to content

Commit

Permalink
Fix collection association with the same name as ancestor private met…
Browse files Browse the repository at this point in the history
…hod.
  • Loading branch information
cctiger36 committed Dec 17, 2014
1 parent 584c86a commit 98cfa16
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ namespace :db do
u.string :name
u.string :commentable_type
u.integer :commentable_id
u.boolean :open, default: false
end

BlankModel.using(shard_symbol).connection.create_table(:parts) do |u|
Expand Down
2 changes: 1 addition & 1 deletion lib/octopus/relation_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(shard, ar_relation)
end

def method_missing(method, *args, &block)
run_on_shard { @ar_relation.send(method, *args, &block) }
run_on_shard { @ar_relation.public_send(method, *args, &block) }
end

def ==(other)
Expand Down
7 changes: 7 additions & 0 deletions spec/octopus/relation_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
expect(@relation.current_shard).to eq(:canada)
end

unless Octopus.rails3?
it 'can define collection association with the same name as ancestor private method' do
@client.comments << Comment.using(:canada).create!(open: true)
expect(@client.comments.open).to be_a_kind_of(ActiveRecord::Relation)
end
end

context 'when comparing to other Relation objects' do
before :each do
@relation.reset
Expand Down
1 change: 1 addition & 0 deletions spec/support/database_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Project < ActiveRecord::Base

class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
scope :open, -> { where(open: true) }
end

class Bacon < ActiveRecord::Base
Expand Down

0 comments on commit 98cfa16

Please sign in to comment.