Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
a8177e03
Commit
a8177e03
authored
Jan 09, 2017
by
Adam Niedzielski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce "stub_env" test helper for safely stubbing environment variables
parent
583deef2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
5 deletions
+14
-5
spec/db/production/settings.rb
spec/db/production/settings.rb
+3
-2
spec/initializers/secret_token_spec.rb
spec/initializers/secret_token_spec.rb
+4
-3
spec/support/stub_env.rb
spec/support/stub_env.rb
+7
-0
No files found.
spec/db/production/settings.rb
View file @
a8177e03
...
...
@@ -2,10 +2,11 @@ require 'spec_helper'
require
'rainbow/ext/string'
describe
'seed production settings'
,
lib:
true
do
include
StubENV
context
'GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN is set in the environment'
do
before
do
allow
(
ENV
).
to
receive
(
:[]
).
and_call_original
allow
(
ENV
).
to
receive
(
:[]
).
with
(
'GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN'
).
and_return
(
'013456789'
)
stub_env
(
'GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN'
,
'013456789'
)
end
it
'writes the token to the database'
do
...
...
spec/initializers/secret_token_spec.rb
View file @
a8177e03
...
...
@@ -2,10 +2,11 @@ require 'spec_helper'
require_relative
'../../config/initializers/secret_token'
describe
'create_tokens'
,
lib:
true
do
include
StubENV
let
(
:secrets
)
{
ActiveSupport
::
OrderedOptions
.
new
}
before
do
allow
(
ENV
).
to
receive
(
:[]
).
and_call_original
allow
(
File
).
to
receive
(
:write
)
allow
(
File
).
to
receive
(
:delete
)
allow
(
Rails
).
to
receive_message_chain
(
:application
,
:secrets
).
and_return
(
secrets
)
...
...
@@ -17,7 +18,7 @@ describe 'create_tokens', lib: true do
context
'setting secret_key_base and otp_key_base'
do
context
'when none of the secrets exist'
do
before
do
allow
(
ENV
).
to
receive
(
:[]
).
with
(
'SECRET_KEY_BASE'
).
and_return
(
nil
)
stub_env
(
'SECRET_KEY_BASE'
,
nil
)
allow
(
File
).
to
receive
(
:exist?
).
with
(
'.secret'
).
and_return
(
false
)
allow
(
File
).
to
receive
(
:exist?
).
with
(
'config/secrets.yml'
).
and_return
(
false
)
allow
(
self
).
to
receive
(
:warn_missing_secret
)
...
...
@@ -69,7 +70,7 @@ describe 'create_tokens', lib: true do
context
'when secret_key_base exists in the environment and secrets.yml'
do
before
do
allow
(
ENV
).
to
receive
(
:[]
).
with
(
'SECRET_KEY_BASE'
).
and_return
(
'env_key'
)
stub_env
(
'SECRET_KEY_BASE'
,
'env_key'
)
secrets
.
secret_key_base
=
'secret_key_base'
secrets
.
otp_key_base
=
'otp_key_base'
end
...
...
spec/support/stub_env.rb
0 → 100644
View file @
a8177e03
module
StubENV
def
stub_env
(
key
,
value
)
allow
(
ENV
).
to
receive
(
:[]
).
and_call_original
unless
@env_already_stubbed
@env_already_stubbed
||=
true
allow
(
ENV
).
to
receive
(
:[]
).
with
(
key
).
and_return
(
value
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment