diff options
author | Stan Hu <stanhu@gmail.com> | 2019-05-26 08:42:42 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-06-06 02:43:31 +0300 |
commit | f8d93b24822937d803da4c9fcc89d50c85de89c7 (patch) | |
tree | 4e26c50a4887dbe46ad0bf7df46c3bc09d48d001 /spec/helpers | |
parent | e6a88b024fa7f8e1ec5b712744d0e0d118b026e6 (diff) |
Set project default visibility to max allowed
If the default, instance-wide visibility were set to internal but a
group were private, the radio button would be set on internal even
though that setting were not allowed. We now consider the allowed
visibility setting for the group in determining what the default should
be.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/62298
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/visibility_level_helper_spec.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/helpers/visibility_level_helper_spec.rb b/spec/helpers/visibility_level_helper_spec.rb index e565ac8c530..25a2fcf5a81 100644 --- a/spec/helpers/visibility_level_helper_spec.rb +++ b/spec/helpers/visibility_level_helper_spec.rb @@ -162,4 +162,49 @@ describe VisibilityLevelHelper do end end end + + describe "selected_visibility_level" do + let(:group) { create(:group, :public) } + let!(:project) { create(:project, :internal, group: group) } + let!(:forked_project) { fork_project(project) } + + using RSpec::Parameterized::TableSyntax + + PUBLIC = Gitlab::VisibilityLevel::PUBLIC + INTERNAL = Gitlab::VisibilityLevel::INTERNAL + PRIVATE = Gitlab::VisibilityLevel::PRIVATE + + # This is a subset of all the permutations + where(:requested_level, :max_allowed, :global_default_level, :restricted_levels, :expected) do + PUBLIC | PUBLIC | PUBLIC | [] | PUBLIC + PUBLIC | PUBLIC | PUBLIC | [PUBLIC] | INTERNAL + INTERNAL | PUBLIC | PUBLIC | [] | INTERNAL + INTERNAL | PRIVATE | PRIVATE | [] | PRIVATE + PRIVATE | PUBLIC | PUBLIC | [] | PRIVATE + PUBLIC | PRIVATE | INTERNAL | [] | PRIVATE + PUBLIC | INTERNAL | PUBLIC | [] | INTERNAL + PUBLIC | PRIVATE | PUBLIC | [] | PRIVATE + PUBLIC | INTERNAL | INTERNAL | [] | INTERNAL + PUBLIC | PUBLIC | INTERNAL | [] | PUBLIC + end + + before do + stub_application_setting(restricted_visibility_levels: restricted_levels, + default_project_visibility: global_default_level) + end + + with_them do + it "provides correct visibility level for forked project" do + project.update(visibility_level: max_allowed) + + expect(selected_visibility_level(forked_project, requested_level)).to eq(expected) + end + + it "provides correct visibiility level for project in group" do + project.group.update(visibility_level: max_allowed) + + expect(selected_visibility_level(project, requested_level)).to eq(expected) + end + end + end end |