padrino-mailer 0.13.0.beta3 → 0.13.0

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: 588f5fbacc42d2a775d8f29adc5ba16b137b965c
4
- data.tar.gz: 5326b3fd0916cd73f4a4a2fbfc32f2cd904a241f
3
+ metadata.gz: e966bcfe7783ad875d3f3d3eb065cf8ac15bf936
4
+ data.tar.gz: 279a169fe389f3c8c31e2313c68cf0dabc75acf2
5
5
  SHA512:
6
- metadata.gz: 6fd20351c96b4671d0ee04d665a83aa024d52f22531b6d6ea0469b886cc12206f4e6e92a8fbd465137b866c1176d345c0dbacc9bf545193087fe78a46a39d0a3
7
- data.tar.gz: 76442ebc78a77cce1117b0bfb731879fa81ddb8bd0f2974e5543052910923c8d11635afe7979db7f8b01b951ddb813bb869b53e012e7ee2cea9e0313adaf8536
6
+ metadata.gz: 1c0d5e2e64bb9e1c6217ebffd6bfe5e9c26b3502f42a1c9f3077bb54c88cf1d1b98ff7c8828e7deaa6b6e26ff058210081d6ccb0979a9aa674736acacaeb19d8
7
+ data.tar.gz: fe2102a39fad06b924517a5e6f4fea4fbf90bb5f0609db76311685ac90cfddd176a93840eecc7cb81d3fc7cb862f8a01e370e967ebe7d4798d2321324cd89e01
@@ -4,6 +4,7 @@ module Mail # @private
4
4
  class Message # @private
5
5
  include Sinatra::Templates
6
6
  include Padrino::Rendering if defined?(Padrino::Rendering)
7
+ include Padrino::Helpers::RenderHelpers if defined? Padrino::Helpers::RenderHelpers
7
8
  attr_reader :template_cache
8
9
 
9
10
  def initialize_with_app(*args, &block)
@@ -262,6 +263,12 @@ module Mail # @private
262
263
  self.body = super(engine, data, options, locals, &block) if provides.empty?
263
264
  end
264
265
 
266
+ alias_method :original_partial, :partial if instance_methods.include?(:partial)
267
+ def partial(template, options={}, &block)
268
+ raise "gem 'padrino-helpers' is required to render partials" unless respond_to?(:original_partial)
269
+ self.body = original_partial(template, options, &block)
270
+ end
271
+
265
272
  ##
266
273
  # Register all special template configurations Padrino has to our fake settings object.
267
274
  #
@@ -106,7 +106,9 @@ module Padrino
106
106
  # deliver(:example, :message, "John")
107
107
  #
108
108
  def deliver(mailer_name, message_name, *attributes)
109
- message = registered_mailers[mailer_name].messages[message_name].call(*attributes)
109
+ mailer = registered_mailers[mailer_name] or fail "mailer '#{mailer_name}' is not registered"
110
+ message = mailer.messages[message_name] or fail "mailer '#{mailer_name}' has no message '#{message_name}'"
111
+ message = message.call(*attributes)
110
112
  message.delivery_method(*delivery_settings)
111
113
  message.deliver
112
114
  end
@@ -44,7 +44,9 @@ class PadrinoApp < Padrino::Application
44
44
  via :test
45
45
  render 'sample/helper_message'
46
46
  end
47
+ end
47
48
 
49
+ mailer :nonexistant do
48
50
  end
49
51
 
50
52
  post "/deliver/inline" do
@@ -72,6 +74,13 @@ class PadrinoApp < Padrino::Application
72
74
  result ? "mail delivered" : 'mail not delivered'
73
75
  end
74
76
 
77
+ post "/deliver/failing_mailer" do
78
+ deliver(:nonregistered, :mailer, "hey")
79
+ end
80
+
81
+ post "/deliver/failing_message" do
82
+ deliver(:nonexistant, :message, "hey")
83
+ end
75
84
  end
76
85
 
77
86
  Padrino.mount("PadrinoApp").to("/")
@@ -0,0 +1 @@
1
+ Object <%= object %><br>
data/test/test_message.rb CHANGED
@@ -152,5 +152,18 @@ describe "Message" do
152
152
  message.encoded
153
153
  assert_equal :plain, message.content_type
154
154
  end
155
+
156
+ it 'should render partials' do
157
+ objects = [1,2,'<evil>','<good>'.html_safe]
158
+ message = Mail::Message.new do
159
+ from 'padrino@me.com'
160
+ to 'padrino@you.com'
161
+ subject 'Hello there Padrino'
162
+ views File.dirname(__FILE__) + '/fixtures/views/mailers'
163
+ partial 'partial/object', :collection => objects
164
+ end
165
+
166
+ assert_equal "Object 1<br>\nObject 2<br>\nObject &lt;evil&gt;<br>\nObject <good><br>", message.body.to_s.chomp
167
+ end
155
168
  end
156
169
  end
@@ -110,5 +110,19 @@ describe "PadrinoMailer" do
110
110
  :content_type => 'text/html', :delivery_method => @app.delivery_method,
111
111
  :subject => 'Welcome Helper!', :body => "<a href=\"#\">jim</a>")
112
112
  end
113
+
114
+ it 'should fail with proper message if mailer is not registered' do
115
+ error = assert_raises RuntimeError do
116
+ post '/deliver/failing_mailer'
117
+ end
118
+ assert_match /is not registered/, error.message
119
+ end
120
+
121
+ it 'should fail with proper message if message does not exist' do
122
+ error = assert_raises RuntimeError do
123
+ post '/deliver/failing_message'
124
+ end
125
+ assert_match /has no message/, error.message
126
+ end
113
127
  end
114
128
  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.0.beta3
4
+ version: 0.13.0
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: 2015-08-02 00:00:00.000000000 Z
14
+ date: 2015-10-11 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.0.beta3
22
+ version: 0.13.0
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.0.beta3
29
+ version: 0.13.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: mail
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,7 @@ files:
80
80
  - test/fixtures/views/mailers/layouts/sample.erb
81
81
  - test/fixtures/views/mailers/multipart/basic.html.erb
82
82
  - test/fixtures/views/mailers/multipart/basic.plain.erb
83
+ - test/fixtures/views/mailers/partial/_object.erb
83
84
  - test/fixtures/views/mailers/sample/foo.erb
84
85
  - test/helper.rb
85
86
  - test/test_email.rb
@@ -102,12 +103,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
103
  version: '0'
103
104
  required_rubygems_version: !ruby/object:Gem::Requirement
104
105
  requirements:
105
- - - '>'
106
+ - - '>='
106
107
  - !ruby/object:Gem::Version
107
- version: 1.3.1
108
+ version: 1.3.6
108
109
  requirements: []
109
110
  rubyforge_project: padrino-mailer
110
- rubygems_version: 2.0.6
111
+ rubygems_version: 2.4.8
111
112
  signing_key:
112
113
  specification_version: 4
113
114
  summary: Mailer system for padrino
@@ -132,6 +133,7 @@ test_files:
132
133
  - test/fixtures/views/mailers/layouts/sample.erb
133
134
  - test/fixtures/views/mailers/multipart/basic.html.erb
134
135
  - test/fixtures/views/mailers/multipart/basic.plain.erb
136
+ - test/fixtures/views/mailers/partial/_object.erb
135
137
  - test/fixtures/views/mailers/sample/foo.erb
136
138
  - test/helper.rb
137
139
  - test/test_email.rb