diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-07-02 00:21:51 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-07-07 05:39:56 +0300 |
commit | cf7c57aaf53036483da35868da84596dcdae2aaf (patch) | |
tree | d978fa5013631d5cec87e8ed0858b94d8e36a570 /spec/support/stub_configuration.rb | |
parent | 4b4351a18c5cc31cc1365b24b8c00360730cd100 (diff) |
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.
Diffstat (limited to 'spec/support/stub_configuration.rb')
-rw-r--r-- | spec/support/stub_configuration.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/support/stub_configuration.rb b/spec/support/stub_configuration.rb index ad86abdbb41..e4004ec8f79 100644 --- a/spec/support/stub_configuration.rb +++ b/spec/support/stub_configuration.rb @@ -1,5 +1,10 @@ module StubConfiguration 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). to receive_messages(messages) end @@ -11,4 +16,25 @@ module StubConfiguration def stub_gravatar_setting(messages) allow(Gitlab.config.gravatar).to receive_messages(messages) 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 |