Skip to content

Commit

Permalink
Revert "rm spec/model_update_arel_10_spec.rb"
Browse files Browse the repository at this point in the history
This reverts commit 8158d2e,
restoring the test file spec/model_update_arel_10_spec.rb.
  • Loading branch information
jamiemccarthy committed Dec 26, 2023
1 parent afb1ed8 commit 7e1c6ab
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions spec/model_update_arel_10_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

# ActiveRecord's update_all invokes compile_update for the Arel::SelectManager returned
# by build_arel. It returns an Arel::UpdateManager. This makes sure that internal call
# assembles the update query correctly.

module Unreliable
class SqlTestingData
class_attribute :update_manager_sql
end
end

RSpec.describe "update_manager" do
it "in ActiveRecord >= 7, updates by subquery with select in random order",
skip: ((ActiveRecord::VERSION::MAJOR < 7) ? "test is for ActiveRecord >= 7 only" : false) do
module Arel
class SelectManager
def testing_compile_update(*args)
um = old_compile_update(*args)
Unreliable::SqlTestingData.update_manager_sql = um.to_sql
um
end
alias_method :old_compile_update, :compile_update
alias_method :compile_update, :testing_compile_update
end
end
Cat.update_all(name: "bar")
expect(Unreliable::SqlTestingData.update_manager_sql).to end_with("ORDER BY RANDOM())")
Cat.where(name: "foo").update_all(name: "bar")
expect(Unreliable::SqlTestingData.update_manager_sql).to end_with("ORDER BY RANDOM())")
Cat.where(name: "bar").order(:id).update_all(name: "baz")
expect(Unreliable::SqlTestingData.update_manager_sql).to end_with("ORDER BY \"cats\".\"id\" ASC)")
ensure
module Arel
class SelectManager
alias_method :compile_update, :old_compile_update
end
end
end
end

0 comments on commit 7e1c6ab

Please sign in to comment.