mandrill_mailer 0.0.2 → 0.0.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/README.md CHANGED
@@ -22,6 +22,11 @@ MandrillMailer.api_key = ENV['MANDRILL_API_KEY']
22
22
 
23
23
  Don't forget to setup your ENV variables on your server
24
24
 
25
+ You will also need to set default_url_options for the mailer, similar to action mailer
26
+ in your environment config files:
27
+
28
+ `MandrillMailer::TransactionalMailer.default_url_options = { :host => 'localhost' }`
29
+
25
30
  ## Creating a new mailer
26
31
  Creating a new Mandrill Mailer is similar to a normal Rails mailer:
27
32
 
@@ -94,7 +99,7 @@ The test for this particular Mailer is setup like so:
94
99
 
95
100
  ```
96
101
  test_setup_for :invite do |mailer, options|
97
- invitation = OpenStruct.new({
102
+ invitation = MandrillMailer::Mock.new({
98
103
  email: options[:email],
99
104
  owner_name: 'foobar',
100
105
  secret: rand(9000000..1000000).to_s
@@ -103,9 +108,22 @@ test_setup_for :invite do |mailer, options|
103
108
  end
104
109
  ```
105
110
 
106
- The mailer and options passed to the `.test` method are yielded to the block.
111
+ Use MandrillMailer::Mock to mock out objects.
107
112
 
108
- The `:email` option is the only required option, make sure to add at least this to your test object.
113
+ If in order to represent a url within a mock, make sure there is a `url` or `path` attribute,
114
+ for example, if I had a course mock and I was using the `course_url` route helper within the mailer
115
+ I would create the mock like so:
116
+
117
+ ```
118
+ course = MandrillMailer::Mock.new({
119
+ title: 'zombies',
120
+ type: 'Ruby',
121
+ url: 'http://funzone.com/zombies'
122
+ })
123
+ ```
124
+
125
+ This would ensure that `course_url(course)` works as expected.
126
+
127
+ The mailer and options passed to the `.test` method are yielded to the block.
109
128
 
110
- ## Helper Methods
111
- * `.test_friendly_url`(object, route helper as a symbol) - This helper is used for using route helpers, but still staying compatible with using OpenStructs for stubing out the mailing test objects (there is probably a much better way of doing this)
129
+ The `:email` option is the only required option, make sure to add at least this to your test object.
@@ -1,4 +1,5 @@
1
1
  require 'action_view'
2
+ require 'mandrill_mailer/mock'
2
3
  require 'mandrill_mailer/transactional_mailer'
3
4
  require 'mandrill_mailer/version'
4
5
 
@@ -0,0 +1,4 @@
1
+ module MandrillMailer
2
+ class Mock < OpenStruct
3
+ end
4
+ end
@@ -229,28 +229,6 @@ module MandrillMailer
229
229
 
230
230
  protected
231
231
 
232
- # Public: Url helper for creating OpenStruct compatible urls
233
- # This is used for making sure urls will still work with
234
- # OpenStructs used in the email testing code
235
- #
236
- # OpenStruct should have a .url property to work with this
237
- #
238
- # object - Object that would normally be passed into the route helper
239
- # route_helper - The route helper as a symbol needed for the url
240
- #
241
- # Examples
242
- #
243
- # 'VIDEO_URL' => open_struct_url(video, :code_tv_video_url)
244
- #
245
- # Returns the url as a string
246
- def test_friendly_url(object, route_helper)
247
- if object.kind_of? OpenStruct
248
- object.url
249
- else
250
- method(route_helper).call(object)
251
- end
252
- end
253
-
254
232
  # Makes this class act as a singleton without it actually being a singleton
255
233
  # This keeps the syntax the same as the orginal mailers so we can swap quickly if something
256
234
  # goes wrong.
@@ -263,10 +241,22 @@ module MandrillMailer
263
241
  super || instance_methods.include?(method)
264
242
  end
265
243
 
266
- # Proxy route helpers to rails if Rails exists
244
+ # Proxy route helpers to rails if Rails exists. Doing routes this way
245
+ # makes it so this gem doesn't need to be a rails engine
267
246
  def method_missing(method, *args)
268
247
  return super unless defined?(Rails) && Rails.application.routes.url_helpers.respond_to?(method)
269
- Rails.application.routes.url_helpers.method(method).call(*args, host: @@url_host)
248
+ # Check to see if one of the args is an open struct. If it is, we'll assume it's the
249
+ # test stub and try to call a path or url attribute.
250
+ if args.any? {|arg| arg.kind_of?(MandrillMailer::Mock)}
251
+ # take the first OpenStruct found in args and look for .url or.path
252
+ args.each do |arg|
253
+ if arg.kind_of?(MandrillMailer::Mock)
254
+ break arg.url || arg.path
255
+ end
256
+ end
257
+ else
258
+ Rails.application.routes.url_helpers.method(method).call(*args, host: @@url_host)
259
+ end
270
260
  end
271
261
 
272
262
  def image_path(image)
@@ -1,3 +1,3 @@
1
1
  module MandrillMailer
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mandrill_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -87,8 +87,10 @@ files:
87
87
  - Gemfile.lock
88
88
  - README.md
89
89
  - lib/mandrill_mailer.rb
90
+ - lib/mandrill_mailer/mock.rb
90
91
  - lib/mandrill_mailer/transactional_mailer.rb
91
92
  - lib/mandrill_mailer/version.rb
93
+ - mandrill_mailer-0.0.2.gem
92
94
  - mandrill_mailer.gemspec
93
95
  - spec/mandrill_mailer_spec.rb
94
96
  - spec/spec_helper.rb