active_model_serializers/test/array_serializer_test.rb
Ben Woosley 0a6c133d25 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
2016-01-07 11:21:19 -08:00

39 lines
1.2 KiB
Ruby

require 'test_helper'
require_relative 'collection_serializer_test'
module ActiveModel
class Serializer
# Minitest.run_one_method isn't present in minitest 4
if $minitest_version > 4 # rubocop:disable Style/GlobalVars
class ArraySerializerTest < CollectionSerializerTest
extend ActiveSupport::Testing::Stream
def self.run_one_method(*)
stderr = (capture(:stderr) do
super
end)
if stderr !~ /Calling deprecated ArraySerializer/
fail Minitest::Assertion, stderr
end
end
def collection_serializer
ArraySerializer
end
end
else
class ArraySerializerTest < ActiveSupport::TestCase
extend ActiveSupport::Testing::Stream
def test_json_key_with_root_warns_when_using_array_serializer
stderr = (capture(:stderr) do
comment = Comment.new
post = Post.new
serializer = ArraySerializer.new([comment, post])
assert_equal 'comments', serializer.json_key
end)
assert_match(/Calling deprecated ArraySerializer/, stderr)
end
end
end
end
end