Sha256: 51b7dd48cd44d709b6e82dfd28dae95fcf3ea30d966f87973e1dceea27b2cc12

Contents?: true

Size: 1.33 KB

Versions: 9

Compression:

Stored size: 1.33 KB

Contents

require 'test_helper'

module ActiveModel
  class Serializer
    class OptionsTest < Minitest::Test
      def setup
        @serializer = ProfileSerializer.new(nil, context: {foo: :bar})
      end

      def test_custom_options_are_accessible_from_serializer
        assert_equal({foo: :bar}, @serializer.context)
      end
    end

    class SerializationOptionsTest < Minitest::Test
      def setup
        @profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
        @profile_serializer = ProfileSerializer.new(@profile)
        @profile_serializer.instance_eval do
          def description
            serialization_options[:force_the_description]
          end
        end

        @category = Category.new({name: 'Category 1'})
        @category_serializer = CategorySerializer.new(@category)
      end

      def test_filtered_attributes_serialization
        forced_description = "This is a test"
        assert_equal({
          'profile' => { name: 'Name 1', description: forced_description }
        }, @profile_serializer.as_json(force_the_description: forced_description))
      end

      def test_filtered_attributes_serialization_across_association
        assert_equal("'T1'",
            @category_serializer.as_json(highlight_keyword: 'T1')['category'][:posts][0][:title])
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
active_model_serializers-0.9.13 test/unit/active_model/serializer/options_test.rb
active_model_serializers-0.9.12 test/unit/active_model/serializer/options_test.rb
active_model_serializers-0.9.11 test/unit/active_model/serializer/options_test.rb
active_model_serializers-0.9.9 test/unit/active_model/serializer/options_test.rb
active_model_serializers-0.9.8 test/unit/active_model/serializer/options_test.rb
active_model_serializers-0.9.7 test/unit/active_model/serializer/options_test.rb
active_model_serializers-0.9.6 test/unit/active_model/serializer/options_test.rb
active_model_serializers-0.9.5 test/unit/active_model/serializer/options_test.rb
active_model_serializers-0.9.4 test/unit/active_model/serializer/options_test.rb