class Heroku::Kensa::PlanChangeCheck

Public Instance Methods

call!() click to toggle source
# File lib/heroku/kensa/check.rb, line 392
def call!
  id = data[:id]
  raise ArgumentError, "No id specified" if id.nil?

  new_plan = data[:plan]
  raise ArgumentError, "No plan specified" if new_plan.nil?

  path = "#{base_path}/#{CGI::escape(id.to_s)}"
  payload = {:plan => new_plan, :heroku_id => heroku_id}

  test "PUT #{path}"
  check "response" do
    code, _ = put(credentials, path, payload)
    if code == 200
      true
    elsif code == -1
      error("unable to connect to #{url}")
    else
      error("expected 200, got #{code}")
    end
  end

  check "authentication" do
    wrong_credentials = ['wrong', 'secret']
    code, _ = put(wrong_credentials, path, payload)
    error("expected 401, got #{code}") if code != 401
    true
  end
end