mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Better lint
Extracted from https://github.com/rails-api/active_model_serializers/pull/1004/files#diff-56455571c4ba7a2b4c640b9e8168f522R40 Correct cache_key lint for ActiveRecord 4.1+ https://github.com/rails/rails/blob/4-0-stable/activerecord/lib/active_record/integration.rb def cache_key https://github.com/rails/rails/blob/4-1-stable/activerecord/lib/active_record/integration.rb def cache_key(*timestamp_names)
This commit is contained in:
parent
b20f1f5f9d
commit
9673b6471c
@ -36,7 +36,17 @@ module ActiveModel::Serializer::Lint
|
||||
# Typically, it is implemented by including ActiveModel::Serialization.
|
||||
def test_read_attribute_for_serialization
|
||||
assert_respond_to resource, :read_attribute_for_serialization, "The resource should respond to read_attribute_for_serialization"
|
||||
assert_equal resource.method(:read_attribute_for_serialization).arity, 1
|
||||
actual_arity = resource.method(:read_attribute_for_serialization).arity
|
||||
if defined?(::Rubinius)
|
||||
# 1 for def read_attribute_for_serialization(name); end
|
||||
# -2 for alias :read_attribute_for_serialization :send for rbx because :shrug:
|
||||
assert_includes [1, -2], actual_arity, "expected #{actual_arity.inspect} to be 1 or -2"
|
||||
else
|
||||
# using absolute value since arity is:
|
||||
# 1 for def read_attribute_for_serialization(name); end
|
||||
# -1 for alias :read_attribute_for_serialization :send
|
||||
assert_includes [1, -1], actual_arity, "expected #{actual_arity.inspect} to be 1 or -1"
|
||||
end
|
||||
end
|
||||
|
||||
# Passes if the object responds to <tt>as_json</tt> and if it takes
|
||||
@ -68,7 +78,7 @@ module ActiveModel::Serializer::Lint
|
||||
end
|
||||
|
||||
# Passes if the object responds to <tt>cache_key</tt> and if it takes no
|
||||
# arguments.
|
||||
# arguments (Rails 4.0) or a splat (Rails 4.1+).
|
||||
# Fails otherwise.
|
||||
#
|
||||
# <tt>cache_key</tt> returns a (self-expiring) unique key for the object,
|
||||
@ -76,7 +86,11 @@ module ActiveModel::Serializer::Lint
|
||||
# It is not required unless caching is enabled.
|
||||
def test_cache_key
|
||||
assert_respond_to resource, :cache_key
|
||||
assert_equal resource.method(:cache_key).arity, 0
|
||||
actual_arity = resource.method(:cache_key).arity
|
||||
# using absolute value since arity is:
|
||||
# 0 for Rails 4.1+, *timestamp_names
|
||||
# -1 for Rails 4.0, no arguments
|
||||
assert_includes [-1, 0], actual_arity, "expected #{actual_arity.inspect} to be 0 or -1"
|
||||
end
|
||||
|
||||
# Passes if the object responds to <tt>id</tt> and if it takes no
|
||||
|
||||
Loading…
Reference in New Issue
Block a user