File: attributes_test.rb

package info (click to toggle)
ruby-active-model-serializers 0.10.12-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,752 kB
  • sloc: ruby: 13,138; sh: 53; makefile: 6
file content (42 lines) | stat: -rw-r--r-- 1,232 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

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