Permalink
Browse files

specs for /github

  • Loading branch information...
1 parent a53d4bb commit 6111e1475d247977113268df48f943fbe5298afa @gorsuch gorsuch committed Aug 28, 2012
Showing with 96 additions and 4 deletions.
  1. +1 −2 lib/backstop/web.rb
  2. +28 −0 spec/backstop/bad_github_data.json
  3. +40 −0 spec/backstop/good_github_data.json
  4. +27 −2 spec/backstop/web_spec.rb
View
@@ -54,8 +54,7 @@ def publisher
repo = data['repository']['name']
author = commit['author']['email'].gsub(/[\.@]/, "-")
measure_time = DateTime.parse(commit["timestamp"]).strftime("%s")
- s = sockets.sample
- s.puts "#{data['source']}.#{repo}.#{data['ref']}.#{author}.#{commit['id']} 1 #{measure_time}"
+ publisher.publish("#{data['source']}.#{repo}.#{data['ref']}.#{author}.#{commit['id']}", 1, measure_time)
end
"ok"
end
@@ -0,0 +1,28 @@
+{
+ "before": "5aef35982fb2d34e9d9d4502f6ede1072793222d",
+ "commits": [
+ {
+ "id": "41a212ee83ca127e3c8cf465891ab7216a705f59",
+ "url": "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
+ "author": {
+ "email": "chris@ozmm.org",
+ "name": "Chris Wanstrath"
+ },
+ "message": "okay i give in",
+ "timestamp": "2008-02-15T14:57:17-08:00",
+ "added": ["filepath.rb"]
+ },
+ {
+ "id": "de8251ff97ee194a289832576287d6f8ad74e3d0",
+ "url": "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0",
+ "author": {
+ "email": "chris@ozmm.org",
+ "name": "Chris Wanstrath"
+ },
+ "message": "update pricing a tad",
+ "timestamp": "2008-02-15T14:36:34-08:00"
+ }
+ ],
+ "after": "de8251ff97ee194a289832576287d6f8ad74e3d0",
+ "ref": "refs/heads/master"
+}
@@ -0,0 +1,40 @@
+{
+ "before": "5aef35982fb2d34e9d9d4502f6ede1072793222d",
+ "repository": {
+ "url": "http://github.com/defunkt/github",
+ "name": "github",
+ "description": "You're lookin' at it.",
+ "watchers": 5,
+ "forks": 2,
+ "private": 1,
+ "owner": {
+ "email": "chris@ozmm.org",
+ "name": "defunkt"
+ }
+ },
+ "commits": [
+ {
+ "id": "41a212ee83ca127e3c8cf465891ab7216a705f59",
+ "url": "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
+ "author": {
+ "email": "chris@ozmm.org",
+ "name": "Chris Wanstrath"
+ },
+ "message": "okay i give in",
+ "timestamp": "2008-02-15T14:57:17-08:00",
+ "added": ["filepath.rb"]
+ },
+ {
+ "id": "de8251ff97ee194a289832576287d6f8ad74e3d0",
+ "url": "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0",
+ "author": {
+ "email": "chris@ozmm.org",
+ "name": "Chris Wanstrath"
+ },
+ "message": "update pricing a tad",
+ "timestamp": "2008-02-15T14:36:34-08:00"
+ }
+ ],
+ "after": "de8251ff97ee194a289832576287d6f8ad74e3d0",
+ "ref": "refs/heads/master"
+}
View
@@ -47,7 +47,7 @@ def app
end
context 'POST /collectd' do
- let(:collectd_data) { File.open(File.dirname(__FILE__) + '/good_collectd_data.json').read }
+ let(:good_collectd_data) { File.open(File.dirname(__FILE__) + '/good_collectd_data.json').read }
let(:bad_collectd_data) { File.open(File.dirname(__FILE__) + '/bad_collectd_data.json').read }
it 'should require JSON' do
@@ -60,7 +60,7 @@ def app
p = double('publisher')
Backstop::Publisher.should_receive(:new) { p }
p.should_receive(:publish).with('mitt.leeloo.octo.it.cpu.0.idle', 1901474177, 1280959128)
- post '/collectd', collectd_data
+ post '/collectd', good_collectd_data
last_response.body.should eq('ok')
last_response.status.should eq(200)
end
@@ -71,6 +71,31 @@ def app
last_response.body.should eq('missing fields')
end
end
+
+ context 'POST /github' do
+ let(:good_github_data) { File.open(File.dirname(__FILE__) + '/good_github_data.json').read }
+ let(:bad_github_data) { File.open(File.dirname(__FILE__) + '/bad_github_data.json').read }
+
+ it 'should require JSON' do
+ post '/github', { :payload => 'foo' }
+ last_response.should_not be_ok
+ last_response.status.should eq(400)
+ end
+
+ it 'should take a github push' do
+ p = double('publisher')
+ Backstop::Publisher.should_receive(:new) { p }
+ p.should_receive(:publish).with('github.github.refs.heads.master.chris-ozmm-org.de8251ff97ee194a289832576287d6f8ad74e3d0', 1, '1203114994')
+ p.should_receive(:publish).with('github.github.refs.heads.master.chris-ozmm-org.41a212ee83ca127e3c8cf465891ab7216a705f59', 1, '1203116237')
+ post '/github', { :payload => good_github_data }
+ last_response.should be_ok
+ end
+
+ it 'should complain if missing fields' do
+ post '/github', { :payload => bad_github_data }
+ last_response.should_not be_ok
+ end
+ end
end

0 comments on commit 6111e14

Please sign in to comment.