BigW Consortium Gitlab

Commit f0cd73bf by Grzegorz Bizon

Fix some detailed statuses specs related to abilities

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