mailhopper 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,33 +12,80 @@ class EmailTest < ActiveSupport::TestCase
12
12
  assert @email.valid?
13
13
  end
14
14
 
15
- should "be generated when mail is sent" do
15
+ should "be generated when mail is sent to individual addresses" do
16
16
  headers = {
17
- :from => 'from@example.com',
18
- :to => 'to@example.com',
19
- :cc => 'cc@example.com',
20
- :bcc => 'bcc@example.com',
17
+ :from => 'from@example.com',
18
+ :to => 'to@example.com',
19
+ :cc => 'cc@example.com',
20
+ :bcc => 'bcc@example.com',
21
21
  :reply_to => 'reply_to@example.com',
22
- :subject => 'Hiya!'
22
+ :subject => 'Hiya!'
23
23
  }
24
24
  content = 'Papaya'
25
25
 
26
- assert_equal Mailhopper::Email.count, 0
27
- SampleMailer.hello(headers, content).deliver
28
- assert_equal Mailhopper::Email.count, 1
26
+ generate_and_verify_email(headers, content)
27
+ end
28
+
29
+ should "be generated when mail is sent to multiple addresses" do
30
+ headers = {
31
+ :from => 'from1@example.com',
32
+ :to => ['to1@example.com', 'to2@example.com'],
33
+ :cc => ['cc1@example.com', 'cc2@example.com'],
34
+ :bcc => ['bcc1@example.com', 'bcc2@example.com'],
35
+ :reply_to => 'reply_to@example.com',
36
+ :subject => 'Hiya!'
37
+ }
38
+ content = 'Papaya'
39
+
40
+ generate_and_verify_email(headers, content)
41
+ end
42
+
43
+ should "be generated when mail is sent to blank addresses" do
44
+ headers = {
45
+ :from => 'from@example.com',
46
+ :to => 'to@example.com',
47
+ :cc => nil,
48
+ :bcc => nil,
49
+ :reply_to => nil,
50
+ :subject => 'Hiya!'
51
+ }
52
+ content = 'Papaya'
53
+
54
+ generate_and_verify_email(headers, content)
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def generate_and_verify_email(headers, content)
61
+ assert_equal Mailhopper::Email.count, 0
62
+ SampleMailer.hello(headers, content).deliver
63
+ assert_equal Mailhopper::Email.count, 1
29
64
 
30
- email = Mailhopper::Email.first
31
- assert_equal email.from_address, headers[:from]
32
- assert_equal email.to_address, headers[:to]
33
- assert_equal email.cc_address, headers[:cc]
34
- assert_equal email.bcc_address, headers[:bcc]
35
- assert_equal email.reply_to_address, headers[:reply_to]
36
- assert_equal email.subject, headers[:subject]
65
+ email = Mailhopper::Email.first
37
66
 
38
- # Email content will include headers as well as content
39
- assert email.content.include?(content)
67
+ assert_email_matches_headers(headers, email)
68
+
69
+ # Email content will include headers as well as content
70
+ assert email.content.include?(content)
71
+
72
+ assert email.sent_at.nil?
73
+ end
74
+
75
+ def assert_email_matches_headers(headers, email)
76
+ assert_address_matches_header headers[:from], email.from_address
77
+ assert_address_matches_header headers[:to], email.to_address
78
+ assert_address_matches_header headers[:cc], email.cc_address
79
+ assert_address_matches_header headers[:bcc], email.bcc_address
80
+ assert_equal headers[:reply_to], email.reply_to_address
81
+ assert_equal headers[:subject], email.subject
82
+ end
40
83
 
41
- assert email.sent_at.nil?
84
+ def assert_address_matches_header(header, address)
85
+ if header.kind_of? Array
86
+ assert_equal header.join(','), address
87
+ else
88
+ assert_equal header, address
42
89
  end
43
90
  end
44
91
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailhopper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dan Gebhardt
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-02 00:00:00 -04:00
18
+ date: 2011-09-16 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -113,7 +113,7 @@ files:
113
113
  - test/dummy/config/routes.rb
114
114
  - test/dummy/config.ru
115
115
  - test/dummy/db/development.sqlite3
116
- - test/dummy/db/migrate/20110801151741_create_emails.rb
116
+ - test/dummy/db/migrate/20110916191655_create_emails.rb
117
117
  - test/dummy/db/schema.rb
118
118
  - test/dummy/db/test.sqlite3
119
119
  - test/dummy/log/development.log
@@ -188,7 +188,7 @@ test_files:
188
188
  - test/dummy/config/routes.rb
189
189
  - test/dummy/config.ru
190
190
  - test/dummy/db/development.sqlite3
191
- - test/dummy/db/migrate/20110801151741_create_emails.rb
191
+ - test/dummy/db/migrate/20110916191655_create_emails.rb
192
192
  - test/dummy/db/schema.rb
193
193
  - test/dummy/db/test.sqlite3
194
194
  - test/dummy/log/development.log