Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/models/exportable_shared_examples.rb')
-rw-r--r--spec/support/shared_examples/models/exportable_shared_examples.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/spec/support/shared_examples/models/exportable_shared_examples.rb b/spec/support/shared_examples/models/exportable_shared_examples.rb
new file mode 100644
index 00000000000..37c3e68fd5f
--- /dev/null
+++ b/spec/support/shared_examples/models/exportable_shared_examples.rb
@@ -0,0 +1,73 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'resource with exportable associations' do
+ before do
+ stub_licensed_features(stubbed_features) if stubbed_features.any?
+ end
+
+ describe '#exportable_association?' do
+ let(:association) { single_association }
+
+ subject { resource.exportable_association?(association, current_user: user) }
+
+ it { is_expected.to be_falsey }
+
+ context 'when user can read resource' do
+ before do
+ group.add_developer(user)
+ end
+
+ it { is_expected.to be_falsey }
+
+ context "when user can read resource's association" do
+ before do
+ other_group.add_developer(user)
+ end
+
+ it { is_expected.to be_truthy }
+
+ context 'for an unknown association' do
+ let(:association) { :foo }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'for an unauthenticated user' do
+ let(:user) { nil }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+ end
+ end
+
+ describe '#readable_records' do
+ subject { resource.readable_records(association, current_user: user) }
+
+ before do
+ group.add_developer(user)
+ end
+
+ context 'when association not supported' do
+ let(:association) { :foo }
+
+ it { is_expected.to be_nil }
+ end
+
+ context 'when association is `:notes`' do
+ let(:association) { :notes }
+
+ it { is_expected.to match_array([readable_note]) }
+
+ context 'when user have access' do
+ before do
+ other_group.add_developer(user)
+ end
+
+ it 'returns all records' do
+ is_expected.to match_array([readable_note, restricted_note])
+ end
+ end
+ end
+ end
+end