Skip to content

Commit

Permalink
Correct cache_key lint for ActiveRecord 4.1+
Browse files Browse the repository at this point in the history
  • Loading branch information
bf4 committed Aug 31, 2015
1 parent 6d7bf34 commit a87243d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/active_model/serializer/lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,19 @@ def test_to_json
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,
# which is used by the adapter.
# 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
Expand Down

0 comments on commit a87243d

Please sign in to comment.