diff options
-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 |