diff --git a/.rubocop.yml b/.rubocop.yml index 9c73801..4db852d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 diff --git a/spec/model_update_arel_10_spec.rb b/spec/model_update_arel_10_spec.rb index 3aa29e8..8068186 100644 --- a/spec/model_update_arel_10_spec.rb +++ b/spec/model_update_arel_10_spec.rb @@ -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 @@ -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( @@ -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( @@ -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( @@ -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 '))