Skip to content

Commit

Permalink
[FIX] Changed that information from Github is read correctly from the…
Browse files Browse the repository at this point in the history
… params, not request.body

See: http://help.github.com/post-receive-hooks/
  • Loading branch information
karmi committed Mar 2, 2011
1 parent 9457f09 commit 6c632c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/hide/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Server < Sinatra::Base

post '/update' do
begin
json = Yajl::Parser.parse(request.body)
json = Yajl::Parser.parse(params[:payload])
before, after = json['before'], json['after']
# p [before, after]

Expand All @@ -27,10 +27,10 @@ class Server < Sinatra::Base
@indexer.update! before, after

rescue Yajl::ParseError
puts request.body.read
STEDRR.puts params[:payload]
error 500, "Invalid JSON"
rescue Hide::GitError
puts request.body.read
STEDRR.puts params[:payload]
error 500, "Invalid JSON payload -- shas missing?"
end
end
Expand Down
12 changes: 9 additions & 3 deletions test/unit/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,28 @@ def app

context "Server" do

should "raise error when payload is missing" do
post '/update'
assert ! last_response.ok?
assert_equal 500, last_response.status
end

should "raise error for invalid JSON" do
post '/update', "DEVNULL"
post '/update', {:payload => "DEVNULL" }
assert ! last_response.ok?
assert_equal 500, last_response.status
end

should "raise error for inadequate JSON" do
post '/update', '{"ok":"true"}'
post '/update', { :payload => '{"ok":"true"}' }
assert ! last_response.ok?
assert_equal 500, last_response.status
end

should "perform index update for valid JSON" do
Hide::Indexer.any_instance.expects(:update!).with('a576986a5a50c98dfa556a2ef0863b3877742aa8', 'd40c96be399e791db154e64cb90324e6b87e97a1')

post '/update', PAYLOAD
post '/update', { :payload => PAYLOAD }
assert last_response.ok?, "#{last_response.status} is NOT OK."
end

Expand Down

0 comments on commit 6c632c7

Please sign in to comment.