Skip to content

Tidy up the tests #1423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/active_model/serializer/lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_cache_key
def test_updated_at
assert_respond_to resource, :updated_at
actual_arity = resource.method(:updated_at).arity
assert_equal actual_arity, 0, "expected #{actual_arity.inspect} to be 0"
assert_equal 0, actual_arity
end

# Passes if the object responds to <tt>id</tt> and if it takes no
Expand All @@ -113,7 +113,7 @@ def test_updated_at
# It is not required unless caching is enabled.
def test_id
assert_respond_to resource, :id
assert_equal resource.method(:id).arity, 0
assert_equal 0, resource.method(:id).arity
end

# Passes if the object's class responds to <tt>model_name</tt> and if it
Expand Down
2 changes: 1 addition & 1 deletion test/array_serializer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_json_key_with_root_warns_when_using_array_serializer
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
Expand Down
20 changes: 10 additions & 10 deletions test/collection_serializer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_each_object_should_be_serialized_with_appropriate_serializer
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
Expand All @@ -47,50 +47,50 @@ def test_serializer_option_not_passed_to_each_serializer

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
Expand Down
4 changes: 2 additions & 2 deletions test/serializers/associations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def test_has_many_with_no_serializer
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
Expand Down