merb-mailer 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +7 -5
- data/lib/merb-mailer/mail_controller.rb +8 -1
- data/spec/mail_controller_spec.rb +174 -0
- data/spec/mailer_spec.rb +87 -0
- data/spec/mailers/views/layout/application.html.erb +3 -0
- data/spec/mailers/views/layout/application.text.erb +3 -0
- data/spec/mailers/views/test_mail_controller/eighth.html.erb +1 -0
- data/spec/mailers/views/test_mail_controller/eighth.text.erb +1 -0
- data/spec/mailers/views/test_mail_controller/first.html.erb +1 -0
- data/spec/mailers/views/test_mail_controller/first.text.erb +1 -0
- data/spec/mailers/views/test_mail_controller/ninth.html.erb +1 -0
- data/spec/mailers/views/test_mail_controller/ninth.text.erb +1 -0
- data/spec/mailers/views/test_mail_controller/second.text.erb +1 -0
- data/spec/mailers/views/test_mail_controller/third.html.erb +1 -0
- data/spec/spec_helper.rb +7 -0
- metadata +20 -3
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require "spec/rake/spectask"
|
|
4
4
|
|
5
5
|
PLUGIN = "merb-mailer"
|
6
6
|
NAME = "merb-mailer"
|
7
|
-
VERSION = "0.9.
|
7
|
+
VERSION = "0.9.3"
|
8
8
|
AUTHOR = "Yehuda Katz"
|
9
9
|
EMAIL = "wycats@gmail.com"
|
10
10
|
HOMEPAGE = "http://merb-plugins.rubyforge.org/merb-mailer/"
|
@@ -21,26 +21,28 @@ spec = Gem::Specification.new do |s|
|
|
21
21
|
s.author = AUTHOR
|
22
22
|
s.email = EMAIL
|
23
23
|
s.homepage = HOMEPAGE
|
24
|
-
s.add_dependency('merb-core', '>= 0.9.
|
24
|
+
s.add_dependency('merb-core', '>= 0.9.3')
|
25
25
|
s.add_dependency("mailfactory", ">= 1.2.3")
|
26
26
|
s.require_path = 'lib'
|
27
27
|
s.autorequire = PLUGIN
|
28
|
-
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,
|
28
|
+
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
|
29
29
|
end
|
30
30
|
|
31
31
|
Rake::GemPackageTask.new(spec) do |pkg|
|
32
32
|
pkg.gem_spec = spec
|
33
33
|
end
|
34
34
|
|
35
|
+
install_home = ENV['GEM_HOME'] ? "-i #{ENV['GEM_HOME']}" : ""
|
36
|
+
|
35
37
|
task :install => [:package] do
|
36
|
-
sh %{sudo gem install pkg/#{NAME}-#{VERSION} --no-update-sources}
|
38
|
+
sh %{sudo gem install #{install_home} pkg/#{NAME}-#{VERSION} --no-update-sources}
|
37
39
|
end
|
38
40
|
|
39
41
|
namespace :jruby do
|
40
42
|
|
41
43
|
desc "Run :package and install the resulting .gem with jruby"
|
42
44
|
task :install => :package do
|
43
|
-
sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
|
45
|
+
sh %{#{SUDO} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
|
44
46
|
end
|
45
47
|
|
46
48
|
end
|
@@ -222,6 +222,13 @@ module Merb
|
|
222
222
|
@mail
|
223
223
|
end
|
224
224
|
|
225
|
+
# Mimic the behavior of absolute_url in AbstractController
|
226
|
+
# but use @base_controller.request
|
227
|
+
def absolute_url(name, rparams={})
|
228
|
+
req = @base_controller.request
|
229
|
+
uri = req.protocol + req.host + url(name, rparams)
|
230
|
+
end
|
231
|
+
|
225
232
|
# Attaches a file or multiple files to an email. You call this from a
|
226
233
|
# method in your MailController (including a before filter).
|
227
234
|
#
|
@@ -325,4 +332,4 @@ module Merb
|
|
325
332
|
|
326
333
|
|
327
334
|
end
|
328
|
-
end
|
335
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
Spec::Runner.configure do |config|
|
4
|
+
config.include Merb::Test::RequestHelper
|
5
|
+
end
|
6
|
+
|
7
|
+
class Merb::Mailer
|
8
|
+
self.delivery_method = :test_send
|
9
|
+
end
|
10
|
+
|
11
|
+
Merb.push_path(:mailer, File.join(File.dirname(__FILE__), "mailers"))
|
12
|
+
|
13
|
+
class TestMailController < Merb::MailController
|
14
|
+
|
15
|
+
def first
|
16
|
+
render_mail
|
17
|
+
end
|
18
|
+
|
19
|
+
def second
|
20
|
+
render_mail
|
21
|
+
end
|
22
|
+
|
23
|
+
def third
|
24
|
+
render_mail :text => :first, :html => :third
|
25
|
+
end
|
26
|
+
|
27
|
+
def fourth
|
28
|
+
render_mail :text => "FOURTH_TEXT", :html => "FOURTH_HTML", :layout => :none
|
29
|
+
end
|
30
|
+
|
31
|
+
def fifth
|
32
|
+
render_mail :action => {:text => :first, :html => :third}
|
33
|
+
end
|
34
|
+
|
35
|
+
def sixth
|
36
|
+
render_mail :action => {:text => :first}, :html => "SIXTH_HTML"
|
37
|
+
end
|
38
|
+
|
39
|
+
def seventh
|
40
|
+
render_mail :text => :first, :html => "SEVENTH_HTML"
|
41
|
+
end
|
42
|
+
|
43
|
+
def eighth
|
44
|
+
@testing = "TEST"
|
45
|
+
render_mail
|
46
|
+
end
|
47
|
+
|
48
|
+
def ninth
|
49
|
+
render_mail
|
50
|
+
end
|
51
|
+
|
52
|
+
def tenth
|
53
|
+
render_mail
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
class TestController < Merb::Controller
|
59
|
+
|
60
|
+
def one
|
61
|
+
send_mail TestMailController, :ninth, {:from => "foo@bar.com", :to => "foo@bar.com"}, {:x => "ONE_CONTROLLER"}
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "A Merb Mail controller" do
|
67
|
+
|
68
|
+
def deliver(action)
|
69
|
+
TestMailController.dispatch_and_deliver action, :from => "foo@bar.com", :to => "foo@bar.com"
|
70
|
+
@delivery = Merb::Mailer.deliveries.last
|
71
|
+
end
|
72
|
+
|
73
|
+
undef :call_action if defined?(call_action)
|
74
|
+
def call_action(action)
|
75
|
+
dispatch_to(TestController, action)
|
76
|
+
@delivery = Merb::Mailer.deliveries.last
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should render files in its directory by default" do
|
80
|
+
deliver :first
|
81
|
+
@delivery.text.should == "TEXT\nFIRST\nENDTEXT"
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should render files in its directory without a mimetype extension by default" do
|
85
|
+
deliver :second
|
86
|
+
@delivery.text.should == "TEXT\nSECOND\nENDTEXT"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should be able to accept a :text => :sym, :html => :sym render_mail" do
|
90
|
+
deliver :third
|
91
|
+
@delivery.text.should == "TEXT\nFIRST\nENDTEXT"
|
92
|
+
@delivery.html.should == "BASIC\nTHIRDHTML\nLAYOUT"
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should be able to accept a :text => STRING, :html => STRING render_mail" do
|
96
|
+
deliver :fourth
|
97
|
+
$DEBUGGER = true
|
98
|
+
@delivery.text.should == "FOURTH_TEXT"
|
99
|
+
@delivery.html.should == "FOURTH_HTML"
|
100
|
+
$DEBUGGER = false
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should be able to accept an :action => {:text => :sym, :html => :sym}" do
|
104
|
+
deliver :fifth
|
105
|
+
@delivery.text.should == "TEXT\nFIRST\nENDTEXT"
|
106
|
+
@delivery.html.should == "BASIC\nTHIRDHTML\nLAYOUT"
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should be able to accept a mix of action and :html => STRING" do
|
110
|
+
deliver :sixth
|
111
|
+
@delivery.text.should == "TEXT\nFIRST\nENDTEXT"
|
112
|
+
@delivery.html.should == "SIXTH_HTML"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should be able to accept a mix of :text => :sym and :html => STRING" do
|
116
|
+
deliver :seventh
|
117
|
+
@delivery.text.should == "TEXT\nFIRST\nENDTEXT"
|
118
|
+
@delivery.html.should == "SEVENTH_HTML"
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should hold onto instance variables" do
|
122
|
+
deliver :eighth
|
123
|
+
@delivery.html.should == "BASIC\nTEST\nLAYOUT"
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should have access to the params sent by the calling controller" do
|
127
|
+
call_action :one
|
128
|
+
@delivery.html.should == "BASIC\nONE_CONTROLLER\nLAYOUT"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should not raise an error if there are no templates" do
|
132
|
+
lambda do
|
133
|
+
deliver :tenth
|
134
|
+
end.should_not raise_error
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should log an error if there are no templates available" do
|
138
|
+
Merb.logger.should_receive(:error).once
|
139
|
+
deliver :tenth
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
# describe "Merb::MailController with url generation" do
|
145
|
+
#
|
146
|
+
# it_should_behave_like "class with general url generation"
|
147
|
+
# it_should_behave_like "non routeable controller with url mixin"
|
148
|
+
#
|
149
|
+
# def new_url_controller(route, params = {:action => 'show', :controller => 'Test'})
|
150
|
+
# request = OpenStruct.new
|
151
|
+
# request.route = route
|
152
|
+
# request.params = params
|
153
|
+
# response = OpenStruct.new
|
154
|
+
# response.read = ""
|
155
|
+
#
|
156
|
+
# @controller = Merb::Controller.build(request, response)
|
157
|
+
# TestMailController.new(params, @controller)
|
158
|
+
# end
|
159
|
+
#
|
160
|
+
# it "should raise an error if no controller is specified and the base controller is not set" do
|
161
|
+
# c = new_url_controller(@default_route, {})
|
162
|
+
# lambda do
|
163
|
+
# the_url = c.url(:action => "bar")
|
164
|
+
# end.should raise_error
|
165
|
+
# end
|
166
|
+
#
|
167
|
+
# it "should use the base controller when it is set to generate a url when no :controller option is specified" do
|
168
|
+
# c = new_url_controller(@defualt_route, :controller => "foo")
|
169
|
+
# lambda do
|
170
|
+
# the_url = c.url(:action => "bar")
|
171
|
+
# the_url.should == "/foo/bar"
|
172
|
+
# end.should_not raise_error
|
173
|
+
# end
|
174
|
+
# end
|
data/spec/mailer_spec.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
class TestMailer < Merb::Mailer
|
4
|
+
self.delivery_method = :test_send
|
5
|
+
end
|
6
|
+
|
7
|
+
class TestSMTPMailer < Merb::Mailer
|
8
|
+
self.delivery_method = :net_smtp
|
9
|
+
self.config = { :host => 'smtp.yourserver.com',
|
10
|
+
:port => '25',
|
11
|
+
:user => 'user',
|
12
|
+
:pass => 'pass',
|
13
|
+
:auth => :plain }
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
class TestSendmailMailer < Merb::Mailer
|
18
|
+
self.delivery_method = :sendmail
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup_test_mailer klass = TestMailer
|
22
|
+
@m = klass.new :to => "test@test.com",
|
23
|
+
:from => "foo@bar.com",
|
24
|
+
:subject => "Test Subject",
|
25
|
+
:body => "Test"
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "a merb mailer" do
|
29
|
+
|
30
|
+
it "should be able to send test emails" do
|
31
|
+
setup_test_mailer
|
32
|
+
@m.deliver!
|
33
|
+
TestMailer.deliveries.size.should == 1
|
34
|
+
delivery = TestMailer.deliveries.last
|
35
|
+
delivery.to.should include("test@test.com")
|
36
|
+
delivery.from.should include("foo@bar.com")
|
37
|
+
delivery.subject.should include("Test Subject")
|
38
|
+
delivery.body.should include("Test")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be able to accept attachments" do
|
42
|
+
setup_test_mailer
|
43
|
+
@m.attach File.open("README")
|
44
|
+
@m.deliver!
|
45
|
+
delivery = TestMailer.deliveries.last
|
46
|
+
delivery.instance_variable_get("@attachments").size.should == 1
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should be able to accept multiple attachments" do
|
50
|
+
setup_test_mailer
|
51
|
+
@m.attach [[File.open("README")], [File.open("LICENSE")]]
|
52
|
+
@m.deliver!
|
53
|
+
delivery = TestMailer.deliveries.last
|
54
|
+
delivery.instance_variable_get("@attachments").size.should == 2
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should be able to send mails via SMTP" do
|
58
|
+
setup_test_mailer TestSMTPMailer
|
59
|
+
Net::SMTP.stub!(:start).and_return(true)
|
60
|
+
Net::SMTP.should_receive(:start).with("smtp.yourserver.com", 25, nil, "user", "pass", :plain)
|
61
|
+
@m.deliver!
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should send mails via SMTP with no auth" do
|
65
|
+
setup_test_mailer TestSMTPMailer
|
66
|
+
@m.config[:auth] = nil
|
67
|
+
Net::SMTP.stub!(:start).and_return(true)
|
68
|
+
Net::SMTP.should_receive(:start).with("smtp.yourserver.com", 25, nil, "user", "pass", nil)
|
69
|
+
@m.deliver!
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should be able to send mails via sendmail" do
|
73
|
+
sendmail = mock("/usr/sbin/sendmail", :null_object => true)
|
74
|
+
setup_test_mailer TestSendmailMailer
|
75
|
+
IO.should_receive(:popen).with("/usr/sbin/sendmail #{@m.mail.to}", "w+").and_return(sendmail)
|
76
|
+
@m.deliver!
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should be able to use a different sendmail path" do
|
80
|
+
sendmail = mock("/somewhere/sendmail", :null_object => true)
|
81
|
+
setup_test_mailer TestSendmailMailer
|
82
|
+
@m.config[:sendmail_path] = '/somewhere/sendmail'
|
83
|
+
IO.should_receive(:popen).with("/somewhere/sendmail #{@m.mail.to}", "w+").and_return(sendmail)
|
84
|
+
@m.deliver!
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @testing %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @testing %>
|
@@ -0,0 +1 @@
|
|
1
|
+
FIRST
|
@@ -0,0 +1 @@
|
|
1
|
+
FIRST
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= params[:x] %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= params[:x] %>
|
@@ -0,0 +1 @@
|
|
1
|
+
SECOND
|
@@ -0,0 +1 @@
|
|
1
|
+
THIRDHTML
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb-mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yehuda Katz
|
@@ -9,7 +9,7 @@ autorequire: merb-mailer
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-05-04 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.9.
|
22
|
+
version: 0.9.3
|
23
23
|
version:
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
25
|
name: mailfactory
|
@@ -50,6 +50,23 @@ files:
|
|
50
50
|
- lib/merb-mailer/mailer.rb
|
51
51
|
- lib/merb-mailer/merb_controller.rb
|
52
52
|
- lib/merb-mailer.rb
|
53
|
+
- spec/mail_controller_spec.rb
|
54
|
+
- spec/mailer_spec.rb
|
55
|
+
- spec/mailers
|
56
|
+
- spec/mailers/views
|
57
|
+
- spec/mailers/views/layout
|
58
|
+
- spec/mailers/views/layout/application.html.erb
|
59
|
+
- spec/mailers/views/layout/application.text.erb
|
60
|
+
- spec/mailers/views/test_mail_controller
|
61
|
+
- spec/mailers/views/test_mail_controller/eighth.html.erb
|
62
|
+
- spec/mailers/views/test_mail_controller/eighth.text.erb
|
63
|
+
- spec/mailers/views/test_mail_controller/first.html.erb
|
64
|
+
- spec/mailers/views/test_mail_controller/first.text.erb
|
65
|
+
- spec/mailers/views/test_mail_controller/ninth.html.erb
|
66
|
+
- spec/mailers/views/test_mail_controller/ninth.text.erb
|
67
|
+
- spec/mailers/views/test_mail_controller/second.text.erb
|
68
|
+
- spec/mailers/views/test_mail_controller/third.html.erb
|
69
|
+
- spec/spec_helper.rb
|
53
70
|
has_rdoc: true
|
54
71
|
homepage: http://merb-plugins.rubyforge.org/merb-mailer/
|
55
72
|
post_install_message:
|