"authorized?" method fails (for users who have permissions to change states and/or edit tickets and/or delete tickets) in the ticket show template when submitting a blank comment since no project object is being specified when reloading the template. This will prevent Edit, Delete links and the select (State) from showing. It is very simple to fix:
class CommentsController < ApplicationController
before_action :require_signin!
before_action :set_ticket
def create
sanitize_parameters!
@comment = CommentWithNotifications.create(@ticket.comments,
current_user,
comment_params)
if @comment.save
flash[:notice] = "Comment has been created."
redirect_to [@ticket.project, @ticket]
else
@states = State.all
```@project = @ticket.project```
@comment = @comment.comment
flash[:alert] = "Comment has not been created."
render template: "tickets/show"
end
end
end
Also update the spec Creating an invalid comment as well. This will further test to make sure that the State select box is there when saving comment fails:
File: creating_comments_spec.rb
scenario "Creating an invalid comment" do
click_link ticket.title
click_button "Create Comment"
expect(page).to have_content("Comment has not been created.")
expect(page).to have_content("Text can't be blank")
within("#new_comment") do
expect(page).to have_content("State Open")
expect(page).to have_selector("#comment_state_id")
end
end
First images shows the issue and the second one show the behaviour after adding @project = @ticket.project!
"authorized?" method fails (for users who have permissions to change states and/or edit tickets and/or delete tickets) in the ticket show template when submitting a blank comment since no project object is being specified when reloading the template. This will prevent Edit, Delete links and the select (State) from showing. It is very simple to fix:
Also update the spec
Creating an invalid comment
as well. This will further test to make sure that the State select box is there when saving comment fails: File: creating_comments_spec.rbFirst images shows the issue and the second one show the behaviour after adding
@project = @ticket.project
!