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
Boxiang Sun
gitlab-ce
Commits
45a14b4f
Commit
45a14b4f
authored
Feb 02, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Variable controllers specs
parent
18232d7e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
42 deletions
+47
-42
spec/controllers/groups/variables_controller_spec.rb
spec/controllers/groups/variables_controller_spec.rb
+23
-20
spec/controllers/projects/variables_controller_spec.rb
spec/controllers/projects/variables_controller_spec.rb
+24
-22
No files found.
spec/controllers/groups/variables_controller_spec.rb
View file @
45a14b4f
...
@@ -25,23 +25,32 @@ describe Groups::VariablesController do
...
@@ -25,23 +25,32 @@ describe Groups::VariablesController do
describe
'POST #update'
do
describe
'POST #update'
do
let!
(
:variable
)
{
create
(
:ci_group_variable
,
group:
group
)
}
let!
(
:variable
)
{
create
(
:ci_group_variable
,
group:
group
)
}
subject
do
patch
:update
,
group_id:
group
,
variables_attributes:
variables_attributes
,
format: :json
end
let
(
:variable_attributes
)
do
let
(
:variable_attributes
)
do
{
id:
variable
.
id
,
key:
variable
.
key
,
{
id:
variable
.
id
,
key:
variable
.
key
,
value:
variable
.
value
,
value:
variable
.
value
,
protected:
variable
.
protected?
.
to_s
}
protected:
variable
.
protected?
.
to_s
}
end
end
let
(
:new_variable_attributes
)
do
let
(
:new_variable_attributes
)
do
{
key:
'new_key'
,
value:
'dummy_value'
,
{
key:
'new_key'
,
value:
'dummy_value'
,
protected:
'false'
}
protected:
'false'
}
end
end
context
'with invalid new variable parameters'
do
context
'with invalid new variable parameters'
do
subject
do
let
(
:variables_attributes
)
do
patch
:update
,
[
group_id:
group
,
variable_attributes
.
merge
(
value:
'other_value'
),
variables_attributes:
[
variable_attributes
.
merge
(
value:
'other_value'
),
new_variable_attributes
.
merge
(
key:
'...?'
)
new_variable_attributes
.
merge
(
key:
'..?'
)],
]
format: :json
end
end
it
'does not update the existing variable'
do
it
'does not update the existing variable'
do
...
@@ -60,12 +69,11 @@ describe Groups::VariablesController do
...
@@ -60,12 +69,11 @@ describe Groups::VariablesController do
end
end
context
'with valid new variable parameters'
do
context
'with valid new variable parameters'
do
subject
do
let
(
:variables_attributes
)
do
patch
:update
,
[
group_id:
group
,
variable_attributes
.
merge
(
value:
'other_value'
),
variables_attributes:
[
variable_attributes
.
merge
(
value:
'other_value'
),
new_variable_attributes
new_variable_attributes
],
]
format: :json
end
end
it
'updates the existing variable'
do
it
'updates the existing variable'
do
...
@@ -90,12 +98,7 @@ describe Groups::VariablesController do
...
@@ -90,12 +98,7 @@ describe Groups::VariablesController do
end
end
context
'with a deleted variable'
do
context
'with a deleted variable'
do
subject
do
let
(
:variables_attributes
)
{
[
variable_attributes
.
merge
(
_destroy:
'true'
)]
}
patch
:update
,
group_id:
group
,
variables_attributes:
[
variable_attributes
.
merge
(
_destroy:
'true'
)],
format: :json
end
it
'destroys the variable'
do
it
'destroys the variable'
do
expect
{
subject
}.
to
change
{
group
.
variables
.
count
}.
by
(
-
1
)
expect
{
subject
}.
to
change
{
group
.
variables
.
count
}.
by
(
-
1
)
...
...
spec/controllers/projects/variables_controller_spec.rb
View file @
45a14b4f
...
@@ -17,8 +17,7 @@ describe Projects::VariablesController do
...
@@ -17,8 +17,7 @@ describe Projects::VariablesController do
end
end
subject
do
subject
do
get
:show
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
get
:show
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
format: :json
format: :json
end
end
it
'renders the ci_variable as json'
do
it
'renders the ci_variable as json'
do
...
@@ -30,13 +29,23 @@ describe Projects::VariablesController do
...
@@ -30,13 +29,23 @@ describe Projects::VariablesController do
describe
'POST #update'
do
describe
'POST #update'
do
let
(
:variable
)
{
create
(
:ci_variable
)
}
let
(
:variable
)
{
create
(
:ci_variable
)
}
subject
do
patch
:update
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
variables_attributes:
variables_attributes
,
format: :json
end
let
(
:variable_attributes
)
do
let
(
:variable_attributes
)
do
{
id:
variable
.
id
,
key:
variable
.
key
,
{
id:
variable
.
id
,
key:
variable
.
key
,
value:
variable
.
value
,
value:
variable
.
value
,
protected:
variable
.
protected?
.
to_s
}
protected:
variable
.
protected?
.
to_s
}
end
end
let
(
:new_variable_attributes
)
do
let
(
:new_variable_attributes
)
do
{
key:
'new_key'
,
value:
'dummy_value'
,
{
key:
'new_key'
,
value:
'dummy_value'
,
protected:
'false'
}
protected:
'false'
}
end
end
...
@@ -45,12 +54,11 @@ describe Projects::VariablesController do
...
@@ -45,12 +54,11 @@ describe Projects::VariablesController do
end
end
context
'with invalid new variable parameters'
do
context
'with invalid new variable parameters'
do
subject
do
let
(
:variables_attributes
)
do
patch
:update
,
[
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
variable_attributes
.
merge
(
value:
'other_value'
),
variables_attributes:
[
variable_attributes
.
merge
(
value:
'other_value'
),
new_variable_attributes
.
merge
(
key:
'...?'
)
new_variable_attributes
.
merge
(
key:
'..?'
)],
]
format: :json
end
end
it
'does not update the existing variable'
do
it
'does not update the existing variable'
do
...
@@ -69,12 +77,11 @@ describe Projects::VariablesController do
...
@@ -69,12 +77,11 @@ describe Projects::VariablesController do
end
end
context
'with valid new variable parameters'
do
context
'with valid new variable parameters'
do
subject
do
let
(
:variables_attributes
)
do
patch
:update
,
[
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
variable_attributes
.
merge
(
value:
'other_value'
),
variables_attributes:
[
variable_attributes
.
merge
(
value:
'other_value'
),
new_variable_attributes
new_variable_attributes
],
]
format: :json
end
end
it
'updates the existing variable'
do
it
'updates the existing variable'
do
...
@@ -99,12 +106,7 @@ describe Projects::VariablesController do
...
@@ -99,12 +106,7 @@ describe Projects::VariablesController do
end
end
context
'with a deleted variable'
do
context
'with a deleted variable'
do
subject
do
let
(
:variables_attributes
)
{
[
variable_attributes
.
merge
(
_destroy:
'true'
)]
}
patch
:update
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
variables_attributes:
[
variable_attributes
.
merge
(
_destroy:
'true'
)],
format: :json
end
it
'destroys the variable'
do
it
'destroys the variable'
do
expect
{
subject
}.
to
change
{
project
.
variables
.
count
}.
by
(
-
1
)
expect
{
subject
}.
to
change
{
project
.
variables
.
count
}.
by
(
-
1
)
...
...
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