require File.expand_path(File.dirname(__FILE__) + '/abstract_unit') class TestController < ActionController::Base end class ModelMailerTest < Test::Unit::TestCase def test_headers email = ModelMailer.create_changes([people(:jonathan)], controller, User.current) assert_equal "1 change by Jonathan", email.subject email = ModelMailer.create_changes([people(:jonathan), people(:david)], controller, User.current) assert_equal "2 changes by Jonathan", email.subject assert_equal [ModelMailer.sender_address], email.from end def test_body_for_new_record person = Person.create!(:name => 'Plonker', :gender => genders(:male)) email = ModelMailer.create_changes([person], controller, User.current) assert_match person.to_summary, email.body assert_no_match /(From|To)/, email.body ['Name', 'Plonker', 'Gender', 'Male'].each do |text| assert_match />#{text}:?<\/td>/, email.body end end def test_body_for_updated_record people(:jonathan).update_attributes!(:name => 'Mr Plonker') email = ModelMailer.create_changes([people(:jonathan), people(:jonathan)], controller, User.current) assert_match people(:jonathan).to_summary, email.body assert_match /From/, email.body assert_match /To/, email.body ['Name', 'Jonathan', 'Mr Plonker'].each do |text| assert_match />#{text}:?<\/td>/, email.body end end def test_update_nil_belongs_to_relationship people(:david).update_attributes!(:user => users(:dblue)) email = ModelMailer.create_changes([people(:david)], controller, User.current) assert_match people(:david).to_summary, email.body # Just dblue because it was blank initially ['User', 'dblue'].each do |text| assert_match />#{text}:?<\/td>/, email.body end end def test_body_includes_controller_and_action_name email = ModelMailer.create_changes([], controller, User.current) assert_match "test/my_action", email.body end private def controller returning TestController.new do |controller| controller.action_name = 'my_action' end end end