2019-10-08 08:06:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-01 01:58:05 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe 'groups/edit.html.haml' do
|
2017-09-01 01:58:05 -04:00
|
|
|
include Devise::Test::ControllerHelpers
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
describe '"Share with group lock" setting' do
|
2017-09-01 01:58:05 -04:00
|
|
|
let(:root_owner) { create(:user) }
|
|
|
|
let(:root_group) { create(:group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
root_group.add_owner(root_owner)
|
|
|
|
end
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
shared_examples_for '"Share with group lock" setting' do |checkbox_options|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'has the correct label, help text, and checkbox options' do
|
2017-09-01 01:58:05 -04:00
|
|
|
assign(:group, test_group)
|
2017-09-05 20:02:11 -04:00
|
|
|
allow(view).to receive(:can?).with(test_user, :admin_group, test_group).and_return(true)
|
2017-09-01 01:58:05 -04:00
|
|
|
allow(view).to receive(:can_change_group_visibility_level?).and_return(false)
|
|
|
|
allow(view).to receive(:current_user).and_return(test_user)
|
2017-09-05 20:02:11 -04:00
|
|
|
expect(view).to receive(:can_change_share_with_group_lock?).and_return(!checkbox_options[:disabled])
|
|
|
|
expect(view).to receive(:share_with_group_lock_help_text).and_return('help text here')
|
2017-09-01 01:58:05 -04:00
|
|
|
|
|
|
|
render
|
|
|
|
|
2017-09-05 20:02:11 -04:00
|
|
|
expect(rendered).to have_content("Prevent sharing a project within #{test_group.name} with other groups")
|
2019-08-28 03:16:29 -04:00
|
|
|
expect(rendered).to have_css('.js-descr', text: 'help text here')
|
2020-10-06 08:08:38 -04:00
|
|
|
expect(rendered).to have_field('group_share_with_group_lock', **checkbox_options)
|
2017-09-01 01:58:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for a root group' do
|
|
|
|
let(:test_group) { root_group }
|
|
|
|
let(:test_user) { root_owner }
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
it_behaves_like '"Share with group lock" setting', { disabled: false, checked: false }
|
2017-09-01 01:58:05 -04:00
|
|
|
end
|
|
|
|
|
2019-07-24 05:20:54 -04:00
|
|
|
context 'for a subgroup' do
|
2017-09-01 01:58:05 -04:00
|
|
|
let!(:subgroup) { create(:group, parent: root_group) }
|
|
|
|
let(:sub_owner) { create(:user) }
|
|
|
|
let(:test_group) { subgroup }
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
context 'when the root_group has "Share with group lock" disabled' do
|
|
|
|
context 'when the subgroup has "Share with group lock" disabled' do
|
2017-09-01 01:58:05 -04:00
|
|
|
context 'as the root_owner' do
|
|
|
|
let(:test_user) { root_owner }
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
it_behaves_like '"Share with group lock" setting', { disabled: false, checked: false }
|
2017-09-01 01:58:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'as the sub_owner' do
|
|
|
|
let(:test_user) { sub_owner }
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
it_behaves_like '"Share with group lock" setting', { disabled: false, checked: false }
|
2017-09-01 01:58:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
context 'when the subgroup has "Share with group lock" enabled' do
|
2017-09-01 01:58:05 -04:00
|
|
|
before do
|
|
|
|
subgroup.update_column(:share_with_group_lock, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as the root_owner' do
|
|
|
|
let(:test_user) { root_owner }
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
it_behaves_like '"Share with group lock" setting', { disabled: false, checked: true }
|
2017-09-01 01:58:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'as the sub_owner' do
|
|
|
|
let(:test_user) { sub_owner }
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
it_behaves_like '"Share with group lock" setting', { disabled: false, checked: true }
|
2017-09-01 01:58:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
context 'when the root_group has "Share with group lock" enabled' do
|
2017-09-01 01:58:05 -04:00
|
|
|
before do
|
|
|
|
root_group.update_column(:share_with_group_lock, true)
|
|
|
|
end
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
context 'when the subgroup has "Share with group lock" disabled (parent overridden)' do
|
2017-09-01 01:58:05 -04:00
|
|
|
context 'as the root_owner' do
|
|
|
|
let(:test_user) { root_owner }
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
it_behaves_like '"Share with group lock" setting', { disabled: false, checked: false }
|
2017-09-01 01:58:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'as the sub_owner' do
|
|
|
|
let(:test_user) { sub_owner }
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
it_behaves_like '"Share with group lock" setting', { disabled: false, checked: false }
|
2017-09-01 01:58:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
context 'when the subgroup has "Share with group lock" enabled (same as parent)' do
|
2017-09-01 01:58:05 -04:00
|
|
|
before do
|
|
|
|
subgroup.update_column(:share_with_group_lock, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as the root_owner' do
|
|
|
|
let(:test_user) { root_owner }
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
it_behaves_like '"Share with group lock" setting', { disabled: false, checked: true }
|
2017-09-01 01:58:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'as the sub_owner' do
|
|
|
|
let(:test_user) { sub_owner }
|
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
it_behaves_like '"Share with group lock" setting', { disabled: true, checked: true }
|
2017-09-01 01:58:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|