Sha256: e8970f834d3c5a3228647275723f305f00c1464710dcba7a09cb51a7c6852bd3

Contents?: true

Size: 1014 Bytes

Versions: 7

Compression:

Stored size: 1014 Bytes

Contents

require 'test_helper'

module ActiveModel
  class Serializer
    class OptionsTest < ActiveSupport::TestCase
      class ModelWithOptions < ActiveModelSerializers::Model
        attributes :name, :description
      end
      class ModelWithOptionsSerializer < ActiveModel::Serializer
        attributes :name, :description

        def arguments_passed_in?
          instance_options[:my_options] == :accessible
        end
      end

      setup do
        @model_with_options = ModelWithOptions.new(name: 'Name 1', description: 'Description 1')
      end

      def test_options_are_accessible
        model_with_options_serializer = ModelWithOptionsSerializer.new(@model_with_options, my_options: :accessible)
        assert model_with_options_serializer.arguments_passed_in?
      end

      def test_no_option_is_passed_in
        model_with_options_serializer = ModelWithOptionsSerializer.new(@model_with_options)
        refute model_with_options_serializer.arguments_passed_in?
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
active_model_serializers-0.10.8 test/serializers/options_test.rb
active_model_serializers-0.10.7 test/serializers/options_test.rb
active_model_serializers-0.10.6 test/serializers/options_test.rb
active_model_serializers-0.10.5 test/serializers/options_test.rb
agi_active_model_serializers-0.10.9 test/serializers/options_test.rb
agi_active_model_serializers-0.10.8 test/serializers/options_test.rb
agi_active_model_serializers-0.10.7 test/serializers/options_test.rb