postageapp 1.0.24 → 1.2.0

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 (54) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +13 -12
  3. data/Gemfile +6 -1
  4. data/LICENSE +1 -1
  5. data/README.md +122 -70
  6. data/Rakefile +19 -4
  7. data/generators/postageapp/postageapp_generator.rb +5 -7
  8. data/lib/generators/postageapp/postageapp_generator.rb +15 -9
  9. data/lib/postageapp.rb +42 -36
  10. data/lib/postageapp/configuration.rb +34 -21
  11. data/lib/postageapp/failed_request.rb +60 -36
  12. data/lib/postageapp/logger.rb +6 -7
  13. data/lib/postageapp/mail.rb +3 -0
  14. data/lib/postageapp/mail/arguments.rb +75 -0
  15. data/lib/postageapp/mail/delivery_method.rb +32 -0
  16. data/lib/postageapp/mail/extensions.rb +21 -0
  17. data/lib/postageapp/mailer.rb +72 -20
  18. data/lib/postageapp/mailer/mailer_2.rb +65 -22
  19. data/lib/postageapp/mailer/mailer_3.rb +45 -28
  20. data/lib/postageapp/mailer/mailer_4.rb +72 -40
  21. data/lib/postageapp/rails/rails.rb +17 -7
  22. data/lib/postageapp/rails/railtie.rb +22 -7
  23. data/lib/postageapp/request.rb +67 -43
  24. data/lib/postageapp/response.rb +11 -8
  25. data/lib/postageapp/utils.rb +11 -3
  26. data/lib/postageapp/version.rb +2 -2
  27. data/postageapp.gemspec +13 -11
  28. data/rails/init.rb +1 -1
  29. data/test/configuration_test.rb +35 -38
  30. data/test/failed_request_test.rb +33 -18
  31. data/test/gemfiles/Gemfile.rails-2.3.x +4 -1
  32. data/test/gemfiles/Gemfile.rails-3.0.x +4 -1
  33. data/test/gemfiles/Gemfile.rails-3.1.x +4 -1
  34. data/test/gemfiles/Gemfile.rails-3.2.x +4 -1
  35. data/test/gemfiles/Gemfile.rails-4.0.x +4 -1
  36. data/test/gemfiles/Gemfile.rails-4.1.x +12 -0
  37. data/test/gemfiles/Gemfile.rails-4.2.x +12 -0
  38. data/test/gemfiles/Gemfile.ruby +11 -0
  39. data/test/helper.rb +52 -33
  40. data/test/live_test.rb +11 -8
  41. data/test/mail_delivery_method_test.rb +161 -0
  42. data/test/mailer/action_mailer_2/notifier.rb +37 -28
  43. data/test/mailer/action_mailer_3/notifier.rb +28 -22
  44. data/test/mailer_2_test.rb +20 -16
  45. data/test/mailer_3_test.rb +16 -22
  46. data/test/mailer_4_test.rb +28 -28
  47. data/test/mailer_helper_methods_test.rb +17 -14
  48. data/test/postageapp_test.rb +8 -9
  49. data/test/rails_initialization_test.rb +14 -14
  50. data/test/request_test.rb +35 -35
  51. data/test/response_test.rb +20 -19
  52. data/test/travis_test.rb +168 -0
  53. data/test/with_environment.rb +27 -0
  54. metadata +23 -17
@@ -1,10 +1,9 @@
1
1
  # Test mailer for ActionMailer 2
2
2
  class Notifier < PostageApp::Mailer
3
-
4
- self.template_root = File.expand_path('../', __FILE__)
5
-
3
+ self.template_root = File.dirname(__FILE__)
4
+
6
5
  def blank
7
- # ... nothing to see here
6
+ # Empty method
8
7
  end
9
8
 
10
9
  def with_no_content
@@ -25,43 +24,53 @@ class Notifier < PostageApp::Mailer
25
24
 
26
25
  def with_manual_parts
27
26
  setup_headers
