gitlab-org--gitlab-foss/features/project
Marin Jankovski 66fa4b09ed Merge branch 'fix-edit-note-with-votes' into 'master'
Fix server error when editing a note to "+1" or "-1"

### Summary

If a user edits a comment with "+1" or "-1" in the beginning, the POST returns an Internal Server error. (issue #1151). This merge request resolves that error.

### Steps to reproduce

1. Comment on an issue with "Test comment".
2. Edit the issue.
3. Write "+1" and click "Save Comment".

### Expected behavior

The edited note should be saved and refreshed. Any previous upvotes/downvotes from the user should contain a strikethrough.

### Observed behavior

Internal Error

### Relevant logs

```
Started PUT "/avocode/avocode-manager/notes/4996" for 185.33.136.107 at 2015-02-28 17:11:53 +0100
Processing by Projects::NotesController#update as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"*removed*", "note"=>{"note"=>"+1\r\n\r\nYes"}, "commit"=>"Save Comment", "project_id"=>"avocode/avocode-manager", "id"=>"4996"}
Completed 500 Internal Server Error in 86ms
ActionView::Template::Error (undefined method `each' for nil:NilClass):
28: %span.note-last-update
29: = note_timestamp(note)
30:
31: - if note.superceded?(@notes)
32: - if note.upvote?
33: %span.vote.upvote.label.label-gray.strikethrough
34: %i.fa.fa-thumbs-up
app/models/note.rb:495:in `superceded?'
app/views/projects/notes/_note.html.haml:31:in `_app_views_projects_notes__note_html_haml___812277000516355462_69988235638820'
app/controllers/projects/notes_controller.rb:71:in `note_to_html'
app/controllers/projects/notes_controller.rb:103:in `render_note_json'
app/controllers/projects/notes_controller.rb:39:in `block (2 levels) in update'
app/controllers/projects/notes_controller.rb:38:in `update'
```

### Fix

It turns out no tests were present for the "Edit Issue" functionality. I added spinach tests to exercise this and reproduced the error.

Most of the routes in `notes_controller.rb` appear to render all notes for the given discussion. `_form.html.haml` needs the full list of notes commented by the user to add strikethroughs for older upvotes/downvotes. However, only the `index` route appeared to obtain this information. The fix is to add a `before_filter` to obtain all the user's notes beforehand, except in the delete case where this information is not needed.

Things to watch: `NotesFinder` needs `target_type` and `target_id` to determine what to do. I'm not sure if there is a conscious effort to phase these keywords out in favor of `noteable_type` and `noteable_id`.

See merge request !360
2015-03-03 21:57:00 +00:00
..
commits Fix bug where editing a comment with "+1" or "-1" would cause a server error 2015-03-02 15:26:00 -08:00
issues Fix bug where editing a comment with "+1" or "-1" would cause a server error 2015-03-02 15:26:00 -08:00
source WebEditor: save to new branch: spinach 2015-02-24 11:43:20 +02:00
active_tab.feature Fix active tab tests 2015-02-19 17:24:34 -08:00
archived.feature Remove dir prefix and suffix from tests inside dir. 2014-02-23 10:34:39 +01:00
create.feature Make Spinach test names consistent 2014-10-05 18:21:11 +02:00
deploy_keys.feature
fork.feature Improve fork to namespaces feature 2014-11-14 16:06:39 +02:00
forked_merge_requests.feature Revert "gitlab shell works if multiple rubies installed" 2014-11-18 17:14:36 +02:00
graph.feature Add tests for commits graph 2014-09-29 12:11:53 +03:00
hooks.feature Prevent 500 if hook url is down, fixes #7376 2014-07-29 11:49:46 +02:00
merge_requests.feature Fix more Markdown preview tests 2014-10-18 18:43:45 -05:00
network_graph.feature Make Spinach test names consistent 2014-10-05 18:21:11 +02:00
project.feature adding avatar to project settings page added avatar removal show project avatar on dashboard, projects page, project page added rspec and feature tests added project avatar from repository new default project icon added added copying af avatar to forking of project added generated icon fixed avatar fork hound fix style fix test fix 2015-01-24 18:51:16 +01:00
redirects.feature Add in the tests. 2014-07-11 19:53:10 +02:00
service.feature Add Irker service 2015-03-01 20:51:03 +01:00
shortcuts.feature Make Spinach test names consistent 2014-10-05 18:21:11 +02:00
snippets.feature Refactor snippets views 2014-06-14 12:36:46 +03:00
star.feature Fix star tests 2014-07-24 23:25:38 +03:00
team_management.feature Make Spinach test names consistent 2014-10-05 18:21:11 +02:00
wiki.feature Unstub after the test is done. 2014-05-07 11:52:07 +02:00