active_model_serializers/test/serializer_support_test.rb
José Valim be70c5c846 Revert "clean up lazy loading of serialization support for
ActiveRecord::Base and ActionController::Base"

The whole idea of having a lazy hook is that it can be executed
in the context of different targets. The moment you hardcode the class,
the hooks can no longer run in the proper context.

This reverts commit 506e2ac9ad.
2012-10-17 19:28:02 +02:00

31 lines
785 B
Ruby

require "test_helper"
class RandomModel
include ActiveModel::SerializerSupport
end
class RandomModelCollection
include ActiveModel::ArraySerializerSupport
end
module ActiveRecord
class Relation
end
end
class SerializerSupportTest < ActiveModel::TestCase
test "it returns nil if no serializer exists" do
assert_equal nil, RandomModel.new.active_model_serializer
end
test "it returns ArraySerializer for a collection" do
assert_equal ActiveModel::ArraySerializer, RandomModelCollection.new.active_model_serializer
end
test "it automatically includes array_serializer in active_record/relation" do
ActiveSupport.run_load_hooks(:active_record)
assert_equal ActiveModel::ArraySerializer, ActiveRecord::Relation.new.active_model_serializer
end
end