Browse files

Add Code Climate service

  • Loading branch information...
1 parent 344366e commit fbc98364be50567533050e2376a587df0d487878 @brynary brynary committed Oct 29, 2011
Showing with 73 additions and 0 deletions.
  1. +19 −0 docs/codeclimate
  2. +14 −0 services/codeclimate.rb
  3. +40 −0 test/codeclimate_test.rb
View
19 docs/codeclimate
@@ -0,0 +1,19 @@
+Code Climate
+============
+
+Install Notes
+-------------
+
+1. Create an account at https://codeclimate.com
+2. Enter your Token (see instructions below)
+
+To get your Token: Log into your Code Climate account, click the gear icon at the top-right, then click the Integration tab.
+
+Developer Notes
+---------------
+
+data
+ - token
+
+payload
+ - refer to docs/github_payload
View
14 services/codeclimate.rb
@@ -0,0 +1,14 @@
+class Service::CodeClimate < Service
+ string :token
+
+ def receive_push
+ http.ssl[:verify] = false
+ http.basic_auth "github", token
+ http_post "https://codeclimate.com/github_pushes", :payload => payload.to_json
+ end
+
+ def token
+ data["token"].to_s.strip
+ end
+
+end
View
40 test/codeclimate_test.rb
@@ -0,0 +1,40 @@
+require File.expand_path('../helper', __FILE__)
+
+class CodeClimateTest < Service::TestCase
+ def setup
+ @stubs = Faraday::Adapter::Test::Stubs.new
+ @svc = service(data, payload)
+ end
+
+ def test_reads_token_from_data
+ assert_equal "5373dd4a3648b88fa9acb8e46ebc188a", @svc.token
+ end
+
+ def test_strips_whitespace_from_token
+ svc = service({'token' => '5373dd4a3648b88fa9acb8e46ebc188a '}, payload)
+ assert_equal '5373dd4a3648b88fa9acb8e46ebc188a', svc.token
+ end
+
+ def test_posts_payload
+ @stubs.post '/github_pushes' do |env|
+ assert_equal 'https', env[:url].scheme
+ assert_equal 'codeclimate.com', env[:url].host
+ assert_equal basic_auth('github', '5373dd4a3648b88fa9acb8e46ebc188a'),
+ env[:request_headers]['authorization']
+ assert_equal payload, JSON.parse(Rack::Utils.parse_query(env[:body])['payload'])
+ end
+
+ @svc.receive_push
+ end
+
+private
+
+ def service(*args)
+ super Service::CodeClimate, *args
+ end
+
+ def data
+ { 'token' => '5373dd4a3648b88fa9acb8e46ebc188a' }
+ end
+
+end

0 comments on commit fbc9836

Please sign in to comment.