talktome 0.2.0 → 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.
- checksums.yaml +5 -5
- data/lib/talktome/strategy/email.rb +5 -1
- data/lib/talktome/version.rb +1 -1
- data/spec/client/test_local.rb +80 -33
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b12474ba945a8c289bc358c4e654667ac7684618b3c19f3babd74dcd6c4dd2dd
|
4
|
+
data.tar.gz: e3a4ebaaa0796bae48cc52e978c3aee64aade68cd80c654616171f9bf49da783
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a64d48bc5544b99ae7868a10d2435b390526ccf9a95fc0ca323952264cb933749d20aea08365b3d9f995143df7514f7624e40dc69b2398791750149db2abc21e
|
7
|
+
data.tar.gz: 9253bdbe2c08c1b75a6eeb9bb4a5e0dbfb6402365d9e925fe64282e872e034bd71da900eb235fe8e674ecd6e586b3a73a81a832775267c21b10f4f5ad1365a95
|
@@ -10,7 +10,7 @@ module Talktome
|
|
10
10
|
|
11
11
|
def send_message(message, user)
|
12
12
|
mail = base_email
|
13
|
-
mail.to = user[:email]
|
13
|
+
mail.to = users(user).map{|u| u[:email] }
|
14
14
|
mail.reply_to = message.metadata["reply_to"] if message.metadata.has_key?("reply_to")
|
15
15
|
mail.subject = message.metadata["subject"]
|
16
16
|
|
@@ -37,6 +37,10 @@ module Talktome
|
|
37
37
|
|
38
38
|
private
|
39
39
|
|
40
|
+
def users(user)
|
41
|
+
user.is_a?(Array) ? user : [user]
|
42
|
+
end
|
43
|
+
|
40
44
|
def base_email
|
41
45
|
default_email = Mail.new
|
42
46
|
@defaulter.call(default_email) if @defaulter
|
data/lib/talktome/version.rb
CHANGED
data/spec/client/test_local.rb
CHANGED
@@ -3,63 +3,110 @@ module Talktome
|
|
3
3
|
class Client
|
4
4
|
describe Local do
|
5
5
|
|
6
|
-
let(:
|
7
|
-
|
6
|
+
let(:user) {
|
7
|
+
{ email: "user@test.com" }
|
8
8
|
}
|
9
9
|
|
10
|
-
let(:
|
11
|
-
|
12
|
-
c.strategy :email, strategy
|
13
|
-
end
|
10
|
+
let(:tpldata) {
|
11
|
+
{ who: "Test user" }
|
14
12
|
}
|
15
13
|
|
16
14
|
let(:folder) {
|
17
15
|
Path.dir/"../fixtures"
|
18
16
|
}
|
19
17
|
|
20
|
-
let(:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
let(:tpldata) {
|
25
|
-
{ who: "Test user" }
|
18
|
+
let(:client){
|
19
|
+
Local.new(folder, options) do |c|
|
20
|
+
c.strategy :email, strategy
|
21
|
+
end
|
26
22
|
}
|
27
23
|
|
28
|
-
|
29
|
-
strategy
|
30
|
-
|
24
|
+
context 'with a debug strategy' do
|
25
|
+
let(:strategy) {
|
26
|
+
Strategy::Debug.new
|
27
|
+
}
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
{}
|
29
|
+
before(:each) {
|
30
|
+
strategy.clear!
|
35
31
|
}
|
36
32
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
context "without templates" do
|
34
|
+
let(:options) {
|
35
|
+
{}
|
36
|
+
}
|
37
|
+
|
38
|
+
it 'sends email when requested' do
|
39
|
+
client.talktome("welcome", user, tpldata, [:email])
|
40
|
+
expect(strategy.last.message).not_to be_nil
|
41
|
+
expect(strategy.last.message.to_html).to eql("<h1>Hello Test user</h1>\n\n<p>Welcome to this email example!</p>\n\n<h3>Test user</h3>\n")
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'lets send the same email to multiple users' do
|
45
|
+
client.talktome("welcome", [user], tpldata, [:email])
|
46
|
+
expect(strategy.last.message).not_to be_nil
|
47
|
+
expect(strategy.last.message.to_html).to eql("<h1>Hello Test user</h1>\n\n<p>Welcome to this email example!</p>\n\n<h3>Test user</h3>\n")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with templates" do
|
52
|
+
let(:options) {
|
53
|
+
{
|
54
|
+
templates: Path.dir/"../fixtures/templates"
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
it 'sends email when requested' do
|
59
|
+
client.talktome("welcome", user, tpldata, [:email])
|
60
|
+
expect(strategy.last.message).not_to be_nil
|
61
|
+
expect(strategy.last.message.to_html).to eql("<html><title>Hello Test user</title><body><h1>Hello Test user</h1>\n\n<p>Welcome to this email example!</p>\n\n<h3>Test user</h3>\n</body></html>\n")
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'yields the callback with the email' do
|
65
|
+
seen = nil
|
66
|
+
client.talktome("welcome", user, tpldata, [:email]){|m|
|
67
|
+
seen = m
|
68
|
+
}
|
69
|
+
expect(seen).not_to be_nil
|
70
|
+
end
|
41
71
|
end
|
42
72
|
end
|
43
73
|
|
44
|
-
context
|
74
|
+
context 'with an email strategy' do
|
75
|
+
before do
|
76
|
+
Mail.defaults do
|
77
|
+
delivery_method :test
|
78
|
+
end
|
79
|
+
Mail::TestMailer.deliveries = []
|
80
|
+
end
|
81
|
+
|
45
82
|
let(:options) {
|
46
|
-
{
|
47
|
-
|
83
|
+
{}
|
84
|
+
}
|
85
|
+
|
86
|
+
let(:strategy) {
|
87
|
+
Strategy::Email.new({}){|m|
|
88
|
+
m.from "hello@test.com"
|
48
89
|
}
|
49
90
|
}
|
50
91
|
|
51
92
|
it 'sends email when requested' do
|
52
93
|
client.talktome("welcome", user, tpldata, [:email])
|
53
|
-
|
54
|
-
expect(
|
94
|
+
mail = Mail::TestMailer.deliveries.first
|
95
|
+
expect(mail).not_to be_nil
|
96
|
+
expect(mail.from).to eql(["hello@test.com"])
|
97
|
+
expect(mail.to).to eql(["user@test.com"])
|
55
98
|
end
|
56
99
|
|
57
|
-
it '
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
expect(
|
100
|
+
it 'allows sending email to multiple users' do
|
101
|
+
client.talktome("welcome", [
|
102
|
+
{ email: "user1@test.com" },
|
103
|
+
{ email: "user2@test.com" }
|
104
|
+
], tpldata, [:email])
|
105
|
+
expect(Mail::TestMailer.deliveries.length).to eql(1)
|
106
|
+
mail = Mail::TestMailer.deliveries.first
|
107
|
+
expect(mail).not_to be_nil
|
108
|
+
expect(mail.from).to eql(["hello@test.com"])
|
109
|
+
expect(mail.to).to eql(["user1@test.com", "user2@test.com"])
|
63
110
|
end
|
64
111
|
end
|
65
112
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: talktome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -150,8 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: '0'
|
152
152
|
requirements: []
|
153
|
-
|
154
|
-
rubygems_version: 2.6.11
|
153
|
+
rubygems_version: 3.1.2
|
155
154
|
signing_key:
|
156
155
|
specification_version: 4
|
157
156
|
summary: Talktome helps you talk to users by email, messaging, sms, etc.
|