Sha256: 479ebd52d1843bba3a5020d40bb4493142ab7926179d3a7a9c5d8182b95ba3a0

Contents?: true

Size: 869 Bytes

Versions: 9

Compression:

Stored size: 869 Bytes

Contents

require 'test_helper'

module ActiveModel
  class Serializer
    class UrlHelpersTest < Minitest::Test
      include Rails.application.routes.url_helpers

      def setup
        Object.const_set 'UserController', Class.new(ActionController::Base) do
          def show
            render text: 'profile'
          end
        end

        Rails.application.routes.draw do
          get '/profile/:id', as: :profile, controller: :user, action: :show
        end
      end

      def test_url_helpers_are_available
        serializer = Class.new(ActiveModel::Serializer) do
          attributes :url

          def url
            profile_url(id: object.object_id)
          end
        end
        profile = Profile.new

        assert_equal({ url: profile_url(id: profile.object_id) },
                     serializer.new(profile).as_json)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
active_model_serializers-0.9.11 test/unit/active_model/serializer/url_helpers_test.rb
active_model_serializers-0.9.9 test/unit/active_model/serializer/url_helpers_test.rb
active_model_serializers-0.9.8 test/unit/active_model/serializer/url_helpers_test.rb
active_model_serializers-0.9.7 test/unit/active_model/serializer/url_helpers_test.rb
active_model_serializers-0.9.6 test/unit/active_model/serializer/url_helpers_test.rb
active_model_serializers-0.9.5 test/unit/active_model/serializer/url_helpers_test.rb
active_model_serializers-0.9.4 test/unit/active_model/serializer/url_helpers_test.rb
active_model_serializers-0.9.3 test/unit/active_model/serializer/url_helpers_test.rb
active_model_serializers-0.9.1 test/unit/active_model/serializer/url_helpers_test.rb