Add spec for not_eq with default scope, failing in Rails 5.2.4

This commit is contained in:
Steven Jones 2020-03-23 14:30:40 -07:00
parent 09cef0cdca
commit d45156a9c2
3 changed files with 23 additions and 1 deletions

View File

@ -17,7 +17,7 @@ rails_version = case rails
gem 'faker', '~> 0.9.5'
gem 'sqlite3', ::Gem::Version.new(rails_version) >= ::Gem::Version.new('6-0-stable') ? '~> 1.4.1' : '~> 1.3.3'
gem 'pg', '~> 1.0'
gem 'pry', '0.10'
gem 'pry', '~> 0.12.2'
gem 'byebug'
case rails

View File

@ -79,6 +79,25 @@ module Ransack
expect(constraint.right.relation.name).to eql 'people'
expect(constraint.right.name).to eql 'id'
end
it 'build correlated subquery for multiple conditions (default scope)' do
search = Search.new(Person, { comments_body_not_eq: 'some_title'})
# Was
# SELECT "people".* FROM "people" WHERE "people"."id" NOT IN (
# SELECT "comments"."disabled" FROM "comments"
# WHERE "comments"."disabled" = "people"."id"
# AND NOT ("comments"."body" != 'some_title')
# ) ORDER BY "people"."id" DESC
# Should Be
# SELECT "people".* FROM "people" WHERE "people"."id" NOT IN (
# SELECT "comments"."person_id" FROM "comments"
# WHERE "comments"."person_id" = "people"."id"
# AND NOT ("comments"."body" != 'some_title')
# ) ORDER BY "people"."id" DESC
expect(search.result.to_sql).to include '"comments"."person_id" = "people"."id"'
end
end
describe 'sharing context across searches' do

View File

@ -164,6 +164,8 @@ end
class Comment < ActiveRecord::Base
belongs_to :article
belongs_to :person
default_scope { where(disabled: false) }
end
class Tag < ActiveRecord::Base
@ -209,6 +211,7 @@ module Schema
t.integer :article_id
t.integer :person_id
t.text :body
t.boolean :disabled, default: false
end
create_table :tags, force: true do |t|