Skip to content

Commit

Permalink
[#5289] Fix error when a journal with a question is destroyed by clea…
Browse files Browse the repository at this point in the history
…ring the notes
  • Loading branch information
edavis10 committed Feb 8, 2011
1 parent 74ad50d commit 2db8898
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/question_journal_hooks.rb
Expand Up @@ -22,8 +22,10 @@ def controller_journals_edit_post(context = { })
journal = context[:journal]
params = context[:params]

# Handle destroying journals through the 'edit' action (done by clearing notes)
return '' if journal.destroyed?

if params[:question] && params[:question][:assigned_to]

if journal.question && params[:question][:assigned_to].blank?
# Wants to remove the question
journal.question.destroy
Expand Down
Expand Up @@ -132,6 +132,24 @@ def setup
end

end

context 'with a removed journal by clearing the notes' do
setup do
@question = Question.generate!(:issue => @issue, :journal => @journal, :assigned_to => @user2, :opened => true)

assert_difference('Journal.count',-1) do
assert_difference('Question.count', -1) do
post "/journals/edit/#{@journal.id}", :format => 'js', :notes => '', :question => { :assigned_to => ''}
assert_response :success
end
end
end

should 'should destroy the question' do
assert_equal nil, Question.find_by_id(@question.id)
end
end

end

end

0 comments on commit 2db8898

Please sign in to comment.