has_emails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +23 -0
- data/MIT-LICENSE +20 -0
- data/README +130 -0
- data/Rakefile +81 -0
- data/app/mailers/application_mailer.rb +85 -0
- data/app/models/email.rb +84 -0
- data/app/models/email_address.rb +123 -0
- data/app/models/email_recipient.rb +78 -0
- data/app/models/email_recipient_build_extension.rb +7 -0
- data/db/bootstrap/events.yml +4 -0
- data/db/bootstrap/states.yml +9 -0
- data/db/migrate/001_create_email_addresses.rb +23 -0
- data/db/migrate/002_add_email_specs.rb +18 -0
- data/db/migrate/003_add_email_recipient_specs.rb +18 -0
- data/init.rb +1 -0
- data/lib/has_emails.rb +92 -0
- data/test/app_root/app/models/department.rb +2 -0
- data/test/app_root/app/models/user.rb +3 -0
- data/test/app_root/config/environment.rb +33 -0
- data/test/app_root/db/migrate/001_create_users.rb +11 -0
- data/test/app_root/db/migrate/002_create_departments.rb +12 -0
- data/test/fixtures/departments.yml +9 -0
- data/test/fixtures/email_addresses.yml +32 -0
- data/test/fixtures/message_recipients.yml +85 -0
- data/test/fixtures/messages.yml +52 -0
- data/test/fixtures/state_changes.yml +128 -0
- data/test/fixtures/users.yml +11 -0
- data/test/test_helper.rb +76 -0
- data/test/unit/application_mailer_test.rb +69 -0
- data/test/unit/email_address_test.rb +200 -0
- data/test/unit/email_recipient_test.rb +79 -0
- data/test/unit/email_test.rb +89 -0
- data/test/unit/has_emails_test.rb +36 -0
- data/test/unit/recipient_extension_test.rb +99 -0
- metadata +113 -0
@@ -0,0 +1,200 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class EmailAddressTest < Test::Unit::TestCase
|
4
|
+
fixtures :departments, :users, :email_addresses, :messages, :message_recipients, :state_changes
|
5
|
+
|
6
|
+
def test_should_convert_email_address_using_same_model
|
7
|
+
e = email_addresses(:bob)
|
8
|
+
assert_same e, EmailAddress.convert_from(e)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_convert_string
|
12
|
+
e = EmailAddress.convert_from('test@email.com')
|
13
|
+
assert_instance_of EmailAddress, e
|
14
|
+
assert_equal 'test@email.com', e.spec
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_convert_record_with_email_address_column
|
18
|
+
department = departments(:marketing)
|
19
|
+
e = EmailAddress.convert_from(department)
|
20
|
+
assert_instance_of EmailAddress, e
|
21
|
+
assert_equal 'marketing@companyxyz.com', e.spec
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_convert_record_with_email_address_association
|
25
|
+
user = users(:bob)
|
26
|
+
class << user
|
27
|
+
def email_address
|
28
|
+
EmailAddress.new(:spec => 'test@email.com')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
e = EmailAddress.convert_from(user)
|
33
|
+
assert_instance_of EmailAddress, e
|
34
|
+
assert_equal 'test@email.com', e.spec
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_convert_record_with_email_addresses_association_using_first_email_address
|
38
|
+
e = EmailAddress.convert_from(users(:bob))
|
39
|
+
assert_instance_of EmailAddress, e
|
40
|
+
assert_equal 'bob@bob.com', e.spec
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_raise_exception_if_converting_unknown_class_to_email_address
|
44
|
+
assert_raise(ArgumentError) {EmailAddress.convert_from(1)}
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_invalid_spec_should_not_be_valid
|
48
|
+
assert !EmailAddress.valid?('invalid')
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_valid_spec_should_be_valid
|
52
|
+
assert EmailAddress.valid?('valid@valid.com')
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_should_be_valid
|
56
|
+
assert_valid email_addresses(:bob)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_should_require_spec
|
60
|
+
assert_invalid email_addresses(:bob), :spec, nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_should_require_unique_spec
|
64
|
+
assert_invalid email_addresses(:bob).clone, :spec
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_should_require_minimum_length_for_spec
|
68
|
+
assert_invalid email_addresses(:bob), :spec, 'ab'
|
69
|
+
assert_valid email_addresses(:bob), :spec, 'a@a'
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_should_require_maximum_length_for_spec
|
73
|
+
assert_invalid email_addresses(:bob), :spec, 'a' * 300 + '@' + 'a' * 20
|
74
|
+
assert_valid email_addresses(:bob), :spec, 'a' * 300 + '@' + 'a' * 19
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_should_require_specific_format_for_spec
|
78
|
+
assert_invalid email_addresses(:bob), :spec, 'aaaaaaaaaa'
|
79
|
+
assert_valid email_addresses(:bob), :spec, 'aaa@aaa.com'
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_should_have_polymorphic_emailable_association
|
83
|
+
assert_equal users(:bob), email_addresses(:bob).emailable
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_should_have_unsent_emails_association
|
87
|
+
assert_equal [messages(:unsent_from_bob)], email_addresses(:bob).unsent_emails
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_should_have_sent_emails_association
|
91
|
+
assert_equal [messages(:sent_from_bob), messages(:queued_from_bob)], email_addresses(:bob).sent_emails
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_should_have_received_emails_association
|
95
|
+
assert_equal [messages(:sent_from_bob), messages(:sent_from_mary)], email_addresses(:john).received_emails.map(&:email)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_initial_state_should_be_unverified
|
99
|
+
assert_equal :unverified, EmailAddress.new.state.to_sym
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_should_verify_if_unverified
|
103
|
+
e = email_addresses(:bob)
|
104
|
+
assert e.unverified?
|
105
|
+
assert e.verify!
|
106
|
+
assert e.verified?
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_should_not_verify_if_verified
|
110
|
+
e = email_addresses(:john)
|
111
|
+
assert e.verified?
|
112
|
+
assert !e.verify!
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_should_create_verification_code_on_create
|
116
|
+
e = EmailAddress.new(:spec => 'test@me.com', :emailable => users(:bob))
|
117
|
+
assert_nil e.verification_code
|
118
|
+
assert e.save!
|
119
|
+
assert_not_nil e.verification_code
|
120
|
+
assert_equal 32, e.verification_code.length
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_should_not_modify_verification_code_on_update
|
124
|
+
e = email_addresses(:bob)
|
125
|
+
original_verification_code = e.verification_code
|
126
|
+
e.spec = 'test@me.com'
|
127
|
+
assert e.save!
|
128
|
+
assert_equal original_verification_code, e.verification_code
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_should_create_code_expiry_on_create
|
132
|
+
e = EmailAddress.new(:spec => 'test@me.com', :emailable => users(:bob))
|
133
|
+
assert_nil e.code_expiry
|
134
|
+
assert e.save!
|
135
|
+
assert_not_nil e.code_expiry
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_should_not_modify_code_expiry_on_update
|
139
|
+
e = email_addresses(:bob)
|
140
|
+
original_code_expiry = e.code_expiry
|
141
|
+
e.spec = 'test@me.com'
|
142
|
+
assert e.save!
|
143
|
+
assert_equal original_code_expiry, e.code_expiry
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_should_not_automatically_parse_local_name_after_find
|
147
|
+
assert_nil email_addresses(:bob).send(:instance_variable_get, '@local_name')
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_should_not_automatically_parse_domain_after_find
|
151
|
+
assert_nil email_addresses(:bob).send(:instance_variable_get, '@domain')
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_should_parse_local_name_when_accessed
|
155
|
+
assert_equal 'bob', email_addresses(:bob).local_name
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_should_parse_domain_when_accessed
|
159
|
+
assert_equal 'bob.com', email_addresses(:bob).domain
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_should_reset_local_name_and_domain_when_new_spec_is_set
|
163
|
+
e = email_addresses(:bob)
|
164
|
+
assert_equal 'bob', e.local_name
|
165
|
+
assert_equal 'bob.com', e.domain
|
166
|
+
|
167
|
+
e.spec = 'test@me.com'
|
168
|
+
assert_equal 'test', e.local_name
|
169
|
+
assert_equal 'me.com', e.domain
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_name_should_be_blank_by_default
|
173
|
+
assert_equal '', EmailAddress.new.name
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_should_set_name_from_attributes
|
177
|
+
assert_equal 'bob', EmailAddress.new(:name => 'bob').name
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_should_return_spec_for_with_name_when_name_is_blank
|
181
|
+
e = email_addresses(:bob)
|
182
|
+
assert_equal e.spec, e.with_name
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_should_return_name_and_spec_for_with_name_when_name_is_not_blank
|
186
|
+
e = email_addresses(:bob)
|
187
|
+
e.instance_eval do
|
188
|
+
def name
|
189
|
+
'Bob'
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
assert_equal 'Bob <bob@bob.com>', e.with_name
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_should_use_spec_for_stringification
|
197
|
+
e = email_addresses(:bob)
|
198
|
+
assert_equal e.spec, e.to_s
|
199
|
+
end
|
200
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class EmailRecipientTest < Test::Unit::TestCase
|
4
|
+
fixtures :users, :email_addresses, :messages, :message_recipients, :state_changes
|
5
|
+
|
6
|
+
def test_recipient_with_email_address_should_be_valid
|
7
|
+
assert_valid message_recipients(:bob_to_john)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_recipient_with_receiver_spec_should_be_valid
|
11
|
+
assert_valid message_recipients(:bob_to_random)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_recipient_with_email_address_attribute_should_be_valid
|
15
|
+
assert_valid message_recipients(:bob_to_marketing)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_require_receiver_spec
|
19
|
+
assert_invalid message_recipients(:bob_to_random), :receiver_spec, nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_require_minimum_length_for_receiver_spec
|
23
|
+
assert_invalid message_recipients(:bob_to_random), :receiver_spec, 'ab'
|
24
|
+
assert_valid message_recipients(:bob_to_random), :receiver_spec, 'a@a'
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_require_maximum_length_for_receiver_spec
|
28
|
+
assert_invalid message_recipients(:bob_to_random), :receiver_spec, 'a' * 300 + '@' + 'a' * 20
|
29
|
+
assert_valid message_recipients(:bob_to_random), :receiver_spec, 'a' * 300 + '@' + 'a' * 19
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_require_specific_format_for_receiver_spec
|
33
|
+
assert_invalid message_recipients(:bob_to_random), :receiver_spec, 'aaaaaaaaaa'
|
34
|
+
assert_valid message_recipients(:bob_to_random), :receiver_spec, 'aaa@aaa.com'
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_email_getter_should_be_same_as_message_getter
|
38
|
+
r = message_recipients(:bob_to_john)
|
39
|
+
assert_equal r.email, r.message
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_email_setter_should_be_same_as_message_setter
|
43
|
+
r = message_recipients(:bob_to_john)
|
44
|
+
r.email = messages(:sent_from_mary)
|
45
|
+
assert_equal r.email, r.message
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_email_id_getter_should_be_same_as_message_id_getter
|
49
|
+
r = message_recipients(:bob_to_john)
|
50
|
+
assert_equal r.email_id, r.message_id
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_email_id_setter_should_be_same_as_message_id_setter
|
54
|
+
r = message_recipients(:bob_to_john)
|
55
|
+
r.email_id = messages(:sent_from_mary).id
|
56
|
+
assert_equal r.email_id, r.message_id
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_receiver_should_be_receiver_spec_if_string_recipient
|
60
|
+
assert_equal 'random@random.com', message_recipients(:bob_to_random).receiver
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_receiver_should_be_model_if_not_string_recipient
|
64
|
+
assert_equal email_addresses(:john), message_recipients(:bob_to_john).receiver
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_should_set_receiver_spec_if_receiver_is_string
|
68
|
+
r = EmailRecipient.new
|
69
|
+
r.receiver = 'test@me.com'
|
70
|
+
assert_equal 'test@me.com', r.receiver_spec
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_should_set_receiver_and_receiver_spec_if_receiver_is_not_string
|
74
|
+
r = EmailRecipient.new
|
75
|
+
r.receiver = email_addresses(:john)
|
76
|
+
assert_equal 'john@john.com', r.receiver_spec
|
77
|
+
assert_equal email_addresses(:john), r.receiver
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class EmailTest < Test::Unit::TestCase
|
4
|
+
fixtures :users, :email_addresses, :messages, :message_recipients, :state_changes
|
5
|
+
|
6
|
+
def test_should_be_valid
|
7
|
+
assert_valid messages(:sent_from_bob)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_require_sender_spec
|
11
|
+
assert_invalid messages(:sent_from_bob), :sender_spec, nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_should_require_minimum_length_for_sender_spec
|
15
|
+
assert_invalid messages(:sent_from_bob), :sender_spec, 'ab'
|
16
|
+
assert_valid messages(:sent_from_bob), :sender_spec, 'a@a'
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_require_maximum_length_for_sender_spec
|
20
|
+
assert_invalid messages(:sent_from_bob), :sender_spec, 'a' * 300 + '@' + 'a' * 20
|
21
|
+
assert_valid messages(:sent_from_bob), :sender_spec, 'a' * 300 + '@' + 'a' * 19
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_require_specific_format_for_sender_spec
|
25
|
+
assert_invalid messages(:sent_from_bob), :sender_spec, 'aaaaaaaaaa'
|
26
|
+
assert_valid messages(:sent_from_bob), :sender_spec, 'aaa@aaa.com'
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_to_should_create_email_recipient
|
30
|
+
assert_instance_of EmailRecipient, messages(:sent_from_bob).to.build
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_cc_should_create_email_recipient
|
34
|
+
assert_instance_of EmailRecipient, messages(:sent_from_bob).cc.build
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_bcc_should_create_email_recipient
|
38
|
+
assert_instance_of EmailRecipient, messages(:sent_from_bob).bcc.build
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_sender_should_be_spec_if_arbitrary_email_address_used
|
42
|
+
assert_equal 'stranger@somewhere.com', messages(:unsent_from_stranger).sender
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_sender_should_be_model_if_known_email_address_used
|
46
|
+
assert_equal email_addresses(:bob), messages(:sent_from_bob).sender
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_set_sender_spec_if_sender_is_arbitrary_email_address
|
50
|
+
email = messages(:unsent_from_stranger)
|
51
|
+
email.sender = 'stranger@somewhereelse.com'
|
52
|
+
assert_equal 'stranger@somewhereelse.com', email.sender_spec
|
53
|
+
assert_nil email.sender_id
|
54
|
+
assert_nil email.sender_type
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_should_set_sender_and_sender_spec_if_sender_is_known_email_address
|
58
|
+
email = messages(:unsent_from_stranger)
|
59
|
+
email.sender_spec = nil
|
60
|
+
email.sender = email_addresses(:john)
|
61
|
+
assert_equal 2, email.sender_id
|
62
|
+
assert_equal 'EmailAddress', email.sender_type
|
63
|
+
assert_equal 'john@john.com', email.sender_spec
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_sender_email_address_should_convert_sender_spec_if_arbitrary_email_address_used
|
67
|
+
email_address = messages(:unsent_from_stranger).sender_email_address
|
68
|
+
assert_instance_of EmailAddress, email_address
|
69
|
+
assert_equal 'stranger@somewhere.com', email_address.spec
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_sender_email_address_should_use_sender_if_known_email_address_used
|
73
|
+
email_address = messages(:sent_from_bob).sender_email_address
|
74
|
+
assert_instance_of EmailAddress, email_address
|
75
|
+
assert_equal 'bob@bob.com', email_address.spec
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_reply_should_use_sender_spec_for_sender_if_arbitrary_email_address_used
|
79
|
+
message = messages(:unsent_from_stranger)
|
80
|
+
reply = message.reply
|
81
|
+
assert_equal 'stranger@somewhere.com', reply.sender
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_forward_should_use_sender_spec_for_sender_if_arbitrary_email_address_used
|
85
|
+
message = messages(:unsent_from_stranger)
|
86
|
+
forward = message.forward
|
87
|
+
assert_equal 'stranger@somewhere.com', forward.sender
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class HasEmailsTest < Test::Unit::TestCase
|
4
|
+
fixtures :users, :email_addresses, :messages, :message_recipients, :state_changes
|
5
|
+
|
6
|
+
def test_should_generate_received_association
|
7
|
+
assert_equal [messages(:sent_from_bob), messages(:sent_from_mary)], users(:john).received_emails.map(&:email)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_generate_unsent_association
|
11
|
+
assert_equal [messages(:unsent_from_bob)], users(:bob).unsent_emails
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_should_generate_sent_association
|
15
|
+
assert_equal [messages(:sent_from_bob), messages(:queued_from_bob)], users(:bob).sent_emails
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_generate_inbox
|
19
|
+
assert_instance_of MessageBox, users(:bob).email_box
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_inbox_should_contain_received_messages
|
23
|
+
u = users(:bob)
|
24
|
+
assert_equal u.received_emails, u.email_box.inbox
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_inbox_should_contain_unsent_messages
|
28
|
+
u = users(:bob)
|
29
|
+
assert_equal u.unsent_emails, u.email_box.unsent
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_inbox_should_contain_sent_messages
|
33
|
+
u = users(:bob)
|
34
|
+
assert_equal u.sent_emails, u.email_box.sent
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class RecipientExtensionTest < Test::Unit::TestCase
|
4
|
+
fixtures :users, :email_addresses, :messages, :message_recipients, :state_changes
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@email = messages(:unsent_from_bob)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_input_string
|
11
|
+
@email.to << 'test@me.com'
|
12
|
+
assert_equal ['john@john.com', 'test@me.com'], @email.to.map(&:email_address).map(&:to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_input_receiver
|
16
|
+
@email.to << email_addresses(:bob)
|
17
|
+
assert_equal [email_addresses(:john), email_addresses(:bob)], @email.to_receivers
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_input_message_recipients
|
21
|
+
@email.to << EmailRecipient.new(:receiver => email_addresses(:bob), :kind => 'to')
|
22
|
+
assert_equal [email_addresses(:john), email_addresses(:bob)], @email.to_receivers
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_push_string
|
26
|
+
@email.to.push('test@me.com')
|
27
|
+
assert_equal ['john@john.com', 'test@me.com'], @email.to.map(&:email_address).map(&:to_s)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_push_receiver
|
31
|
+
@email.to.push(email_addresses(:bob))
|
32
|
+
assert_equal [email_addresses(:john), email_addresses(:bob)], @email.to_receivers
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_push_message_recipients
|
36
|
+
@email.to.push(EmailRecipient.new(:receiver => email_addresses(:bob), :kind => 'to'))
|
37
|
+
assert_equal [email_addresses(:john), email_addresses(:bob)], @email.to_receivers
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_should_concat_string
|
41
|
+
@email.to.concat(['test@me.com'])
|
42
|
+
assert_equal ['john@john.com', 'test@me.com'], @email.to.map(&:email_address).map(&:to_s)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_concat_receiver
|
46
|
+
@email.to.concat([email_addresses(:bob)])
|
47
|
+
assert_equal [email_addresses(:john), email_addresses(:bob)], @email.to_receivers
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_should_concat_message_recipients
|
51
|
+
@email.to.concat([EmailRecipient.new(:receiver => email_addresses(:bob), :kind => 'to')])
|
52
|
+
assert_equal [email_addresses(:john), email_addresses(:bob)], @email.to_receivers
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_should_delete_string
|
56
|
+
@email.to.delete('john@john.com')
|
57
|
+
assert_equal [], @email.to_receivers
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_should_delete_receiver
|
61
|
+
@email.to.delete(email_addresses(:john))
|
62
|
+
assert_equal [], @email.to_receivers
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_should_delete_message_recipients
|
66
|
+
@email.to.delete(@email.to.first)
|
67
|
+
assert_equal [], @email.to
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_should_replace_string
|
71
|
+
@email.to.replace(['bob@bob.com'])
|
72
|
+
assert_equal ['bob@bob.com'], @email.to.map(&:email_address).map(&:to_s)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_should_replace_receiver
|
76
|
+
@email.to.replace([email_addresses(:bob)])
|
77
|
+
assert_equal [email_addresses(:bob)], @email.to_receivers
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_should_replace_message_recipients
|
81
|
+
@email.to.replace([])
|
82
|
+
assert_equal [], @email.to_receivers
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_should_set_kind_for_to_recipients
|
86
|
+
@email.to << users(:bob)
|
87
|
+
assert_equal 'to', @email.to.last.kind
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_should_set_kind_for_cc_recipients
|
91
|
+
@email.cc << users(:bob)
|
92
|
+
assert_equal 'cc', @email.cc.last.kind
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_should_set_kind_for_bcc_recipients
|
96
|
+
@email.bcc << users(:bob)
|
97
|
+
assert_equal 'bcc', @email.bcc.last.kind
|
98
|
+
end
|
99
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: has_emails
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-09-26 00:00:00 -04:00
|
8
|
+
summary: Adds support for emailing capabilities between ActiveRecord models.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: info@pluginaweek.org
|
12
|
+
homepage: http://www.pluginaweek.org
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: has_emails
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Aaron Pfeifer, Neil Abraham
|
31
|
+
files:
|
32
|
+
- app/mailers
|
33
|
+
- app/models
|
34
|
+
- app/mailers/application_mailer.rb
|
35
|
+
- app/models/email_recipient.rb
|
36
|
+
- app/models/email_recipient_build_extension.rb
|
37
|
+
- app/models/email_address.rb
|
38
|
+
- app/models/email.rb
|
39
|
+
- db/bootstrap
|
40
|
+
- db/migrate
|
41
|
+
- db/bootstrap/events.yml
|
42
|
+
- db/bootstrap/states.yml
|
43
|
+
- db/migrate/001_create_email_addresses.rb
|
44
|
+
- db/migrate/003_add_email_recipient_specs.rb
|
45
|
+
- db/migrate/002_add_email_specs.rb
|
46
|
+
- lib/has_emails.rb
|
47
|
+
- test/test_helper.rb
|
48
|
+
- test/fixtures
|
49
|
+
- test/app_root
|
50
|
+
- test/unit
|
51
|
+
- test/fixtures/users.yml
|
52
|
+
- test/fixtures/message_recipients.yml
|
53
|
+
- test/fixtures/state_changes.yml
|
54
|
+
- test/fixtures/messages.yml
|
55
|
+
- test/fixtures/departments.yml
|
56
|
+
- test/fixtures/email_addresses.yml
|
57
|
+
- test/app_root/config
|
58
|
+
- test/app_root/app
|
59
|
+
- test/app_root/db
|
60
|
+
- test/app_root/config/environment.rb
|
61
|
+
- test/app_root/app/models
|
62
|
+
- test/app_root/app/models/user.rb
|
63
|
+
- test/app_root/app/models/department.rb
|
64
|
+
- test/app_root/db/migrate
|
65
|
+
- test/app_root/db/migrate/002_create_departments.rb
|
66
|
+
- test/app_root/db/migrate/001_create_users.rb
|
67
|
+
- test/unit/email_test.rb
|
68
|
+
- test/unit/email_address_test.rb
|
69
|
+
- test/unit/has_emails_test.rb
|
70
|
+
- test/unit/email_recipient_test.rb
|
71
|
+
- test/unit/recipient_extension_test.rb
|
72
|
+
- test/unit/application_mailer_test.rb
|
73
|
+
- CHANGELOG
|
74
|
+
- init.rb
|
75
|
+
- MIT-LICENSE
|
76
|
+
- Rakefile
|
77
|
+
- README
|
78
|
+
test_files:
|
79
|
+
- test/unit/email_test.rb
|
80
|
+
- test/unit/email_address_test.rb
|
81
|
+
- test/unit/has_emails_test.rb
|
82
|
+
- test/unit/email_recipient_test.rb
|
83
|
+
- test/unit/recipient_extension_test.rb
|
84
|
+
- test/unit/application_mailer_test.rb
|
85
|
+
rdoc_options: []
|
86
|
+
|
87
|
+
extra_rdoc_files: []
|
88
|
+
|
89
|
+
executables: []
|
90
|
+
|
91
|
+
extensions: []
|
92
|
+
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
dependencies:
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: has_messages
|
98
|
+
version_requirement:
|
99
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.0.1
|
104
|
+
version:
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: validates_as_email_address
|
107
|
+
version_requirement:
|
108
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 0.0.1
|
113
|
+
version:
|