File: association_macros_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 (39 lines) | stat: -rw-r--r-- 1,097 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
# frozen_string_literal: true

require 'test_helper'

module ActiveModel
  class Serializer
    class AssociationMacrosTest < ActiveSupport::TestCase
      class AuthorSummarySerializer < ActiveModel::Serializer; end

      class AssociationsTestSerializer < Serializer
        belongs_to :author, serializer: AuthorSummarySerializer
        has_many :comments
        has_one :category
      end

      def before_setup
        @reflections = AssociationsTestSerializer._reflections.values
      end

      def test_has_one_defines_reflection
        has_one_reflection = HasOneReflection.new(:category, {})

        assert_includes(@reflections, has_one_reflection)
      end

      def test_has_many_defines_reflection
        has_many_reflection = HasManyReflection.new(:comments, {})

        assert_includes(@reflections, has_many_reflection)
      end

      def test_belongs_to_defines_reflection
        belongs_to_reflection = BelongsToReflection.new(:author, serializer: AuthorSummarySerializer)

        assert_includes(@reflections, belongs_to_reflection)
      end
    end
  end
end