diff options
-rw-r--r-- | app/models/commit.rb | 6 | ||||
-rw-r--r-- | lib/api/commits.rb | 1 | ||||
-rw-r--r-- | spec/requests/api/commits_spec.rb | 36 |
3 files changed, 39 insertions, 4 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index 6817101..184d3a0 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -57,7 +57,7 @@ class Commit < ActiveRecord::Base end def git_commit_message - commit_data[:message] if commit_data + commit_data[:message] if commit_data && commit_data[:message] end def short_before_sha @@ -69,8 +69,8 @@ class Commit < ActiveRecord::Base end def commit_data - push_data[:commits].each do |commit| - return commit if commit[:id] == sha + push_data[:commits].find do |commit| + commit[:id] == sha end rescue nil diff --git a/lib/api/commits.rb b/lib/api/commits.rb index 032233e..6aa060c 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -62,4 +62,3 @@ module API end end end - diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb index 8c2d2cb..87072bb 100644 --- a/spec/requests/api/commits_spec.rb +++ b/spec/requests/api/commits_spec.rb @@ -25,4 +25,40 @@ describe API::API, 'Commits' do json_response.first["sha"].should == commit.sha end end + + describe "POST /commits" do + let(:data) { + { + "before" => "95790bf891e76fee5e1747ab589903a6a1f80f22", + "after" => "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", + "ref" => "refs/heads/master", + "commits" => [ + { + "id" => "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", + "message" => "Update Catalan translation to e38cb41.", + "timestamp" => "2011-12-12T14:27:31+02:00", + "url" => "http://localhost/diaspora/commits/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", + "author" => { + "name" => "Jordi Mallach", + "email" => "jordi@softcatala.org", + } + } + ] + } + } + + it "should create a build" do + post api("/commits"), options.merge(data: data) + + response.status.should == 201 + json_response['sha'].should == "da1560886d4f094c3e6c9ef40349f7d38b5d27d7" + end + + it "should return 400 error if no data passed" do + post api("/commits"), options + + response.status.should == 400 + json_response['message'].should == "400 (Bad request) \"data\" not given" + end + end end |