28
- part :content_type => 'text/html',
29
- :body => 'html content'
30
- part :content_type => 'text/plain',
31
- :body => 'text content'
32
- attachment :content_type => 'image/jpeg',
33
- :filename => 'foo.jpg',
34
- :body => '123456789'
27
+
28
+ part(
29
+ :content_type => 'text/html',
30
+ :body => 'html content'
31
+ )
32
+
33
+ part(
34
+ :content_type => 'text/plain',
35
+ :body => 'text content'
36
+ )
37
+
38
+ attachment(
39
+ :content_type => 'image/jpeg',
40
+ :filename => 'foo.jpg',
41
+ :body => '123456789'
42
+ )
35
43
  end
36
44
 
37
45
  def with_body_and_attachment
38
46
  setup_headers
39
- attachment :content_type => 'image/jpeg',
40
- :filename => 'foo.jpg',
41
- :body => '123456789'
47
+
48
+ attachment(
49
+ :content_type => 'image/jpeg',
50
+ :filename => 'foo.jpg',
51
+ :body => '123456789'
52
+ )
42
53
  end
43
54
 
44
55
  def with_custom_postage_variables
45
- postageapp_template 'test-template'
46
- postageapp_variables 'variable' => 'value'
47
- postageapp_uid 'custom_uid'
48
- postageapp_api_key 'custom_api_key'
56
+ postageapp_template 'test-template'
57
+ postageapp_variables 'variable' => 'value'
58
+ postageapp_uid 'custom_uid'
59
+ postageapp_api_key 'custom_api_key'
49
60
 
50
- from 'test@test.test'
61
+ from 'sender@example.com'
51
62
  subject 'Test Email'
52
63
 
53
- recipients ({
54
- 'test1@test.text' => { 'name' => 'Test 1' },
55
- 'test2@test.text' => { 'name' => 'Test 2' }
56
- })
64
+ recipients(
65
+ 'test1@example.net' => { 'name' => 'Test 1' },
66
+ 'test2@example.net' => { 'name' => 'Test 2' }
67
+ )
57
68
  end
58
69
 
59
70
  private
60
-
61
71
  def setup_headers
62
- recipients 'test@test.test'
63
- from 'text@test.test'
64
- subject 'Test Email'
72
+ recipients 'recipient@example.net'
73
+ from 'sender@example.com'
74
+ subject 'Test Email'
65
75
  end
66
-
67
76
  end
@@ -1,7 +1,7 @@
1
- # Test mailer for ActionMailer 3
2
- class Notifier < PostageApp::Mailer
1
+ # Test mailer for ActionMailer 3 and 4
3
2
 
4
- self.append_view_path(File.expand_path('../', __FILE__))
3
+ class Notifier < PostageApp::Mailer
4
+ self.append_view_path(File.dirname(__FILE__))
5
5
 
6
6
  def blank
7
7
  # ... nothing to see here
@@ -14,6 +14,7 @@ class Notifier < PostageApp::Mailer
14
14
  def with_no_subject
15
15
  hash_without_subject = headers_hash
16
16
  hash_without_subject.delete(:subject)
17
+
17
18
  mail(hash_without_subject)
18
19
  end
19
20
 
@@ -34,18 +35,24 @@ class Notifier < PostageApp::Mailer
34
35
 
35
36
  def with_body_and_attachment_as_file
36
37
  attachments['sample_file.txt'] = 'File content'
38
+
37
39
  mail(headers_hash) do |format|
38
- format.html { render :text => 'manual body text'}
40
+ format.html do
41
+ render(:text => 'manual body text')
42
+ end
39
43
  end
40
44
  end
41
45
 
42
46
  def with_body_and_attachment_as_hash
43
47
  attachments['sample_file.txt'] = {
44
48
  :content_type => 'text/rich',
45
- :body => 'File content'
49
+ :body => 'File content'
46
50
  }
51
+
47
52
  mail(headers_hash) do |format|
48
- format.html { render :text => 'manual body text'}
53
+ format.html do
54
+ render(:text => 'manual body text')
55
+ end
49
56
  end
50
57
  end
51
58
 
