2017-05-01 07:38:57 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-05-02 05:27:10 -04:00
|
|
|
describe EnvironmentPolicy do
|
2017-05-01 07:38:57 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-08-01 14:51:52 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2017-05-01 07:38:57 -04:00
|
|
|
|
|
|
|
let(:environment) do
|
|
|
|
create(:environment, :with_review_app, project: project)
|
|
|
|
end
|
|
|
|
|
2017-04-06 17:09:58 -04:00
|
|
|
let(:policy) do
|
|
|
|
described_class.new(user, environment)
|
2017-05-01 07:38:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#rules' do
|
|
|
|
context 'when user does not have access to the project' do
|
2017-08-01 14:51:52 -04:00
|
|
|
let(:project) { create(:project, :private, :repository) }
|
2017-05-01 07:38:57 -04:00
|
|
|
|
|
|
|
it 'does not include ability to stop environment' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(policy).to be_disallowed :stop_environment
|
2017-05-01 07:38:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when anonymous user has access to the project' do
|
2017-08-01 14:51:52 -04:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2017-05-01 07:38:57 -04:00
|
|
|
|
|
|
|
it 'does not include ability to stop environment' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(policy).to be_disallowed :stop_environment
|
2017-05-01 07:38:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when team member has access to the project' do
|
2017-08-01 14:51:52 -04:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2017-05-01 07:38:57 -04:00
|
|
|
|
|
|
|
before do
|
2017-05-09 07:47:22 -04:00
|
|
|
project.add_developer(user)
|
2017-05-01 07:38:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when team member has ability to stop environment' do
|
|
|
|
it 'does includes ability to stop environment' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(policy).to be_allowed :stop_environment
|
2017-05-01 07:38:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when team member has no ability to stop environment' do
|
|
|
|
before do
|
|
|
|
create(:protected_branch, :no_one_can_push,
|
|
|
|
name: 'master', project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include ability to stop environment' do
|
2017-04-06 17:09:58 -04:00
|
|
|
expect(policy).to be_disallowed :stop_environment
|
2017-05-01 07:38:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|