Commit cf7c57aa authored by Robert Speicher's avatar Robert Speicher

Use stub_application_setting in a few more specs

These specs also failed when run by themselves before this change, so
we've likely got some kind of cross-test contamination going on.
parent 4b4351a1
...@@ -9,8 +9,7 @@ describe 'Profile account page', feature: true do ...@@ -9,8 +9,7 @@ describe 'Profile account page', feature: true do
describe 'when signup is enabled' do describe 'when signup is enabled' do
before do before do
allow_any_instance_of(ApplicationSetting). stub_application_setting(signup_enabled: true)
to receive(:signup_enabled?).and_return(true)
visit profile_account_path visit profile_account_path
end end
...@@ -24,8 +23,7 @@ describe 'Profile account page', feature: true do ...@@ -24,8 +23,7 @@ describe 'Profile account page', feature: true do
describe 'when signup is disabled' do describe 'when signup is disabled' do
before do before do
allow_any_instance_of(ApplicationSetting). stub_application_setting(signup_enabled: false)
to receive(:signup_enabled?).and_return(false)
visit profile_account_path visit profile_account_path
end end
......
...@@ -220,9 +220,7 @@ describe API::API, api: true do ...@@ -220,9 +220,7 @@ describe API::API, api: true do
context 'when a visibility level is restricted' do context 'when a visibility level is restricted' do
before do before do
@project = attributes_for(:project, { public: true }) @project = attributes_for(:project, { public: true })
allow_any_instance_of(ApplicationSetting).to( stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
receive(:restricted_visibility_levels).and_return([20])
)
end end
it 'should not allow a non-admin to use a restricted visibility level' do it 'should not allow a non-admin to use a restricted visibility level' do
......
...@@ -14,11 +14,7 @@ describe CreateSnippetService do ...@@ -14,11 +14,7 @@ describe CreateSnippetService do
context 'When public visibility is restricted' do context 'When public visibility is restricted' do
before do before do
allow_any_instance_of(ApplicationSetting).to( stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
receive(:restricted_visibility_levels).and_return(
[Gitlab::VisibilityLevel::PUBLIC]
)
)
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) @opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
end end
......
...@@ -124,9 +124,7 @@ describe GitPushService do ...@@ -124,9 +124,7 @@ describe GitPushService do
end end
it "when pushing a branch for the first time with default branch protection disabled" do it "when pushing a branch for the first time with default branch protection disabled" do
allow(ApplicationSetting.current_application_settings). stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_NONE)
to receive(:default_branch_protection).
and_return(Gitlab::Access::PROTECTION_NONE)
expect(project).to receive(:execute_hooks) expect(project).to receive(:execute_hooks)
expect(project.default_branch).to eq("master") expect(project.default_branch).to eq("master")
...@@ -135,9 +133,7 @@ describe GitPushService do ...@@ -135,9 +133,7 @@ describe GitPushService do
end end
it "when pushing a branch for the first time with default branch protection set to 'developers can push'" do it "when pushing a branch for the first time with default branch protection set to 'developers can push'" do
allow(ApplicationSetting.current_application_settings). stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_DEV_CAN_PUSH)
to receive(:default_branch_protection).
and_return(Gitlab::Access::PROTECTION_DEV_CAN_PUSH)
expect(project).to receive(:execute_hooks) expect(project).to receive(:execute_hooks)
expect(project.default_branch).to eq("master") expect(project.default_branch).to eq("master")
......
...@@ -58,9 +58,7 @@ describe Projects::CreateService do ...@@ -58,9 +58,7 @@ describe Projects::CreateService do
context 'restricted visibility level' do context 'restricted visibility level' do
before do before do
allow_any_instance_of(ApplicationSetting).to( stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
receive(:restricted_visibility_levels).and_return([20])
)
@opts.merge!( @opts.merge!(
visibility_level: Gitlab::VisibilityLevel.options['Public'] visibility_level: Gitlab::VisibilityLevel.options['Public']
......
...@@ -47,9 +47,7 @@ describe Projects::UpdateService do ...@@ -47,9 +47,7 @@ describe Projects::UpdateService do
context 'respect configured visibility restrictions setting' do context 'respect configured visibility restrictions setting' do
before(:each) do before(:each) do
allow_any_instance_of(ApplicationSetting).to( stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
receive(:restricted_visibility_levels).and_return([20])
)
end end
context 'should be private when updated to private' do context 'should be private when updated to private' do
......
...@@ -14,11 +14,7 @@ describe UpdateSnippetService do ...@@ -14,11 +14,7 @@ describe UpdateSnippetService do
context 'When public visibility is restricted' do context 'When public visibility is restricted' do
before do before do
allow_any_instance_of(ApplicationSetting).to( stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
receive(:restricted_visibility_levels).and_return(
[Gitlab::VisibilityLevel::PUBLIC]
)
)
@snippet = create_snippet(@project, @user, @opts) @snippet = create_snippet(@project, @user, @opts)
@opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) @opts.merge!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
......
module StubConfiguration module StubConfiguration
def stub_application_setting(messages) def stub_application_setting(messages)
add_predicates(messages)
# Stubbing both of these because we're not yet consistent with how we access
# current application settings
allow_any_instance_of(ApplicationSetting).to receive_messages(messages)
allow(Gitlab::CurrentSettings.current_application_settings). allow(Gitlab::CurrentSettings.current_application_settings).
to receive_messages(messages) to receive_messages(messages)
end end
...@@ -11,4 +16,25 @@ module StubConfiguration ...@@ -11,4 +16,25 @@ module StubConfiguration
def stub_gravatar_setting(messages) def stub_gravatar_setting(messages)
allow(Gitlab.config.gravatar).to receive_messages(messages) allow(Gitlab.config.gravatar).to receive_messages(messages)
end end
private
# Modifies stubbed messages to also stub possible predicate versions
#
# Examples:
#
# add_predicates(foo: true)
# # => {foo: true, foo?: true}
#
# add_predicates(signup_enabled?: false)
# # => {signup_enabled? false}
def add_predicates(messages)
# Only modify keys that aren't already predicates
keys = messages.keys.map(&:to_s).reject { |k| k.end_with?('?') }
keys.each do |key|
predicate = key + '?'
messages[predicate.to_sym] = messages[key.to_sym]
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment