mail_spy 0.0.2 → 0.1.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.
Files changed (56) hide show
  1. data/README.rdoc +86 -24
  2. data/app/assets/images/mail_spy/background_tile.gif +0 -0
  3. data/app/assets/images/mail_spy/mailspy_sprite.png +0 -0
  4. data/app/assets/images/mail_spy/spy.ico +0 -0
  5. data/app/assets/javascripts/mail_spy/lib/backbone.js +1256 -0
  6. data/app/assets/javascripts/mail_spy/lib/underscore.js +999 -0
  7. data/app/assets/javascripts/mail_spy/reports.js +2 -0
  8. data/app/assets/javascripts/mail_spy/sendgrid.js +2 -0
  9. data/app/assets/stylesheets/mail_spy/application.css +62 -1
  10. data/app/assets/stylesheets/mail_spy/reports.css.scss +128 -0
  11. data/app/assets/stylesheets/mail_spy/sendgrid.css +4 -0
  12. data/app/controllers/mail_spy/reports_controller.rb +29 -0
  13. data/app/controllers/mail_spy/sendgrid_controller.rb +26 -0
  14. data/app/controllers/mail_spy/tracking_controller.rb +19 -11
  15. data/app/helpers/mail_spy/email_helper.rb +21 -3
  16. data/app/helpers/mail_spy/reports_helper.rb +4 -0
  17. data/app/helpers/mail_spy/sendgrid_helper.rb +4 -0
  18. data/app/mailers/mail_spy/core_mailer.rb +15 -18
  19. data/app/models/mail_spy/email.rb +127 -19
  20. data/app/models/mail_spy/process_log.rb +25 -0
  21. data/app/views/layouts/mail_spy/application.html.erb +3 -0
  22. data/app/views/mail_spy/reports/campaigns.html.erb +138 -0
  23. data/config/routes.rb +6 -0
  24. data/lib/generators/mail_spy/templates/mail_spy.rb +25 -1
  25. data/lib/mail_spy/manager.rb +100 -54
  26. data/lib/mail_spy/sendgrid/smtp_api_header.rb +68 -0
  27. data/lib/mail_spy/version.rb +1 -1
  28. data/lib/mail_spy.rb +39 -5
  29. data/test/dummy/app/views/email_templates/helper_test.html.erb +15 -0
  30. data/test/dummy/app/views/email_templates/helper_test.text.erb +11 -0
  31. data/test/dummy/config/environments/development.rb +1 -1
  32. data/test/dummy/config/environments/production.rb +5 -1
  33. data/test/dummy/config/environments/test.rb +4 -1
  34. data/test/dummy/config/initializers/mail_spy.rb +42 -0
  35. data/test/dummy/config/routes.rb +1 -2
  36. data/test/dummy/db/schema.rb +16 -0
  37. data/test/dummy/db/seeds.rb +16 -13
  38. data/test/dummy/lib/tasks/emails.rake +8 -0
  39. data/test/dummy/log/development.log +782 -0
  40. data/test/dummy/log/test.log +9952 -0
  41. data/test/fixtures/mail_spy/process_logs.yml +15 -0
  42. data/test/functional/mail_spy/core_mailer_test.rb +16 -9
  43. data/test/functional/mail_spy/reports_controller_test.rb +9 -0
  44. data/test/functional/mail_spy/sendgrid_controller_test.rb +9 -0
  45. data/test/functional/mail_spy/tracking_controller_test.rb +16 -11
  46. data/test/test_email_credentials.yml +2 -2
  47. data/test/test_email_credentials.yml.sample +0 -8
  48. data/test/test_helper.rb +15 -41
  49. data/test/unit/helpers/mail_spy/reports_helper_test.rb +6 -0
  50. data/test/unit/helpers/mail_spy/sendgrid_helper_test.rb +6 -0
  51. data/test/unit/mail_spy/manager_test.rb +101 -122
  52. data/test/unit/mail_spy/{email_template_test.rb → process_log_test.rb} +1 -1
  53. metadata +122 -34
  54. data/app/models/mail_spy/email_template.rb +0 -17
  55. data/test/fixtures/mail_spy/email_templates.yml +0 -9
  56. /data/lib/generators/mail_spy/{initialize_generator.rb → initializer_generator.rb} +0 -0
