Sha256: fb30680a556b28a4be80c06840066b14212afe1cbe9c5b3f86af56b25c80fcdf

Contents?: true

Size: 1.12 KB

Versions: 14

Compression:

Stored size: 1.12 KB

Contents

require 'test_helper'

module ActiveModel
  class Serializer
    class ScopeTest < Minitest::Test
      def setup
        @serializer = ProfileSerializer.new(nil, scope: current_user)
      end

      def test_scope
        assert_equal('user', @serializer.scope)
      end

      private

      def current_user
        'user'
      end
    end

    class NestedScopeTest < Minitest::Test
      def setup
        @association = UserSerializer._associations[:profile]
        @old_association = @association.dup
        @user = User.new({ name: 'Name 1', email: 'mail@server.com', gender: 'M' })
        @user_serializer = UserSerializer.new(@user, scope: 'user')
      end

      def teardown
        UserSerializer._associations[:profile] = @old_association
      end

      def test_scope_passed_through
        @association.serializer_from_options = Class.new(Serializer) do
          def name
            scope
          end

          attributes :name
        end

        assert_equal({
          name: 'Name 1', email: 'mail@server.com', profile: { name: 'user' }
        }, @user_serializer.serializable_hash)
      end
    end

  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
active_model_serializers-0.9.13 test/unit/active_model/serializer/scope_test.rb
active_model_serializers-0.9.12 test/unit/active_model/serializer/scope_test.rb
active_model_serializers-0.9.11 test/unit/active_model/serializer/scope_test.rb
active_model_serializers-0.9.9 test/unit/active_model/serializer/scope_test.rb
active_model_serializers-0.9.8 test/unit/active_model/serializer/scope_test.rb
active_model_serializers-0.9.7 test/unit/active_model/serializer/scope_test.rb
active_model_serializers-0.9.6 test/unit/active_model/serializer/scope_test.rb
active_model_serializers-0.9.5 test/unit/active_model/serializer/scope_test.rb
active_model_serializers-0.9.4 test/unit/active_model/serializer/scope_test.rb
active_model_serializers-0.9.3 test/unit/active_model/serializer/scope_test.rb
active_model_serializers-0.9.2 test/unit/active_model/serializer/scope_test.rb
active_model_serializers-0.9.1 test/unit/active_model/serializer/scope_test.rb
active_model_serializers-0.9.0 test/unit/active_model/serializer/scope_test.rb
active_model_serializers_rails_2.3-0.9.0.alpha1 test/unit/active_model/serializer/scope_test.rb