Commit c7e00aca2d68a15c901506f1af4242df92670b6a

Authored by Dmitriy Zaporozhets
1 parent 10ee137e

Better specs for Compare API

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
lib/api/entities.rb
... ... @@ -202,7 +202,9 @@ module API
202 202  
203 203 class Compare < Grape::Entity
204 204 expose :commit, using: Entities::RepoCommit do |compare, options|
205   - Commit.new compare.commit
  205 + if compare.commit
  206 + Commit.new compare.commit
  207 + end
206 208 end
207 209 expose :commits, using: Entities::RepoCommit do |compare, options|
208 210 Commit.decorate compare.commits
... ...
spec/requests/api/repositories_spec.rb
... ... @@ -114,25 +114,41 @@ describe API::API, api: true do
114 114 end
115 115  
116 116 describe 'GET /GET /projects/:id/repository/compare' do
117   - it "should compare 2 branches" do
  117 + it "should compare branches" do
118 118 get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'simple_merge_request'
119 119 response.status.should == 200
120   - json_response['commits'].size.should == 3
121   - json_response['diffs'].size.should == 1
  120 + json_response['commits'].should be_present
  121 + json_response['diffs'].should be_present
122 122 end
123 123  
124   - it "should compare 2 commits" do
  124 + it "should compare tags" do
  125 + get api("/projects/#{project.id}/repository/compare", user), from: 'v1.0.1', to: 'v1.0.2'
  126 + response.status.should == 200
  127 + json_response['commits'].should be_present
  128 + json_response['diffs'].should be_present
  129 + end
  130 +
  131 + it "should compare commits" do
125 132 get api("/projects/#{project.id}/repository/compare", user), from: 'b1e6a9dbf1c85', to: '1e689bfba395'
126 133 response.status.should == 200
127   - json_response['commits'].size.should == 0
128   - json_response['diffs'].size.should == 0
  134 + json_response['commits'].should be_empty
  135 + json_response['diffs'].should be_empty
  136 + json_response['compare_same_ref'].should be_false
129 137 end
130 138  
131   - it "should compare 2 commits" do
  139 + it "should compare commits in reverse order" do
132 140 get api("/projects/#{project.id}/repository/compare", user), from: '1e689bfba395', to: 'b1e6a9dbf1c85'
133 141 response.status.should == 200
134   - json_response['commits'].size.should == 4
135   - json_response['diffs'].size.should == 9
  142 + json_response['commits'].should be_present
  143 + json_response['diffs'].should be_present
  144 + end
  145 +
  146 + it "should compare same refs" do
  147 + get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'master'
  148 + response.status.should == 200
  149 + json_response['commits'].should be_empty
  150 + json_response['diffs'].should be_empty
  151 + json_response['compare_same_ref'].should be_true
136 152 end
137 153 end
138 154 end
... ...