talktome 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2817b7e3a3e6d077e889d0d53ac368195785af09
4
- data.tar.gz: e5d9c60306e644301a1029739f16041f3b740be2
2
+ SHA256:
3
+ metadata.gz: b12474ba945a8c289bc358c4e654667ac7684618b3c19f3babd74dcd6c4dd2dd
4
+ data.tar.gz: e3a4ebaaa0796bae48cc52e978c3aee64aade68cd80c654616171f9bf49da783
5
5
  SHA512:
6
- metadata.gz: 8cf1e843cfd0ce3187bc693889ed5baf7e0deeddff436cf483ec0af6f20f6698e5d91eea60717f990b270f274bddd1ff959e75a1dca8fc7e5ad7325873c31f56
7
- data.tar.gz: f312d5300c8eeacee34bd90097d61bd996246081b0400e013f59a63147a374719a59c904b3bd191481fc9d08e1417c5eebf266374931273a448e05b047ff0c8f
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
@@ -2,7 +2,7 @@ module Talktome
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 0
5
+ TINY = 1
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
@@ -3,63 +3,110 @@ module Talktome
3
3
  class Client
4
4
  describe Local do
5
5
 
6
- let(:strategy) {
7
- Strategy::Debug.new
6
+ let(:user) {
7
+ { email: "user@test.com" }
8
8
  }
9
9
 
10
- let(:client){
11
- Local.new(folder, options) do |c|
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(:user) {
21
- { email: "user@test.com" }
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
- before(:each) {
29
- strategy.clear!
30
- }
24
+ context 'with a debug strategy' do
25
+ let(:strategy) {
26
+ Strategy::Debug.new
27
+ }
31
28
 
32
- context "without templates" do
33
- let(:options) {
34
- {}
29
+ before(:each) {
30
+ strategy.clear!
35
31
  }
36
32
 
37
- it 'sends email when requested' do
38
- client.talktome("welcome", user, tpldata, [:email])
39
- expect(strategy.last.message).not_to be_nil
40
- 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")
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 "with templates" do
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
- templates: Path.dir/"../fixtures/templates"
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
- expect(strategy.last.message).not_to be_nil
54
- 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")
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 'yields the callback with the email' do
58
- seen = nil
59
- client.talktome("welcome", user, tpldata, [:email]){|m|
60
- seen = m
61
- }
62
- expect(seen).not_to be_nil
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.0
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: 2019-03-20 00:00:00.000000000 Z
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
- rubyforge_project:
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.