2016-09-29 09:46:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ProjectFeature do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:empty_project) }
|
2016-09-29 09:46:39 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
describe '#feature_available?' do
|
2016-11-03 12:29:30 +05:30
|
|
|
let(:features) { %w(issues wiki builds merge_requests snippets repository) }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
context 'when features are disabled' do
|
|
|
|
it "returns false" do
|
|
|
|
features.each do |feature|
|
|
|
|
project.project_feature.update_attribute("#{feature}_access_level".to_sym, ProjectFeature::DISABLED)
|
|
|
|
expect(project.feature_available?(:issues, user)).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when features are enabled only for team members' do
|
|
|
|
it "returns false when user is not a team member" do
|
|
|
|
features.each do |feature|
|
|
|
|
project.project_feature.update_attribute("#{feature}_access_level".to_sym, ProjectFeature::PRIVATE)
|
|
|
|
expect(project.feature_available?(:issues, user)).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true when user is a team member" do
|
|
|
|
project.team << [user, :developer]
|
|
|
|
|
|
|
|
features.each do |feature|
|
|
|
|
project.project_feature.update_attribute("#{feature}_access_level".to_sym, ProjectFeature::PRIVATE)
|
|
|
|
expect(project.feature_available?(:issues, user)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true when user is a member of project group" do
|
|
|
|
group = create(:group)
|
2017-08-17 22:00:37 +05:30
|
|
|
project = create(:empty_project, namespace: group)
|
2016-09-29 09:46:39 +05:30
|
|
|
group.add_developer(user)
|
|
|
|
|
|
|
|
features.each do |feature|
|
|
|
|
project.project_feature.update_attribute("#{feature}_access_level".to_sym, ProjectFeature::PRIVATE)
|
|
|
|
expect(project.feature_available?(:issues, user)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true if user is an admin" do
|
|
|
|
user.update_attribute(:admin, true)
|
|
|
|
|
|
|
|
features.each do |feature|
|
|
|
|
project.project_feature.update_attribute("#{feature}_access_level".to_sym, ProjectFeature::PRIVATE)
|
|
|
|
expect(project.feature_available?(:issues, user)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when feature is enabled for everyone' do
|
|
|
|
it "returns true" do
|
|
|
|
features.each do |feature|
|
|
|
|
expect(project.feature_available?(:issues, user)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
context 'repository related features' do
|
|
|
|
before do
|
|
|
|
project.project_feature.update_attributes(
|
|
|
|
merge_requests_access_level: ProjectFeature::DISABLED,
|
|
|
|
builds_access_level: ProjectFeature::DISABLED,
|
|
|
|
repository_access_level: ProjectFeature::PRIVATE
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not allow repository related features have higher level" do
|
|
|
|
features = %w(builds merge_requests)
|
|
|
|
project_feature = project.project_feature
|
|
|
|
|
|
|
|
features.each do |feature|
|
|
|
|
field = "#{feature}_access_level".to_sym
|
|
|
|
project_feature.update_attribute(field, ProjectFeature::ENABLED)
|
|
|
|
expect(project_feature.valid?).to be_falsy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
describe '#*_enabled?' do
|
|
|
|
let(:features) { %w(wiki builds merge_requests) }
|
|
|
|
|
|
|
|
it "returns false when feature is disabled" do
|
|
|
|
features.each do |feature|
|
|
|
|
project.project_feature.update_attribute("#{feature}_access_level".to_sym, ProjectFeature::DISABLED)
|
|
|
|
expect(project.public_send("#{feature}_enabled?")).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true when feature is enabled only for team members" do
|
|
|
|
features.each do |feature|
|
|
|
|
project.project_feature.update_attribute("#{feature}_access_level".to_sym, ProjectFeature::PRIVATE)
|
|
|
|
expect(project.public_send("#{feature}_enabled?")).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true when feature is enabled for everyone" do
|
|
|
|
features.each do |feature|
|
|
|
|
expect(project.public_send("#{feature}_enabled?")).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|