2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-01 18:31:21 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe ProjectFeaturesCompatibility do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2021-02-18 13:10:41 -05:00
|
|
|
let(:features_enabled) { %w(issues wiki builds merge_requests snippets security_and_compliance) }
|
2021-03-08 07:09:01 -05:00
|
|
|
let(:features) { features_enabled + %w(repository pages operations container_registry) }
|
2016-08-01 18:31:21 -04:00
|
|
|
|
|
|
|
# We had issues_enabled, snippets_enabled, builds_enabled, merge_requests_enabled and issues_enabled fields on projects table
|
|
|
|
# All those fields got moved to a new table called project_feature and are now integers instead of booleans
|
|
|
|
# This spec tests if the described concern makes sure parameters received by the API are correctly parsed to the new table
|
|
|
|
# So we can keep it compatible
|
|
|
|
|
|
|
|
it "converts fields from 'true' to ProjectFeature::ENABLED" do
|
2020-01-23 07:08:38 -05:00
|
|
|
features_enabled.each do |feature|
|
2016-08-01 18:31:21 -04:00
|
|
|
project.update_attribute("#{feature}_enabled".to_sym, "true")
|
|
|
|
expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::ENABLED)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "converts fields from 'false' to ProjectFeature::DISABLED" do
|
2020-01-23 07:08:38 -05:00
|
|
|
features_enabled.each do |feature|
|
2016-08-01 18:31:21 -04:00
|
|
|
project.update_attribute("#{feature}_enabled".to_sym, "false")
|
|
|
|
expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::DISABLED)
|
|
|
|
end
|
|
|
|
end
|
2016-10-28 16:56:13 -04:00
|
|
|
|
|
|
|
it "converts fields from true to ProjectFeature::ENABLED" do
|
2020-01-23 07:08:38 -05:00
|
|
|
features_enabled.each do |feature|
|
2016-10-28 16:56:13 -04:00
|
|
|
project.update_attribute("#{feature}_enabled".to_sym, true)
|
|
|
|
expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::ENABLED)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "converts fields from false to ProjectFeature::DISABLED" do
|
2020-01-23 07:08:38 -05:00
|
|
|
features_enabled.each do |feature|
|
2016-10-28 16:56:13 -04:00
|
|
|
project.update_attribute("#{feature}_enabled".to_sym, false)
|
|
|
|
expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::DISABLED)
|
|
|
|
end
|
|
|
|
end
|
2019-05-15 07:19:16 -04:00
|
|
|
|
2020-01-23 07:08:38 -05:00
|
|
|
describe "access levels" do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
where(:access_level, :expected_result) do
|
|
|
|
'disabled' | ProjectFeature::DISABLED
|
|
|
|
'private' | ProjectFeature::PRIVATE
|
|
|
|
'enabled' | ProjectFeature::ENABLED
|
|
|
|
'public' | ProjectFeature::PUBLIC
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it "accepts access level" do
|
|
|
|
features.each do |feature|
|
|
|
|
# Only pages as public access level
|
|
|
|
next if feature != 'pages' && access_level == 'public'
|
|
|
|
|
|
|
|
project.update!("#{feature}_access_level".to_sym => access_level)
|
|
|
|
expect(project.project_feature.public_send("#{feature}_access_level")).to eq(expected_result)
|
|
|
|
end
|
|
|
|
end
|
2019-05-15 07:19:16 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-01 18:31:21 -04:00
|
|
|
end
|