Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
eriol12 opened this issue Nov 28, 2014 · 1 comment
Open

Comments

@eriol12
Copy link

eriol12 commented Nov 28, 2014

"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

@radar
Copy link
Contributor

radar commented Dec 3, 2014

Thanks very much for the bug report @eriol12. We will look into this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants