From c7e00aca2d68a15c901506f1af4242df92670b6a Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 27 May 2014 11:27:42 +0300 Subject: [PATCH] Better specs for Compare API Signed-off-by: Dmitriy Zaporozhets --- lib/api/entities.rb | 4 ++- spec/requests/api/repositories_spec.rb | 34 +++++++++++++++++++------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 4a9220a7f49..6bad6c74bca 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -202,7 +202,9 @@ module API class Compare < Grape::Entity expose :commit, using: Entities::RepoCommit do |compare, options| - Commit.new compare.commit + if compare.commit + Commit.new compare.commit + end end expose :commits, using: Entities::RepoCommit do |compare, options| Commit.decorate compare.commits diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb index eaf217f0af4..a902a1542cc 100644 --- a/spec/requests/api/repositories_spec.rb +++ b/spec/requests/api/repositories_spec.rb @@ -114,25 +114,41 @@ describe API::API, api: true do end describe 'GET /GET /projects/:id/repository/compare' do - it "should compare 2 branches" do + it "should compare branches" do get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'simple_merge_request' response.status.should == 200 - json_response['commits'].size.should == 3 - json_response['diffs'].size.should == 1 + json_response['commits'].should be_present + json_response['diffs'].should be_present end - it "should compare 2 commits" do + it "should compare tags" do + get api("/projects/#{project.id}/repository/compare", user), from: 'v1.0.1', to: 'v1.0.2' + response.status.should == 200 + json_response['commits'].should be_present + json_response['diffs'].should be_present + end + + it "should compare commits" do get api("/projects/#{project.id}/repository/compare", user), from: 'b1e6a9dbf1c85', to: '1e689bfba395' response.status.should == 200 - json_response['commits'].size.should == 0 - json_response['diffs'].size.should == 0 + json_response['commits'].should be_empty + json_response['diffs'].should be_empty + json_response['compare_same_ref'].should be_false end - it "should compare 2 commits" do + it "should compare commits in reverse order" do get api("/projects/#{project.id}/repository/compare", user), from: '1e689bfba395', to: 'b1e6a9dbf1c85' response.status.should == 200 - json_response['commits'].size.should == 4 - json_response['diffs'].size.should == 9 + json_response['commits'].should be_present + json_response['diffs'].should be_present + end + + it "should compare same refs" do + get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'master' + response.status.should == 200 + json_response['commits'].should be_empty + json_response['diffs'].should be_empty + json_response['compare_same_ref'].should be_true end end end