Sha256: 86b0f17a89061250eba4057f5638249c2ed592b6dd41600f44aa28fcb3fd0c7a

Contents?: true

Size: 1.99 KB

Versions: 12

Compression:

Stored size: 1.99 KB

Contents

module Heroku
  class API
    module Mock

      # stub DELETE /apps/:app/collaborators/:email
      Excon.stub(:expects => 200, :method => :delete, :path => %r{^/apps/([^/]+)/collaborators/([^/]+)$}) do |params|
        request_params, mock_data = parse_stub_params(params)
        app, email, _ = request_params[:captures][:path]
        email = CGI.unescape(email)
        with_mock_app(mock_data, app) do
          if collaborator_data = get_mock_collaborator(mock_data, app, email)
            mock_data[:collaborators][app].delete(collaborator_data)
            {
              :body   => "#{email} has been removed as collaborator on #{app}",
              :status => 200
            }
          else
            { :body => 'User not found.', :status => 404 }
          end
        end
      end

      # stub GET /apps/:app/:collaborators
      Excon.stub(:expects => 200, :method => :get, :path => %r{^/apps/([^/]+)/collaborators}) do |params|
        request_params, mock_data = parse_stub_params(params)
        app, _ = request_params[:captures][:path]
        with_mock_app(mock_data, app) do
          {
            :body   => MultiJson.dump(mock_data[:collaborators][app]),
            :status => 200
          }
        end
      end

      # stub POST /apps/:app/collaborators
      Excon.stub(:expects => [200, 201], :method => :post, :path => %r{^/apps/([^/]+)/collaborators}) do |params|
        request_params, mock_data = parse_stub_params(params)
        app, _ = request_params[:captures][:path]
        email = request_params[:query]['collaborator[email]']
        with_mock_app(mock_data, app) do
          mock_data[:collaborators][app] |= [{'access' => 'edit', 'email' => email, 'name' => nil}]
          {
            :body   => "#{email} added as a collaborator on #{app}.",
            :status => 201
          }
          # Existing user response
          #{
          #  :body => "#{email} added as a collaborator on #{app}",
          #  :status => 200
          #}
        end
      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/collaborators.rb
heroku-api-0.4.2 lib/heroku/api/mock/collaborators.rb
heroku-api-0.4.1 lib/heroku/api/mock/collaborators.rb
heroku-api-0.4.0 lib/heroku/api/mock/collaborators.rb
heroku-api-0.3.23 lib/heroku/api/mock/collaborators.rb
heroku-api-0.3.22 lib/heroku/api/mock/collaborators.rb
heroku-api-0.3.21 lib/heroku/api/mock/collaborators.rb
heroku-api-0.3.20 lib/heroku/api/mock/collaborators.rb
heroku-api-0.3.19 lib/heroku/api/mock/collaborators.rb
heroku-api-0.3.18 lib/heroku/api/mock/collaborators.rb
heroku-api-0.3.17 lib/heroku/api/mock/collaborators.rb
heroku-api-0.3.16 lib/heroku/api/mock/collaborators.rb