Sha256: 1acb34c1b11c39c6ecbd10344567c8f86fb7d0b5365e0b143019b12a13baf1bb

Contents?: true

Size: 1.42 KB

Versions: 12

Compression:

Stored size: 1.42 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   => MultiJson.dump(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

12 entries across 12 versions & 1 rubygems

Version Path
heroku-api-0.4.3 lib/heroku/api/mock/keys.rb
heroku-api-0.4.2 lib/heroku/api/mock/keys.rb
heroku-api-0.4.1 lib/heroku/api/mock/keys.rb
heroku-api-0.4.0 lib/heroku/api/mock/keys.rb
heroku-api-0.3.23 lib/heroku/api/mock/keys.rb
heroku-api-0.3.22 lib/heroku/api/mock/keys.rb
heroku-api-0.3.21 lib/heroku/api/mock/keys.rb
heroku-api-0.3.20 lib/heroku/api/mock/keys.rb
heroku-api-0.3.19 lib/heroku/api/mock/keys.rb
heroku-api-0.3.18 lib/heroku/api/mock/keys.rb
heroku-api-0.3.17 lib/heroku/api/mock/keys.rb
heroku-api-0.3.16 lib/heroku/api/mock/keys.rb