padrino-mailer 0.13.2 → 0.13.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dcadea24539f54965f30482d6ba1031e2d2c1735
4
- data.tar.gz: 7072ecef88d36253f720ff449e4b4472548d3854
3
+ metadata.gz: adc0d683d6b9dd4c72b0e9d357981fcf7f701b07
4
+ data.tar.gz: 750b27c369a4f1aec4f1db417a4ac5e5b7a687a0
5
5
  SHA512:
6
- metadata.gz: 715759f9eafb48d542337f4f42205228d6b875edc3fe4b9c26c414d6c48525abb5476dd42a4802fdf3755ce277a345762b80485876ba53f480ab148464af4691
7
- data.tar.gz: e9509f3b64f2aa534886c746bd8747721dcdae10f5da81b0d9aa703f594a32283efb4a588f2b0a22e8c1f6def4be1ca0e00c4e9db413329e3960fdc1c066331b
6
+ metadata.gz: 6c6100bd09fc0514db1f1b79f33b1645abe34a34965f73c74b45f95bac57ca3f00df8fe961973fc3f1747f29e3a623e54ebe30f51ffb72ca4abfc2b69536a92c
7
+ data.tar.gz: e79bf65fb5f875bc1961114256bc0a5f884f7b7b2af968e9cc89a5b0318aaebad56a2ddbb62c6e8901a072925906588874dbd67ca6b7f0ac95fe89e330c365e7
@@ -84,6 +84,8 @@ module Padrino
84
84
  raise "The email '#{name}' is already defined" if self.messages[name].present?
