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.
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in ahoy_email.gemspec
4
- gemspec path: "../../"
5
-
6
- gem "actionmailer", "~> 5.1.0"
@@ -1,3 +0,0 @@
1
- test:
2
- adapter: sqlite3
3
- database: db/combustion_test.sqlite
@@ -1,3 +0,0 @@
1
- Rails.application.routes.draw do
2
- #
3
- end
@@ -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&amp;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&amp;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&amp;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&amp;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