Sha256: 91d098bd43ad3642dff53b06d28558388022b4b400536021630a5ddfab25ec56

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

require 'test_helper'

module ActiveModelSerializers
  module Adapter
    class AttributesTest < ActiveSupport::TestCase
      class Person < ActiveModelSerializers::Model
        attributes :first_name, :last_name
      end

      class PersonSerializer < ActiveModel::Serializer
        attributes :first_name, :last_name
      end

      def setup
        ActionController::Base.cache_store.clear
      end

      def test_serializable_hash
        person = Person.new(first_name: 'Arthur', last_name: 'Dent')
        serializer = PersonSerializer.new(person)
        adapter = ActiveModelSerializers::Adapter::Attributes.new(serializer)

        assert_equal({ first_name: 'Arthur', last_name: 'Dent' },
          adapter.serializable_hash)
      end

      def test_serializable_hash_with_transform_key_casing
        person = Person.new(first_name: 'Arthur', last_name: 'Dent')
        serializer = PersonSerializer.new(person)
        adapter = ActiveModelSerializers::Adapter::Attributes.new(
          serializer,
          key_transform: :camel_lower
        )

        assert_equal({ firstName: 'Arthur', lastName: 'Dent' },
          adapter.serializable_hash)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_model_serializers-0.10.8 test/adapter/attributes_test.rb
active_model_serializers-0.10.7 test/adapter/attributes_test.rb
active_model_serializers-0.10.6 test/adapter/attributes_test.rb
active_model_serializers-0.10.5 test/adapter/attributes_test.rb