@@ -0,0 +1,15 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ start: 2012-02-06 23:54:22
5
+ end: 2012-02-06 23:54:22
6
+ seconds_elapsed: 1
7
+ running: false
8
+ success: false
9
+
10
+ two:
11
+ start: 2012-02-06 23:54:22
12
+ end: 2012-02-06 23:54:22
13
+ seconds_elapsed: 1
14
+ running: false
15
+ success: false
@@ -1,10 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module MailSpy
4
- class CoreMailerTest < ActionMailer::TestCase
4
+ class CoreMailerTest < ActiveSupport::TestCase #ActionMailer::TestCase
5
5
 
6
6
  def teardown
7
- MailSpy::EmailTemplate.delete_all
8
7
  MailSpy::Email.delete_all
9
8
  end
10
9
 
@@ -12,17 +11,25 @@ module MailSpy
12
11
  assert true
13
12
  end
14
13
 
15
- def test_template_email_helpers
16
- initialize_mail_spy_test_esp
14
+ def test_subject_evaluation
15
+ emails = create_emails(:campaign => "tests", :stream => "a-stream", :component => "a-helper_test")
16
+
17
17
 
18
- html_erb = "A link : <%= track_link 'My home', 'www.google.com' %> <br> A Bug <%= tracking_bug %>"
19
- text_erb = "A link : <%= track_link 'My home', 'www.google.com' %> <br> A Bug <%= tracking_bug %>"
20
- template_values_definition = {}
18
+ email = emails.first
19
+ email.template_values = {:user_name => "bob"}
20
+ email.subject = "hi <%= @template_values[:user_name] %>"
21
+
22
+ mail = MailSpy::CoreMailer.template(emails.first)
23
+ assert(mail.subject == "hi bob", "subject lines should be interpreted")
24
+ end
25
+
26
+
27
+ def test_template_email_helpers
28
+ create_emails(:campaign => "tests", :stream => "a-stream", :component => "a-helper_test")
21
29
 
22
- template = MailSpy.add_template("a test template", html_erb, text_erb, template_values_definition)
23
- create_emails(template)
24
30
  email = MailSpy::Email.first
25
31
  mail = MailSpy::CoreMailer.template(email)
32
+ mail.deliver
26
33
 
27
34
  assert(mail.present?, "Mail should render without error")
28
35
  assert(mail.html_part.body.present?, "Mail should have a html part")
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module MailSpy
4
+ class ReportsControllerTest < ActionController::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module MailSpy
4
+ class SendgridControllerTest < ActionController::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -4,19 +4,12 @@ module MailSpy
4
4
  class TrackingControllerTest < ActionController::TestCase
5
5
 
6
6
  def setup
7
- initialize_mail_spy_test_esp
8
-
9
- html_erb = "A link : <%= track_link 'My home', 'www.google.com' %> <br> A Bug <%= tracking_bug %>"
10
- text_erb = "A link : <%= track_link 'My home', 'www.google.com' %> <br> A Bug <%= tracking_bug %>"
11
- template_values_definition = {}
12
-
13
- template = MailSpy.add_template("a test template", html_erb, text_erb, template_values_definition)
14
- create_emails(template)
7
+ MailSpy::Email.delete_all
8
+ create_emails(:campaign => "tests", :stream => "a-stream", :component => "a-helper_test")
15
9
  @email = MailSpy::Email.first
16
10
  end
17
11
 
18
12
  def teardown
19
- MailSpy::EmailTemplate.delete_all
20
13
  MailSpy::Email.delete_all
21
14
  end
22
15
 
@@ -33,7 +26,19 @@ module MailSpy
33
26
 
34
27
  get "link", params
35
28
 
36
- assert_redirected_to params[:url]
29
+ #Load up the generated GA tokens
30
+ ga_hash = {}
31
+ email = MailSpy::Email.first
32
+ ga_hash[:utm_source] = email.utm_source if email.utm_source.present?
33
+ ga_hash[:utm_medium] = email.utm_medium if email.utm_medium.present?
34
+ ga_hash[:utm_campaign] = email.utm_campaign if email.utm_campaign.present?
35
+ ga_hash[:utm_term] = email.utm_term if email.utm_term.present?
36
+ ga_hash[:utm_content] = email.utm_content if email.utm_content.present?
37
+
38
+ #Parse tokens into uri
39
+ uri = URI.parse(params[:url])
40
+ uri.query = [uri.query, ga_hash.to_param].compact.join('&')
41
+ assert_redirected_to uri.to_s
37
42
 
38
43
  email = @email.reload
39
44
  details = email.actions.first.details
@@ -74,7 +79,7 @@ module MailSpy
74
79
  email = @email.reload
75
80
  assert(email.actions.length == 1, "The email should only have on action at this point")
76
81
  assert(email.actions.first.action_type == params[:action_type],"Action type should be conversion")
