gitlab-org--gitlab-foss/app/controllers
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
..
admin Merge branch 'master' into rails-4.1.9 2015-02-19 20:53:05 -07:00
explore Respect star ordering on explore page 2015-02-18 16:40:22 -08:00
groups Add tests for remove group member feature in admin area 2014-10-20 13:18:07 +03:00
import Fix import check for case sensetive namespaces 2015-03-02 23:06:59 -08:00
oauth Application admin scaffold 2015-01-17 15:40:09 -08:00
profiles Allow users that signed up via OAuth to set their password in order to use Git over HTTP(S). 2015-02-13 14:44:42 +01:00
projects Merge branch 'fix-edit-note-with-votes' into 'master' 2015-03-03 21:57:00 +00:00
application_controller.rb Include route helper shortcut in controller 2015-02-26 09:34:20 -08:00
confirmations_controller.rb Try signing in the user after user confirmation is correct and redirect to dashboard, otherwise redirect to signin page 2014-10-02 14:38:26 +02:00
dashboard_controller.rb Reduce amount of sql queries on dashboard projects page 2015-03-02 14:02:09 -08:00
groups_controller.rb Fix event loading with associations 2015-02-18 09:38:46 -08:00
help_controller.rb
namespaces_controller.rb Rubocop: no trailing newlines 2015-02-02 21:53:27 -08:00
omniauth_callbacks_controller.rb When add new social account - redirect to accounts page and show notice message 2015-02-08 00:53:31 -08:00
passwords_controller.rb Use ruby 1.9 hash syntax 2015-01-23 17:41:10 -08:00
profiles_controller.rb Use shorter map() syntax 2015-02-15 20:50:53 -07:00
projects_controller.rb Render go-import meta tag for private repos. 2015-03-03 11:22:30 +01:00
registrations_controller.rb Redirect signup page to signin page. 2015-02-05 15:56:28 +01:00
search_controller.rb Merge pull request #7695 from coverer/search_wiki 2014-09-09 16:50:43 +03:00
sessions_controller.rb Improve application settings and write tests 2015-01-08 09:53:35 -08:00
snippets_controller.rb Link head panel titles to relevant root page. 2015-02-13 14:31:51 +01:00
uploads_controller.rb Add brakeman rake task and improve code security 2015-03-02 18:11:50 -08:00
users_controller.rb Exclude forks from profile contributions list. 2015-02-24 16:28:23 +01:00