Merge @jhdavids8's failing spec for #374

and clean up schema.rb a bit.

Thanks to Jamie Davidson for the test!

This is to help anyone who wants / needs to fix #374.

- Fork Ransack to your repo

- Open the file `ransack/spec/ransack/search_spec.rb` and uncomment the
test beginning at line 220

- Set the Rails version you'd like to test in ransack's Gemfile
('4-1-stable', '4.2.1', etc.)

- In the console, run `bundle install` then `bundle exec rake spec`

- Write a fix that makes this test pass!

- Send a pull request :)
This commit is contained in:
Jon Atack 2015-03-25 15:36:59 +05:30
parent 29bc5b8681
commit 8fe8368b07
3 changed files with 40 additions and 14 deletions

View File

@ -0,0 +1,5 @@
Recommendation.blueprint do
article
person
target_person { person }
end

View File

@ -214,6 +214,16 @@ module Ransack
children_people_name_field} = 'Ernie'/
end
# Uncomment the following failing spec by Jamie Davidson / @jhdavids8
# for testing issue #374:
# https://github.com/activerecord-hackery/ransack/issues/374
#
# 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').result
expect(search).to be_an ActiveRecord::Relation

View File

@ -1,6 +1,6 @@
require 'active_record'
case ENV['DB'].downcase
case ENV['DB'].try(:downcase)
when 'mysql', 'mysql2'
# To test with MySQL: `DB=mysql bundle exec rake spec`
ActiveRecord::Base.establish_connection(
@ -113,6 +113,12 @@ class Article < ActiveRecord::Base
end
end
class Recommendation < ActiveRecord::Base
belongs_to :person
belongs_to :target_person, class_name: 'Person'
belongs_to :article
end
module Namespace
class Article < ::Article
@ -161,33 +167,38 @@ module Schema
end
create_table :articles, :force => true do |t|
t.integer :person_id
t.string :title
t.text :subject_header
t.text :body
t.integer :person_id
t.string :title
t.text :subject_header
t.text :body
end
create_table :comments, :force => true do |t|
t.integer :article_id
t.integer :person_id
t.text :body
t.integer :article_id
t.integer :person_id
t.text :body
end
create_table :tags, :force => true do |t|
t.string :name
t.string :name
end
create_table :articles_tags, :force => true, :id => false do |t|
t.integer :article_id
t.integer :tag_id
t.integer :article_id
t.integer :tag_id
end
create_table :notes, :force => true do |t|
t.integer :notable_id
t.string :notable_type
t.string :note
t.integer :notable_id
t.string :notable_type
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