Sha256: f00e93e6634eb88fd24376083369bd6091c68e19496ab9cbfffee945aeb6ad5f

Contents?: true

Size: 1.28 KB

Versions: 17

Compression:

Stored size: 1.28 KB

Contents

require "test_helper"

class RandomModel
  include ActiveModel::SerializerSupport
end

class OtherRandomModel
  include ActiveModel::SerializerSupport
end

class OtherRandomModelSerializer
end

class RandomModelCollection
  include ActiveModel::ArraySerializerSupport
end

module ActiveRecord
  class Relation
  end
end

module Mongoid
  class Criteria
  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 a deducted serializer if it exists exists" do
    assert_equal OtherRandomModelSerializer, OtherRandomModel.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

  test "it automatically includes array_serializer in mongoid/criteria" do
    ActiveSupport.run_load_hooks(:mongoid)
    assert_equal ActiveModel::ArraySerializer, Mongoid::Criteria.new.active_model_serializer
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
active_model_serializers-0.8.4 test/serializer_support_test.rb
active_model_serializers-0.8.3 test/serializer_support_test.rb
active_model_serializers-0.8.2 test/serializer_support_test.rb
gpi-active_model_serializers-0.8.5 test/serializer_support_test.rb
gpi-active_model_serializers-0.8.5.alpha1 test/serializer_support_test.rb
gpi-active_model_serializers-0.8.4 test/serializer_support_test.rb
gpi-active_model_serializers-0.8.4.alpha5 test/serializer_support_test.rb
gpi-active_model_serializers-0.8.4.alpha4 test/serializer_support_test.rb
gpi-active_model_serializers-0.8.4.alpha3 test/serializer_support_test.rb
gpi-active_model_serializers-0.8.4.alpha2 test/serializer_support_test.rb
gpi-active_model_serializers-0.8.4.alpha1 test/serializer_support_test.rb
gpi-active_model_serializers-0.8.3.rc1 test/serializer_support_test.rb
gpi-active_model_serializers-0.8.3.alpha2 test/serializer_support_test.rb
gpi-active_model_serializers-0.8.3.alpha1 test/serializer_support_test.rb
gpi-active_model_serializers-0.8.2 test/serializer_support_test.rb
active_model_serializers-0.8.1 test/serializer_support_test.rb
active_model_serializers-0.8.0 test/serializer_support_test.rb