Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Commit

Permalink
Implement controller
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed May 20, 2014
1 parent a98910f commit b1e2ffe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
10 changes: 10 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ class Server < Sinatra::Base
nn.notify! if nn.valid?
end

if ENV['AIRBRAKE_API_KEY'] and ENV['AIRBRAKE_RAILS_ENV'] and ENV['AIRBRAKE_REPOSITORY']
an = AirbrakeNotification.new(api_key: ENV['AIRBRAKE_API_KEY'],
rails_env: ENV['AIRBRAKE_RAILS_ENV'],
local_username: params[:user],
scm_revision: params[:head_long],
scm_repository: ENV['AIRBRAKE_REPOSITORY'])

an.notify!
end

"ok"
end
end
27 changes: 18 additions & 9 deletions test/controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,36 @@ class ControllerTest < TestCase
include Rack::Test::Methods

def setup
ENV["NEWRELIC_API_KEY"] = "example"
ENV["NEWRELIC_APP_ID"] = "123456"
ENV['NEWRELIC_API_KEY'] = 'example'
ENV['NEWRELIC_APP_ID'] = '123456'

ENV['AIRBRAKE_API_KEY'] = 'airbrake_api_key'
ENV['AIRBRAKE_RAILS_ENV'] = 'production'
ENV['AIRBRAKE_REPOSITORY'] = '[email protected]:ubiregiinc/ping.git'
end

def teardown
ENV.delete("NEWRELIC_API_KEY")
ENV.delete("NEWRELIC_APP_ID")
ENV.delete('NEWRELIC_API_KEY')
ENV.delete('NEWRELIC_APP_ID')
ENV.delete('AIRBRAKE_API_KEY')
ENV.delete('AIRBRAKE_RAILS_ENV')
ENV.delete('AIRBRAKE_REPOSITORY')
end

def app
Server
end

def test_should_send_notification_to_newrelic
stub_request :any, "https://api.newrelic.com/deployments.xml"

mock.proxy(NewrelicNotification).new(api_key: "example", app_id: "123456", user: "Soutaro Matsumoto", revision: "testtest", git_log: "Git Log Message") {|n|
def test_sending_notifications
mock.proxy(NewrelicNotification).new(api_key: "example", app_id: "123456", user: "soutaro", revision: "testtest", git_log: "Git Log Message") {|n|
mock(n).notify!
}

post '/notify', { "app" => "finger and register", "user" => "Soutaro Matsumoto", "head_long" => "testtest", 'git_log' => "Git Log Message"}
mock.proxy(AirbrakeNotification).new(api_key: "airbrake_api_key", rails_env: "production", scm_repository: "[email protected]:ubiregiinc/ping.git", scm_revision: "testtest", local_username: "soutaro") do |n|
mock(n).notify!
end

post '/notify', { "app" => "finger and register", "user" => "soutaro", "head_long" => "testtest", 'git_log' => "Git Log Message"}

assert last_response.ok?
end
Expand Down

0 comments on commit b1e2ffe

Please sign in to comment.