1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

⚠️ "Use assert_nil if expecting nil. This will fail in MT6."

These are followups for 307065f959,
but TBH I'm personally not very much confortable with this style.
Maybe we could override assert_equal in our test_helper not to warn?
This commit is contained in:
Akira Matsuda 2017-01-18 16:09:58 +09:00
parent 044f8bdf62
commit 5349d4ee08
7 changed files with 50 additions and 18 deletions

View file

@ -66,12 +66,20 @@ class ParametersPermitTest < ActiveSupport::TestCase
values.each do |value|
params = ActionController::Parameters.new(id: value)
permitted = params.permit(:id)
assert_equal value, permitted[:id]
if value.nil?
assert_nil permitted[:id]
else
assert_equal value, permitted[:id]
end
@struct_fields.each do |sf|
params = ActionController::Parameters.new(sf => value)
permitted = params.permit(:sf)
assert_equal value, permitted[sf]
if value.nil?
assert_nil permitted[sf]
else
assert_equal value, permitted[sf]
end
end
end
end

View file

@ -21,16 +21,20 @@ class ActionController::TestRequestTest < ActionController::TestCase
@request.get_header("CONTENT_LENGTH"))
end
ActionDispatch::Session::AbstractStore::DEFAULT_OPTIONS.each_key do |option|
test "rack default session options #{option} exists in session options and is default" do
assert_equal(ActionDispatch::Session::AbstractStore::DEFAULT_OPTIONS[option],
@request.session_options[option],
"Missing rack session default option #{option} in request.session_options")
ActionDispatch::Session::AbstractStore::DEFAULT_OPTIONS.each_pair do |key, value|
test "rack default session options #{key} exists in session options and is default" do
if value.nil?
assert_nil(@request.session_options[key],
"Missing rack session default option #{key} in request.session_options")
else
assert_equal(value, @request.session_options[key],
"Missing rack session default option #{key} in request.session_options")
end
end
test "rack default session options #{option} exists in session options" do
assert(@request.session_options.has_key?(option),
"Missing rack session option #{option} in request.session_options")
test "rack default session options #{key} exists in session options" do
assert(@request.session_options.has_key?(key),
"Missing rack session option #{key} in request.session_options")
end
end
end

View file

@ -51,7 +51,12 @@ class ErbUtilTest < ActiveSupport::TestCase
def test_json_escape_does_not_alter_json_string_meaning
JSON_ESCAPE_TEST_CASES.each do |(raw, _)|
assert_equal ActiveSupport::JSON.decode(raw), ActiveSupport::JSON.decode(json_escape(raw))
expected = ActiveSupport::JSON.decode(raw)
if expected.nil?
assert_nil ActiveSupport::JSON.decode(json_escape(raw))
else
assert_equal expected, ActiveSupport::JSON.decode(json_escape(raw))
end
end
end

View file

@ -41,8 +41,8 @@ class CopyTableTest < ActiveRecord::SQLite3TestCase
test_copy_table("comments", "comments_with_index") do
@connection.add_index("comments_with_index", ["post_id", "type"])
test_copy_table("comments_with_index", "comments_with_index2") do
assert_equal table_indexes_without_name("comments_with_index"),
table_indexes_without_name("comments_with_index2")
assert_nil table_indexes_without_name("comments_with_index")
assert_nil table_indexes_without_name("comments_with_index2")
end
end
end
@ -59,7 +59,8 @@ class CopyTableTest < ActiveRecord::SQLite3TestCase
copied_id = @connection.columns("goofy_string_id2").detect { |col| col.name == "id" }
assert_equal original_id.type, copied_id.type
assert_equal original_id.sql_type, copied_id.sql_type
assert_equal original_id.limit, copied_id.limit
assert_nil original_id.limit
assert_nil copied_id.limit
end
end

View file

@ -933,7 +933,11 @@ class EagerAssociationTest < ActiveRecord::TestCase
d2 = find_all_ordered(Firm, :account)
d1.each_index do |i|
assert_equal(d1[i], d2[i])
assert_equal(d1[i].account, d2[i].account)
if d1[i].account.nil?
assert_nil(d2[i].account)
else
assert_equal(d1[i].account, d2[i].account)
end
end
end
@ -943,7 +947,13 @@ class EagerAssociationTest < ActiveRecord::TestCase
d2 = find_all_ordered(Client, firm_types)
d1.each_index do |i|
assert_equal(d1[i], d2[i])
firm_types.each { |type| assert_equal(d1[i].send(type), d2[i].send(type)) }
firm_types.each do |type|
if (expected = d1[i].send(type)).nil?
assert_nil(d2[i].send(type))
else
assert_equal(expected, d2[i].send(type))
end
end
end
end
def test_eager_with_valid_association_as_string_not_symbol

View file

@ -443,7 +443,7 @@ class InverseHasManyTests < ActiveRecord::TestCase
assert man.equal?(man.interests.first.man), "Two inverses should lead back to the same object that was originally held"
assert man.equal?(man.interests.find(interest.id).man), "Two inversions should lead back to the same object that was originally held"
assert_equal man.name, man.interests.find(interest.id).man.name, "The name of the man should match before the name is changed"
assert_nil man.interests.find(interest.id).man.name, "The name of the man should match before the name is changed"
man.name = "Ben Bitdiddle"
assert_equal man.name, man.interests.find(interest.id).man.name, "The name of the man should match after the parent name is changed"
man.interests.find(interest.id).man.name = "Alyssa P. Hacker"

View file

@ -279,7 +279,11 @@ class TransactionTest < ActiveRecord::TestCase
e = assert_raises(RuntimeError) { new_topic.save }
assert_equal "Make the transaction rollback", e.message
assert_equal new_record_snapshot, !new_topic.persisted?, "The topic should have its old persisted value"
assert_equal id_snapshot, new_topic.id, "The topic should have its old id"
if id_snapshot.nil?
assert_nil new_topic.id, "The topic should have its old id"
else
assert_equal id_snapshot, new_topic.id, "The topic should have its old id"
end
assert_equal id_present, new_topic.has_attribute?(Topic.primary_key)
end
end