Sha256: e3eb964b2c86dc4dcab35e3eeb238032f8908e7c5f843798458da7d998e330ab

Contents?: true

Size: 1.43 KB

Versions: 17

Compression:

Stored size: 1.43 KB

Contents

module Heroku
  class API
    module Mock

      # stub DELETE /user/keys/:key
      Excon.stub(:expects => 200, :method => :delete, :path => %r{^/user/keys/([^/]+)}) do |params|
        request_params, mock_data = parse_stub_params(params)
        key, _ = request_params[:captures][:path]
        key = unescape(key)
        if key_data = get_mock_key(mock_data, key)
          mock_data[:keys].delete(key_data)
          { :status => 200 }
        else
          { :body => "Key not found.", :status => 404 }
        end
      end

      # stub DELETE /user/keys
      Excon.stub(:expects => 200, :method => :delete, :path => %r{^/user/keys$}) do |params|
        request_params, mock_data = parse_stub_params(params)
        mock_data[:keys] = []
        { :status => 200 }
      end

      # stub GET /user/keys
      Excon.stub(:expects => 200, :method => :get, :path => %r{^/user/keys}) do |params|
        request_params, mock_data = parse_stub_params(params)
        {
          :body   => Heroku::API::OkJson.encode(mock_data[:keys]),
          :status => 200
        }
      end

      # stub POST /user/keys
      Excon.stub(:expects => 200, :method => :post, :path => %r{^/user/keys}) do |params|
        request_params, mock_data = parse_stub_params(params)
        mock_data[:keys] |= [{
          'email'     => 'email@example.com',
          'contents'  => request_params[:body]
        }]
        { :status => 200 }
      end

    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
heroku-api-0.3.15 lib/heroku/api/mock/keys.rb
heroku-api-0.3.14 lib/heroku/api/mock/keys.rb
heroku-api-0.3.13 lib/heroku/api/mock/keys.rb
heroku-api-0.3.12 lib/heroku/api/mock/keys.rb
heroku-api-0.3.11 lib/heroku/api/mock/keys.rb
heroku-api-0.3.10 lib/heroku/api/mock/keys.rb
pogoapp-api-0.3.8 lib/heroku/api/mock/keys.rb
heroku-api-0.3.9 lib/heroku/api/mock/keys.rb
heroku-api-0.3.8 lib/heroku/api/mock/keys.rb
heroku-api-0.3.7 lib/heroku/api/mock/keys.rb
heroku-api-0.3.6 lib/heroku/api/mock/keys.rb
heroku-api-0.3.5 lib/heroku/api/mock/keys.rb
heroku-api-0.3.4 lib/heroku/api/mock/keys.rb
heroku-api-0.3.3 lib/heroku/api/mock/keys.rb
heroku-api-0.3.2 lib/heroku/api/mock/keys.rb
heroku-api-0.3.1 lib/heroku/api/mock/keys.rb
heroku-api-0.3.0 lib/heroku/api/mock/keys.rb