File: fieldset_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 (26 lines) | stat: -rw-r--r-- 663 bytes parent folder | download
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
# frozen_string_literal: true

require 'test_helper'

module ActiveModel
  class Serializer
    class FieldsetTest < ActiveSupport::TestCase
      def setup
        @fieldset = ActiveModel::Serializer::Fieldset.new('post' => %w(id title), 'comment' => ['body'])
      end

      def test_fieldset_with_hash
        expected = { post: [:id, :title], comment: [:body] }

        assert_equal(expected, @fieldset.fields)
      end

      def test_fields_for_accepts_string_or_symbol
        expected = [:id, :title]

        assert_equal(expected, @fieldset.fields_for(:post))
        assert_equal(expected, @fieldset.fields_for('post'))
      end
    end
  end
end