active_mailer 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +6 -0
- data/Gemfile.lock +1 -1
- data/active_mailer.gemspec +5 -5
- data/app/models/active_mailer/base.rb +36 -35
- data/test/active_mailer_test.rb +13 -4
- metadata +2 -2
data/ChangeLog.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
= 0.0.7
|
2
|
+
* support for setting custom email headers. Give us the hassssh.
|
3
|
+
|
4
|
+
= 0.0.6
|
5
|
+
* support for setting layouts
|
6
|
+
|
1
7
|
= 0.0.5
|
2
8
|
* Fixed bug where the subject was not being set correctly.
|
3
9
|
* The ActionMailer object used behind the scenese is now available through #mailer
|
data/Gemfile.lock
CHANGED
data/active_mailer.gemspec
CHANGED
@@ -7,16 +7,16 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.authors = ["Matt Gordon"]
|
8
8
|
s.email = 'support@expectedbehavior.com'
|
9
9
|
s.files = Dir["{app,lib,config}/**/*"] + ["MIT-LICENSE", "Rakefile", "Gemfile", "README.rdoc"]
|
10
|
-
s.version = "0.0.
|
10
|
+
s.version = "0.0.7"
|
11
11
|
s.homepage =
|
12
12
|
'https://github.com/expectedbehavior/active_mailer'
|
13
|
-
|
14
|
-
|
13
|
+
|
14
|
+
|
15
15
|
s.required_rubygems_version = "> 1.3.6"
|
16
|
-
|
16
|
+
|
17
17
|
s.add_dependency "activesupport" , "~> 3.2"
|
18
18
|
s.add_dependency "rails" , "~> 3.2"
|
19
|
-
|
19
|
+
|
20
20
|
s.files = `git ls-files`.split("\n")
|
21
21
|
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
22
22
|
s.require_path = 'lib'
|
@@ -6,24 +6,24 @@
|
|
6
6
|
module ActiveMailer #:nodoc:
|
7
7
|
class Base < ActiveRecord::Base
|
8
8
|
self.abstract_class = true
|
9
|
-
|
9
|
+
|
10
10
|
has_many :email_user_associations, :as => :emailable
|
11
11
|
has_many :recipients, :through => :email_user_associations, :source => "email_user"
|
12
12
|
belongs_to :sender, :class_name => "ActiveMailer::EmailUser", :foreign_key => "sender_id"
|
13
13
|
attr_accessor :body # leave this as an accessor for now since it's complicated
|
14
14
|
attr_accessor :rendered_contents # contains the actual sent email after `send!` is called
|
15
|
-
|
15
|
+
|
16
16
|
validates_presence_of :sender
|
17
17
|
validates_length_of :subject, :minimum => 1
|
18
|
-
|
18
|
+
|
19
19
|
validate :must_have_at_least_one_recipient_of_some_kind
|
20
|
-
|
20
|
+
|
21
21
|
def must_have_at_least_one_recipient_of_some_kind
|
22
22
|
if self.recipients.blank? and self.cc.blank? and self.bcc.blank?
|
23
23
|
self.errors[:base] << "You have to have at least one recipient in the to, cc, or bcc fields"
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
cattr_accessor :before_send_actions
|
28
28
|
cattr_accessor :after_send_actions
|
29
29
|
|
@@ -35,7 +35,7 @@ module ActiveMailer #:nodoc:
|
|
35
35
|
self.ar_sender = EmailUser.find_or_create_by_email_address(email)
|
36
36
|
else
|
37
37
|
self.ar_sender = email
|
38
|
-
end
|
38
|
+
end
|
39
39
|
end
|
40
40
|
|
41
41
|
alias :ar_recipients= :recipients=
|
@@ -48,17 +48,16 @@ module ActiveMailer #:nodoc:
|
|
48
48
|
else
|
49
49
|
email
|
50
50
|
end
|
51
|
-
end
|
51
|
+
end
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def render(*args)
|
55
55
|
ActionMailer::Base.send(:new).send(:render, *args)
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
58
|
before_save :do_before_send
|
60
59
|
after_save :do_after_send
|
61
|
-
|
60
|
+
|
62
61
|
def do_before_send
|
63
62
|
self.before_send_actions.each do |m|
|
64
63
|
self.send(m)
|
@@ -70,7 +69,7 @@ module ActiveMailer #:nodoc:
|
|
70
69
|
self.send(m)
|
71
70
|
end unless self.after_send_actions.blank?
|
72
71
|
end
|
73
|
-
|
72
|
+
|
74
73
|
def self.before_send(action)
|
75
74
|
self.before_send_actions ||= []
|
76
75
|
self.before_send_actions << action
|
@@ -88,8 +87,8 @@ module ActiveMailer #:nodoc:
|
|
88
87
|
# self.delegate_to_action_mailer.flatten!
|
89
88
|
# create_delegator
|
90
89
|
# end
|
91
|
-
|
92
|
-
|
90
|
+
|
91
|
+
|
93
92
|
# cattr_accessor :template_variables
|
94
93
|
# def self.template_variable(variable_name)
|
95
94
|
# self.template_variables ||= []
|
@@ -97,23 +96,23 @@ module ActiveMailer #:nodoc:
|
|
97
96
|
# self.template_variables.flatten!
|
98
97
|
# attr_accessor variable_name
|
99
98
|
# end
|
100
|
-
|
99
|
+
|
101
100
|
def mailer_variables
|
102
101
|
mvars = {}
|
103
102
|
|
104
103
|
vars_to_include = self.class.mailer_variables + self.class.content_columns.map(&:name) + self.class.reflect_on_all_associations.map(&:name)
|
105
|
-
|
104
|
+
|
106
105
|
vars_to_include.each do |var|
|
107
106
|
mvars[var] = self.send(var.to_sym)
|
108
107
|
end
|
109
|
-
|
108
|
+
|
110
109
|
# TODO: this should be less ghetto
|
111
110
|
mvars[:from] = self.sender.email_address unless mvars[:from]
|
112
111
|
mvars[:recipients] = self.recipients.map(&:email_address) unless mvars[:recipients].all? {|r| r.is_a? String }
|
113
|
-
|
112
|
+
|
114
113
|
mvars
|
115
114
|
end
|
116
|
-
|
115
|
+
|
117
116
|
# All the mailer methods will be defined on this ActionMailer class
|
118
117
|
class DefaultActionMailer < ActionMailer::Base
|
119
118
|
# add_template_helper(ApplicationHelper)
|
@@ -121,13 +120,13 @@ module ActiveMailer #:nodoc:
|
|
121
120
|
include Rails.application.routes.url_helpers
|
122
121
|
# def self.create_method(name, &block) # syntactically convenient
|
123
122
|
# self.send(:define_method, name, &block)
|
124
|
-
# end
|
123
|
+
# end
|
125
124
|
end
|
126
|
-
|
125
|
+
|
127
126
|
def mailer(reload = false)
|
128
127
|
@mailer ||= DefaultActionMailer.send("#{self.class.default_email_method_name}".to_sym, self.mailer_variables)
|
129
128
|
end
|
130
|
-
|
129
|
+
|
131
130
|
def send! # should take false to avoid validations i.e. sending it again
|
132
131
|
if self.save!
|
133
132
|
logger.info "sending email to #{self.recipients.join(", ")}"
|
@@ -138,11 +137,11 @@ module ActiveMailer #:nodoc:
|
|
138
137
|
self.update_attribute("sent_at", Time.now)
|
139
138
|
end
|
140
139
|
end
|
141
|
-
|
140
|
+
|
142
141
|
def self.layout(*args)
|
143
142
|
DefaultActionMailer.send("layout", *args)
|
144
143
|
end
|
145
|
-
|
144
|
+
|
146
145
|
def self.mailer_variable(*variable_name)
|
147
146
|
self.mailer_variables = Set.new(variable_name.map(&:to_s)) + (mailer_variables || [])
|
148
147
|
attr_accessor *variable_name
|
@@ -153,9 +152,9 @@ module ActiveMailer #:nodoc:
|
|
153
152
|
mailer_variable :body
|
154
153
|
mailer_variable :content_type
|
155
154
|
mailer_variable :attachments
|
155
|
+
mailer_variable :headers
|
156
|
+
|
156
157
|
|
157
|
-
|
158
|
-
|
159
158
|
class << self # Class methods
|
160
159
|
def define_action_mailer_method
|
161
160
|
method_name = default_email_method_name
|
@@ -170,26 +169,28 @@ module ActiveMailer #:nodoc:
|
|
170
169
|
self.instance_eval("@#{k.to_s} = options[k]") if options[k]
|
171
170
|
# instance_variable_set(k.to_s, options[k])
|
172
171
|
end
|
173
|
-
|
174
|
-
attachments_to_set.each do |att|
|
172
|
+
|
173
|
+
attachments_to_set.each do |att|
|
175
174
|
attachment(
|
176
|
-
:content_type => (att[:content_type] || att.content_type),
|
177
|
-
:body => File.read(att[:path] || att.path),
|
178
|
-
:filename
|
175
|
+
:content_type => (att[:content_type] || att.content_type),
|
176
|
+
:body => File.read(att[:path] || att.path),
|
177
|
+
:filename => (att[:file_name] || att.file_name)
|
179
178
|
)
|
180
179
|
end
|
181
180
|
|
182
|
-
|
183
|
-
|
184
|
-
|
181
|
+
mail_options = {
|
182
|
+
:to => options[:recipients],
|
183
|
+
:subject => options[:subject],
|
184
|
+
:from => options[:sender].email_address }
|
185
|
+
mail_options[:headers] = options[:headers].to_json if options[:headers].present?
|
186
|
+
mail(mail_options)
|
185
187
|
end
|
186
188
|
end
|
187
189
|
end
|
188
|
-
|
190
|
+
|
189
191
|
def default_email_method_name
|
190
192
|
"#{self.name.underscore}"
|
191
193
|
end
|
192
|
-
|
193
194
|
end
|
194
195
|
end
|
195
196
|
end
|
data/test/active_mailer_test.rb
CHANGED
@@ -5,7 +5,7 @@ class ActiveMailerTest < ActiveSupport::TestCase
|
|
5
5
|
test "removes nil from recipients list automatically" do
|
6
6
|
email = nil
|
7
7
|
assert_nothing_raised do
|
8
|
-
email = InvitationEmail.new(:sender => "spammy@example.com",
|
8
|
+
email = InvitationEmail.new(:sender => "spammy@example.com",
|
9
9
|
:recipients => ["takesit@upemail.com", nil],
|
10
10
|
:subject => "YOU GUYS!"
|
11
11
|
)
|
@@ -13,16 +13,16 @@ class ActiveMailerTest < ActiveSupport::TestCase
|
|
13
13
|
assert { email.save }
|
14
14
|
deny { email.recipients.length == 2 }
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
test "sends with correct subject" do
|
18
|
-
email = InvitationEmail.new(:sender => "spammy@example.com",
|
18
|
+
email = InvitationEmail.new(:sender => "spammy@example.com",
|
19
19
|
:recipients => ["takesit@upemail.com", nil],
|
20
20
|
:subject => "YOU GUYS!"
|
21
21
|
)
|
22
22
|
assert { email.send! }
|
23
23
|
assert { email.mailer.subject == email.subject }
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
test "sends with correct layout" do
|
27
27
|
InvitationEmail.layout "email"
|
28
28
|
email = create(:invitation_email)
|
@@ -30,4 +30,13 @@ class ActiveMailerTest < ActiveSupport::TestCase
|
|
30
30
|
actual_layout = ActiveMailer::Base::DefaultActionMailer.instance_variable_get("@_layout")
|
31
31
|
assert { "email" == actual_layout }
|
32
32
|
end
|
33
|
+
|
34
|
+
test "sends headers" do
|
35
|
+
email = InvitationEmail.new(:sender => "spammy@example.com",
|
36
|
+
:recipients => ["takesit@upemail.com", nil],
|
37
|
+
:subject => "YOU GUYS!")
|
38
|
+
email.headers = { :something => "else" }
|
39
|
+
assert { email.send! }
|
40
|
+
assert { email.mailer["headers"].to_s == '{"something":"else"}' }
|
41
|
+
end
|
33
42
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|