Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Update comment from /mentors/applications/:id page #973

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/mentors/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def create
end

def update
comment = mentor_comments.update(params[:id], update_params)
comment = mentor_comments.update(params[:mentor_comment][:commentable_id], update_params)
redirect_to path_for(comment)
end

Expand All @@ -20,7 +20,7 @@ def create_params
end

def update_params
params.require(:mentor_comment).permit(:text)
params.require(:mentor_comment).permit(:id, :text)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this potentially allows to edit other user's comments (it shouldn't in this case, since we fetch the comments scoped by commenter in mentor_comments) I would like to have a test that catches a regression: can you add a test example where the a user attempts to update some other user's mentor comment please?

end

def path_for(comment)
Expand Down
3 changes: 2 additions & 1 deletion app/views/mentors/applications/_comment.html.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
hr(id="#{dom_id comment}")
= simple_form_for comment, url: mentors_comments_path do |f|
= simple_form_for comment, :url => comment.new_record? ? url_for(action: 'create', controller: 'mentors/comments') :url_for(action: 'update', controller: 'mentors/comments') do |f|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the following work?

= simple_form_for [:mentors, comment] do |f|

.form-inputs.clearfix
= f.input :commentable_id, as: :hidden, value: comment.commentable_id
= f.input :id, as: :hidden, value: comment.id
= f.input :text, as: :text, label: 'My Comment', input_html: { rows: 5 }, hint: 'This is a place for you to take notes for yourself about this application. Your comment is only visible to yourself as well as the selection committee and you can update and remove it as you like.'
.form-actions
= f.button :submit
2 changes: 1 addition & 1 deletion spec/controllers/mentors/comments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

context 'when comment exists' do
let!(:comment) { Mentor::Comment.create(user: user, commentable_id: 1, text: 'something') }
let(:params) {{ id: comment.id, mentor_comment: { text: 'something else' } }}
let(:params) {{ id: comment.id, mentor_comment: { text: 'something else', commentable_id: comment.id } }}

subject { put :update, params: params }

Expand Down