85
85
  self.messages[name] = Proc.new { |*attrs|
86
86
  message = app.settings._padrino_mailer::Message.new(self.app)
87
+ message.mailer_name = mailer_name
88
+ message.message_name = name
87
89
  message.defaults = self.defaults if self.defaults.any?
88
90
  message.delivery_method(*delivery_settings)
89
91
  message.instance_exec(*attrs, &block)
@@ -6,6 +6,7 @@ module Mail # @private
6
6
  include Padrino::Rendering if defined?(Padrino::Rendering)
7
7
  include Padrino::Helpers::RenderHelpers if defined? Padrino::Helpers::RenderHelpers
8
8
  attr_reader :template_cache
9
+ attr_accessor :mailer_name, :message_name
9
10
 
10
11
  def initialize_with_app(*args, &block)
11
12
  @template_cache = Tilt::Cache.new
@@ -253,10 +254,17 @@ module Mail # @private
253
254
  ##
254
255
  # Defines the render for the mailer utilizing the padrino 'rendering' module
255
256
  #
256
- def render(engine, data=nil, options={}, locals={}, &block)
257
+ def render(engine=nil, data=nil, options={}, locals={}, &block)
257
258
  locals = @_locals if options[:locals].blank? && locals.blank?
258
259
  @template_cache.clear if settings.reload_templates?
259
260
 
261
+ engine ||= message_name
262
+
263
+ if mailer_name
264
+ settings.views += "/#{mailer_name}"
265
+ engine = engine.to_s.sub(%r{^#{mailer_name}/}, '')
266
+ end
267
+
260
268
  provides.each do |format|
261
269
  part do |p|
262
270
  p.content_type(format)
@@ -44,6 +44,24 @@ class PadrinoApp < Padrino::Application
44
44
  via :test
45
45
  render 'sample/helper_message'
46
46
  end
47
+
48
+ message :default_mailer_name do |name|
49
+ subject "Welcome Helper!"
50
+ to 'jim@fake.com'
51
+ from 'noreply@custom.com'
52
+ locals :name => name
53
+ via :test
54
+ render 'default_mailer_name'
55
+ end
56
+
57
+ message :default_mailer_email_name do |name|
58
+ subject "Welcome Helper!"
59
+ to 'jim@fake.com'
60
+ from 'noreply@custom.com'
61
+ locals :name => name
62
+ via :test
63
+ render
64
+ end
47
65
  end
48
66
 
49
67
  mailer :nonexistant do
@@ -81,6 +99,16 @@ class PadrinoApp < Padrino::Application
81
99
  post "/deliver/failing_message" do
82
100
  deliver(:nonexistant, :message, "hey")
83
101
  end
102
+
103
+ post "/deliver/default_mailer_name" do
104
+ result = deliver(:sample, :default_mailer_name, "Jim")
105
+ result ? "mail delivered" : 'mail not delivered'
106
+ end
107
+
108
+ post "/deliver/default_mailer_email_name" do
109
+ result = deliver(:sample, :default_mailer_email_name, "Jim")
110
+ result ? "mail delivered" : 'mail not delivered'
111
+ end
84
112
  end
85
113
 
86
114
  Padrino.mount("PadrinoApp").to("/")
data/test/helper.rb CHANGED
@@ -6,6 +6,7 @@ require 'minitest/pride'
6
6
  require 'rack/test'
7
7
  require 'padrino-core'
8
8
  require 'padrino-helpers'
9
+ require 'padrino/rendering'
9
10
  require 'padrino-mailer/ext'
10
11
  require 'padrino-mailer'
11
12
 
@@ -34,11 +35,13 @@ class MiniTest::Spec
34
35
  mail_message = Mail::TestMailer.deliveries.last
35
36
  raise "No mail message has been sent!" unless mail_message.present?
36
37
  delivery_attributes = mail_attributes
37
- delivery_attributes = { :to => Array(mail_attributes[:to]), :from => Array(mail_attributes[:from]) }
38
- delivery_attributes.each_pair do |k, v|
39
- unless mail_message.method(k).call == v
40
- raise "Mail failure (#{k}): #{mail_message.attributes.inspect} does not match #{delivery_attributes.inspect}"
41
- end
38
+ delivery_attributes.update(:to => Array(mail_attributes[:to]), :from => Array(mail_attributes[:from]))
39
+ delivery_attributes.each_pair do |key, expected|
40
+ next unless mail_message.respond_to?(key)
41
+ actual = mail_message.send(key)
42
+ actual = actual.to_s.chomp if key == :body
43
+ actual = mail_message.content_type_without_symbol.split(';').first if key == :content_type
44
+ assert_equal expected, actual, "Mail failure at field '#{key}'"
42
45
  end
43
46
  Mail::TestMailer.deliveries.clear
44
47
  end
@@ -12,8 +12,7 @@ describe "PadrinoMailer" do
12
12
  assert_email_sent(:to => 'john@apple.com',
13
13
  :from => 'joe@smith.com',
14
14
  :subject => 'Test Email',
15
- :body => 'Test Body',
16
- :delivery_method => @app.delivery_method)
15
+ :body => 'Test Body')
17
16
  end
18
17
 
19
18
  it 'should be able to deliver plain text emails' do
@@ -21,7 +20,6 @@ describe "PadrinoMailer" do
21
20
  assert_equal 'mail delivered', body
22
21
  assert_email_sent(:to => 'john@fake.com',
23
22
  :from => 'noreply@birthday.com',
24
- :delivery_method => @app.delivery_method,
25
23
  :subject => "Happy Birthday!",
26
24
  :body => "Happy Birthday Joey!\nYou are turning 21")
27
25
  end
@@ -32,7 +30,6 @@ describe "PadrinoMailer" do
32
30
  assert_email_sent(:template => 'mailers/sample/foo_message',
33
31
  :to => 'john@fake.com',
34
32
  :from => 'noreply@custom.com',
35
- :delivery_method => @app.delivery_method,
36
33
  :subject => 'Welcome Message!',
37
34
  :body => 'Hello to Bobby')
38
35
  end
@@ -43,9 +40,8 @@ describe "PadrinoMailer" do
43
40
  assert_email_sent(:to => 'julie@fake.com',
44
41
  :from => 'noreply@anniversary.com',
45
42
  :content_type => 'text/html',
46
- :delivery_method => @app.delivery_method,
47
43
  :subject => 'Happy anniversary!',
48
- :body => "<p>Yay Joey & Charlotte!</p>\n<p>You have been married 16 years</p>")
44
+ :body => "<p>Yay Joey &amp; Charlotte!</p>\n<p>You have been married 16 years</p>")
49
45
  end
50
46
 
51
47
  it 'should be able to deliver a basic email using app settings' do
@@ -53,8 +49,7 @@ describe "PadrinoMailer" do
53
49
  :subject => 'Test Email', :body => 'Test Body',
54
50
  :via => :test)
