Skip to content

Commit

Permalink
test from nil in rails 7.07
Browse files Browse the repository at this point in the history
  • Loading branch information
khiav223577 committed Sep 4, 2023
1 parent 99cc69d commit cfc0a9b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,21 @@ def assert_queries(expected_count, event_key = 'sql.active_record')
ensure
ActiveSupport::Notifications.unsubscribe(subscriber)
end

def assert_sqls(expected_sqls, event_key = 'sql.active_record')
sqls = []
subscriber = ActiveSupport::Notifications.subscribe(event_key) do |_, _, _, _, payload|
next if payload[:sql].start_with?('PRAGMA table_info')
next if payload[:sql] =~ /\A(?:BEGIN TRANSACTION|COMMIT TRANSACTION|BEGIN|COMMIT)\z/i

sqls << payload[:sql]
end
yield

missing_sqls = expected_sqls - sqls
if missing_sqls.any?
assert_equal "expect #{expected_sqls} queried, but query following sqls:\n#{sqls.join("\n").tr('"', "'")}\n", "\nmissing sqls:\n#{missing_sqls.join("\n").tr('"', "'")}\n"
end
ensure
ActiveSupport::Notifications.unsubscribe(subscriber)
end
11 changes: 11 additions & 0 deletions test/update_all_and_get_ids_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,15 @@ def test_on_relation_and_with_race_condition
assert_equal ['bomb', '', 'flame thrower'], Item.order('id').pluck(:name)
end
end

def test_select_from_dual
skip if not Atomically::AdapterCheckService.new(UserItem).mysql?

in_sandbox do
assert_sqls(['SELECT @ids FROM DUAL']) do
assert_equal [1, 2], Item.joins(:users).atomically.update_all_and_get_ids('items.name = ""')
assert_equal ['', '', 'flame thrower'], Item.order('id').pluck(:name)
end
end
end
end

0 comments on commit cfc0a9b

Please sign in to comment.