mandrill_mailer 0.1.10 → 0.2.1

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/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mandrill_mailer (0.0.2)
4
+ mandrill_mailer (0.2.0)
5
5
  actionpack
6
6
  activesupport
7
+ mailchimp (= 0.0.7.alpha)
7
8
 
8
9
  GEM
9
10
  remote: http://rubygems.org/
@@ -29,10 +30,16 @@ GEM
29
30
  diff-lcs (1.1.3)
30
31
  erubis (2.7.0)
31
32
  hike (1.2.1)
33
+ httparty (0.9.0)
34
+ multi_json (~> 1.0)
35
+ multi_xml
32
36
  i18n (0.6.1)
33
37
  journey (1.0.4)
38
+ mailchimp (0.0.7.alpha)
39
+ httparty
34
40
  method_source (0.8)
35
41
  multi_json (1.3.6)
42
+ multi_xml (0.5.1)
36
43
  pry (0.9.10)
37
44
  coderay (~> 1.0.5)
38
45
  method_source (~> 0.8)
@@ -40,7 +47,7 @@ GEM
40
47
  rack (1.4.1)
41
48
  rack-cache (1.2)
42
49
  rack (>= 0.4)
43
- rack-test (0.6.1)
50
+ rack-test (0.6.2)
44
51
  rack (>= 1.0)
45
52
  rspec (2.11.0)
46
53
  rspec-core (~> 2.11.0)
data/README.md CHANGED
@@ -3,7 +3,6 @@ MandrilMailer class for sending transactional emails through mandril.
3
3
  Only template based emails are supported at this time.
4
4
 
5
5
  ## Usage
6
- Add `gem 'mailchimp'`
7
6
  Add `gem 'mandrill_mailer'` to your Gemfile
8
7
 
9
8
  Add this to your `mail.rb` in initializers.
@@ -5,15 +5,22 @@ require 'mandrill_mailer/template_mailer'
5
5
  require 'mandrill_mailer/version'
6
6
 
7
7
  module MandrillMailer
8
- def self.configure(&block)
9
- if block_given?
10
- block.call(MandrillMailer::Railtie.config.mandrill_mailer)
11
- else
12
- MandrillMailer::Railtie.config.mandrill_mailer
8
+ if defined?(Rails)
9
+ def self.configure(&block)
10
+ if block_given?
11
+ block.call(MandrillMailer::Railtie.config.mandrill_mailer)
12
+ else
13
+ MandrillMailer::Railtie.config.mandrill_mailer
14
+ end
13
15
  end
14
- end
15
16
 
16
- def self.config
17
- MandrillMailer::Railtie.config.mandrill_mailer
17
+ def self.config
18
+ MandrillMailer::Railtie.config.mandrill_mailer
19
+ end
20
+ else
21
+ def self.config
22
+ @@config ||= OpenStruct.new(api_key: nil)
23
+ @@config
24
+ end
18
25
  end
19
26
  end
@@ -1,3 +1,4 @@
1
+ require 'ostruct'
1
2
  module MandrillMailer
2
3
  class Mock < OpenStruct
3
4
  end
@@ -1,7 +1,8 @@
1
- require 'rails'
2
-
3
- module MandrillMailer
4
- class Railtie < Rails::Railtie
5
- config.mandrill_mailer = ActiveSupport::OrderedOptions.new
1
+ if defined?(Rails)
2
+ require 'rails'
3
+ module MandrillMailer
4
+ class Railtie < Rails::Railtie
5
+ config.mandrill_mailer = ActiveSupport::OrderedOptions.new
6
+ end
6
7
  end
7
8
  end
@@ -251,7 +251,11 @@ module MandrillMailer
251
251
  end
252
252
 
253
253
  def image_path(image)
254
- ActionController::Base.helpers.asset_path(image)
254
+ if defined? Rails
255
+ ActionController::Base.helpers.asset_path(image)
256
+ else
257
+ method_missing(:image_path, image)
258
+ end
255
259
  end
256
260
 
257
261
  def image_url(image)
@@ -278,7 +282,7 @@ module MandrillMailer
278
282
 
279
283
  # single to params item
280
284
  def to_params_item(item)
281
- return {"email" => item, "name" => "Code School Customer"} unless item.kind_of? Hash
285
+ return {"email" => item, "name" => item} unless item.kind_of? Hash
282
286
  item
283
287
  end
284
288
 
@@ -1,3 +1,3 @@
1
1
  module MandrillMailer
2
- VERSION = "0.1.10"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -19,6 +19,9 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_dependency 'activesupport'
21
21
  s.add_dependency 'actionpack'
22
+ s.add_dependency 'mailchimp', '0.0.7.alpha'
23
+
22
24
  s.add_development_dependency 'pry'
23
25
  s.add_development_dependency 'rspec'
26
+
24
27
  end
@@ -0,0 +1,71 @@
1
+ # Public: This fake rails class is used to test things such as the method_missing route proxy
2
+ # and image_url helpers
3
+ #
4
+ # Use Rails.unload! to 'unrequire' this class, you should call this after every test
5
+ # which uses it so other tests aren't polluted by having a Rails class defined
6
+ #
7
+ # You can define routes to be used in testing by doing:
8
+ #
9
+ # Rails.application.routes.draw do |builder|
10
+ # builder.course_url "/course/1"
11
+ # end
12
+ #
13
+ # So then sending the course url helper to the mailer will return the desired url.
14
+ #
15
+ # In order to use the url helpers, the MandrillMailer.config.default_url_options[:host]
16
+ # option needs to be set. So you can set it to something like:
17
+ #
18
+ # MandrillMailer.config.default_url_options[:host] = 'localhost'
19
+ #
20
+ class Rails
21
+ def self.unload!
22
+ Object.send(:remove_const, :Rails)
23
+ Object.send(:remove_const, :ActionController)
24
+ end
25
+ # Rails.application.routes.url_helpers
26
+ def self.application
27
+ self
28
+ end
29
+
30
+ def self.routes
31
+ self
32
+ end
33
+
34
+ def self.url_helpers
35
+ @@url_helpers
36
+ end
37
+
38
+ def self.draw(&block)
39
+ @@url_helpers = RouteBuilder.new(block)
40
+ end
41
+
42
+ def self.default_url_options
43
+ @@url_options ||= {}
44
+ end
45
+
46
+ class RouteBuilder
47
+ def initialize(routes_proc)
48
+ routes_proc.call(self)
49
+ end
50
+
51
+ def method_missing(method, *args)
52
+ define_singleton_method(method) do |*method_args|
53
+ internal_args = args || ['']
54
+ "http://#{method_args.extract_options![:host]}#{internal_args.first}"
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ # ActionController::Base.helpers.asset_path(image)
61
+ module ActionController
62
+ class Base
63
+ def self.helpers
64
+ self
65
+ end
66
+
67
+ def self.asset_path(asset)
68
+ "http://#{Rails.default_url_options[:host]}assets/#{asset}"
69
+ end
70
+ end
71
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rspec'
2
2
  require 'mandrill_mailer'
3
+ require 'pry'
3
4
 
4
5
  # Requires supporting files with custom matchers and macros, etc,
5
6
  # in ./support/ and its subdirectories.
@@ -12,14 +12,37 @@ describe MandrillMailer::TemplateMailer do
12
12
  MandrillMailer.config.any_instance.stub(:image_path).and_return(image_path)
13
13
  end
14
14
 
15
- # this only works from within a Rails application
16
- # describe '#image_url' do
17
- # subject { mailer.send(:image_url, 'image.jpg') }
15
+ describe '#image_path' do
16
+ subject { mailer.image_path('logo.png') }
17
+
18
+ context 'Rails exists' do
19
+ let(:image) { 'image.png' }
20
+ let(:host) { 'codeschool.com' }
21
+ let(:router) { Rails.application.routes.url_helpers }
22
+
23
+ before do
24
+ # use load instead of require since we have to reload for every test
25
+ mailer.send(:load, 'fake_rails/fake_rails.rb')
26
+ MandrillMailer.config.default_url_options[:host] = host
27
+ end
28
+
29
+ # Essentially un-requiring the fake rails class so it doesn't pollute
30
+ # the rest of the tests
31
+ after do
32
+ Rails.unload!
33
+ end
18
34
 
19
- # it 'should return the full path to the image' do
20
- # should eq "http://#{default_host}#{image_path}"
21
- # end
22
- # end
35
+ it 'should return the image url' do
36
+ mailer.send(:image_path, image).should eq ActionController::Base.asset_path(image)
37
+ end
38
+ end
39
+
40
+ context 'Rails does not exist' do
41
+ it 'should raise exception' do
42
+ ->{ subject }.should raise_error
43
+ end
44
+ end
45
+ end
23
46
 