55
51
  assert_email_sent(:to => 'john@apple.com', :from => 'joe@smith.com',
56
- :subject => 'Test Email', :body => 'Test Body',
57
- :delivery_method => @app.delivery_method)
52
+ :subject => 'Test Email', :body => 'Test Body')
58
53
  end
59
54
  end
60
55
 
@@ -65,7 +60,7 @@ describe "PadrinoMailer" do
65
60
  post '/deliver/inline'
66
61
  assert_equal 'mail delivered', body
67
62
  assert_email_sent(:to => 'john@apple.com', :from => 'joe@smith.com',
68
- :delivery_method => @app.delivery_method, :subject => 'Test Email',
63
+ :subject => 'Test Email',
69
64
  :body => 'Test Body')
70
65
  end
71
66
 
@@ -73,7 +68,7 @@ describe "PadrinoMailer" do
73
68
  post '/deliver/plain'
74
69
  assert_equal 'mail delivered', body
75
70
  assert_email_sent(:to => 'john@fake.com', :from => 'noreply@birthday.com',
76
- :delivery_method => @app.delivery_method, :subject => "Happy Birthday!",
71
+ :subject => "Happy Birthday!",
77
72
  :body => "Happy Birthday Joey!\nYou are turning 21")
78
73
  end
79
74
 
@@ -81,7 +76,7 @@ describe "PadrinoMailer" do
81
76
  post '/deliver/custom'
82
77
  assert_equal 'mail delivered', body
83
78
  assert_email_sent(:template => 'mailers/sample/foo_message', :to => 'john@fake.com',
84
- :from => 'noreply@custom.com', :delivery_method => @app.delivery_method,
79
+ :from => 'noreply@custom.com',
85
80
  :subject => 'Welcome Message!', :body => 'Hello to Bobby')
86
81
  end
87
82
 
@@ -89,8 +84,8 @@ describe "PadrinoMailer" do
89
84
  post '/deliver/html'
90
85
  assert_equal 'mail delivered', body
91
86
  assert_email_sent(:to => 'julie@fake.com', :from => 'noreply@anniversary.com',
92
- :content_type => 'text/html', :delivery_method => @app.delivery_method,
93
- :subject => 'Happy anniversary!', :body => "<p>Yay Joey & Charlotte!</p>\n<p>You have been married 16 years</p>")
87
+ :content_type => 'text/html',
88
+ :subject => 'Happy anniversary!', :body => "<p>Yay Joey &amp; Charlotte!</p>\n<p>You have been married 16 years</p>")
94
89
  end
95
90
 
96
91
  it 'should be able to deliver a basic email using app settings' do
@@ -98,8 +93,7 @@ describe "PadrinoMailer" do
98
93
  :subject => 'Test Email', :body => 'Test Body',
99
94
  :via => :test)
100
95
  assert_email_sent(:to => 'john@apple.com', :from => 'joe@smith.com',
101
- :subject => 'Test Email', :body => 'Test Body',
102
- :delivery_method => @app.delivery_method)
96
+ :subject => 'Test Email', :body => 'Test Body')
103
97
  end
104
98
 
105
99
  it 'should be able to deliver a basic email using Padrino::Helpers' do
@@ -107,7 +101,7 @@ describe "PadrinoMailer" do
107
101
  post '/deliver/helper'
108
102
  assert_equal 'mail delivered', body
109
103
  assert_email_sent(:to => 'jim@fake.com', :from => 'noreply@custom.com',
110
- :content_type => 'text/html', :delivery_method => @app.delivery_method,
104
+ :content_type => 'text/html',
111
105
  :subject => 'Welcome Helper!', :body => "<a href=\"#\">jim</a>")
