sendwithus_ruby_action_mailer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +84 -0
- data/Rakefile +11 -0
- data/lib/send_with_us_mailer/base.rb +144 -0
- data/lib/send_with_us_mailer/mail_params.rb +46 -0
- data/lib/send_with_us_mailer/version.rb +3 -0
- data/lib/send_with_us_mailer.rb +3 -0
- data/send_with_us_mailer.gemspec +27 -0
- data/test/lib/send_with_us_mailer/base_test.rb +70 -0
- data/test/lib/send_with_us_mailer/integration_test.rb +112 -0
- data/test/lib/send_with_us_mailer/mail_params_test.rb +65 -0
- data/test/test_helper.rb +3 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cb92d4846ee580488478b70d1a9149e19493186a
|
4
|
+
data.tar.gz: f6373e3336cb4071df22121e0ee1c79dacc4812f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b73e0d6cfa96393ebb545912e01910fb9478c047d7702e2a634127bfe33bff2c55da2cbcafdc8f8210df1281565c2d68dc400c7497231cb5524a8b6a42e71b76
|
7
|
+
data.tar.gz: 55b6a04bd2025fd875a9909a9550c32eba8140f90220fd2cb3200fbfa95d9a5cee46ebb33c50b313e061e226a7040c3ab8a882cd1d6482f3e313bf1e70007466
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 David Lokhorst
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# SendWithUsMailer
|
2
|
+
|
3
|
+
[Send With Us](http://sendwithus.com) is a service that provides a convenient way for non-developers to create and edit
|
4
|
+
the email content from your app. Send With Us created a gem, `send_with_us`, that communicates to
|
5
|
+
their service using their low-level RESTful API.
|
6
|
+
|
7
|
+
Ruby on Rails developers are familiar with the ActionMailer interface for sending email. This
|
8
|
+
gem implements a small layer over the `send_with_us` gem that provides and ActionMailer-like API.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'send_with_us_mailer'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install send_with_us_mailer
|
23
|
+
|
24
|
+
## Setup
|
25
|
+
|
26
|
+
(TODO)
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Mailer models inherit from `SendWithUsMailer::Base`. A mailer model defines methods
|
31
|
+
used to generate an email message. In these methods, you can assign variables to be sent to
|
32
|
+
the Send With Us service and options on the mail itself such as the `:from` address.
|
33
|
+
|
34
|
+
`````Ruby
|
35
|
+
class Notifier < SendWithUsMailer::Base
|
36
|
+
default from: 'no-reply@example.com'
|
37
|
+
|
38
|
+
def welcome(recipient)
|
39
|
+
assign(:account, recipient)
|
40
|
+
mail(email_id: 'ID-CODE-FROM-SEND-WITH-US', recipient_address: recipient.email)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
`````
|
44
|
+
|
45
|
+
Within the mailer method, you have access to the following methods:
|
46
|
+
|
47
|
+
* `assign` - Allows you to assign key-value pairs that will be
|
48
|
+
data payload used by Send With Us within the email.
|
49
|
+
* `mail` - Allows you to specify the email to be sent.
|
50
|
+
|
51
|
+
|
52
|
+
### Sending mail
|
53
|
+
|
54
|
+
Once a mailer action is defined, you can deliver your message or create it and save it
|
55
|
+
for delivery later:
|
56
|
+
|
57
|
+
`````Ruby
|
58
|
+
Notifier.welcome(david).deliver # sends the email
|
59
|
+
|
60
|
+
mail = Notifier.welcome(david) # => a SendWithUsMailer::MailParams object
|
61
|
+
mail.deliver # sends the email
|
62
|
+
`````
|
63
|
+
|
64
|
+
You never instantiate your mailer class. Rather, you just call the method you defined
|
65
|
+
on the class itself.
|
66
|
+
|
67
|
+
|
68
|
+
### Default Hash
|
69
|
+
|
70
|
+
SendWithUsMailer allows you to specify default values inside the class definition:
|
71
|
+
|
72
|
+
`````Ruby
|
73
|
+
class Notifier < SendWithUsMailer::Base
|
74
|
+
default from: 'system@example.com'
|
75
|
+
end
|
76
|
+
`````
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
1. Fork it
|
81
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
82
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
83
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
84
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
module SendWithUsMailer
|
2
|
+
# Mailer models inherit from <tt>SendWithUsMailer::Base</tt>. A mailer model defines methods
|
3
|
+
# used to generate an email message. In these methods, you can assign variables to be sent to
|
4
|
+
# the Send With Us service and options on the mail itself such as the <tt>:from</tt> address.
|
5
|
+
#
|
6
|
+
# class Notifier < SendWithUsMailer::Base
|
7
|
+
# default from: 'no-reply@example.com'
|
8
|
+
#
|
9
|
+
# def welcome(recipient)
|
10
|
+
# assign(:account, recipient)
|
11
|
+
# mail(email_id: 'ID-CODE-FROM-SEND-WITH-US', to: recipient.email)
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# Within the mailer method, you have access to the following methods:
|
16
|
+
#
|
17
|
+
# * <tt>assign</tt> - Allows you to assign key-value pairs that will be
|
18
|
+
# data payload used by SendWithUs to interpolate the content.
|
19
|
+
# * <tt>mail</tt> - Allows you to specify email to be sent.
|
20
|
+
#
|
21
|
+
# The mail method is used to set the header parameters.
|
22
|
+
#
|
23
|
+
#
|
24
|
+
# = Sending mail
|
25
|
+
#
|
26
|
+
# Once a mailer action is defined, you can deliver your message or create it and save it
|
27
|
+
# for delivery later:
|
28
|
+
#
|
29
|
+
# Notifier.welcome(david).deliver # sends the email
|
30
|
+
# mail = Notifier.welcome(david) # => a SendWithUsMailer::MailParams object
|
31
|
+
# mail.deliver # sends the email
|
32
|
+
#
|
33
|
+
# You never instantiate your mailer class. Rather, you just call the method you defined
|
34
|
+
# on the class itself.
|
35
|
+
#
|
36
|
+
#
|
37
|
+
# = Default Hash
|
38
|
+
#
|
39
|
+
# SendWithUsMailer allows you to specify default values inside the class definition:
|
40
|
+
#
|
41
|
+
# class Notifier < SendWithUsMailer::Base
|
42
|
+
# default from: 'system@example.com'
|
43
|
+
# end
|
44
|
+
class Base
|
45
|
+
|
46
|
+
#---------------------- Singleton methods ----------------------------
|
47
|
+
class << self
|
48
|
+
def defaults
|
49
|
+
@defaults || {}
|
50
|
+
end
|
51
|
+
|
52
|
+
# Set default values for any of the parameters passed to the <tt>#mail</tt>
|
53
|
+
# method. For example:
|
54
|
+
#
|
55
|
+
# class Notifier < SendWithUsMailer::Base
|
56
|
+
# default from: 'no-reply@test.lindsaar.net',
|
57
|
+
# reply_to: 'bounces@test.lindsaar.net'
|
58
|
+
# end
|
59
|
+
def default(value = nil)
|
60
|
+
@defaults = defaults.merge(value)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Return the mailer methods that are defined in any instance
|
64
|
+
# of <tt>SendWithUsMailer::Base</tt>. There should not be
|
65
|
+
# any reason to call this directly.
|
66
|
+
def mailer_methods
|
67
|
+
public_instance_methods - superclass.public_instance_methods
|
68
|
+
end
|
69
|
+
|
70
|
+
# We use <tt>::method_missing</tt> to delegate
|
71
|
+
# mailer methods to a new instance and return the
|
72
|
+
# <tt>SendWithUsMailer::MailParams</tt> object.
|
73
|
+
def method_missing(method_name, *args)
|
74
|
+
if mailer_methods.include?(method_name.to_sym)
|
75
|
+
new(method_name, *args).message
|
76
|
+
else
|
77
|
+
super
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
#----------------------- Instance methods ----------------------------
|
83
|
+
attr_reader :message
|
84
|
+
|
85
|
+
# Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
|
86
|
+
# will be initialized according to the named method.
|
87
|
+
def initialize(method_name, *args)
|
88
|
+
@message = MailParams.new
|
89
|
+
self.send(method_name, *args)
|
90
|
+
end
|
91
|
+
|
92
|
+
# The main method that creates the message parameters. The method accepts
|
93
|
+
# a headers hash. This hash allows you to specify the certain headers
|
94
|
+
# in an email message, these are:
|
95
|
+
#
|
96
|
+
# * <tt>:email_id</tt> - The unique code associated with the SendWithUs specific email.
|
97
|
+
# * <tt>:recipient_address</tt> - Who the message is destined for. Must be a valid email address.
|
98
|
+
# * <tt>:recipient_name</tt> - Recipient's name
|
99
|
+
# * <tt>:from_address</tt> - Who the message is from. Must be a valid email address.
|
100
|
+
# * <tt>:from_name</tt> - Who the email is from
|
101
|
+
# * <tt>:reply_to</tt> - Who to set the Reply-To header of the email to.
|
102
|
+
#
|
103
|
+
# You can set default values for any of the above headers by using the <tt>::default</tt>
|
104
|
+
# class method.
|
105
|
+
#
|
106
|
+
# For example:
|
107
|
+
#
|
108
|
+
# class Notifier < ActionMailer::Base
|
109
|
+
# default from: 'no-reply@test.example.net'
|
110
|
+
#
|
111
|
+
# def welcome
|
112
|
+
# mail(email_id: 'EMAIL_ID from Send With Us', to: 'dave@test.example.net')
|
113
|
+
# end
|
114
|
+
# end
|
115
|
+
def mail(params = {})
|
116
|
+
@message.merge!(self.class.defaults.merge(params))
|
117
|
+
end
|
118
|
+
|
119
|
+
# Assign variables that will be sent in the payload to Send With Us.
|
120
|
+
#
|
121
|
+
# For example:
|
122
|
+
#
|
123
|
+
# class Notifier < ActionMailer::Base
|
124
|
+
# def welcome
|
125
|
+
#
|
126
|
+
# assign :login_url, "http://thefastguys.example.com"
|
127
|
+
# assign :user, {name: "Dave Lokhorst", role: "admin"}
|
128
|
+
# assign :team, {name: "The Fast Guys", captain: "Joe"}
|
129
|
+
#
|
130
|
+
# mail(email_id: 'EMAIL_ID from Send With Us', to: 'dave@test.example.net')
|
131
|
+
# end
|
132
|
+
# end
|
133
|
+
#
|
134
|
+
# makes the following parameters accessible to the Send With Us email:
|
135
|
+
# {{ login_url }} => "http://thefastguys.example.com"
|
136
|
+
# {{ user.name }} => "Dave Lokhorst"
|
137
|
+
# {{ user.role }} => "admin"
|
138
|
+
# {{ team.name }} => "The Fast Guys"
|
139
|
+
# {{ team.captain }} => "Joe"
|
140
|
+
def assign(key, value)
|
141
|
+
@message.assign(key, value)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "send_with_us"
|
2
|
+
|
3
|
+
module SendWithUsMailer
|
4
|
+
class MailParams
|
5
|
+
attr_reader :to, :from, :email_id, :email_data
|
6
|
+
|
7
|
+
def initialize #:nodoc:
|
8
|
+
@email_data = {}
|
9
|
+
@to = {}
|
10
|
+
@from = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def assign(key, value) #:nodoc:
|
14
|
+
@email_data.merge!( key.to_sym => value )
|
15
|
+
end
|
16
|
+
|
17
|
+
def merge!(params={}) #:nodoc:
|
18
|
+
params.each_pair do |key, value|
|
19
|
+
case key
|
20
|
+
when :email_id
|
21
|
+
@email_id = value
|
22
|
+
when :recipient_name
|
23
|
+
@to.merge!(name: value)
|
24
|
+
when :recipient_address
|
25
|
+
@to.merge!(address: value)
|
26
|
+
when :from_name
|
27
|
+
@from.merge!(name: value)
|
28
|
+
when :from_address
|
29
|
+
@from.merge!(address: value)
|
30
|
+
when :reply_to
|
31
|
+
@from.merge!(reply_to: value)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Invoke <tt>SendWithUs::Api</tt> to deliver the message.
|
37
|
+
# The <tt>SendWithUs</tt> module is implemented in the +send_with_us+ gem.
|
38
|
+
#
|
39
|
+
# IMPORTANT NOTE: <tt>SendWithUs</tt> must be configured prior to calling this method.
|
40
|
+
# In particular, the +api_key+ must be set (following the guidelines in the
|
41
|
+
# +send_with_us+ documentation).
|
42
|
+
def deliver
|
43
|
+
SendWithUs::Api.new.send_with(@email_id, @to, @email_data, @from)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'send_with_us_mailer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "sendwithus_ruby_action_mailer"
|
8
|
+
gem.version = SendWithUsMailer::VERSION
|
9
|
+
gem.authors = ["David Lokhorst", "Nicholas Rempel"]
|
10
|
+
gem.email = ["nick@sendwithus.com"]
|
11
|
+
gem.description = %q{A convenient way to use the Send With Us email
|
12
|
+
service with a Ruby on Rails app. SendWilthUsMailer implements a
|
13
|
+
mailer API similar to the ActionMailer railtie.}
|
14
|
+
gem.summary = %q{An ActionMailer look alike for Send With Us.}
|
15
|
+
gem.homepage = 'http://github.com/nrempel/SendWithUs-Mailer'
|
16
|
+
gem.license = 'MIT'
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split($/)
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
|
+
gem.require_paths = ["lib"]
|
22
|
+
|
23
|
+
gem.add_runtime_dependency 'send_with_us'
|
24
|
+
gem.add_development_dependency 'rake'
|
25
|
+
gem.add_development_dependency 'minitest-colorize'
|
26
|
+
gem.add_development_dependency 'mocha'
|
27
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe SendWithUsMailer::Base do
|
4
|
+
class FirstMailer < SendWithUsMailer::Base
|
5
|
+
def send_an_email; end
|
6
|
+
end
|
7
|
+
|
8
|
+
class SecondMailer < SendWithUsMailer::Base
|
9
|
+
def send_a_second_email; end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "::default" do
|
13
|
+
it "responds to default" do
|
14
|
+
SendWithUsMailer::Base.must_respond_to :default
|
15
|
+
FirstMailer.must_respond_to :default
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "::mailer_methods" do
|
20
|
+
it "finds the instance methods defined in the classes" do
|
21
|
+
FirstMailer.mailer_methods.must_include(:send_an_email)
|
22
|
+
SecondMailer.mailer_methods.must_include(:send_a_second_email)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "does not include instance methods from other mailers" do
|
26
|
+
FirstMailer.mailer_methods.wont_include(:send_a_second_email)
|
27
|
+
SecondMailer.mailer_methods.wont_include(:send_an_email)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "does not include the Base class instance methods" do
|
31
|
+
SendWithUsMailer::Base.public_instance_methods.each do |method|
|
32
|
+
FirstMailer.mailer_methods.wont_include(method)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "methods should be called on the class object" do
|
38
|
+
class ThirdMailer < SendWithUsMailer::Base
|
39
|
+
def send_an_email(a=nil,b=nil) # an instance method
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "class wraps the call to the mailer method (which is an instance method)" do
|
44
|
+
ThirdMailer.any_instance.expects(:send_an_email)
|
45
|
+
ThirdMailer.send_an_email
|
46
|
+
end
|
47
|
+
|
48
|
+
it "calls to mailer methods return a MailParams object" do
|
49
|
+
FirstMailer.send_an_email.must_be_kind_of SendWithUsMailer::MailParams
|
50
|
+
end
|
51
|
+
|
52
|
+
it "relays the arguments to the instance" do
|
53
|
+
ThirdMailer.any_instance.expects(:send_an_email).with("a","b")
|
54
|
+
ThirdMailer.send_an_email("a","b")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#assign" do
|
59
|
+
class MailerWithAssign < SendWithUsMailer::Base
|
60
|
+
def example
|
61
|
+
assign :user, "dave"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "delegates the method to its message" do
|
66
|
+
SendWithUsMailer::MailParams.any_instance.expects(:assign)
|
67
|
+
MailerWithAssign.example
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe SendWithUsMailer do
|
4
|
+
describe "minimum requirements" do
|
5
|
+
class ExampleMailer < SendWithUsMailer::Base
|
6
|
+
def send_an_email
|
7
|
+
mail email_id: '4bBEddKbhKBu5xsU2p58KX', recipient_address: 'dave@example.com', recipient_name: 'dave'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "sets the email_id" do
|
12
|
+
mail = ExampleMailer.send_an_email
|
13
|
+
mail.email_id.must_equal '4bBEddKbhKBu5xsU2p58KX'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "sets the recipient" do
|
17
|
+
mail = ExampleMailer.send_an_email
|
18
|
+
mail.to[:address].must_equal 'dave@example.com'
|
19
|
+
mail.to[:name].must_equal 'dave'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "more mail options" do
|
24
|
+
class MoreOptionsMailer < SendWithUsMailer::Base
|
25
|
+
def example_email
|
26
|
+
mail email_id: 'a4bBEddKbhKBu5xsU2p58KX',
|
27
|
+
to: 'adave@example.com',
|
28
|
+
from_address: 'asender@company.com',
|
29
|
+
from_name: 'asender',
|
30
|
+
reply_to: 'ano-reply@company.com'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "sets the sender" do
|
35
|
+
mail = MoreOptionsMailer.example_email
|
36
|
+
mail.from[:address].must_equal 'asender@company.com'
|
37
|
+
mail.from[:name].must_equal 'asender'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "sets the reply-to address" do
|
41
|
+
mail = MoreOptionsMailer.example_email
|
42
|
+
mail.from[:reply_to].must_equal 'ano-reply@company.com'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "using default to set a parameter" do
|
47
|
+
class MailerWithDefault < SendWithUsMailer::Base
|
48
|
+
default email_id: 'def-4bBEddKbhKBu5xsU2p58KX'
|
49
|
+
|
50
|
+
def send_an_email
|
51
|
+
mail recipient_address: 'def-dave@example.com'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it "sets the email_id" do
|
56
|
+
mail = MailerWithDefault.send_an_email
|
57
|
+
mail.email_id.must_equal 'def-4bBEddKbhKBu5xsU2p58KX'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "sets the recipient" do
|
61
|
+
mail = MailerWithDefault.send_an_email
|
62
|
+
mail.to[:address].must_equal 'def-dave@example.com'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "all parameters can be set by default" do
|
67
|
+
class AllDefaultMailer < SendWithUsMailer::Base
|
68
|
+
default email_id: 'all4bBEddKbhKBu5xsU2p58KX',
|
69
|
+
recipient_address: 'alldave@example.com',
|
70
|
+
recipient_name: 'alldave',
|
71
|
+
from: 'allsender@company.com',
|
72
|
+
reply_to: 'allno-reply@company.com'
|
73
|
+
|
74
|
+
def send_default_email
|
75
|
+
mail
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "sets the email_id" do
|
80
|
+
mail = AllDefaultMailer.send_default_email
|
81
|
+
mail.email_id.must_equal 'all4bBEddKbhKBu5xsU2p58KX'
|
82
|
+
end
|
83
|
+
|
84
|
+
it "sets the recipient" do
|
85
|
+
mail = AllDefaultMailer.send_default_email
|
86
|
+
mail.to[:address].must_equal 'alldave@example.com'
|
87
|
+
mail.to[:name].must_equal 'alldave'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "using #assign" do
|
92
|
+
User = Struct.new(:first_name, :last_name, :email)
|
93
|
+
|
94
|
+
class MailerWithAssign < SendWithUsMailer::Base
|
95
|
+
default email_id: '4bBEddKbhKBu5xsU2p58KX'
|
96
|
+
|
97
|
+
def team_notification(user)
|
98
|
+
assign :team, "The Winners"
|
99
|
+
assign :user, {first_name: user.first_name, last_name: user.last_name}
|
100
|
+
mail recipient_address: user.email
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "creates the nested email_data hash" do
|
105
|
+
mail = MailerWithAssign.team_notification(User.new("Dave","Lokhorst","dave@example.com"))
|
106
|
+
mail.email_data.must_equal({
|
107
|
+
team: "The Winners",
|
108
|
+
user: {first_name: "Dave", last_name: "Lokhorst"}
|
109
|
+
})
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe SendWithUsMailer::MailParams do
|
4
|
+
subject { SendWithUsMailer::MailParams.new }
|
5
|
+
|
6
|
+
describe "initialization" do
|
7
|
+
it "email_data is empty on initialization" do
|
8
|
+
subject.email_data.empty?.must_equal true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#assign" do
|
13
|
+
let(:ep) { SendWithUsMailer::MailParams.new }
|
14
|
+
|
15
|
+
it "adds (key,value) pairs to :email_data Hash" do
|
16
|
+
ep.assign(:user, {:name => "Dave", :email => "dave@example.com"})
|
17
|
+
ep.email_data.must_equal({
|
18
|
+
:user => {:name => "Dave", :email => "dave@example.com"}
|
19
|
+
})
|
20
|
+
|
21
|
+
ep.assign(:url, "http://test.example.com")
|
22
|
+
ep.email_data.must_equal({
|
23
|
+
:user => {:name => "Dave", :email => "dave@example.com"},
|
24
|
+
:url => "http://test.example.com"
|
25
|
+
})
|
26
|
+
end
|
27
|
+
|
28
|
+
it "symbolizes the keys" do
|
29
|
+
ep.assign("company", "Big Co Inc")
|
30
|
+
ep.email_data.has_key?(:company).must_equal true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#email_id" do
|
35
|
+
it "is readable" do
|
36
|
+
subject.respond_to?(:email_id).must_equal true
|
37
|
+
subject.respond_to?(:email_id=).must_equal false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#to" do
|
42
|
+
it "is readable" do
|
43
|
+
subject.respond_to?(:to).must_equal true
|
44
|
+
subject.respond_to?(:to=).must_equal false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#from" do
|
49
|
+
it "is readable" do
|
50
|
+
subject.respond_to?(:from).must_equal true
|
51
|
+
subject.respond_to?(:from=).must_equal false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#deliver" do
|
56
|
+
it "method exists" do
|
57
|
+
subject.respond_to?(:deliver).must_equal true
|
58
|
+
end
|
59
|
+
|
60
|
+
it "calls the send_with_us gem" do
|
61
|
+
SendWithUs::Api.any_instance.expects(:send_with)
|
62
|
+
subject.deliver
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sendwithus_ruby_action_mailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Lokhorst
|
8
|
+
- Nicholas Rempel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-01-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: send_with_us
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest-colorize
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: mocha
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: |-
|
71
|
+
A convenient way to use the Send With Us email
|
72
|
+
service with a Ruby on Rails app. SendWilthUsMailer implements a
|
73
|
+
mailer API similar to the ActionMailer railtie.
|
74
|
+
email:
|
75
|
+
- nick@sendwithus.com
|
76
|
+
executables: []
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- .gitignore
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- lib/send_with_us_mailer.rb
|
86
|
+
- lib/send_with_us_mailer/base.rb
|
87
|
+
- lib/send_with_us_mailer/mail_params.rb
|
88
|
+
- lib/send_with_us_mailer/version.rb
|
89
|
+
- send_with_us_mailer.gemspec
|
90
|
+
- test/lib/send_with_us_mailer/base_test.rb
|
91
|
+
- test/lib/send_with_us_mailer/integration_test.rb
|
92
|
+
- test/lib/send_with_us_mailer/mail_params_test.rb
|
93
|
+
- test/test_helper.rb
|
94
|
+
homepage: http://github.com/nrempel/SendWithUs-Mailer
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.0.6
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: An ActionMailer look alike for Send With Us.
|
118
|
+
test_files:
|
119
|
+
- test/lib/send_with_us_mailer/base_test.rb
|
120
|
+
- test/lib/send_with_us_mailer/integration_test.rb
|
121
|
+
- test/lib/send_with_us_mailer/mail_params_test.rb
|
122
|
+
- test/test_helper.rb
|