the_merger 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.org +2 -1
- data/lib/the_merger/version.rb +1 -1
- data/lib/the_merger.rb +27 -9
- data/spec/lib/the_merger_spec.rb +42 -1
- metadata +4 -4
data/README.org
CHANGED
@@ -75,7 +75,8 @@ Currently it's just one method and this is how you pass it information
|
|
75
75
|
- [X] Create a helper method to have a dropdown of fields
|
76
76
|
- [X] Turn this into an engine so that I can include asset pipeline javascript.
|
77
77
|
- [X] Get the Email all button to work
|
78
|
-
- [
|
78
|
+
- [X] Write tests
|
79
|
+
- [ ] Allow filtering or passing a subset of users to send email to.
|
79
80
|
- [ ] Schedule repetitive mail outs
|
80
81
|
- [ ] Make compatible with tinymce
|
81
82
|
|
data/lib/the_merger/version.rb
CHANGED
data/lib/the_merger.rb
CHANGED
@@ -10,16 +10,34 @@ module TheMerger
|
|
10
10
|
#
|
11
11
|
# Merge the fields into the body and send emails
|
12
12
|
#
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
# Options;
|
14
|
+
# from
|
15
|
+
# subject
|
16
|
+
# body
|
17
|
+
# group (optional subset of users)
|
18
|
+
# single (optional single user)
|
19
|
+
#
|
20
|
+
def mail_merge(opts={})
|
21
|
+
|
22
|
+
# Go through and get the collection to merge & send.
|
23
|
+
if opts[:group] # Subset
|
24
|
+
results = opts[:group]
|
25
|
+
elsif opts[:single] # Single
|
26
|
+
results = [opts[:single]]
|
27
|
+
else # ALL entries in model
|
28
|
+
results = model.all
|
22
29
|
end
|
30
|
+
|
31
|
+
# Go through all results, merge & send.
|
32
|
+
results.each {|user| merge_and_send(opts[:from], opts[:subject], opts[:body].dup, user)}
|
33
|
+
end
|
34
|
+
|
35
|
+
def merge_and_send(from,subject,body,user)
|
36
|
+
# Merge fields for this user into the body
|
37
|
+
body = merge_fields(body, user)
|
38
|
+
|
39
|
+
# Send the emails
|
40
|
+
TheMerger::Mailer.batch_mail(from, subject, body, user).deliver
|
23
41
|
end
|
24
42
|
|
25
43
|
#
|
data/spec/lib/the_merger_spec.rb
CHANGED
@@ -8,7 +8,48 @@ end
|
|
8
8
|
describe TheMerger do
|
9
9
|
|
10
10
|
before do
|
11
|
-
@user = User.create(firstname: "Michael",
|
11
|
+
@user = User.create(firstname: "Michael",
|
12
|
+
lastname: "Pope",
|
13
|
+
email: "map7777@gmail.com",
|
14
|
+
age: 99)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#mail_merge" do
|
18
|
+
before do
|
19
|
+
@second_user = User.create(firstname: "John",
|
20
|
+
lastname: "Smith",
|
21
|
+
email: "john.smith@gmail.com",
|
22
|
+
age: 30)
|
23
|
+
@mailer = double()
|
24
|
+
@mailer.stub(:deliver)
|
25
|
+
end
|
26
|
+
|
27
|
+
context "on model" do
|
28
|
+
it "calls batch twice" do
|
29
|
+
TheMerger::Mailer.should_receive(:batch_mail).twice.and_return(@mailer)
|
30
|
+
mail_merge(from: 'user@example.com', subject: 'test merge', body: 'Hello [firstname]')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "subset of the model" do
|
35
|
+
it "calls batch once" do
|
36
|
+
TheMerger::Mailer.should_receive(:batch_mail).once.and_return(@mailer)
|
37
|
+
mail_merge(from: 'user@example.com',
|
38
|
+
subject: 'test merge',
|
39
|
+
body: 'Hello [firstname]',
|
40
|
+
group: [@user])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "email one user" do
|
45
|
+
it "calls batch once" do
|
46
|
+
TheMerger::Mailer.should_receive(:batch_mail).once.and_return(@mailer)
|
47
|
+
mail_merge(from: 'user@example.com',
|
48
|
+
subject: 'test merge',
|
49
|
+
body: 'Hello [firstname]',
|
50
|
+
single: @user)
|
51
|
+
end
|
52
|
+
end
|
12
53
|
end
|
13
54
|
|
14
55
|
describe "#merge_fields" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_merger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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: 2013-07-
|
12
|
+
date: 2013-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Mail merge a table of fields into a standard letter
|
15
15
|
email:
|
@@ -53,7 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
53
|
version: '0'
|
54
54
|
segments:
|
55
55
|
- 0
|
56
|
-
hash: -
|
56
|
+
hash: -155754027735557007
|
57
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
58
|
none: false
|
59
59
|
requirements:
|
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
62
|
version: '0'
|
63
63
|
segments:
|
64
64
|
- 0
|
65
|
-
hash: -
|
65
|
+
hash: -155754027735557007
|
66
66
|
requirements: []
|
67
67
|
rubyforge_project:
|
68
68
|
rubygems_version: 1.8.23
|