Module: Clearance::Test::Unit::ClearanceMailerTest

Defined in:
lib/clearance/test/unit/clearance_mailer_test.rb

Class Method Summary collapse

Class Method Details

.included(mailer_test) ⇒ Object



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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/clearance/test/unit/clearance_mailer_test.rb', line 6

def self.included(mailer_test)
  mailer_test.class_eval do
    
    context "A change password email" do
      setup do
        @user  = Factory(:registered_user)
        @email = ClearanceMailer.create_change_password @user
      end

      should "set its from address to DO_NOT_REPLY" do
        assert_equal DO_NOT_REPLY, @email.from[0]
      end

      should "contain a link to edit the user's password" do
        host = ActionMailer::Base.default_url_options[:host]
        regexp = %r{http://#{host}/users/#{@user.id}/password/edit\?token=#{@user.token}}
        assert_match regexp, @email.body
      end

      should "be sent to the user" do
        assert_equal [@user.email], @email.to
      end

      should "set its subject" do
        assert_match /Change your password/, @email.subject
      end
    end
    
    context "A confirmation email" do
      setup do
        @user  = Factory(:registered_user)
        @email = ClearanceMailer.create_confirmation @user
      end

      should "set its recipient to the given user" do
        assert_equal @user.email, @email.to[0]
      end

      should "set its subject" do
        assert_match /Account confirmation/, @email.subject
      end

      should "set its from address to DO_NOT_REPLY" do
        assert_equal DO_NOT_REPLY, @email.from[0]
      end

      should "contain a link to confirm the user's account" do
        host = ActionMailer::Base.default_url_options[:host]
        regexp = %r{http://#{host}/users/#{@user.id}/confirmation/new\?token=#{@user.token}}
        assert_match regexp, @email.body
      end
    end
  
  end
end