mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use capture_sql
instead of assert_sql
with no pattern
And no longer need to except SCHEMA SQLs manually since 0810c07
.
This commit is contained in:
parent
3453c5d4c0
commit
95e952626d
3 changed files with 12 additions and 15 deletions
|
@ -22,7 +22,7 @@ class Mysql2CaseSensitivityTest < ActiveRecord::Mysql2TestCase
|
|||
CollationTest.validates_uniqueness_of(:string_ci_column, case_sensitive: false)
|
||||
CollationTest.create!(string_ci_column: "A")
|
||||
invalid = CollationTest.new(string_ci_column: "a")
|
||||
queries = assert_sql { invalid.save }
|
||||
queries = capture_sql { invalid.save }
|
||||
ci_uniqueness_query = queries.detect { |q| q.match(/string_ci_column/) }
|
||||
assert_no_match(/lower/i, ci_uniqueness_query)
|
||||
end
|
||||
|
@ -31,7 +31,7 @@ class Mysql2CaseSensitivityTest < ActiveRecord::Mysql2TestCase
|
|||
CollationTest.validates_uniqueness_of(:string_cs_column, case_sensitive: false)
|
||||
CollationTest.create!(string_cs_column: "A")
|
||||
invalid = CollationTest.new(string_cs_column: "a")
|
||||
queries = assert_sql { invalid.save }
|
||||
queries = capture_sql { invalid.save }
|
||||
cs_uniqueness_query = queries.detect { |q| q.match(/string_cs_column/) }
|
||||
assert_match(/lower/i, cs_uniqueness_query)
|
||||
end
|
||||
|
@ -40,7 +40,7 @@ class Mysql2CaseSensitivityTest < ActiveRecord::Mysql2TestCase
|
|||
CollationTest.validates_uniqueness_of(:string_ci_column, case_sensitive: true)
|
||||
CollationTest.create!(string_ci_column: "A")
|
||||
invalid = CollationTest.new(string_ci_column: "A")
|
||||
queries = assert_sql { invalid.save }
|
||||
queries = capture_sql { invalid.save }
|
||||
ci_uniqueness_query = queries.detect { |q| q.match(/string_ci_column/) }
|
||||
assert_match(/binary/i, ci_uniqueness_query)
|
||||
end
|
||||
|
@ -49,7 +49,7 @@ class Mysql2CaseSensitivityTest < ActiveRecord::Mysql2TestCase
|
|||
CollationTest.validates_uniqueness_of(:string_cs_column, case_sensitive: true)
|
||||
CollationTest.create!(string_cs_column: "A")
|
||||
invalid = CollationTest.new(string_cs_column: "A")
|
||||
queries = assert_sql { invalid.save }
|
||||
queries = capture_sql { invalid.save }
|
||||
cs_uniqueness_query = queries.detect { |q| q.match(/string_cs_column/) }
|
||||
assert_no_match(/binary/i, cs_uniqueness_query)
|
||||
end
|
||||
|
@ -58,7 +58,7 @@ class Mysql2CaseSensitivityTest < ActiveRecord::Mysql2TestCase
|
|||
CollationTest.validates_uniqueness_of(:binary_column, case_sensitive: true)
|
||||
CollationTest.create!(binary_column: "A")
|
||||
invalid = CollationTest.new(binary_column: "A")
|
||||
queries = assert_sql { invalid.save }
|
||||
queries = capture_sql { invalid.save }
|
||||
bin_uniqueness_query = queries.detect { |q| q.match(/binary_column/) }
|
||||
assert_no_match(/\bBINARY\b/, bin_uniqueness_query)
|
||||
end
|
||||
|
|
|
@ -185,7 +185,7 @@ class CalculationsTest < ActiveRecord::TestCase
|
|||
def test_limit_is_kept
|
||||
return if current_adapter?(:OracleAdapter)
|
||||
|
||||
queries = assert_sql { Account.limit(1).count }
|
||||
queries = capture_sql { Account.limit(1).count }
|
||||
assert_equal 1, queries.length
|
||||
assert_match(/LIMIT/, queries.first)
|
||||
end
|
||||
|
@ -193,7 +193,7 @@ class CalculationsTest < ActiveRecord::TestCase
|
|||
def test_offset_is_kept
|
||||
return if current_adapter?(:OracleAdapter)
|
||||
|
||||
queries = assert_sql { Account.offset(1).count }
|
||||
queries = capture_sql { Account.offset(1).count }
|
||||
assert_equal 1, queries.length
|
||||
assert_match(/OFFSET/, queries.first)
|
||||
end
|
||||
|
@ -201,14 +201,14 @@ class CalculationsTest < ActiveRecord::TestCase
|
|||
def test_limit_with_offset_is_kept
|
||||
return if current_adapter?(:OracleAdapter)
|
||||
|
||||
queries = assert_sql { Account.limit(1).offset(1).count }
|
||||
queries = capture_sql { Account.limit(1).offset(1).count }
|
||||
assert_equal 1, queries.length
|
||||
assert_match(/LIMIT/, queries.first)
|
||||
assert_match(/OFFSET/, queries.first)
|
||||
end
|
||||
|
||||
def test_no_limit_no_offset
|
||||
queries = assert_sql { Account.count }
|
||||
queries = capture_sql { Account.count }
|
||||
assert_equal 1, queries.length
|
||||
assert_no_match(/LIMIT/, queries.first)
|
||||
assert_no_match(/OFFSET/, queries.first)
|
||||
|
@ -224,15 +224,12 @@ class CalculationsTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_apply_distinct_in_count
|
||||
queries = assert_sql do
|
||||
queries = capture_sql do
|
||||
Account.distinct.count
|
||||
Account.group(:firm_id).distinct.count
|
||||
end
|
||||
|
||||
queries.each do |query|
|
||||
# `table_alias_length` in `column_alias_for` would execute
|
||||
# "SHOW max_identifier_length" statement in PostgreSQL adapter.
|
||||
next if query == "SHOW max_identifier_length"
|
||||
assert_match %r{\ASELECT(?! DISTINCT) COUNT\(DISTINCT\b}, query
|
||||
end
|
||||
end
|
||||
|
@ -464,7 +461,7 @@ class CalculationsTest < ActiveRecord::TestCase
|
|||
|
||||
def test_should_not_perform_joined_include_by_default
|
||||
assert_equal Account.count, Account.includes(:firm).count
|
||||
queries = assert_sql { Account.includes(:firm).count }
|
||||
queries = capture_sql { Account.includes(:firm).count }
|
||||
assert_no_match(/join/i, queries.last)
|
||||
end
|
||||
|
||||
|
|
|
@ -706,7 +706,7 @@ class RelationTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_to_sql_on_eager_join
|
||||
expected = assert_sql {
|
||||
expected = capture_sql {
|
||||
Post.eager_load(:last_comment).order("comments.id DESC").to_a
|
||||
}.first
|
||||
actual = Post.eager_load(:last_comment).order("comments.id DESC").to_sql
|
||||
|
|
Loading…
Reference in a new issue