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
Léo-Paul Géneau
gitlab-ce
Commits
32c7e42b
Commit
32c7e42b
authored
Apr 04, 2016
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve code
parent
5d428030
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
17 deletions
+22
-17
app/controllers/groups/milestones_controller.rb
app/controllers/groups/milestones_controller.rb
+13
-16
app/views/groups/milestones/new.html.haml
app/views/groups/milestones/new.html.haml
+8
-0
spec/controllers/groups/milestones_controller_spec.rb
spec/controllers/groups/milestones_controller_spec.rb
+1
-1
No files found.
app/controllers/groups/milestones_controller.rb
View file @
32c7e42b
...
@@ -24,7 +24,7 @@ class Groups::MilestonesController < Groups::ApplicationController
...
@@ -24,7 +24,7 @@ class Groups::MilestonesController < Groups::ApplicationController
if
create_milestones
(
project_ids
,
title
)
if
create_milestones
(
project_ids
,
title
)
redirect_to
milestone_path
(
title
)
redirect_to
milestone_path
(
title
)
else
else
render_new_with_error
(
@error
)
render_new_with_error
(
project_ids
.
empty?
)
end
end
end
end
...
@@ -42,12 +42,8 @@ class Groups::MilestonesController < Groups::ApplicationController
...
@@ -42,12 +42,8 @@ class Groups::MilestonesController < Groups::ApplicationController
private
private
def
create_milestones
(
project_ids
,
title
)
def
create_milestones
(
project_ids
,
title
)
unless
project_ids
.
present?
return
false
unless
project_ids
.
present?
@error
=
"Please select at least one project."
return
false
end
begin
ActiveRecord
::
Base
.
transaction
do
ActiveRecord
::
Base
.
transaction
do
@projects
.
where
(
id:
project_ids
).
each
do
|
project
|
@projects
.
where
(
id:
project_ids
).
each
do
|
project
|
Milestones
::
CreateService
.
new
(
project
,
current_user
,
milestone_params
).
execute
Milestones
::
CreateService
.
new
(
project
,
current_user
,
milestone_params
).
execute
...
@@ -55,15 +51,16 @@ class Groups::MilestonesController < Groups::ApplicationController
...
@@ -55,15 +51,16 @@ class Groups::MilestonesController < Groups::ApplicationController
end
end
true
true
rescue
=>
e
rescue
=>
e
@error
=
"Error creating milestone:
#{
e
.
message
}
."
flash
.
now
[
:alert
]
=
"An error occurred while creating the milestone:
#{
e
.
message
}
"
false
false
end
end
end
def
render_new_with_error
(
e
rror
)
def
render_new_with_error
(
e
mpty_project_ids
)
@milestone
=
Milestone
.
new
(
milestone_params
)
@milestone
=
Milestone
.
new
(
milestone_params
)
flash
[
:alert
]
=
error
@milestone
.
errors
.
add
(
:project_id
,
"Please select at least one project."
)
if
empty_project_ids
render
:new
render
:new
end
end
...
...
app/views/groups/milestones/new.html.haml
View file @
32c7e42b
...
@@ -10,6 +10,14 @@
...
@@ -10,6 +10,14 @@
=
form_for
@milestone
,
url:
group_milestones_path
(
@group
),
html:
{
class:
'form-horizontal milestone-form gfm-form js-quick-submit js-requires-input'
}
do
|
f
|
=
form_for
@milestone
,
url:
group_milestones_path
(
@group
),
html:
{
class:
'form-horizontal milestone-form gfm-form js-quick-submit js-requires-input'
}
do
|
f
|
.row
.row
-
if
@milestone
.
errors
.
any?
#error_explanation
.alert.alert-danger
%ul
-
@milestone
.
errors
.
full_messages
.
each
do
|
msg
|
%li
=
msg
.col-md-6
.col-md-6
.form-group
.form-group
=
f
.
label
:title
,
"Title"
,
class:
"control-label"
=
f
.
label
:title
,
"Title"
,
class:
"control-label"
...
...
spec/controllers/groups/milestones_controller_spec.rb
View file @
32c7e42b
...
@@ -27,7 +27,7 @@ describe Groups::MilestonesController do
...
@@ -27,7 +27,7 @@ describe Groups::MilestonesController do
it
"redirects to new when there are no project ids"
do
it
"redirects to new when there are no project ids"
do
post
:create
,
group_id:
group
.
id
,
milestone:
{
title:
title
,
project_ids:
[
""
]
}
post
:create
,
group_id:
group
.
id
,
milestone:
{
title:
title
,
project_ids:
[
""
]
}
expect
(
response
).
to
render_template
:new
expect
(
response
).
to
render_template
:new
expect
(
flash
[
:alert
]
).
to_not
be_nil
expect
(
assigns
(
:milestone
).
errors
).
to_not
be_nil
end
end
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