diff options
author | Valery Sizov <vsv2711@gmail.com> | 2015-06-23 13:19:42 +0300 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2015-06-23 13:32:22 +0300 |
commit | b9b466204e6d8ad174488d2a9a2f0e7ef7c41e55 (patch) | |
tree | b606772f6d18ff238d2fa4c20dc05bd6c3689fef | |
parent | 01b79e8c2d10cdf0560e5653934f461d876405be (diff) | |
download | gitlab-ci-commit_not_found_error.tar.gz |
not_found status of commitcommit_not_found_error
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/controllers/commits_controller.rb | 7 | ||||
-rw-r--r-- | spec/controllers/commits_controller_spec.rb | 27 |
3 files changed, 33 insertions, 2 deletions
@@ -1,5 +1,6 @@ v7.12.1 - Runner without tag should pick builds without tag only + - Explicit error in the GitLab when commit not found. v7.12.0 - Endless scroll on the dashboard diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index 06c24d6..ee045bc 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -2,7 +2,7 @@ class CommitsController < ApplicationController before_filter :authenticate_user!, except: [:status, :show] before_filter :authenticate_public_page!, only: :show before_filter :project - before_filter :commit + before_filter :commit, only: :show before_filter :authorize_access_project!, except: [:status, :show] def show @@ -10,7 +10,10 @@ class CommitsController < ApplicationController end def status - render json: @commit.to_json(only: [:id, :sha], methods: [:status, :coverage]) + commit = Project.find(params[:project_id]).commits.find_by_sha_and_ref!(params[:id], params[:ref_id]) + render json: commit.to_json(only: [:id, :sha], methods: [:status, :coverage]) + rescue ActiveRecord::RecordNotFound + render json: { status: "not_found" } end private diff --git a/spec/controllers/commits_controller_spec.rb b/spec/controllers/commits_controller_spec.rb new file mode 100644 index 0000000..f32d6f8 --- /dev/null +++ b/spec/controllers/commits_controller_spec.rb @@ -0,0 +1,27 @@ +require "spec_helper" + +describe CommitsController do + before do + @project = FactoryGirl.create :project + end + + describe "GET /status" do + it "returns status of commit" do + commit = FactoryGirl.create :commit, project: @project + get :status, id: commit.sha, ref_id: commit.ref, project_id: @project.id + + expect(response).to be_success + expect(response.code).to eq('200') + JSON.parse(response.body)["status"] == "pending" + end + + it "returns not_found status" do + commit = FactoryGirl.create :commit, project: @project + get :status, id: commit.sha, ref_id: "deploy", project_id: @project.id + + expect(response).to be_success + expect(response.code).to eq('200') + JSON.parse(response.body)["status"] == "not_found" + end + end +end |