77
- assert(email.actions.first.count == params[:count], "the action count should be 1")
82
+ assert(email.actions.first.count == params[:count], "the action count should be 3")
78
83
 
79
84
  end
80
85
 
@@ -2,8 +2,8 @@ name: sendgrid
2
2
  address: smtp.sendgrid.net
3
3
  port: 587
4
4
  domain: herokuapp.com
5
- user_name: app2546146@heroku.com
6
- password: g4eiapwq
5
+ user_name: app2602840@heroku.com
6
+ password: qb6qnim0
7
7
  authentication: plain
8
8
  enable_starttls_auto: 1
9
9
  test_email_address: trcarden@gmail.com
@@ -1,9 +1 @@
1
- name: sendgrid
2
- address: smtp.sendgrid.net
3
- port: 587
4
- domain: herokuapp.com
5
- user_name: username
6
- password: pass
7
- authentication: plain
8
- enable_starttls_auto: 1
9
1
  test_email_address: test@test.com
data/test/test_helper.rb CHANGED
@@ -33,23 +33,6 @@ class ActiveSupport::TestCase
33
33
  # Add more helper methods to be used by all tests here...
34
34
 
35
35
 
36
-
37
- # Adds the ESP settings for a test email
38
- def initialize_mail_spy_test_esp
39
- path = File.expand_path ".././test_email_credentials.yml", __FILE__
40
- credentials = YAML.load(File.open(path)).to_options
41
- MailSpy.add_email_service_provider do |esp|
42
- esp.name = credentials[:name]
43
- esp.address = credentials[:address]
44
- esp.port = credentials[:port]
45
- esp.domain = credentials[:domain]
46
- esp.user_name = credentials[:user_name]
47
- esp.password = credentials[:password]
48
- esp.authentication = credentials[:authentication]
49
- esp.enable_starttls_auto = (credentials[:enable_starttls_auto].to_i == 1)
50
- end
51
- end
52
-
53
36
  # Gets the test email address from the setup file
54
37
  def email_address_for_test
55
38
  path = File.expand_path ".././test_email_credentials.yml", __FILE__
@@ -57,36 +40,26 @@ class ActiveSupport::TestCase
57
40
  credentials[:test_email_address]
58
41
  end
59
42
 
60
- # Provides a template to operate on
61
- def do_with_template(&block)
62
- template_name = "test"
63
- html_erb = "Hello World"
64
- text_erb = "Hello World"
65
- template_values_definition = {}
66
-
67
- template = MailSpy.add_template(template_name, html_erb, text_erb, template_values_definition)
68
- block.call(template)
69
- end
43
+ # Creates a test email
44
+ def create_emails( options={}, num_emails=1)
45
+ options.to_options!
70
46
 
71
- # Creates a test email from a given template
72
- def create_emails(template, num_emails=1)
47
+ emails = []
73
48
  num_emails.times do
