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
0bfcdd66
Commit
0bfcdd66
authored
Jan 29, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `resource` in Project Variables routing scheme
parent
6b82a9ef
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
12 deletions
+40
-12
app/controllers/projects/variables_controller.rb
app/controllers/projects/variables_controller.rb
+12
-1
app/presenters/ci/variable_presenter.rb
app/presenters/ci/variable_presenter.rb
+2
-2
config/routes/project.rb
config/routes/project.rb
+1
-3
spec/controllers/projects/variables_controller_spec.rb
spec/controllers/projects/variables_controller_spec.rb
+23
-4
spec/presenters/ci/variable_presenter_spec.rb
spec/presenters/ci/variable_presenter_spec.rb
+2
-2
No files found.
app/controllers/projects/variables_controller.rb
View file @
0bfcdd66
class
Projects::VariablesController
<
Projects
::
ApplicationController
class
Projects::VariablesController
<
Projects
::
ApplicationController
before_action
:authorize_admin_build!
before_action
:authorize_admin_build!
def
save_multiple
def
show
respond_to
do
|
format
|
format
.
json
do
variables
=
@project
.
variables
.
map
{
|
variable
|
variable
.
present
(
current_user:
current_user
)
}
render
status: :ok
,
json:
{
variables:
variables
}
end
end
end
def
update
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
json
do
format
.
json
do
return
head
:ok
if
@project
.
update
(
variables_params
)
return
head
:ok
if
@project
.
update
(
variables_params
)
...
...
app/presenters/ci/variable_presenter.rb
View file @
0bfcdd66
...
@@ -11,11 +11,11 @@ module Ci
...
@@ -11,11 +11,11 @@ module Ci
end
end
def
edit_path
def
edit_path
project_variables_
save_multiple_
path
(
project
)
project_variables_path
(
project
)
end
end
def
delete_path
def
delete_path
project_variables_
save_multiple_
path
(
project
)
project_variables_path
(
project
)
end
end
end
end
end
end
config/routes/project.rb
View file @
0bfcdd66
...
@@ -156,9 +156,7 @@ constraints(ProjectUrlConstrainer.new) do
...
@@ -156,9 +156,7 @@ constraints(ProjectUrlConstrainer.new) do
end
end
end
end
namespace
:variables
do
resource
:variables
,
only:
[
:show
,
:update
]
post
:save_multiple
end
resources
:triggers
,
only:
[
:index
,
:create
,
:edit
,
:update
,
:destroy
]
do
resources
:triggers
,
only:
[
:index
,
:create
,
:edit
,
:update
,
:destroy
]
do
member
do
member
do
...
...
spec/controllers/projects/variables_controller_spec.rb
View file @
0bfcdd66
...
@@ -9,7 +9,26 @@ describe Projects::VariablesController do
...
@@ -9,7 +9,26 @@ describe Projects::VariablesController do
project
.
add_master
(
user
)
project
.
add_master
(
user
)
end
end
describe
'POST #save_multiple'
do
describe
'GET #show'
do
let
(
:variable
)
{
create
(
:ci_variable
)
}
before
do
project
.
variables
<<
variable
end
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
.
body
).
to
include
(
variable
.
to_json
)
end
end
describe
'POST #update'
do
let
(
:variable
)
{
create
(
:ci_variable
)
}
let
(
:variable
)
{
create
(
:ci_variable
)
}
before
do
before
do
...
@@ -18,7 +37,7 @@ describe Projects::VariablesController do
...
@@ -18,7 +37,7 @@ describe Projects::VariablesController do
context
'with invalid new variable parameters'
do
context
'with invalid new variable parameters'
do
subject
do
subject
do
post
:
save_multipl
e
,
post
:
updat
e
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
variables_attributes:
[{
id:
variable
.
id
,
key:
variable
.
key
,
variables_attributes:
[{
id:
variable
.
id
,
key:
variable
.
key
,
value:
'other_value'
,
value:
'other_value'
,
...
@@ -45,7 +64,7 @@ describe Projects::VariablesController do
...
@@ -45,7 +64,7 @@ describe Projects::VariablesController do
context
'with valid new variable parameters'
do
context
'with valid new variable parameters'
do
subject
do
subject
do
post
:
save_multipl
e
,
post
:
updat
e
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
variables_attributes:
[{
id:
variable
.
id
,
key:
variable
.
key
,
variables_attributes:
[{
id:
variable
.
id
,
key:
variable
.
key
,
value:
'other_value'
,
value:
'other_value'
,
...
@@ -72,7 +91,7 @@ describe Projects::VariablesController do
...
@@ -72,7 +91,7 @@ describe Projects::VariablesController do
context
'with a deleted variable'
do
context
'with a deleted variable'
do
subject
do
subject
do
post
:
save_multipl
e
,
post
:
updat
e
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
variables_attributes:
[{
id:
variable
.
id
,
key:
variable
.
key
,
variables_attributes:
[{
id:
variable
.
id
,
key:
variable
.
key
,
value:
variable
.
value
,
value:
variable
.
value
,
...
...
spec/presenters/ci/variable_presenter_spec.rb
View file @
0bfcdd66
...
@@ -43,12 +43,12 @@ describe Ci::VariablePresenter do
...
@@ -43,12 +43,12 @@ describe Ci::VariablePresenter do
describe
'#edit_path'
do
describe
'#edit_path'
do
subject
{
described_class
.
new
(
variable
).
edit_path
}
subject
{
described_class
.
new
(
variable
).
edit_path
}
it
{
is_expected
.
to
eq
(
project_variables_
save_multiple_
path
(
project
))
}
it
{
is_expected
.
to
eq
(
project_variables_path
(
project
))
}
end
end
describe
'#delete_path'
do
describe
'#delete_path'
do
subject
{
described_class
.
new
(
variable
).
delete_path
}
subject
{
described_class
.
new
(
variable
).
delete_path
}
it
{
is_expected
.
to
eq
(
project_variables_
save_multiple_
path
(
project
))
}
it
{
is_expected
.
to
eq
(
project_variables_path
(
project
))
}
end
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