diff options
Diffstat (limited to 'spec/models/work_items/parent_link_spec.rb')
-rw-r--r-- | spec/models/work_items/parent_link_spec.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/models/work_items/parent_link_spec.rb b/spec/models/work_items/parent_link_spec.rb index a16b15bbfc9..070b2eef86a 100644 --- a/spec/models/work_items/parent_link_spec.rb +++ b/spec/models/work_items/parent_link_spec.rb @@ -69,6 +69,70 @@ RSpec.describe WorkItems::ParentLink do expect(link1).to be_valid end end + + context 'when setting confidentiality' do + using RSpec::Parameterized::TableSyntax + + where(:confidential_parent, :confidential_child, :valid) do + false | false | true + true | true | true + false | true | true + true | false | false + end + + with_them do + before do + issue.confidential = confidential_parent + task1.confidential = confidential_child + end + + it 'validates if child confidentiality is compatible with parent' do + link = build(:parent_link, work_item_parent: issue, work_item: task1) + + expect(link.valid?).to eq(valid) + end + end + end + end + end + + context 'with confidential work items' do + let_it_be(:project) { create(:project) } + let_it_be(:confidential_child) { create(:work_item, :task, confidential: true, project: project) } + let_it_be(:putlic_child) { create(:work_item, :task, project: project) } + let_it_be(:confidential_parent) { create(:work_item, confidential: true, project: project) } + let_it_be(:public_parent) { create(:work_item, project: project) } + + describe '.has_public_children?' do + subject { described_class.has_public_children?(public_parent.id) } + + context 'with confidential child' do + let_it_be(:link) { create(:parent_link, work_item_parent: public_parent, work_item: confidential_child) } + + it { is_expected.to be_falsey } + + context 'with also public child' do + let_it_be(:link) { create(:parent_link, work_item_parent: public_parent, work_item: putlic_child) } + + it { is_expected.to be_truthy } + end + end + end + + describe '.has_confidential_parent?' do + subject { described_class.has_confidential_parent?(confidential_child.id) } + + context 'with confidential parent' do + let_it_be(:link) { create(:parent_link, work_item_parent: confidential_parent, work_item: confidential_child) } + + it { is_expected.to be_truthy } + end + + context 'with public parent' do + let_it_be(:link) { create(:parent_link, work_item_parent: public_parent, work_item: confidential_child) } + + it { is_expected.to be_falsey } + end end end end |