pending_task_notifier_test.rb
1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require File.dirname(__FILE__) + '/../test_helper'
class PendingTaskNotifierTest < ActiveSupport::TestCase
  FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
  CHARSET = "utf-8"
  def setup
    ActionMailer::Base.delivery_method = :test
    ActionMailer::Base.perform_deliveries = true
    ActionMailer::Base.deliveries = []
  end
  should 'be able to deliver notification' do
    env = Environment.default
    p = create_user('maelcum').person
    response = PendingTaskNotifier.notification(p).deliver
    assert_equal "[#{env.name}] Pending tasks", response.subject
    assert_equal p.email, response.to[0]
  end
  should 'list organization pending tasks' do
    p = create_user('maelcum').person
    c = fast_create(Community)
    c.add_admin(p)
    c.tasks << Task.new(:requestor => p)
    response = PendingTaskNotifier.notification(p).deliver
    assert_match /sent you a task/, response.body.to_s
  end
  private
    def read_fixture(action)
      IO.readlines("#{FIXTURES_PATH}/mail_sender/#{action}")
    end
    def encode(subject)
      quoted_printable(subject, CHARSET)
    end
end