Tidy up the tests

* Use assert_nil where appropriate
* Lead with the expected value in collection_serializer_test.rb, etc
 so that expected/actual in test failure messages are not reversed
This commit is contained in:
Ben Woosley
2016-01-07 11:19:14 -08:00
parent 7d4f0c5c8a
commit 0a6c133d25
4 changed files with 15 additions and 15 deletions

View File

@@ -28,7 +28,7 @@ module ActiveModel
comment = Comment.new
post = Post.new
serializer = ArraySerializer.new([comment, post])
assert_equal serializer.json_key, 'comments'
assert_equal 'comments', serializer.json_key
end)
assert_match(/Calling deprecated ArraySerializer/, stderr)
end

View File

@@ -36,7 +36,7 @@ module ActiveModel
assert_kind_of PostSerializer, serializers.last
assert_kind_of Post, serializers.last.object
assert_equal serializers.last.custom_options[:some], :options
assert_equal :options, serializers.last.custom_options[:some]
end
def test_serializer_option_not_passed_to_each_serializer
@@ -47,50 +47,50 @@ module ActiveModel
def test_root_default
@serializer = collection_serializer.new([@comment, @post])
assert_equal @serializer.root, nil
assert_nil @serializer.root
end
def test_root
expected = 'custom_root'
@serializer = collection_serializer.new([@comment, @post], root: expected)
assert_equal @serializer.root, expected
assert_equal expected, @serializer.root
end
def test_root_with_no_serializers
expected = 'custom_root'
@serializer = collection_serializer.new([], root: expected)
assert_equal @serializer.root, expected
assert_equal expected, @serializer.root
end
def test_json_key
assert_equal @serializer.json_key, 'comments'
assert_equal 'comments', @serializer.json_key
end
def test_json_key_with_resource_with_name_and_no_serializers
serializer = collection_serializer.new(build_named_collection)
assert_equal serializer.json_key, 'me_resources'
assert_equal 'me_resources', serializer.json_key
end
def test_json_key_with_resource_with_nil_name_and_no_serializers
resource = []
resource.define_singleton_method(:name) { nil }
serializer = collection_serializer.new(resource)
assert_equal serializer.json_key, nil
assert_nil serializer.json_key
end
def test_json_key_with_resource_without_name_and_no_serializers
serializer = collection_serializer.new([])
assert_equal serializer.json_key, nil
assert_nil serializer.json_key
end
def test_json_key_with_root
serializer = collection_serializer.new(@resource, root: 'custom_root')
assert_equal serializer.json_key, 'custom_roots'
assert_equal 'custom_roots', serializer.json_key
end
def test_json_key_with_root_and_no_serializers
serializer = collection_serializer.new(build_named_collection, root: 'custom_root')
assert_equal serializer.json_key, 'custom_roots'
assert_equal 'custom_roots', serializer.json_key
end
end
end

View File

@@ -52,8 +52,8 @@ module ActiveModel
serializer = association.serializer
options = association.options
assert_equal key, :tags
assert_equal serializer, nil
assert_equal :tags, key
assert_nil serializer
assert_equal [{ name: '#hashtagged' }].to_json, options[:virtual_value].to_json
end
end