112
106
  end
113
107
 
@@ -124,5 +118,19 @@ describe "PadrinoMailer" do
124
118
  end
125
119
  assert_match /has no message/, error.message
126
120
  end
121
+
122
+ it 'should be able to render default mailer names' do
123
+ post '/deliver/default_mailer_name'
124
+ assert_equal 'mail delivered', body
125
+ assert_email_sent(:to => 'jim@fake.com', :from => 'noreply@custom.com',
126
+ :content_type => 'text/plain', :body => "dmn")
127
+ end
128
+
129
+ it 'should be able to render default mailer email names' do
130
+ post '/deliver/default_mailer_email_name'
131
+ assert_equal 'mail delivered', body
132
+ assert_email_sent(:to => 'jim@fake.com', :from => 'noreply@custom.com',
133
+ :content_type => 'text/plain', :body => "dmen")
134
+ end
127
135
  end
128
136
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2
4
+ version: 0.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-05-09 00:00:00.000000000 Z
14
+ date: 2016-08-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: padrino-core
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.13.2
22
+ version: 0.13.3
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.13.2
29
+ version: 0.13.3
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: mime-types
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,8 @@ files:
80
80
  - test/fixtures/padrino_app/views/mailers/demo/sample_mail.erb
81
81
  - test/fixtures/padrino_app/views/mailers/sample/anniversary.erb
82
82
  - test/fixtures/padrino_app/views/mailers/sample/birthday.erb
83
+ - test/fixtures/padrino_app/views/mailers/sample/default_mailer_email_name.erb
84
+ - test/fixtures/padrino_app/views/mailers/sample/default_mailer_name.erb
83
85
  - test/fixtures/padrino_app/views/mailers/sample/foo_message.erb
84
86
  - test/fixtures/padrino_app/views/mailers/sample/helper_message.erb
85
87
  - test/fixtures/sinatra_app/app.rb
@@ -122,36 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
124
  version: 1.3.6
123
125
  requirements: []
124
126
  rubyforge_project: padrino-mailer
125
- rubygems_version: 2.4.8
127
+ rubygems_version: 2.6.4
126
128
  signing_key:
127
129
  specification_version: 4
128
130
  summary: Mailer system for padrino
129
- test_files:
130
- - test/fixtures/basic.erb
131
- - test/fixtures/layout.erb
132
- - test/fixtures/padrino_app/app.rb
133
- - test/fixtures/padrino_app/views/mailers/demo/sample_mail.erb
134
- - test/fixtures/padrino_app/views/mailers/sample/anniversary.erb
135
- - test/fixtures/padrino_app/views/mailers/sample/birthday.erb
136
- - test/fixtures/padrino_app/views/mailers/sample/foo_message.erb
137
- - test/fixtures/padrino_app/views/mailers/sample/helper_message.erb
138
- - test/fixtures/sinatra_app/app.rb
139
- - test/fixtures/sinatra_app/views/mailers/demo/sample_mail.erb
140
- - test/fixtures/sinatra_app/views/mailers/sample/anniversary.erb
141
- - test/fixtures/sinatra_app/views/mailers/sample/birthday.erb
142
- - test/fixtures/sinatra_app/views/mailers/sample/foo_message.erb
143
- - test/fixtures/views/mailers/alternate/foo.erb
144
- - test/fixtures/views/mailers/bar.erb
145
- - test/fixtures/views/mailers/i18n/hello.en.erb
146
- - test/fixtures/views/mailers/i18n/hello.it.erb
147
- - test/fixtures/views/mailers/layouts/sample.erb
148
- - test/fixtures/views/mailers/multipart/basic.html.erb
149
- - test/fixtures/views/mailers/multipart/basic.plain.erb
150
- - test/fixtures/views/mailers/partial/_object.erb
151
- - test/fixtures/views/mailers/sample/foo.erb
152
- - test/helper.rb
153
- - test/test_email.rb
154
- - test/test_message.rb
155
- - test/test_padrino_mailer.rb
156
- - test/test_part.rb
157
- has_rdoc:
131
+ test_files: []