debian-mirror-gitlab/spec/models/concerns/project_features_compatibility_spec.rb

50 lines
2.1 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2016-09-29 09:46:39 +05:30
require 'spec_helper'
describe ProjectFeaturesCompatibility do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2019-09-30 21:07:59 +05:30
let(:features_except_repository) { %w(issues wiki builds merge_requests snippets) }
let(:features) { features_except_repository + ['repository'] }
2016-09-29 09:46:39 +05:30
# 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
2019-09-30 21:07:59 +05:30
features_except_repository.each do |feature|
2016-09-29 09:46:39 +05:30
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
2019-09-30 21:07:59 +05:30
features_except_repository.each do |feature|
2016-09-29 09:46:39 +05:30
project.update_attribute("#{feature}_enabled".to_sym, "false")
expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::DISABLED)
end
end
2016-11-24 13:41:30 +05:30
it "converts fields from true to ProjectFeature::ENABLED" do
2019-09-30 21:07:59 +05:30
features_except_repository.each do |feature|
2016-11-24 13:41:30 +05:30
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
2019-09-30 21:07:59 +05:30
features_except_repository.each do |feature|
2016-11-24 13:41:30 +05:30
project.update_attribute("#{feature}_enabled".to_sym, false)
expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::DISABLED)
end
end
2019-09-30 21:07:59 +05:30
it "accepts private as ProjectFeature::PRIVATE" do
features.each do |feature|
project.update!("#{feature}_access_level".to_sym => 'private')
expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::PRIVATE)
end
end
2016-09-29 09:46:39 +05:30
end