Skip to content

Commit 5f03454

Browse files
committed
Merge pull request #1108 from bf4/better_lint
Better lint
2 parents b20f1f5 + 9673b64 commit 5f03454

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/active_model/serializer/lint.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,17 @@ def test_serializable_hash
3636
# Typically, it is implemented by including ActiveModel::Serialization.
3737
def test_read_attribute_for_serialization
3838
assert_respond_to resource, :read_attribute_for_serialization, "The resource should respond to read_attribute_for_serialization"
39-
assert_equal resource.method(:read_attribute_for_serialization).arity, 1
39+
actual_arity = resource.method(:read_attribute_for_serialization).arity
40+
if defined?(::Rubinius)
41+
# 1 for def read_attribute_for_serialization(name); end
42+
# -2 for alias :read_attribute_for_serialization :send for rbx because :shrug:
43+
assert_includes [1, -2], actual_arity, "expected #{actual_arity.inspect} to be 1 or -2"
44+
else
45+
# using absolute value since arity is:
46+
# 1 for def read_attribute_for_serialization(name); end
47+
# -1 for alias :read_attribute_for_serialization :send
48+
assert_includes [1, -1], actual_arity, "expected #{actual_arity.inspect} to be 1 or -1"
49+
end
4050
end
4151

4252
# Passes if the object responds to <tt>as_json</tt> and if it takes
@@ -68,15 +78,19 @@ def test_to_json
6878
end
6979

7080
# Passes if the object responds to <tt>cache_key</tt> and if it takes no
71-
# arguments.
81+
# arguments (Rails 4.0) or a splat (Rails 4.1+).
7282
# Fails otherwise.
7383
#
7484
# <tt>cache_key</tt> returns a (self-expiring) unique key for the object,
7585
# which is used by the adapter.
7686
# It is not required unless caching is enabled.
7787
def test_cache_key
7888
assert_respond_to resource, :cache_key
79-
assert_equal resource.method(:cache_key).arity, 0
89+
actual_arity = resource.method(:cache_key).arity
90+
# using absolute value since arity is:
91+
# 0 for Rails 4.1+, *timestamp_names
92+
# -1 for Rails 4.0, no arguments
93+
assert_includes [-1, 0], actual_arity, "expected #{actual_arity.inspect} to be 0 or -1"
8094
end
8195

8296
# Passes if the object responds to <tt>id</tt> and if it takes no

0 commit comments

Comments
 (0)