Commit 8faf0c7a authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add detailed statuses for external commit statuses

parent 2d6d52ca
module Gitlab
module Ci
module Status
module External
module Common
def has_details?
can?(user, :read_commit_status, subject) &&
subject.target_url.present?
end
def details_path
subject.target_url
end
def has_action?
false
end
end
end
end
end
end
module Gitlab
module Ci
module Status
module External
class Factory < Status::Factory
def self.common_helpers
Status::External::Common
end
end
end
end
end
end
require 'spec_helper'
describe Gitlab::Ci::Status::External::Common do
let(:user) { create(:user) }
let(:project) { external_status.project }
let(:external_target_url) { 'http://example.gitlab.com/status' }
let(:external_status) do
create(:generic_commit_status, target_url: external_target_url)
end
subject do
Gitlab::Ci::Status::Core
.new(external_status, user)
.extend(described_class)
end
describe '#has_action?' do
it { is_expected.not_to have_action }
end
describe '#has_details?' do
context 'when user has access to read commit status' do
before { project.team << [user, :developer] }
it { is_expected.to have_details }
end
context 'when user does not have access to read commit status' do
it { is_expected.not_to have_details }
end
end
describe '#details_path' do
it 'links to the external target URL' do
expect(subject.details_path).to eq external_target_url
end
end
end
require 'spec_helper'
describe Gitlab::Ci::Status::External::Factory do
let(:user) { create(:user) }
let(:project) { resource.project }
let(:status) { factory.fabricate! }
let(:factory) { described_class.new(resource, user) }
let(:external_url) { 'http://gitlab.com/status' }
before do
project.team << [user, :developer]
end
context 'when external status has a simple core status' do
HasStatus::AVAILABLE_STATUSES.each do |simple_status|
context "when core status is #{simple_status}" do
let(:resource) do
create(:generic_commit_status, status: simple_status,
target_url: external_url)
end
let(:expected_status) do
Gitlab::Ci::Status.const_get(simple_status.capitalize)
end
it "fabricates a core status #{simple_status}" do
expect(status).to be_a expected_status
end
it 'extends core status with common methods' do
expect(status).to have_details
expect(status).not_to have_action
expect(status.details_path).to eq external_url
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment