require File.dirname(__FILE__) + '/../test_helper' require 'subscriber_controller' # Re-raise errors caught by the controller. class SubscriberController; def rescue_action(e) raise e end; end class SubscriberControllerTest < Test::Unit::TestCase fixtures :people, :users, :elts, :mails, :attachments, :subscribers def setup @controller = SubscriberController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.deliveries = [] @expected = TMail::Mail.new @expected.set_content_type "text", "plain", { "charset" => CHARSET } end def test_subscribe login elt = Elt.find('0') numSubscribers = elt.subscribers.size post :subscribe, :id => '0' elt = Elt.find('0') assert_equal (numSubscribers + 1), elt.subscribers.size end def test_unsubscribe login post :subscribe, :id => '0' elt = Elt.find('0') numSubscribers = elt.subscribers.size post :subscribe, :id => '0' elt = Elt.find('0') assert_equal (numSubscribers - 1), elt.subscribers.size end def test_post_elt #puts "CCCCCCCC" #puts Elt.find('0').all_recipients.join(', ') controller = @controller @controller = EltController.new numChildren = Elt.find(0).children.size numMails = Mail.find_all.size post :create, :elt => { :parent_id => '0', :subject => 'A new mail', :body => 'testing a new mail' } assert_equal 1, ActionMailer::Base.deliveries.size assert_equal (numChildren + 1), Elt.find(0).children.size assert_equal (numMails + 1), Mail.find_all.size mail = ActionMailer::Base.deliveries[0] elt = Elt.find(0).children[0] assert_equal mail.destinations, elt.all_recipients.collect { |i| i.email }.reject { |i| i == nil } assert_equal '0@'+ActionMailer::Base.server_settings[:domain], mail.to[0] assert_equal ANONYMOUS_POSTER+' <'+ANONYMOUS_POSTER+'@'+ActionMailer::Base.server_settings[:domain]+'>', mail.from_addrs[0].to_s @controller = controller end def test_post_loggedin_elt login controller = @controller @controller = EltController.new post :create, :elt => { :parent_id => '0', :subject => 'A new mail', :body => 'testing a new mail as user my_bob' } mail = ActionMailer::Base.deliveries[1] elt = Elt.find(0).children[0] # Because the logged in user is not email verified! assert_equal 'my_bob <'+ANONYMOUS_POSTER+'@'+ActionMailer::Base.server_settings[:domain]+'>', mail.from_addrs[0].to_s assert_equal elt.parent.mail.message, mail.references.to_s # Check every body replies to the mailing list assert_equal mail.to, mail.reply_to @controller = controller end def test_send_elt fixture = read_fixture('mail_ruby').to_s orig = TMail::Mail.parse(fixture) Mailman.receive(fixture) # Created the elt itself, and a parent mailing list element called # "mailingList assert_equal 2, ActionMailer::Base.deliveries.size mail = ActionMailer::Base.deliveries[0] assert_equal 'mailingList', mail.subject mail = ActionMailer::Base.deliveries[1] assert_equal orig.message_id, mail.message_id assert_equal orig.references, mail.references assert_equal orig.subject, mail.subject assert_equal orig.body, mail.body assert_equal orig.to, mail.to assert_equal orig.cc, mail.cc assert_equal orig.from, mail.from assert_equal orig.sender(nil), mail.sender(nil) assert_equal orig.date, mail.date assert_equal orig.reply_to, mail.reply_to # Check that we are actually sending the mail to other recipients assert_not_equal orig.bcc, mail.bcc assert_equal mail.destinations, mail.bcc elt = Mail.find_by_message(mail.message_id).elt assert_equal mail.destinations, elt.all_recipients.collect { |i| i.email }.reject { |i| i == nil } end end