74
- to = email_address_for_test
75
- from = "test@test.com"
76
- reply_to = "testGuy"
77
- subject = "test subject"
78
- template_name = template.name
79
- campaign = "test campaign"
80
- stream = "test stream"
81
- component = "test component"
82
- schedule_at = DateTime.now
83
-
84
- MailSpy.add_instance(
49
+ to = options[:to] || email_address_for_test
50
+ from = options[:from]|| "test@test.com"
51
+ reply_to = options[:reply_to] || "testGuy"
52
+ subject = options[:subject] || "test subject"
53
+ campaign = options[:campaign] || "test campaign"
54
+ stream = options[:stream] || "test stream"
55
+ component = options[:component] || "test component"
56
+ schedule_at = options[:schedule_at] || DateTime.now
57
+
58
+ emails << MailSpy.create_email(
85
59
  :to => to,
86
60
  :from => from,
87
61
  :reply_to => reply_to,
88
62
  :subject => subject,
89
- :template_name => template_name,
90
63
  :template_values => {},
91
64
  :campaign => campaign,
92
65
  :stream => stream,
@@ -94,6 +67,7 @@ class ActiveSupport::TestCase
94
67
  :schedule_at => schedule_at
95
68
  )
96
69
  end
70
+ return emails
97
71
  end
98
72
 
99
73
 
@@ -0,0 +1,6 @@
1
+ require 'test_helper'
2
+
3
+ module MailSpy
4
+ class ReportsHelperTest < ActionView::TestCase
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'test_helper'
2
+
3
+ module MailSpy
4
+ class SendgridHelperTest < ActionView::TestCase
5
+ end
6
+ end
@@ -6,159 +6,138 @@ module MailSpy
6
6
  assert true
7
7
  end
8
8
 
9
+
9
10
  def setup
10
- MailSpy::EmailTemplate.delete_all
11
+ MailSpy::ProcessLog.delete_all
11
12
  MailSpy::Email.delete_all
12
13
  end
13
14
 
14
- # ------------------------------------------- ADD_TEMPLATE
15
- def test_add_template
16
- template_name = "test"
17
- html_erb = "Hello World"
18
- text_erb = "Hello World"
19
- template_values_definition = {}
15
+ def teardown
16
+ MailSpy::ProcessLog.delete_all
17
+ end
20
18
 
21
- template = MailSpy.add_template(template_name, html_erb, text_erb, template_values_definition)
22
19
 
23
- assert(template.html_erb == html_erb, "values should be written")
24
- assert(template.text_erb == text_erb, "values should be written")
25
- assert(template.template_values_definition == template_values_definition, "values should be written")
26
- assert(template.name == template_name, "values should be written")
20
+ # ------------------------------------------- CREATE EMAIL
21
+ def test_create_email
22
+ to = "test@test.com"
23
+ from = "test@test.com"
24
+ reply_to = "testGuy"
25
+ subject = "test subject"
26
+ campaign = "tests"
27
+ stream = "a-stream"
28
+ component = "a-helper_test"
29
+ schedule_at = DateTime.now
30
+
31
+ email = MailSpy.create_email(
32
+ :to => to,
33
+ :from => from,
34
+ :reply_to => reply_to,
35
+ :subject => subject,
36
+ :template_values => {},
37
+ :campaign => campaign,
38
+ :stream => stream,
39
+ :component => component,
40
+ :schedule_at => schedule_at
41
+ )
42
+
43
+ assert(email.to == to, "email subject must be set")
44
+ assert(email.subject == subject, "email subject must be set")
45
+ assert(email.campaign == campaign, "email campaign must be set")
46
+ assert(email.stream == stream, "email stream must be set")
47
+ assert(email.component == component, "email component must be set")
48
+ assert(email.schedule_at.to_i == schedule_at.to_i, "email schedule_at must be set")
27
49
  end
28
50
 
29
- # ------------------------------------------- ADD_INSTANCE
30
- def test_add_instance
31
- do_with_template do |template|
32
- to = "test@test.com"
33
- from = "test@test.com"
34
- reply_to = "testGuy"
35
- subject = "test subject"
36
- template_name = template.name
37
- campaign = "test campaign"
38
- stream = "test stream"
39
- component = "test component"
40
- schedule_at = DateTime.now
41
-
42
- email = MailSpy.add_instance(
43
- :to => to,
51
+ def test_missing_sender
52
+ from = "test@test.com"
53
+ reply_to = "testGuy"
54
+ subject = "test subject"
55
+ campaign = "tests"
56
+ stream = "a-stream"
57
+ component = "a-helper_test"
58
+ schedule_at = DateTime.now
59
+
60
+ assert_raise RuntimeError do
61
+ MailSpy.create_email(
44
62
  :from => from,
45
63
  :reply_to => reply_to,
46
64
  :subject => subject,
47
- :template_name => template_name,
48
65
  :template_values => {},
49
66
  :campaign => campaign,
50
67
  :stream => stream,
51
68
  :component => component,
52
69
  :schedule_at => schedule_at
53
70
  )
54
-
55
- assert(email.to == to, "email subject must be set")
56
- assert(email.subject == subject, "email subject must be set")
57
- assert(email.template_name == template_name, "email template_name must be set")
58
- assert(email.campaign == campaign, "email campaign must be set")
59
- assert(email.stream == stream, "email stream must be set")
60
- assert(email.component == component, "email component must be set")
61
- assert(email.schedule_at.to_i == schedule_at.to_i, "email schedule_at must be set")
62
71
  end
63
72
  end
64
73
 
65
- def test_missing_sender
66
- do_with_template do |template|
67
- from = "test@test.com"
68
- reply_to = "testGuy"
69
- subject = "test subject"
70
- template_name = template.name
71
- campaign = "test campaign"
72
- stream = "test stream"
73
- component = "test component"
74
- schedule_at = DateTime.now
75
-
76
- assert_raise RuntimeError do
77
- MailSpy.add_instance(
78
- :from => from,
79
- :reply_to => reply_to,
80
- :subject => subject,
81
- :template_name => template_name,
82
- :template_values => {},
83
- :campaign => campaign,
84
- :stream => stream,
85
- :component => component,
86
- :schedule_at => schedule_at
87
- )
88
- end
74
+ def test_missing_required_field
75
+
76
+ to = "test@test.com"
77
+ from = "test@test.com"
78
+ reply_to = "testGuy"
79
+ campaign = "tests"
80
+ stream = "a-stream"
81
+ component = "a-helper_test"
82
+ schedule_at = DateTime.now
83
+
84
+ assert_raise RuntimeError do
85
+ MailSpy.create_email(
86
+ :to => to,
87
+ :from => from,
88
+ :reply_to => reply_to,
89
+ :template_values => {},
90
+ :campaign => campaign,
91
+ :stream => stream,
92
+ :component => component,
93
+ :schedule_at => schedule_at
94
+ )
89
95
  end
90
96
  end
91
97
 
92
- def test_missing_required_field
93
98
 
94
- do_with_template do |template|
95
- to = "test@test.com"
96
- from = "test@test.com"
97
- reply_to = "testGuy"
98
- template_name = template.name
99
- campaign = "test campaign"
100
- stream = "test stream"
101
- component = "test component"
102
- schedule_at = DateTime.now
103
-
104
- assert_raise RuntimeError do
105
- MailSpy.add_instance(
106
- :to => to,
107
- :from => from,
108
- :reply_to => reply_to,
109
- :template_name => template_name,
110
- :template_values => {},
111
- :campaign => campaign,
112
- :stream => stream,
113
- :component => component,
114
- :schedule_at => schedule_at
115
- )
116
- end
117
- end
118
99
 
100
+ def test_referencing_missing_template
101
+ to = "test@test.com"
102
+ from = "test@test.com"
103
+ reply_to = "testGuy"
104
+ subject = "test subject"
105
+ campaign = "NO SUCH CAMPAIGN"
106
+ stream = "NO SUCH STREAM"
107
+ component = "NO SUCH COMPONENT"
108
+ schedule_at = DateTime.now
109
+
110
+ assert_raise RuntimeError do
111
+ MailSpy.create_email(
112
+ :to => to,
113
+ :subject => subject,
114
+ :from => from,
115
+ :reply_to => reply_to,
116
+ :template_values => {},
117
+ :campaign => campaign,
118
+ :stream => stream,
119
+ :component => component,
120
+ :schedule_at => schedule_at
121
+ )
119
122
  end
123
+ end
120
124
 
121
- def test_referencing_missing_template
122
- do_with_template do |template|
123
- to = "test@test.com"
124
- from = "test@test.com"
125
- reply_to = "testGuy"
126
- subject = "test subject"
127
- campaign = "test campaign"
128
- stream = "test stream"
129
- component = "test component"
130
- schedule_at = DateTime.now
131
-
132
- assert_raise RuntimeError do
133
- MailSpy.add_instance(
134
- :to => to,
135
- :subject => subject,
136
- :from => from,
137
- :reply_to => reply_to,
138
- :template_name => "NOT HERE",
139
- :template_values => {},
140
- :campaign => campaign,
141
- :stream => stream,
142
- :component => component,
143
- :schedule_at => schedule_at
144
- )
145
- end
146
- end
147
- end
125
+ # ------------------------------------------- SEND_OUTSTANDING_EMAILS
148
126
 
149
- # ------------------------------------------- SEND_OUTSTANDING_EMAILS
150
127
 
151
- #TODO need to document the testing methods for setting up the test_email
152
- def test_send_outstanding_emails
153
- initialize_mail_spy_test_esp
128
+ def test_send_outstanding_emails
129
+ create_emails(:campaign => "tests", :stream => "a-stream", :component => "a-helper_test")
154
130
 
155
- do_with_template do |template|
156
- create_emails(template)
157
- end
131
+ num_sent = MailSpy.send_outstanding_emails
132
+ process_log = MailSpy::ProcessLog.first
133
+ assert(num_sent == 1, "We should have sent a email")
134
+
135
+ assert(process_log.success, "process should have been successful")
136
+ assert(!process_log.running, "process should have finished")
137
+ end
138
+
139
+ #TODO need to document the testing methods for setting up the test_email
158
140
 
159
- num_sent = MailSpy.send_outstanding_emails
160
- assert(num_sent == 1, "We should have sent a email")
161
- end
162
141
 
163
142
  end
164
143
  end
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module MailSpy
4
- class EmailTemplateTest < ActiveSupport::TestCase
4
+ class ProcessLogTest < ActiveSupport::TestCase
5
5
  # test "the truth" do
6
6
  # assert true
7
7
  # end