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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
dfeb412d
Commit
dfeb412d
authored
Jan 25, 2019
by
Brett Walker
Committed by
Fatih Acet
Jan 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Specs for Issue::UpdateService
parent
2dc30485
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
10 deletions
+93
-10
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+4
-3
app/services/task_list_toggle_service.rb
app/services/task_list_toggle_service.rb
+19
-7
spec/services/issues/update_service_spec.rb
spec/services/issues/update_service_spec.rb
+70
-0
No files found.
app/services/issuable_base_service.rb
View file @
dfeb412d
...
@@ -267,10 +267,11 @@ class IssuableBaseService < BaseService
...
@@ -267,10 +267,11 @@ class IssuableBaseService < BaseService
return
unless
update_task_params
return
unless
update_task_params
toggler
=
TaskListToggleService
.
new
(
issue
.
description
,
issue
.
description_html
,
toggler
=
TaskListToggleService
.
new
(
issue
.
description
,
issue
.
description_html
,
index:
update_task_params
[
:index
],
currently_checked:
!
update_task_params
[
:checked
],
line_source:
update_task_params
[
:line_source
],
line_source:
update_task_params
[
:line_source
],
line_number:
update_task_params
[
:line_number
])
line_number:
update_task_params
[
:line_number
],
currently_checked:
!
update_task_params
[
:checked
],
index:
update_task_params
[
:index
],
sourcepos:
false
)
if
toggler
.
execute
if
toggler
.
execute
# by updating the description_html field at the same time,
# by updating the description_html field at the same time,
...
...
app/services/task_list_toggle_service.rb
View file @
dfeb412d
# frozen_string_literal: true
# frozen_string_literal: true
# Finds the correct checkbox in the passed in markdown/html and toggles it's state,
# Finds the correct checkbox in the passed in markdown/html and toggles it's state,
# returning the updated markdown/html
# returning the updated markdown/html
.
# We don't care if the text has changed above or below the specific checkbox, as long
# We don't care if the text has changed above or below the specific checkbox, as long
# the checkbox still exists at exactly the same line number and the text is equal
# the checkbox still exists at exactly the same line number and the text is equal
.
# If successful, new values are available in `updated_markdown` and `updated_markdown_html`
# If successful, new values are available in `updated_markdown` and `updated_markdown_html`
#
# Note: once we've removed RedCarpet support, we can remove the `index` and `sourcepos`
# parameters
class
TaskListToggleService
class
TaskListToggleService
attr_reader
:updated_markdown
,
:updated_markdown_html
attr_reader
:updated_markdown
,
:updated_markdown_html
def
initialize
(
markdown
,
markdown_html
,
index
:,
currently_checked
:,
line_source
:,
line_number
:
)
def
initialize
(
markdown
,
markdown_html
,
line_source
:,
line_number
:,
currently_checked
:,
index
:,
sourcepos:
false
)
@markdown
,
@markdown_html
=
markdown
,
markdown_html
@markdown
,
@markdown_html
=
markdown
,
markdown_html
@index
,
@currently_checked
=
index
,
currently_checked
@line_source
,
@line_number
=
line_source
,
line_number
@line_source
,
@line_number
=
line_source
,
line_number
@currently_checked
=
currently_checked
@index
,
@use_sourcepos
=
index
,
sourcepos
@updated_markdown
,
@updated_markdown_html
=
nil
@updated_markdown
,
@updated_markdown_html
=
nil
end
end
...
@@ -24,7 +28,8 @@ class TaskListToggleService
...
@@ -24,7 +28,8 @@ class TaskListToggleService
private
private
attr_reader
:markdown
,
:markdown_html
,
:index
,
:currently_checked
,
:line_source
,
:line_number
attr_reader
:markdown
,
:markdown_html
,
:index
,
:currently_checked
attr_reader
:line_source
,
:line_number
,
:use_sourcepos
def
toggle_markdown
def
toggle_markdown
source_lines
=
markdown
.
split
(
"
\n
"
)
source_lines
=
markdown
.
split
(
"
\n
"
)
...
@@ -45,8 +50,7 @@ class TaskListToggleService
...
@@ -45,8 +50,7 @@ class TaskListToggleService
def
toggle_html
def
toggle_html
html
=
Nokogiri
::
HTML
.
fragment
(
markdown_html
)
html
=
Nokogiri
::
HTML
.
fragment
(
markdown_html
)
html_checkbox
=
html
.
css
(
'.task-list-item-checkbox'
)[
index
-
1
]
html_checkbox
=
get_html_checkbox
(
html
)
# html_checkbox = html.css(".task-list-item[data-sourcepos^='#{changed_line_number}:'] > input.task-list-item-checkbox").first
return
unless
html_checkbox
return
unless
html_checkbox
if
currently_checked
if
currently_checked
...
@@ -57,4 +61,12 @@ class TaskListToggleService
...
@@ -57,4 +61,12 @@ class TaskListToggleService
@updated_markdown_html
=
html
.
to_html
@updated_markdown_html
=
html
.
to_html
end
end
def
get_html_checkbox
(
html
)
if
use_sourcepos
html
.
css
(
".task-list-item[data-sourcepos^='
#{
line_number
}
:'] > input.task-list-item-checkbox"
).
first
else
html
.
css
(
'.task-list-item-checkbox'
)[
index
-
1
]
end
end
end
end
spec/services/issues/update_service_spec.rb
View file @
dfeb412d
...
@@ -543,6 +543,76 @@ describe Issues::UpdateService, :mailer do
...
@@ -543,6 +543,76 @@ describe Issues::UpdateService, :mailer do
end
end
end
end
context
'when updating a single task'
do
before
do
update_issue
(
description:
"- [ ] Task 1
\n
- [ ] Task 2"
)
end
it
{
expect
(
issue
.
tasks?
).
to
eq
(
true
)
}
context
'when a task is marked as completed'
do
before
do
update_issue
(
update_task:
{
index:
1
,
checked:
true
,
line_source:
'- [ ] Task 1'
,
line_number:
1
})
end
it
'creates system note about task status change'
do
note1
=
find_note
(
'marked the task **Task 1** as completed'
)
expect
(
note1
).
not_to
be_nil
description_notes
=
find_notes
(
'description'
)
expect
(
description_notes
.
length
).
to
eq
(
1
)
end
end
context
'when a task is marked as incomplete'
do
before
do
update_issue
(
description:
"- [x] Task 1
\n
- [X] Task 2"
)
update_issue
(
update_task:
{
index:
2
,
checked:
false
,
line_source:
'- [X] Task 2'
,
line_number:
2
})
end
it
'creates system note about task status change'
do
note1
=
find_note
(
'marked the task **Task 2** as incomplete'
)
expect
(
note1
).
not_to
be_nil
description_notes
=
find_notes
(
'description'
)
expect
(
description_notes
.
length
).
to
eq
(
1
)
end
end
context
'when the task position has been modified'
do
before
do
update_issue
(
description:
"- [ ] Task 1
\n
- [ ] Task 3
\n
- [ ] Task 2"
)
end
it
'raises an exception'
do
expect
(
Note
.
count
).
to
eq
(
2
)
expect
do
update_issue
(
update_task:
{
index:
2
,
checked:
true
,
line_source:
'- [ ] Task 2'
,
line_number:
2
})
end
.
to
raise_error
(
ActiveRecord
::
StaleObjectError
)
expect
(
Note
.
count
).
to
eq
(
2
)
end
end
context
'when the content changes but not task line number'
do
before
do
update_issue
(
description:
"Paragraph
\n\n
- [ ] Task 1
\n
- [x] Task 2"
)
update_issue
(
description:
"Paragraph with more words
\n\n
- [ ] Task 1
\n
- [x] Task 2"
)
update_issue
(
update_task:
{
index:
2
,
checked:
false
,
line_source:
'- [x] Task 2'
,
line_number:
4
})
end
it
'creates system note about task status change'
do
note1
=
find_note
(
'marked the task **Task 2** as incomplete'
)
expect
(
note1
).
not_to
be_nil
description_notes
=
find_notes
(
'description'
)
expect
(
description_notes
.
length
).
to
eq
(
2
)
end
end
end
context
'updating labels'
do
context
'updating labels'
do
let
(
:label3
)
{
create
(
:label
,
project:
project
)
}
let
(
:label3
)
{
create
(
:label
,
project:
project
)
}
let
(
:result
)
{
described_class
.
new
(
project
,
user
,
params
).
execute
(
issue
).
reload
}
let
(
:result
)
{
described_class
.
new
(
project
,
user
,
params
).
execute
(
issue
).
reload
}
...
...
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