Skip to content

authorized? fails in ticket show when submitting a blank comment! #8

@eriol12

Description

@eriol12

"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!
2-0
1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions