139 lines
4.1 KiB
Ruby
139 lines
4.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
<<<<<<< HEAD
|
|
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 }
|
|
=======
|
|
RSpec.shared_examples 'an exportable' do |restricted_association: :project|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
describe '#exportable_association?' do
|
|
let(:association) { restricted_association }
|
|
>>>>>>> 68c65fd975 (New upstream version 15.10.8+ds1)
|
|
|
|
subject { resource.exportable_association?(association, current_user: user) }
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
<<<<<<< HEAD
|
|
context 'when user can read resource' do
|
|
before do
|
|
group.add_developer(user)
|
|
=======
|
|
context 'when user can only read resource' do
|
|
before do
|
|
allow(Ability).to receive(:allowed?).and_call_original
|
|
allow(Ability).to receive(:allowed?)
|
|
.with(user, :"read_#{resource.to_ability_name}", resource)
|
|
.and_return(true)
|
|
>>>>>>> 68c65fd975 (New upstream version 15.10.8+ds1)
|
|
end
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
context "when user can read resource's association" do
|
|
before do
|
|
<<<<<<< HEAD
|
|
other_group.add_developer(user)
|
|
=======
|
|
allow(resource).to receive(:readable_record?).with(anything, user).and_return(true)
|
|
>>>>>>> 68c65fd975 (New upstream version 15.10.8+ds1)
|
|
end
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
context 'for an unknown association' do
|
|
let(:association) { :foo }
|
|
|
|
it { is_expected.to be_falsey }
|
|
end
|
|
<<<<<<< HEAD
|
|
|
|
context 'for an unauthenticated user' do
|
|
let(:user) { nil }
|
|
|
|
it { is_expected.to be_falsey }
|
|
end
|
|
=======
|
|
>>>>>>> 68c65fd975 (New upstream version 15.10.8+ds1)
|
|
end
|
|
end
|
|
end
|
|
|
|
<<<<<<< HEAD
|
|
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])
|
|
=======
|
|
describe '#to_authorized_json' do
|
|
let(:options) { { include: [{ notes: { only: [:id] } }] } }
|
|
|
|
subject { resource.to_authorized_json(keys, user, options) }
|
|
|
|
before do
|
|
allow(Ability).to receive(:allowed?).and_call_original
|
|
allow(Ability).to receive(:allowed?)
|
|
.with(user, :"read_#{resource.to_ability_name}", resource)
|
|
.and_return(true)
|
|
end
|
|
|
|
context 'when association not supported' do
|
|
let(:keys) { [:foo] }
|
|
|
|
it { is_expected.not_to include('foo') }
|
|
end
|
|
|
|
context 'when association is `:notes`' do
|
|
let_it_be(:readable_note) { create(:system_note, noteable: resource, project: project, note: 'readable') }
|
|
let_it_be(:restricted_note) { create(:system_note, noteable: resource, project: project, note: 'restricted') }
|
|
|
|
let(:restricted_note_access) { false }
|
|
let(:keys) { [:notes] }
|
|
|
|
before do
|
|
allow(Ability).to receive(:allowed?).and_call_original
|
|
allow(Ability).to receive(:allowed?).with(user, :read_note, readable_note).and_return(true)
|
|
allow(Ability).to receive(:allowed?).with(user, :read_note, restricted_note).and_return(restricted_note_access)
|
|
end
|
|
|
|
it { is_expected.to include("\"notes\":[{\"id\":#{readable_note.id}}]") }
|
|
|
|
context 'when user have access to all notes' do
|
|
let(:restricted_note_access) { true }
|
|
|
|
it 'string includes all notes' do
|
|
is_expected.to include("\"notes\":[{\"id\":#{readable_note.id}},{\"id\":#{restricted_note.id}}]")
|
|
>>>>>>> 68c65fd975 (New upstream version 15.10.8+ds1)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|