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
f7ed0964
Commit
f7ed0964
authored
Feb 02, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract Variables controllers specs to shared_examples
parent
45a14b4f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
191 deletions
+112
-191
spec/controllers/groups/variables_controller_spec.rb
spec/controllers/groups/variables_controller_spec.rb
+4
-90
spec/controllers/projects/variables_controller_spec.rb
spec/controllers/projects/variables_controller_spec.rb
+8
-101
spec/support/shared_examples/controllers/variables_shared_examples.rb
.../shared_examples/controllers/variables_shared_examples.rb
+100
-0
No files found.
spec/controllers/groups/variables_controller_spec.rb
View file @
f7ed0964
...
...
@@ -16,15 +16,12 @@ describe Groups::VariablesController do
get
:show
,
group_id:
group
,
format: :json
end
it
'renders the ci_group_variable as json'
do
subject
expect
(
response
).
to
match_response_schema
(
'variables'
)
end
include_examples
'GET #show lists all variables'
end
describe
'P
OST
#update'
do
describe
'P
ATCH
#update'
do
let!
(
:variable
)
{
create
(
:ci_group_variable
,
group:
group
)
}
let
(
:owner
)
{
group
}
subject
do
patch
:update
,
...
...
@@ -33,89 +30,6 @@ describe Groups::VariablesController do
format: :json
end
let
(
:variable_attributes
)
do
{
id:
variable
.
id
,
key:
variable
.
key
,
value:
variable
.
value
,
protected:
variable
.
protected?
.
to_s
}
end
let
(
:new_variable_attributes
)
do
{
key:
'new_key'
,
value:
'dummy_value'
,
protected:
'false'
}
end
context
'with invalid new variable parameters'
do
let
(
:variables_attributes
)
do
[
variable_attributes
.
merge
(
value:
'other_value'
),
new_variable_attributes
.
merge
(
key:
'...?'
)
]
end
it
'does not update the existing variable'
do
expect
{
subject
}.
not_to
change
{
variable
.
reload
.
value
}
end
it
'does not create the new variable'
do
expect
{
subject
}.
not_to
change
{
group
.
variables
.
count
}
end
it
'returns a bad request response'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
end
context
'with valid new variable parameters'
do
let
(
:variables_attributes
)
do
[
variable_attributes
.
merge
(
value:
'other_value'
),
new_variable_attributes
]
end
it
'updates the existing variable'
do
expect
{
subject
}.
to
change
{
variable
.
reload
.
value
}.
to
(
'other_value'
)
end
it
'creates the new variable'
do
expect
{
subject
}.
to
change
{
group
.
variables
.
count
}.
by
(
1
)
end
it
'returns a successful response'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
it
'has all variables in response'
do
subject
expect
(
response
).
to
match_response_schema
(
'variables'
)
end
end
context
'with a deleted variable'
do
let
(
:variables_attributes
)
{
[
variable_attributes
.
merge
(
_destroy:
'true'
)]
}
it
'destroys the variable'
do
expect
{
subject
}.
to
change
{
group
.
variables
.
count
}.
by
(
-
1
)
expect
{
variable
.
reload
}.
to
raise_error
ActiveRecord
::
RecordNotFound
end
it
'returns a successful response'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
it
'has all variables in response'
do
subject
expect
(
response
).
to
match_response_schema
(
'variables'
)
end
end
include_examples
'PATCH #update updates variables'
end
end
spec/controllers/projects/variables_controller_spec.rb
View file @
f7ed0964
...
...
@@ -10,120 +10,27 @@ describe Projects::VariablesController do
end
describe
'GET #show'
do
let
(
:variable
)
{
create
(
:ci_variable
)
}
before
do
project
.
variables
<<
variable
end
let!
(
:variable
)
{
create
(
:ci_variable
,
project:
project
)
}
subject
do
get
:show
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
format: :json
end
it
'renders the ci_variable as json'
do
subject
expect
(
response
).
to
match_response_schema
(
'variables'
)
end
include_examples
'GET #show lists all variables'
end
describe
'POST #update'
do
let
(
:variable
)
{
create
(
:ci_variable
)
}
describe
'PATCH #update'
do
let!
(
:variable
)
{
create
(
:ci_variable
,
project:
project
)
}
let
(
:owner
)
{
project
}
subject
do
patch
:update
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
variables_attributes:
variables_attributes
,
format: :json
end
let
(
:variable_attributes
)
do
{
id:
variable
.
id
,
key:
variable
.
key
,
value:
variable
.
value
,
protected:
variable
.
protected?
.
to_s
}
end
let
(
:new_variable_attributes
)
do
{
key:
'new_key'
,
value:
'dummy_value'
,
protected:
'false'
}
end
before
do
project
.
variables
<<
variable
end
context
'with invalid new variable parameters'
do
let
(
:variables_attributes
)
do
[
variable_attributes
.
merge
(
value:
'other_value'
),
new_variable_attributes
.
merge
(
key:
'...?'
)
]
end
it
'does not update the existing variable'
do
expect
{
subject
}.
not_to
change
{
variable
.
reload
.
value
}
end
it
'does not create the new variable'
do
expect
{
subject
}.
not_to
change
{
project
.
variables
.
count
}
end
it
'returns a bad request response'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
end
context
'with valid new variable parameters'
do
let
(
:variables_attributes
)
do
[
variable_attributes
.
merge
(
value:
'other_value'
),
new_variable_attributes
]
end
it
'updates the existing variable'
do
expect
{
subject
}.
to
change
{
variable
.
reload
.
value
}.
to
(
'other_value'
)
end
it
'creates the new variable'
do
expect
{
subject
}.
to
change
{
project
.
variables
.
count
}.
by
(
1
)
end
it
'returns a successful response'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
it
'has all variables in response'
do
subject
expect
(
response
).
to
match_response_schema
(
'variables'
)
end
end
context
'with a deleted variable'
do
let
(
:variables_attributes
)
{
[
variable_attributes
.
merge
(
_destroy:
'true'
)]
}
it
'destroys the variable'
do
expect
{
subject
}.
to
change
{
project
.
variables
.
count
}.
by
(
-
1
)
expect
{
variable
.
reload
}.
to
raise_error
ActiveRecord
::
RecordNotFound
end
it
'returns a successful response'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
it
'has all variables in response'
do
subject
expect
(
response
).
to
match_response_schema
(
'variables'
)
end
end
include_examples
'PATCH #update updates variables'
end
end
spec/support/shared_examples/controllers/variables_shared_examples.rb
0 → 100644
View file @
f7ed0964
shared_examples
'GET #show lists all variables'
do
it
'renders the variables as json'
do
subject
expect
(
response
).
to
match_response_schema
(
'variables'
)
end
it
'has only one variable'
do
subject
expect
(
json_response
[
'variables'
].
count
).
to
eq
(
1
)
end
end
shared_examples
'PATCH #update updates variables'
do
let
(
:variable_attributes
)
do
{
id:
variable
.
id
,
key:
variable
.
key
,
value:
variable
.
value
,
protected:
variable
.
protected?
.
to_s
}
end
let
(
:new_variable_attributes
)
do
{
key:
'new_key'
,
value:
'dummy_value'
,
protected:
'false'
}
end
context
'with invalid new variable parameters'
do
let
(
:variables_attributes
)
do
[
variable_attributes
.
merge
(
value:
'other_value'
),
new_variable_attributes
.
merge
(
key:
'...?'
)
]
end
it
'does not update the existing variable'
do
expect
{
subject
}.
not_to
change
{
variable
.
reload
.
value
}
end
it
'does not create the new variable'
do
expect
{
subject
}.
not_to
change
{
owner
.
variables
.
count
}
end
it
'returns a bad request response'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
end
context
'with valid new variable parameters'
do
let
(
:variables_attributes
)
do
[
variable_attributes
.
merge
(
value:
'other_value'
),
new_variable_attributes
]
end
it
'updates the existing variable'
do
expect
{
subject
}.
to
change
{
variable
.
reload
.
value
}.
to
(
'other_value'
)
end
it
'creates the new variable'
do
expect
{
subject
}.
to
change
{
owner
.
variables
.
count
}.
by
(
1
)
end
it
'returns a successful response'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
it
'has all variables in response'
do
subject
expect
(
response
).
to
match_response_schema
(
'variables'
)
end
end
context
'with a deleted variable'
do
let
(
:variables_attributes
)
{
[
variable_attributes
.
merge
(
_destroy:
'true'
)]
}
it
'destroys the variable'
do
expect
{
subject
}.
to
change
{
owner
.
variables
.
count
}.
by
(
-
1
)
expect
{
variable
.
reload
}.
to
raise_error
ActiveRecord
::
RecordNotFound
end
it
'returns a successful response'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
it
'has all variables in response'
do
subject
expect
(
response
).
to
match_response_schema
(
'variables'
)
end
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