Skip to content

Commit

Permalink
Pretty poor attempt at a spec to showcase the 4.1 branch's issue
Browse files Browse the repository at this point in the history
with multiple joins on the same table
  • Loading branch information
jhdavids8 committed May 20, 2014
1 parent c427b48 commit 0e58515
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/blueprints/recommendations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Recommendation.blueprint do
article
person
target_person { person }
end
6 changes: 6 additions & 0 deletions spec/ransack/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ module Ransack
expect(where.to_sql).to match /#{children_people_name_field} = 'Ernie'/
end

it 'evaluates conditions for multiple belongs_to associations to the same table contextually' do
search = Search.new(Recommendation, person_name_eq: 'Ernie', target_person_parent_name_eq: 'Test')
search.result.should be_an ActiveRecord::Relation
search.result.to_sql.should == "SELECT \"recommendations\".* FROM \"recommendations\" LEFT OUTER JOIN \"people\" ON \"people\".\"id\" = \"recommendations\".\"person_id\" LEFT OUTER JOIN \"people\" \"target_people_recommendations\" ON \"target_people_recommendations\".\"id\" = \"recommendations\".\"target_person_id\" LEFT OUTER JOIN \"people\" \"parents_people\" ON \"parents_people\".\"id\" = \"target_people_recommendations\".\"parent_id\" WHERE ((\"people\".\"name\" = 'Ernie' AND \"parents_people\".\"name\" = 'Test'))"
end

it 'evaluates compound conditions contextually' do
search = Search.new(Person, :children_name_or_name_eq => 'Ernie')
expect(search.result).to be_an ActiveRecord::Relation
Expand Down
12 changes: 12 additions & 0 deletions spec/support/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ class Article < ActiveRecord::Base
has_many :notes, :as => :notable
end

class Recommendation < ActiveRecord::Base
belongs_to :person
belongs_to :target_person, class_name: 'Person'
belongs_to :article
end

module Namespace
class Article < ::Article

Expand Down Expand Up @@ -155,6 +161,12 @@ def self.create
t.string :note
end

create_table :recommendations, :force => true do |t|
t.integer :person_id
t.integer :target_person_id
t.integer :article_id
end

end

10.times do
Expand Down

0 comments on commit 0e58515

Please sign in to comment.