Skip to content

Commit

Permalink
Fix Arel 10.0 update_manager tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiemccarthy committed Jan 15, 2024
1 parent 6210962 commit 3319377
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
3 changes: 0 additions & 3 deletions spec/execute_queries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class CatTest < UnreliableTest
end

it "adds, updates-via-instance, and selects some cats" do
# TODO: remove extra logging
ActiveRecord::Base.logger = Logger.new($stdout)
ActiveRecord::Base.logger.level = :debug
expect(Cat.count).to eq(0)
CatTest::NAMES.shuffle.each { |name| Cat.new(name: name).save! }
expect(Cat.where(name: "Rashad").to_a.size).to eq(1)
Expand Down
29 changes: 24 additions & 5 deletions spec/model_update_arel_10_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,31 @@ def testing_compile_update(*args)
alias_method :compile_update, :testing_compile_update
end
end
Cat.update_all(name: "bar")
expect(Unreliable::SqlTestingData.update_manager_sql).to end_with(adapter_text("ORDER BY RANDOM())"))

# rubocop:disable Layout/SpaceInsideParens,Layout/DotPosition

# Single subquery: "update cats where id in (select cats where name=bar)"
Cat.where(name: "foo").update_all(name: "bar")
expect(Unreliable::SqlTestingData.update_manager_sql).to end_with(adapter_text("ORDER BY RANDOM())"))
Cat.where(name: "bar").order(:id).update_all(name: "baz")
expect(Unreliable::SqlTestingData.update_manager_sql).to end_with(adapter_text("ORDER BY \"cats\".\"id\" ASC)"))
expect(Unreliable::SqlTestingData.update_manager_sql).
to end_with(adapter_text("ORDER BY RANDOM())"))

# Double-nested subquery: "update cats where id in (select cats where id in (select owners where name=baz))"
Cat.where( id: Owner.where(name: "bar") ).update_all(name: "baz")
expect(Unreliable::SqlTestingData.update_manager_sql).
to end_with(adapter_text("ORDER BY RANDOM()) ORDER BY RANDOM())"))

# Single ordered subquery: "update cats where id in (select cats where name=bar order by id limit ?)"
# The presence of the primary-key order means Unreliable does not apply its own order.
Cat.where(name: "bar").order(:id).limit(1).update_all(name: "baz")
expect(Unreliable::SqlTestingData.update_manager_sql).
to end_with(adapter_text("ORDER BY \"cats\".\"id\" ASC LIMIT ?)"))

# Single ordered subquery: "update cats where id in (select cats where name=bar limit ?)"
Cat.where(name: "bar").limit(1).update_all(name: "baz")
expect(Unreliable::SqlTestingData.update_manager_sql).
to end_with(adapter_text("ORDER BY RANDOM() LIMIT ?)"))

# rubocop:enable Layout/SpaceInsideParens,Layout/DotPosition
ensure
module Arel
class SelectManager
Expand Down

0 comments on commit 3319377

Please sign in to comment.