Commit c1db5b91 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Fix some detailed statuses specs related to abilities

parent 7d883994
class Ability
module Allowable
def can?(user, action, subject)
Ability.allowed?(user, action, subject)
end
end
class << self
# Given a list of users and a project this method returns the users that can
# read the given project.
......
......@@ -5,6 +5,7 @@ module Gitlab
#
class Core
include Gitlab::Routing.url_helpers
include Ability::Allowable
attr_reader :subject, :user
......
......@@ -4,7 +4,7 @@ module Gitlab
module Stage
module Common
def has_details?
can?(user, :read_pipeline, subject)
can?(user, :read_pipeline, subject.pipeline)
end
def details_path
......
......@@ -16,8 +16,4 @@ describe Gitlab::Ci::Status::Canceled do
describe '#icon' do
it { expect(subject.icon).to eq 'icon_status_canceled' }
end
describe '#title' do
it { expect(subject.title).to eq 'Double: canceled' }
end
end
......@@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::Ci::Status::Extended do
subject do
Class.new.extend(described_class)
Class.new.include(described_class)
end
it 'requires subclass to implement matcher' do
......
......@@ -2,7 +2,8 @@ require 'spec_helper'
describe Gitlab::Ci::Status::Pipeline::Common do
let(:user) { create(:user) }
let(:pipeline) { create(:ci_pipeline) }
let(:project) { create(:empty_project) }
let(:pipeline) { create(:ci_pipeline, project: project) }
subject do
Class.new(Gitlab::Ci::Status::Core)
......@@ -10,6 +11,10 @@ describe Gitlab::Ci::Status::Pipeline::Common do
.extend(described_class)
end
before do
project.team << [user, :developer]
end
it 'does not have action' do
expect(subject).not_to have_action
end
......
......@@ -2,6 +2,7 @@ require 'spec_helper'
describe Gitlab::Ci::Status::Pipeline::Factory do
let(:user) { create(:user) }
let(:project) { pipeline.project }
subject do
described_class.new(pipeline, user)
......@@ -11,6 +12,10 @@ describe Gitlab::Ci::Status::Pipeline::Factory do
subject.fabricate!
end
before do
project.team << [user, :developer]
end
context 'when pipeline has a core status' do
HasStatus::AVAILABLE_STATUSES.each do |core_status|
context "when core status is #{core_status}" do
......
......@@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::Ci::Status::Pipeline::SuccessWithWarnings do
subject do
described_class.new(double('status'), double('user'))
described_class.new(double('status'))
end
describe '#test' do
......@@ -29,13 +29,13 @@ describe Gitlab::Ci::Status::Pipeline::SuccessWithWarnings do
end
it 'is a correct match' do
expect(described_class.matches?(pipeline)).to eq true
expect(described_class.matches?(pipeline, double)).to eq true
end
end
context 'when pipeline does not have warnings' do
it 'does not match' do
expect(described_class.matches?(pipeline)).to eq false
expect(described_class.matches?(pipeline, double)).to eq false
end
end
end
......@@ -51,13 +51,13 @@ describe Gitlab::Ci::Status::Pipeline::SuccessWithWarnings do
end
it 'does not match' do
expect(described_class.matches?(pipeline)).to eq false
expect(described_class.matches?(pipeline, double)).to eq false
end
end
context 'when pipeline does not have warnings' do
it 'does not match' do
expect(described_class.matches?(pipeline)).to eq false
expect(described_class.matches?(pipeline, double)).to eq false
end
end
end
......
......@@ -2,7 +2,8 @@ require 'spec_helper'
describe Gitlab::Ci::Status::Stage::Common do
let(:user) { create(:user) }
let(:pipeline) { create(:ci_empty_pipeline) }
let(:project) { create(:empty_project) }
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
let(:stage) do
build(:ci_stage, pipeline: pipeline, name: 'test')
......@@ -17,14 +18,26 @@ describe Gitlab::Ci::Status::Stage::Common do
expect(subject).not_to have_action
end
it 'has details' do
expect(subject).to have_details
end
it 'links to the pipeline details page' do
expect(subject.details_path)
.to include "pipelines/#{pipeline.id}"
expect(subject.details_path)
.to include "##{stage.name}"
end
context 'when user has permission to read pipeline' do
before do
project.team << [user, :master]
end
it 'has details' do
expect(subject).to have_details
end
end
context 'when user does not have permission to read pipeline' do
it 'does not have details' do
expect(subject).not_to have_details
end
end
end
......@@ -2,7 +2,8 @@ require 'spec_helper'
describe Gitlab::Ci::Status::Stage::Factory do
let(:user) { create(:user) }
let(:pipeline) { create(:ci_empty_pipeline) }
let(:project) { create(:empty_project) }
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
let(:stage) do
build(:ci_stage, pipeline: pipeline, name: 'test')
......@@ -16,6 +17,10 @@ describe Gitlab::Ci::Status::Stage::Factory do
subject.fabricate!
end
before do
project.team << [user, :developer]
end
context 'when stage has a core status' do
HasStatus::AVAILABLE_STATUSES.each do |core_status|
context "when core status is #{core_status}" do
......
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