Skip to content

Commit

Permalink
Ensure specs that create models in threads are rolled back with trunc…
Browse files Browse the repository at this point in the history
…ation (#4146)

* Also prefix shared_examples and other RSpec methods so they don't error when using `--bisect`
  • Loading branch information
sethboyles authored Dec 19, 2024
1 parent 0545c0c commit 0d37cbe
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions spec/support/shared_examples/access/access_levels.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shared_examples 'full access' do
RSpec.shared_examples 'full access' do
it { is_expected.to allow_op_on_object :create, object }
it { is_expected.to allow_op_on_object :read, object }
it { is_expected.to allow_op_on_object :read_for_update, object }
Expand All @@ -7,7 +7,7 @@
it { is_expected.to allow_op_on_object :index, object.class }
end

shared_examples 'read only access' do
RSpec.shared_examples 'read only access' do
it { is_expected.not_to allow_op_on_object :create, object }
it { is_expected.to allow_op_on_object :read, object }
it { is_expected.not_to allow_op_on_object :read_for_update, object }
Expand All @@ -17,7 +17,7 @@
it { is_expected.to allow_op_on_object :index, object.class }
end

shared_examples 'no access' do
RSpec.shared_examples 'no access' do
it { is_expected.not_to allow_op_on_object :create, object }
it { is_expected.not_to allow_op_on_object :read, object }
it { is_expected.not_to allow_op_on_object :read_for_update, object }
Expand All @@ -29,22 +29,22 @@
# override the default behavior of always allowing access to :index
end

shared_examples 'admin full access' do
RSpec.shared_examples 'admin full access' do
include_context 'admin setup'
it_behaves_like 'full access'
end

shared_examples 'admin read only access' do
RSpec.shared_examples 'admin read only access' do
include_context 'admin read only setup'
it_behaves_like 'read only access'
end

shared_examples 'global auditor access' do
RSpec.shared_examples 'global auditor access' do
include_context 'global auditor setup'
it_behaves_like 'read only access'
end

shared_context 'admin setup' do
RSpec.shared_context 'admin setup' do
before do
token = { 'scope' => [VCAP::CloudController::Roles::CLOUD_CONTROLLER_ADMIN_SCOPE] }
VCAP::CloudController::SecurityContext.set(user, token)
Expand All @@ -53,7 +53,7 @@
after { VCAP::CloudController::SecurityContext.clear }
end

shared_context 'global auditor setup' do
RSpec.shared_context 'global auditor setup' do
before do
token = { 'scope' => [VCAP::CloudController::Roles::CLOUD_CONTROLLER_GLOBAL_AUDITOR] }
VCAP::CloudController::SecurityContext.set(user, token)
Expand All @@ -62,7 +62,7 @@
after { VCAP::CloudController::SecurityContext.clear }
end

shared_context 'admin read only setup' do
RSpec.shared_context 'admin read only setup' do
before do
token = { 'scope' => [VCAP::CloudController::Roles::CLOUD_CONTROLLER_ADMIN_READ_ONLY_SCOPE] }
VCAP::CloudController::SecurityContext.set(user, token)
Expand Down
4 changes: 2 additions & 2 deletions spec/support/shared_examples/controllers/permissions.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shared_context 'permissions' do
RSpec.shared_context 'permissions' do
before do
@org_a = VCAP::CloudController::Organization.make
@org_a_manager = VCAP::CloudController::User.make
Expand Down Expand Up @@ -44,7 +44,7 @@
end
end

shared_examples 'permission enumeration' do |perm_name, opts|
RSpec.shared_examples 'permission enumeration' do |perm_name, opts|
name = opts[:name]
path = opts[:path]
expected = opts[:enumerate]
Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared_examples/controllers/resource_pool.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shared_context 'resource pool' do
RSpec.shared_context 'resource pool' do
before(:all) do
@max_file_size = 1098 # this is arbitrary
num_dirs = 3
Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared_examples/models/encrypted_attribute.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'cloud_controller/encryptor'

module VCAP::CloudController
shared_examples 'a model with an encrypted attribute' do
RSpec.shared_examples 'a model with an encrypted attribute' do
before do
allow(Encryptor).to receive(:database_encryption_keys).
and_return({ Encryptor.current_encryption_key_label.to_sym => 'correct-key' })
Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared_examples/models/stager_interface.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module VCAP::CloudController
shared_examples 'a stager' do
RSpec.shared_examples 'a stager' do
it 'defines #stage' do
expect(subject).to respond_to(:stage)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/middleware/service_broker_rate_limiter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module CloudFoundry
module Middleware
RSpec.describe ServiceBrokerRateLimiter do
RSpec.describe ServiceBrokerRateLimiter, isolation: :truncation do
let(:app) { double(:app) }
let(:logger) { double }
let(:instance) { VCAP::CloudController::Service.make(instances_retrievable: true) }
Expand Down

0 comments on commit 0d37cbe

Please sign in to comment.