ahoy_email 0.5.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/CONTRIBUTING.md +47 -0
- data/LICENSE.txt +1 -1
- data/README.md +174 -96
- data/app/controllers/ahoy/messages_controller.rb +20 -22
- data/app/models/ahoy/message.rb +1 -1
- data/config/routes.rb +1 -3
- data/lib/ahoy_email/engine.rb +3 -3
- data/lib/ahoy_email/mailer.rb +31 -21
- data/lib/ahoy_email/observer.rb +7 -0
- data/lib/ahoy_email/processor.rb +52 -67
- data/lib/ahoy_email/tracker.rb +19 -0
- data/lib/ahoy_email/version.rb +1 -1
- data/lib/ahoy_email.rb +50 -22
- data/lib/generators/ahoy_email/install_generator.rb +3 -20
- data/lib/generators/ahoy_email/templates/install.rb.tt +11 -0
- metadata +15 -64
- data/.gitignore +0 -24
- data/.travis.yml +0 -16
- data/Gemfile +0 -6
- data/Rakefile +0 -9
- data/ahoy_email.gemspec +0 -35
- data/lib/ahoy_email/interceptor.rb +0 -9
- data/lib/generators/ahoy_email/templates/install.rb +0 -30
- data/test/gemfiles/actionmailer42.gemfile +0 -6
- data/test/gemfiles/actionmailer50.gemfile +0 -6
- data/test/gemfiles/actionmailer51.gemfile +0 -6
- data/test/internal/config/database.yml +0 -3
- data/test/internal/config/routes.rb +0 -3
- data/test/internal/db/schema.rb +0 -30
- data/test/mailer_test.rb +0 -153
- data/test/test_helper.rb +0 -16
data/test/internal/db/schema.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
ActiveRecord::Schema.define do
|
2
|
-
create_table :ahoy_messages, force: true do |t|
|
3
|
-
t.string :token
|
4
|
-
|
5
|
-
# user
|
6
|
-
t.text :to
|
7
|
-
t.integer :user_id
|
8
|
-
t.string :user_type
|
9
|
-
|
10
|
-
# optional - feel free to remove
|
11
|
-
t.string :mailer
|
12
|
-
t.text :subject
|
13
|
-
t.text :content
|
14
|
-
|
15
|
-
# optional
|
16
|
-
t.string :utm_source
|
17
|
-
t.string :utm_medium
|
18
|
-
t.string :utm_term
|
19
|
-
t.string :utm_content
|
20
|
-
t.string :utm_campaign
|
21
|
-
|
22
|
-
# timestamps
|
23
|
-
t.timestamp :sent_at
|
24
|
-
t.timestamp :opened_at
|
25
|
-
t.timestamp :clicked_at
|
26
|
-
end
|
27
|
-
|
28
|
-
add_index :ahoy_messages, [:token]
|
29
|
-
add_index :ahoy_messages, [:user_id, :user_type]
|
30
|
-
end
|
data/test/mailer_test.rb
DELETED
@@ -1,153 +0,0 @@
|
|
1
|
-
require_relative "test_helper"
|
2
|
-
|
3
|
-
class UserMailer < ActionMailer::Base
|
4
|
-
default from: "from@example.com"
|
5
|
-
after_action :prevent_delivery_to_guests, only: [:welcome2] if Rails.version >= "4.0.0"
|
6
|
-
|
7
|
-
def welcome
|
8
|
-
mail to: "test@example.org", subject: "Hello", body: "World"
|
9
|
-
end
|
10
|
-
|
11
|
-
def welcome2
|
12
|
-
mail to: "test@example.org", subject: "Hello", body: "World"
|
13
|
-
end
|
14
|
-
|
15
|
-
def welcome3
|
16
|
-
track message: false
|
17
|
-
mail to: "test@example.org", subject: "Hello", body: "World"
|
18
|
-
end
|
19
|
-
|
20
|
-
def welcome4
|
21
|
-
html_message('<a href="http://example.org">Hi<a>')
|
22
|
-
end
|
23
|
-
|
24
|
-
def welcome5
|
25
|
-
html_message('<a href="http://example.org?baz[]=1&baz[]=2">Hi<a>')
|
26
|
-
end
|
27
|
-
|
28
|
-
def heuristic_parse
|
29
|
-
track heuristic_parse: true
|
30
|
-
html_message('<a href="example.org">Hi<a>')
|
31
|
-
end
|
32
|
-
|
33
|
-
def mailto
|
34
|
-
track heuristic_parse: true
|
35
|
-
html_message('<a href="mailto:someone@yoursite.com">Email Us</a>')
|
36
|
-
end
|
37
|
-
|
38
|
-
def app_link
|
39
|
-
track heuristic_parse: true
|
40
|
-
html_message('<a href="fb://profile/33138223345">Email Us</a>')
|
41
|
-
end
|
42
|
-
|
43
|
-
def welcome4_heuristic
|
44
|
-
track heuristic_parse: true
|
45
|
-
html_message('<a href="http://example.org">Hi<a>')
|
46
|
-
end
|
47
|
-
|
48
|
-
def welcome5_heuristic
|
49
|
-
track heuristic_parse: true
|
50
|
-
html_message('<a href="http://example.org?baz[]=1&baz[]=2">Hi<a>')
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def prevent_delivery_to_guests
|
56
|
-
mail.perform_deliveries = false
|
57
|
-
end
|
58
|
-
|
59
|
-
def html_message(html)
|
60
|
-
track click: false
|
61
|
-
mail to: "test@example.org", subject: "Hello" do |format|
|
62
|
-
format.html { render plain: html }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
class MailerTest < Minitest::Test
|
68
|
-
def setup
|
69
|
-
Ahoy::Message.delete_all
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_basic
|
73
|
-
assert_message :welcome
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_prevent_delivery
|
77
|
-
assert_message :welcome2
|
78
|
-
if Rails.version >= "4.0.0"
|
79
|
-
assert_nil Ahoy::Message.first.sent_at
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_no_message
|
84
|
-
UserMailer.welcome3.to
|
85
|
-
assert_equal 0, Ahoy::Message.count
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_utm_params
|
89
|
-
message = UserMailer.welcome4
|
90
|
-
body = message.body.to_s
|
91
|
-
assert_match "utm_campaign=welcome4", body
|
92
|
-
assert_match "utm_medium=email", body
|
93
|
-
assert_match "utm_source=user_mailer", body
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_array_params
|
97
|
-
message = UserMailer.welcome5
|
98
|
-
body = message.body.to_s
|
99
|
-
assert_match "baz%5B%5D=1&baz%5B%5D=2", body
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_heuristic_parse
|
103
|
-
# Should convert the URI fragment into a URI
|
104
|
-
message = UserMailer.heuristic_parse
|
105
|
-
body = message.body.to_s
|
106
|
-
assert_match "http://example.org", body
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_mailto
|
110
|
-
# heuristic parse should ignore the mailto link
|
111
|
-
message = UserMailer.mailto
|
112
|
-
body = message.body.to_s
|
113
|
-
assert_match "<a href=\"mailto:someone@yoursite.com\">", body
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_app_link
|
117
|
-
# heuristic parse should ignore the app link
|
118
|
-
message = UserMailer.app_link
|
119
|
-
body = message.body.to_s
|
120
|
-
assert_match "<a href=\"fb://profile/33138223345\">", body
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_utm_params_heuristic_parse
|
124
|
-
# heuristic parse should not have unexpected side effects
|
125
|
-
message = UserMailer.welcome4_heuristic
|
126
|
-
body = message.body.to_s
|
127
|
-
assert_match "utm_campaign=welcome4", body
|
128
|
-
assert_match "utm_medium=email", body
|
129
|
-
assert_match "utm_source=user_mailer", body
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_array_params_heuristic_parse
|
133
|
-
# heuristic parse should not have unexpected side effects
|
134
|
-
message = UserMailer.welcome5_heuristic
|
135
|
-
body = message.body.to_s
|
136
|
-
assert_match "baz%5B%5D=1&baz%5B%5D=2", body
|
137
|
-
end
|
138
|
-
|
139
|
-
private
|
140
|
-
|
141
|
-
def assert_message(method)
|
142
|
-
message = UserMailer.send(method)
|
143
|
-
message.respond_to?(:deliver_now) ? message.deliver_now : message.deliver
|
144
|
-
ahoy_message = Ahoy::Message.first
|
145
|
-
assert_equal 1, Ahoy::Message.count
|
146
|
-
assert_equal "test@example.org", ahoy_message.to
|
147
|
-
assert_equal "UserMailer##{method}", ahoy_message.mailer
|
148
|
-
assert_equal "Hello", ahoy_message.subject
|
149
|
-
assert_equal "user_mailer", ahoy_message.utm_source
|
150
|
-
assert_equal "email", ahoy_message.utm_medium
|
151
|
-
assert_equal method.to_s, ahoy_message.utm_campaign
|
152
|
-
end
|
153
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require "bundler/setup"
|
2
|
-
Bundler.require(:default)
|
3
|
-
require "minitest/autorun"
|
4
|
-
require "minitest/pride"
|
5
|
-
require "combustion"
|
6
|
-
|
7
|
-
Minitest::Test = Minitest::Unit::TestCase unless defined?(Minitest::Test)
|
8
|
-
|
9
|
-
Combustion.path = "test/internal"
|
10
|
-
Combustion.initialize! :all do
|
11
|
-
if config.active_record.sqlite3.respond_to?(:represent_boolean_as_integer)
|
12
|
-
config.active_record.sqlite3.represent_boolean_as_integer = true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
ActionMailer::Base.delivery_method = :test
|