24
47
  describe '#mandrill_args' do
25
48
  let(:arg_name) { 'USER_NAME' }
@@ -35,13 +58,12 @@ describe MandrillMailer::TemplateMailer do
35
58
  describe '#format_to_params' do
36
59
  let(:email) { 'bob@email.com' }
37
60
  let(:name) { 'bob' }
38
- let(:default_name) { 'Code School Customer' }
39
61
 
40
62
  context 'with a single email string' do
41
63
  subject { mailer.send(:format_to_params, email) }
42
64
 
43
65
  it 'should format args to a format mandrill likes' do
44
- should eq [{"email" => email, "name" => default_name}]
66
+ should eq [{"email" => email, "name" => email}]
45
67
  end
46
68
  end
47
69
 
@@ -49,7 +71,7 @@ describe MandrillMailer::TemplateMailer do
49
71
  subject { mailer.send(:format_to_params, [email]) }
50
72
 
51
73
  it 'should format args to a format mandrill likes' do
52
- should eq [{"email" => email, "name" => default_name}]
74
+ should eq [{"email" => email, "name" => email}]
53
75
  end
54
76
  end
55
77
 
@@ -129,4 +151,45 @@ describe MandrillMailer::TemplateMailer do
129
151
  })
130
152
  end
131
153
  end
154
+
155
+ describe 'url helpers in mailer' do
156
+ subject { mailer.send(:course_url) }
157
+
158
+ context 'Rails is defined (Rails app)' do
159
+ let(:url) { '/courses/1' }
160
+ let(:host) { 'codeschool.com' }
161
+ let(:router) { Rails.application.routes.url_helpers }
162
+
163
+ before do
164
+ # use load since we are loading multiple times
165
+ mailer.send(:load, 'fake_rails/fake_rails.rb')
166
+ MandrillMailer.config.default_url_options[:host] = host
167
+ Rails.application.routes.draw do |builder|
168
+ builder.course_url "#{url}"
169
+ end
170
+ end
171
+
172
+ # Essentially un-requiring the fake rails class so it doesn't pollute
173
+ # the rest of the tests
174
+ after do
175
+ Rails.unload!
176
+ end
177
+
178
+ it 'should return the correct route' do
179
+ subject.should eq router.course_url(host: host)
180
+ end
181
+
182
+ context 'route helper with an argument' do
183
+ it 'should return the correct route' do
184
+ subject.should eq router.course_url({id: 1, title: 'zombies'}, host: host)
185
+ end
186
+ end
187
+ end
188
+
189
+ context 'Rails is not defined' do
190
+ it 'should raise an exception' do
191
+ ->{subject}.should raise_error
192
+ end
193
+ end
194
+ end
132
195
  end
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.1.10
4
+ version: 0.2.1
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: 2012-09-28 00:00:00.000000000 Z
12
+ date: 2012-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mailchimp
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.7.alpha
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.7.alpha
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: pry
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -83,6 +99,7 @@ extensions: []
83
99
  extra_rdoc_files: []
84
100
  files:
85
101
  - .gitignore
102
+ - .rspec
86
103
  - Gemfile
87
104
  - Gemfile.lock
88
105
  - README.md
@@ -93,8 +110,9 @@ files:
93
110
  - lib/mandrill_mailer/version.rb
94
111
  - mandrill_mailer-0.0.2.gem
95
112
  - mandrill_mailer.gemspec
96
- - spec/mandrill_mailer_spec.rb
113
+ - spec/fake_rails/fake_rails.rb
97
114
  - spec/spec_helper.rb
115
+ - spec/template_mailer_spec.rb
98
116
  homepage: https://github.com/renz45/mandrill_mailer
99
117
  licenses: []
100
118
  post_install_message:
@@ -120,5 +138,6 @@ signing_key:
120
138
  specification_version: 3
121
139
  summary: Transactional Mailer for Mandrill
122
140
  test_files:
123
- - spec/mandrill_mailer_spec.rb
141
+ - spec/fake_rails/fake_rails.rb
124
142
  - spec/spec_helper.rb
143
+ - spec/template_mailer_spec.rb