Skip to content

Commit

Permalink
rubocop, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiemccarthy committed Jan 15, 2024
1 parent 58ec493 commit e591e7f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ Metrics/AbcSize:
Metrics/BlockLength:
Max: 40
Exclude:
- spec/textual_order_raw_spec.rb
- spec/execute_queries_spec.rb
- spec/model_update_arel_10_spec.rb
- spec/textual_order_raw_spec.rb

Metrics/CyclomaticComplexity:
Max: 9
Expand Down
27 changes: 19 additions & 8 deletions spec/model_update_arel_10_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SqlTestingData
end

RSpec.describe "update_manager" do
it "in ActiveRecord >= 7, updates by subquery with select in random order",
it "in ActiveRecord >= 7, updates by subquery with select",
skip: ((ActiveRecord::VERSION::MAJOR < 7) ? "test is for ActiveRecord >= 7 only" : false) do
module Arel
class SelectManager
Expand All @@ -36,8 +36,11 @@ def testing_compile_update(*args)

# rubocop:disable Layout/SpaceInsideParens,Layout/DotPosition

# Single subquery for sqlite/postgresql: "update cats where id in (select cats where name=bar)"
# Direct update for mysql: "update cats where name=bar"
# Single subquery for sqlite/postgresql:
# "update cats where id in (select cats where name=bar)"
# Direct update for mysql:
# "update cats where name=bar"

Cat.where(name: "foo").update_all(name: "bar")
expect(Unreliable::SqlTestingData.update_manager_sql).
to end_with(
Expand All @@ -49,8 +52,11 @@ def testing_compile_update(*args)
end
)

# Double-nested subquery for sqlite/postgresql: "update cats where id in (select cats where id in (select owners where name=baz))"
# Single-nested for mysql: "update cats where id in (select owners where name=baz)"
# Double-nested subquery for sqlite/postgresql:
# "update cats where id in (select cats where id in (select owners where name=baz))"
# Single-nested for mysql:
# "update 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(
Expand All @@ -62,8 +68,11 @@ def testing_compile_update(*args)
end
)

# Single ordered subquery for sqlite/postgresql: "update cats where id in (select cats where name=bar limit ?)"
# Direct update for mysql: "update cats where name=baz"
# Single ordered subquery for sqlite/postgresql:
# "update cats where id in (select cats where name=bar limit ?)"
# Direct update for mysql:
# "update cats where name=baz"

Cat.where(name: "bar").limit(1).update_all(name: "baz")
expect(Unreliable::SqlTestingData.update_manager_sql).
to match(
Expand All @@ -75,8 +84,10 @@ def testing_compile_update(*args)
end
)

# Single ordered subquery: "update cats where id in (select cats where name=bar order by id limit ?)"
# 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 match(adapter_text('ORDER BY "cats"\."id" ASC LIMIT '))
Expand Down

0 comments on commit e591e7f

Please sign in to comment.