@@ -53,28 +60,27 @@ class Notifier < PostageApp::Mailer
53
60
  headers['CustomHeader1'] = 'CustomValue1'
54
61
  headers 'CustomHeader2' => 'CustomValue2'
55
62
 
56
- postageapp_template 'test-template'
57
- postageapp_variables 'variable' => 'value'
58
- postageapp_api_key 'custom_api_key'
59
- postageapp_uid 'custom_uid'
63
+ postageapp_template 'test-template'
64
+ postageapp_variables 'variable' => 'value'
65
+ postageapp_api_key 'custom_api_key'
66
+ postageapp_uid 'custom_uid'
60
67
 
61
68
  mail(
62
- :from => 'test@test.test',
63
- :subject => 'Test Message',
64
- :to => {
65
- 'test1@test.test' => { 'name' => 'Test 1' },
66
- 'test2@test.test' => { 'name' => 'Test 2' }
69
+ :from => 'sender@example.com',
70
+ :subject => 'Test Message',
71
+ :to => {
72
+ 'test1@example.net' => { 'name' => 'Test 1' },
73
+ 'test2@example.net' => { 'name' => 'Test 2' }
67
74
  }
68
75
  )
69
76
  end
70
77
 
71
78
  private
72
-
73
- def headers_hash(options = {})
74
- { :from => 'sender@test.test',
75
- :subject => 'Test Message',
76
- :to => 'test@test.test'
79
+ def headers_hash(options = { })
80
+ {
81
+ :from => 'sender@example.com',
82
+ :to => 'recipient@example.net',
83
+ :subject => 'Test Message'
77
84
  }.merge(options)
78
85
  end
79
-
80
- end
86
+ end
@@ -1,15 +1,15 @@
1
- require File.expand_path('../helper', __FILE__)
1
+ require File.expand_path('helper', File.dirname(__FILE__))
2
2
 
3
3
  # tests for ActionMailer bundled with Rails 2
4
- class Mailer2Test < Minitest::Test
5
- case (ActionMailer::VERSION::MAJOR)
6
- when 2
7
- require File.expand_path('../mailer/action_mailer_2/notifier', __FILE__)
4
+ class Mailer2Test < MiniTest::Test
5
+ require_action_mailer(2) do
6
+ require File.expand_path('mailer/action_mailer_2/notifier', File.dirname(__FILE__))
8
7
 
9
8
  puts "\e[0m\e[32mRunning #{File.basename(__FILE__)} for action_mailer #{ActionMailer::VERSION::STRING}\e[0m"
10
9
 
11
10
  def test_create_blank
12
11
  assert mail = Notifier.create_blank
12
+
13
13
  assert_equal 'send_message', mail.method
14
14
  assert_equal 'https://api.postageapp.com/v.1.0/send_message.json', mail.url.to_s
15
15
  assert mail.arguments.blank?
@@ -17,18 +17,21 @@ class Mailer2Test < Minitest::Test
17
17
 
18
18
  def test_create_with_no_content
19
19
  assert mail = Notifier.create_with_no_content
20
- assert_equal 'test@test.test', mail.arguments['recipients']
21
- assert_equal ({ 'from' => 'text@test.test', 'subject' => 'Test Email' }), mail.arguments['headers']
20
+
21
+ assert_equal 'recipient@example.net', mail.arguments['recipients']
22
+ assert_equal ({ 'from' => 'sender@example.com', 'subject' => 'Test Email' }), mail.arguments['headers']
22
23
  assert mail.arguments['content'].blank?
23
24
  end
24
25
 
25
26
  def test_create_with_text_only_view
26
27
  assert mail = Notifier.create_with_text_only_view
28
+
27
29
  assert_equal 'text only: plain text', mail.arguments['content']['text/plain']
28
30
  end
29
31
 
30
32
  def test_create_with_html_and_text_views
31
33
  assert mail = Notifier.create_with_html_and_text_views
34
+
32
35
  assert_equal 'html and text: plain text', mail.arguments['content']['text/plain']
33
36
  assert_equal 'html and text: html', mail.arguments['content']['text/html']
34
37
  end
@@ -37,6 +40,7 @@ class Mailer2Test < Minitest::Test
37
40
  mock_successful_send
38
41
 
39
42
  assert response = Notifier.deliver_with_html_and_text_views
43
+
40
44
  assert response.is_a?(PostageApp::Response)
41
45
  assert response.ok?
42
46
  end
@@ -48,6 +52,7 @@ class Mailer2Test < Minitest::Test
48
52
 
49
53
  def test_create_with_manual_parts
50
54
  assert mail = Notifier.create_with_manual_parts
55
+
51
56
  assert_equal 'text content', mail.arguments['content']['text/plain']
52
57
  assert_equal 'html content', mail.arguments['content']['text/html']
53
58
  assert !mail.arguments['attachments'].blank?
@@ -57,6 +62,7 @@ class Mailer2Test < Minitest::Test
57
62
 
58
63
  def test_create_with_body_and_attachment
59
64
  assert mail = Notifier.create_with_body_and_attachment
65
+
60
66
  assert !mail.arguments['content'].blank?
61
67
  assert !mail.arguments['content']['text/plain'].blank?
62
68
  assert_equal 'body text', mail.arguments['content']['text/plain']
@@ -67,26 +73,24 @@ class Mailer2Test < Minitest::Test
67
73
 
68
74
  def test_create_with_custom_postage_variables
69
75
  assert mail = Notifier.create_with_custom_postage_variables
76
+
70
77
  assert_equal 'custom_uid', mail.uid
71
78
  assert_equal 'custom_api_key', mail.api_key
72
79
  assert_equal 'test-template', mail.arguments['template']
73
80
  assert_equal ({ 'variable' => 'value' }), mail.arguments['variables']
74
- assert_equal ({ 'test2@test.text' => { 'name' => 'Test 2'},
75
- 'test1@test.text' => { 'name' => 'Test 1'}}), mail.arguments['recipients']
81
+ assert_equal ({ 'test2@example.net' => { 'name' => 'Test 2'},
82
+ 'test1@example.net' => { 'name' => 'Test 1'}}), mail.arguments['recipients']
76
83
  assert_equal 'text content', mail.arguments['content']['text/plain']
77
84
  assert_equal 'html content', mail.arguments['content']['text/html']
78
85
  end
79
86
 
80
87
  def test_create_with_recipient_override
81
- PostageApp.configuration.recipient_override = 'oleg@test.test'
88
+ PostageApp.configuration.recipient_override = 'override@example.net'
89
+
82
90
  assert mail = Notifier.create_with_html_and_text_views
83
- assert_equal 'test@test.test', mail.arguments['recipients']
84
- assert_equal 'oleg@test.test', mail.arguments_to_send['arguments']['recipient_override']
85
- end
86
- else
87
- puts "\e[0m\e[31mSkipping #{File.basename(__FILE__)}\e[0m"
88
91
 
89
- def test_nothing
92
+ assert_equal 'recipient@example.net', mail.arguments['recipients']
93
+ assert_equal 'override@example.net', mail.arguments_to_send['arguments']['recipient_override']
90
94
  end
91
95
  end
92
96
  end
@@ -1,10 +1,9 @@
1
- require File.expand_path('../helper', __FILE__)
1
+ require File.expand_path('helper', File.dirname(__FILE__))
2
2
 
3
3
  # tests for ActionMailer bundled with Rails 3
4
- class Mailer3Test < Minitest::Test
5
- case (ActionMailer::VERSION::MAJOR)
6
- when 3
7
- require File.expand_path('../mailer/action_mailer_3/notifier', __FILE__)
4
+ class Mailer3Test < MiniTest::Test
5
+ require_action_mailer(3) do
6
+ require File.expand_path('mailer/action_mailer_3/notifier', File.dirname(__FILE__))
8
7
 
9
8
  puts "\e[0m\e[32mRunning #{File.basename(__FILE__)} for action_mailer #{ActionMailer::VERSION::STRING}\e[0m"
10
9
 
@@ -35,8 +34,8 @@ class Mailer3Test < Minitest::Test
35
34
  def test_create_with_html_and_text_views
36
35
  mail = Notifier.with_html_and_text_views
37
36
 
38
- assert_equal 'text content', mail.arguments['content']['text/plain']
39
- assert_equal 'with layout html content', mail.arguments['content']['text/html']
37
+ assert_equal 'text content', mail.arguments['content']['text/plain']
38
+ assert_equal 'with layout html content', mail.arguments['content']['text/html']
40
39
  end
41
40
 
42
41
  def test_deliver_with_html_and_text_views
@@ -74,25 +73,25 @@ class Mailer3Test < Minitest::Test
74
73
  args = args['arguments']
75
74
 
76
75
  assert_equal ({
77
- 'test1@test.test' => { 'name' => 'Test 1'},
78
- 'test2@test.test' => { 'name' => 'Test 2'}
76
+ 'test1@example.net' => { 'name' => 'Test 1'},
77
+ 'test2@example.net' => { 'name' => 'Test 2'}
79
78
  }), args['recipients']
80
79
 
81
- assert_equal 'test-template', args['template']
80
+ assert_equal 'test-template', args['template']
82
81
  assert_equal ({ 'variable' => 'value' }), args['variables']
83
- assert_equal 'CustomValue1', args['headers']['CustomHeader1']
84
- assert_equal 'CustomValue2', args['headers']['CustomHeader2']
85
- assert_equal 'text content', args['content']['text/plain']
86
- assert_equal 'with layout html content', args['content']['text/html']
82
+ assert_equal 'CustomValue1', args['headers']['CustomHeader1']
83
+ assert_equal 'CustomValue2', args['headers']['CustomHeader2']
84
+ assert_equal 'text content', args['content']['text/plain']
85
+ assert_equal 'with layout html content', args['content']['text/html']
87
86
  end
88
87
 
89
88
  def test_create_with_recipient_override
90
- PostageApp.configuration.recipient_override = 'oleg@test.test'
89
+ PostageApp.configuration.recipient_override = 'override@example.net'
91
90
 
92
91
  assert mail = Notifier.with_html_and_text_views
93
92
 
94
- assert_equal 'test@test.test', mail.arguments['recipients']
95
- assert_equal 'oleg@test.test', mail.arguments_to_send['arguments']['recipient_override']
93
+ assert_equal 'recipient@example.net', mail.arguments['recipients']
94
+ assert_equal 'override@example.net', mail.arguments_to_send['arguments']['recipient_override']
96
95
  end
97
96
 
98
97
  def test_deliver_for_test_mailer
@@ -113,10 +112,5 @@ class Mailer3Test < Minitest::Test
113
112
 
114
113
  assert_equal [ ], ActionMailer::Base.deliveries
115
114
  end
116
- else
117
- puts "\e[0m\e[31mSkipping #{File.basename(__FILE__)}\e[0m"
118
-
119
- def test_nothing
120
- end
121
115
  end
122
116
  end
@@ -1,16 +1,15 @@
1
- require File.expand_path('../helper', __FILE__)
1
+ require File.expand_path('helper', File.dirname(__FILE__))
2
2
 
3
3
  # tests for ActionMailer bundled with Rails 3
4
- class Mailer4Test < Minitest::Test
5
- case (ActionMailer::VERSION::MAJOR)
6
- when 4
7
- require File.expand_path('../mailer/action_mailer_3/notifier', __FILE__)
4
+ class Mailer4Test < MiniTest::Test
5
+ require_action_mailer(4) do
6
+ require File.expand_path('mailer/action_mailer_3/notifier', File.dirname(__FILE__))
8
7
 
9
8
  puts "\e[0m\e[32mRunning #{File.basename(__FILE__)} for action_mailer #{ActionMailer::VERSION::STRING}\e[0m"
10
9
 
11
10
  def test_create_with_no_content
12
11
  mail = Notifier.with_no_content
13
- assert_equal ({}), mail.arguments['content']
12
+ assert_equal ({ }), mail.arguments['content']
14
13
  end
15
14
 
16
15
  def test_create_with_no_subject
@@ -30,8 +29,8 @@ class Mailer4Test < Minitest::Test
30
29
 
31
30
  def test_create_with_html_and_text_views
32
31
  mail = Notifier.with_html_and_text_views
33
- assert_equal 'text content', mail.arguments['content']['text/plain']
34
- assert_equal 'with layout html content', mail.arguments['content']['text/html']
32
+ assert_equal 'text content', mail.arguments['content']['text/plain']
33
+ assert_equal 'with layout html content', mail.arguments['content']['text/html']
35
34
  end
36
35
 
37
36
  def test_deliver_with_html_and_text_views
@@ -60,49 +59,50 @@ class Mailer4Test < Minitest::Test
60
59
  mail = Notifier.with_custom_postage_variables
61
60
  args = mail.arguments_to_send
62
61
 
63
- assert_equal 'custom_uid', args['uid']
64
- assert_equal 'custom_api_key', args['api_key']
62
+ assert_equal 'custom_uid', args['uid']
63
+ assert_equal 'custom_api_key', args['api_key']
65
64
 
66
65
  args = args['arguments']
67
66
 
68
- assert_equal ({
69
- 'test1@test.test' => { 'name' => 'Test 1'},
70
- 'test2@test.test' => { 'name' => 'Test 2'}
71
- }), args['recipients']
67
+ assert_equal({
68
+ 'test1@example.net' => { 'name' => 'Test 1' },
69
+ 'test2@example.net' => { 'name' => 'Test 2' }
70
+ }, args['recipients'])
72
71
 
73
- assert_equal 'test-template', args['template']
72
+ assert_equal 'test-template', args['template']
74
73
  assert_equal ({ 'variable' => 'value' }), args['variables']
75
- assert_equal 'CustomValue1', args['headers']['CustomHeader1']
76
- assert_equal 'CustomValue2', args['headers']['CustomHeader2']
77
- assert_equal 'text content', args['content']['text/plain']
78
- assert_equal 'with layout html content', args['content']['text/html']
74
+ assert_equal 'CustomValue1', args['headers']['CustomHeader1']
75
+ assert_equal 'CustomValue2', args['headers']['CustomHeader2']
76
+
77
+ assert_equal 'text content', args['content']['text/plain']
78
+ assert_equal 'with layout html content', args['content']['text/html']
79
79
  end
80
80
 
81
81
  def test_create_with_recipient_override
82
- PostageApp.configuration.recipient_override = 'oleg@test.test'
82
+ PostageApp.configuration.recipient_override = 'override@example.org'
83
+
83
84
  assert mail = Notifier.with_html_and_text_views
84
- assert_equal 'test@test.test', mail.arguments['recipients']
85
- assert_equal 'oleg@test.test', mail.arguments_to_send['arguments']['recipient_override']
85
+
86
+ assert_equal 'recipient@example.net', mail.arguments['recipients']
87
+ assert_equal 'override@example.org', mail.arguments_to_send['arguments']['recipient_override']
86
88
  end
87
89
 
88
90
  def test_deliver_for_test_mailer
89
91
  mail = Notifier.with_simple_view
90
92
  mail.delivery_method(Mail::TestMailer)
91
93
  mail.deliver
92
- assert_equal [mail], ActionMailer::Base.deliveries
94
+
95
+ assert_equal [ mail ], ActionMailer::Base.deliveries
93
96
  end
94
97
 
95
98
  def test_deliver_for_not_performing_deliveries_with_test_mailer
96
99
  mail = Notifier.with_simple_view
100
+
97
101
  mail.perform_deliveries = false
98
102
  mail.delivery_method(Mail::TestMailer)
99
103
  mail.deliver
100
- assert_equal [], ActionMailer::Base.deliveries
101
- end
102
- else
103
- puts "\e[0m\e[31mSkipping #{File.basename(__FILE__)}\e[0m"
104
104
 
105
- def test_nothing
105
+ assert_equal [ ], ActionMailer::Base.deliveries
106
106
  end
107
107
  end
108
108
  end