Permalink
Browse files

Fixes issue #7 and fixes issue #9

  • Loading branch information...
1 parent 5d18c68 commit ba30446784c59309117009458d81ee14bc23bb43 @drapergeek drapergeek committed Nov 16, 2011
Showing with 45 additions and 10 deletions.
  1. +9 −2 app/mailers/ticket_mailer.rb
  2. +7 −2 app/models/comment.rb
  3. +29 −6 test/unit/comment_test.rb
@@ -11,9 +11,16 @@ def send_ticket_to_submitter(ticket)
mail(:to => "#{ticket.submitter.email}", :subject => "#{APP_CONFIG['ticket_subject']}#{ticket.id} Successfully Submitted")
end
- def send_reply_comment(comment)
+ def send_reply_comment(comment, params={})
@comment = comment
@ticket = @comment.ticket
- mail(:to => "#{@ticket.submitter.email}", :subject => "#{APP_CONFIG['ticket_subject']}#{@ticket.id} Reply from Ticket")
+ to = ""
+ if params[:send_to_submitter]
+ to += @ticket.submitter.email.to_s
+ end
+ if params[:send_to_worker]
+ to += @ticket.worker.email.to_s
+ end
+ mail(:to => to, :subject => "#{APP_CONFIG['ticket_subject']}#{@ticket.id} Reply from Ticket")
end
end
View
@@ -9,11 +9,16 @@ class Comment < ActiveRecord::Base
def send_emails
if self.reply
- TicketMailer.send_reply_comment(self).deliver
+ if self.user == self.ticket.worker
+ TicketMailer.send_reply_comment(self, :send_to_submitter=>true).deliver
+ elsif self.user == self.ticket.submitter
+ TicketMailer.send_reply_comment(self, :send_to_worker=>true).deliver
+ else
+ TicketMailer.send_reply_comment(self, :send_to_worker=>true, :send_to_submitter=>true).deliver
+ end
end
end
-
def self.create_from_email(ticket_id, from, subject, body)
#get the user first
user = User.find_or_create_by_email(from)
View
@@ -94,12 +94,35 @@ def test_should_be_valid
assert comment.body.include?("Status changed to Open on a new comment email")
end
- test "an email is dispatched to ticket owner when a reply is submitted" do
- owner = Factory.create(:user)
- ticket = Factory.create(:ticket, :owner=>owner)
- assert_difference "Ticket.comments.count" do
- ticket.create_comment(:user_id, owner)
- end
+ test "an email is dispatched to only the ticket owner when a reply is submitted" do
+ reset_email
+ worker = Factory.create(:user)
+ ticket = Factory.create(:ticket, :worker=>worker)
+ ticket.comments.create!(:user=>worker, :body=>"I have looked at this", :reply=>true)
+ assert last_email.to.include?(ticket.submitter.email)
+ assert !last_email.to.include?(ticket.worker.email)
+ assert last_email.subject.include?("Reply from Ticket")
+ end
+
+ test "email to worker and submitter new outside comments" do
+ reset_email
+ worker = Factory.create(:user)
+ commenter = Factory.create(:user)
+ ticket = Factory.create(:ticket, :worker=>worker)
+ ticket.comments.create!(:user=>commenter, :body=>"I have looked at this", :reply=>true)
+ assert last_email.to.include?(ticket.submitter.email)
+ assert last_email.to.include?(ticket.worker.email)
+ assert last_email.subject.include?("Reply from Ticket")
+ end
+
+ test "email to just worker when reply from submitter" do
+ reset_email
+ worker = Factory.create(:user)
+ ticket = Factory.create(:ticket, :worker=>worker)
+ ticket.comments.create!(:user=>ticket.submitter, :body=>"I have looked at this", :reply=>true)
+ assert !last_email.to.include?(ticket.submitter.email)
+ assert last_email.to.include?(ticket.worker.email)
+ assert last_email.subject.include?("Reply from Ticket")
end
end

0 comments on commit ba30446

Please sign in to comment.