On 12/13/07, Daniel Tenner <[EMAIL PROTECTED]> wrote: > Hi Rick, > > Could you paste us what your after_save and your deliver_xyz methods > look like? I think it would be helpful to make the discussion more > concrete. > > I've found that whenever my code is hard to spec, it's usually poorly > designed in the first place, and a better split of responsibilities > helps make the code both clearer and easily spec'ed. > > In this specific case, I'm a bit perplexed that you're sending a pre- > generated body/subject/sender/etc to the Mailer. Shouldn't that code > be in the Mailer's deliver_xyz method?
In this case the bulk of the message is coming from, surprise, the message object. This is a secret santa site, the idea is to allow folks to communicate without giving away who is who. class Message < ActiveRecord::Base belongs_to :sender, :class_name => "Person", :foreign_key => :sender_id belongs_to :recipient, :class_name => "Person", :foreign_key => :recipient_id after_create do |msg| puts "\n**** after_create #{msg}\n#{caller.join("\n")}\n" SantasMailbox.deliver_secret_santa(msg) end ... end class SantasMailbox < ActionMailer::Base ... def secret_santa(message) subject message.subject body( {:sender => message.sender_name, :recipient => message.recipient_first_name, :text => body}) recipients "#{recipient.full_name} <#{recipient.email}>" from "#{message.sender_full_name} <[EMAIL PROTECTED]" sent_on message.created_at content_type 'text/html' headers {} end ... end Where methods like sender_name etc. on the Message object produce appropriate clear or obfuscated (e.g. 'Your Secret Santa' depending on the message state. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users