postageapp 1.0.24 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
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,22 +1,25 @@
1
- require File.expand_path('../helper', __FILE__)
1
+ require File.expand_path('helper', File.dirname(__FILE__))
2
2
 
3
- class MailerHelperMethodsTest < Minitest::Test
4
-
3
+ class MailerHelperMethodsTest < MiniTest::Test
5
4
  def test_mailer_helper_methods
6
- request = PostageApp::Request.new(:send_message, {
7
- :headers => { 'from' => 'sender@test.test',
8
- 'subject' => 'Test Message'},
5
+ request = PostageApp::Request.new(
6
+ :send_message,
7
+ :headers => {
8
+ 'from' => 'sender@test.test',
9
+ 'subject' => 'Test Message'
10
+ },
9
11
  :recipients => 'test@test.test',
10
- :content => {
11
- 'text/plain' => 'text content',
12
- 'text/html' => 'html content'
12
+ :content => {
13
+ 'text/plain' => 'text content',
14
+ 'text/html' => 'html content'
13
15
  }
14
- })
15
- assert_equal ['test@test.test'], request.to
16
- assert_equal ['sender@test.test'], request.from
16
+ )
17
+
18
+ assert_equal [ 'test@test.test' ], request.to
19
+ assert_equal [ 'sender@test.test' ], request.from
17
20
  assert_equal 'Test Message', request.subject
21
+
18
22
  assert_match 'html content', request.body
19
23
  assert_match 'text content', request.body
20
24
  end
21
-
22
- end
25
+ end
@@ -1,18 +1,17 @@
1
- require File.expand_path('../helper', __FILE__)
1
+ require File.expand_path('helper', File.dirname(__FILE__))
2
2
 
3
- class PostageAppTest < Minitest::Test
4
-
3
+ class PostageAppTest < MiniTest::Test
5
4
  def test_method_configure
6
5
  PostageApp.configure do |config|
7
- config.api_key = 'abcdefg12345'
8
- config.host = 'test.test'
6
+ config.api_key = 'abcdefg12345'
7
+ config.host = 'test.test'
9
8
  end
10
- assert_equal 'abcdefg12345', PostageApp.configuration.api_key
11
- assert_equal 'test.test', PostageApp.configuration.host
9
+
10
+ assert_equal 'abcdefg12345', PostageApp.configuration.api_key
11
+ assert_equal 'test.test', PostageApp.configuration.host
12
12
  end
13
13
 
14
14
  def test_logger
15
15
  assert PostageApp.logger.is_a?(Logger)
16
16
  end
17
-
18
- end
17
+ end
@@ -1,29 +1,29 @@
1
- require File.expand_path('../helper', __FILE__)
1
+ require File.expand_path('helper', File.dirname(__FILE__))
2
2
 
3
- require File.expand_path('../../lib/postageapp/rails/rails', __FILE__)
3
+ require File.expand_path('../lib/postageapp/rails/rails', File.dirname(__FILE__))
4
4
 
5
- class RailsInitializationTest < Minitest::Test
6
-
7
- include ConstantDefinitions
8
-
5
+ class RailsInitializationTest < MiniTest::Test
9
6
  def test_initialization
10
7
  rails = Module.new do
11
8
  def self.version
12
9
  '9.9.9'
13
10
  end
11
+
14
12
  def self.root
15
13
  'RAILS ROOT'
16
14
  end
15
+
17
16
  def self.env
18
17
  "RAILS ENV"
19
18
  end
20
19
  end
21
- define_constant('Rails', rails)
22
- PostageApp::Rails.initialize
23
-
24
- assert_equal 'Rails 9.9.9', PostageApp.configuration.framework
25
- assert_equal 'RAILS ROOT', PostageApp.configuration.project_root
26
- assert_equal 'RAILS ENV', PostageApp.configuration.environment
20
+
21
+ const_replace(:Rails, rails) do
22
+ PostageApp::Rails.initialize
23
+
24
+ assert_equal 'Rails 9.9.9', PostageApp.configuration.framework
25
+ assert_equal 'RAILS ROOT', PostageApp.configuration.project_root
26
+ assert_equal 'RAILS ENV', PostageApp.configuration.environment
27
+ end
27
28
  end
28
-
29
- end
29
+ end
@@ -1,6 +1,6 @@
1
- require File.expand_path('../helper', __FILE__)
1
+ require File.expand_path('helper', File.dirname(__FILE__))
2
2
 
3
- class RequestTest < Minitest::Test
3
+ class RequestTest < MiniTest::Test
4
4
  def test_method_uid
5
5
  request = PostageApp::Request.new('test_method')
6
6
 
@@ -14,26 +14,23 @@ class RequestTest < Minitest::Test
14
14
  def test_method_url
15
15
  request = PostageApp::Request.new('test_method')
16
16
 
17
- assert_equal 'api.postageapp.com', request.url.host
18
- assert_equal 443, request.url.port
17
+ assert_equal 'api.postageapp.com', request.url.host
18
+ assert_equal 443, request.url.port
19
19
  assert_equal '/v.1.0/test_method.json', request.url.path
20
20
  end
21
21
 
22
22
  def test_method_arguments_to_send
23
- request = PostageApp::Request.new('send_message', {
24
- 'headers' => {
25
- 'from' => 'sender@test.test',
26
- 'subject' => 'Test Message'
23
+ request = PostageApp::Request.new('send_message',
24
+ 'headers' => {
25
+ 'from' => 'sender@test.test',
26
+ 'subject' => 'Test Message'
27
27
  },
28
- 'recipients' => 'test@test.test',
29
- 'content' => {
30
- 'text/plain' => 'text content',
31
- 'text/html' => 'html content'
28
+ 'recipients' => 'test@test.test',
29
+ 'content' => {
30
+ 'text/plain' => 'text content',
31
+ 'text/html' => 'html content'
32
32
  }
33
- })
34
-
35
- assert_equal 'text content', request.text_part
36
- assert_equal 'html content', request.html_part
33
+ )
37
34
 
38
35
  args = request.arguments_to_send
39
36
 
@@ -85,37 +82,40 @@ class RequestTest < Minitest::Test
85
82
  def test_send
86
83
  mock_successful_send
87
84
 
88
- request = PostageApp::Request.new('send_message', {
89
- 'headers' => {
90
- 'from' => 'sender@test.test',
91
- 'subject' => 'Test Message'
85
+ request = PostageApp::Request.new('send_message',
86
+ 'headers' => {
87
+ 'from' => 'sender@test.test',
88
+ 'subject' => 'Test Message'
92
89
  },
93
- 'recipients' => 'test@test.test',
94
- 'content' => {
95
- 'text/plain' => 'text content',
96
- 'text/html' => 'html content'
90
+ 'recipients' => 'test@test.test',
91
+ 'content' => {
92
+ 'text/plain' => 'text content',
93
+ 'text/html' => 'html content'
97
94
  }
98
- })
95
+ )
96
+
99
97
  response = request.send
98
+
100
99
  assert_equal 'ok', response.status
101
100
  assert_equal 'sha1hashuid23456789012345678901234567890', response.uid
102
- assert_equal({'message' => { 'id' => 999 }}, response.data)
101
+ assert_equal({ 'message' => { 'id' => 999 } }, response.data)
103
102
  end
104
103
 
105
104
  def test_send_failure
106
105
  mock_failed_send
107
106
 
108
- request = PostageApp::Request.new('send_message', {
109
- 'headers' => {
110
- 'from' => 'sender@test.test',
111
- 'subject' => 'Test Message'
107
+ request = PostageApp::Request.new(
108
+ 'send_message',
109
+ 'headers' => {
110
+ 'from' => 'sender@test.test',
111
+ 'subject' => 'Test Message'
112
112
  },
113
- 'recipients' => 'test@test.test',
114
- 'content' => {
115
- 'text/plain' => 'text content',
116
- 'text/html' => 'html content'
113
+ 'recipients' => 'test@test.test',
114
+ 'content' => {
115
+ 'text/plain' => 'text content',
116
+ 'text/html' => 'html content'
117
117
  }
118
- })
118
+ )
119
119
 
120
120
  response = request.send
121
121
 
@@ -1,24 +1,26 @@
1
- require File.expand_path('../helper', __FILE__)
1
+ require File.expand_path('helper', File.dirname(__FILE__))
2
2
 
3
- class ResponseTest < Minitest::Test
4
-
3
+ class ResponseTest < MiniTest::Test
5
4
  def test_initialization
6
- object = stub(:body => {
7
- 'response' => {
8
- 'uid' => 'md5_hash_uid',
9
- 'status' => 'ok',
10
- 'message' => 'api reply message'
11
- },
12
- 'data' => {
13
- 'key' => 'value'
14
- }
15
- }.to_json)
5
+ object = stub(
6
+ :body => {
7
+ 'response' => {
8
+ 'uid' => 'md5_hash_uid',
9
+ 'status' => 'ok',
10
+ 'message' => 'api reply message'
11
+ },
12
+ 'data' => {
13
+ 'key' => 'value'
14
+ }
15
+ }.to_json
16
+ )
16
17
 
17
18
  response = PostageApp::Response.new(object)
18
- assert_equal 'md5_hash_uid', response.uid
19
- assert_equal 'ok', response.status
20
- assert_equal 'api reply message', response.message
21
- assert_equal ({'key' => 'value'}), response.data
19
+ assert_equal 'md5_hash_uid', response.uid
20
+ assert_equal 'ok', response.status
21
+ assert_equal 'api reply message', response.message
22
+ assert_equal ({'key' => 'value'}), response.data
23
+
22
24
  assert response.ok?
23
25
  end
24
26
 
@@ -36,5 +38,4 @@ class ResponseTest < Minitest::Test
36
38
  assert true
37
39
  end
38
40
  end
39
-
40
- end
41
+ end
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'yaml'
4
+
5
+ require File.expand_path('with_environment', File.dirname(__FILE__))
6
+
7
+ class TravisTest
8
+ extend WithEnvironment
9
+
10
+ ENV_VARIABLE = {
11
+ :rvm => "RBENV_VERSION",
12
+ :gemfile => "BUNDLE_GEMFILE"
13
+ }
14
+
15
+ def self.bash_env(env)
16
+ env.collect do |key, value|
17
+ variable = ENV_VARIABLE[key]
18
+
19
+ variable ? '%s=%s' % [ variable, value ] : nil
20
+ end.compact.join(' ')
21
+ end
22
+
23
+ def self.env_expanded(env)
24
+ Hash[
25
+ env.collect do |key, value|
26
+ [ ENV_VARIABLE[key], value ]
27
+ end
28
+ ]
29
+ end
30
+
31
+ def self.shell_command!(args, env)
32
+ commands = args.collect do |s|
33
+ s % env
34
+ end
35
+
36
+ env_expanded(env).each do |key, value|
37
+ puts 'export %s=%s' % [ key, value ]
38
+ end
39
+ puts(commands.join(' && '))
40
+
41
+ with_environment(env_expanded(env)) do
42
+ result = system(commands.join(' && '))
43
+
44
+ yield(result) if (block_given?)
45
+
46
+ result
47
+ end
48
+ end
49
+
50
+ def self.install_versions!
51
+ travis_test = self.new
52
+
53
+ travis_test.matrix.collect do |entry|
54
+ {
55
+ :rvm => entry[:rvm]
56
+ }
57
+ end.uniq.each do |entry|
58
+ puts "Ruby %{rvm}" % entry
59
+
60
+ shell_command!(
61
+ [
62
+ "rbenv install %{version}",
63
+ "gem install bundler"
64
+ ],
65
+ entry
66
+ )
67
+ end
68
+ end
69
+
70
+ def self.validate_ruby_versions!
71
+ travis_test = self.new
72
+
73
+ versions = { }
74
+
75
+ travis_test.matrix.each do |entry|
76
+ next if (versions[entry[:rvm]])
77
+
78
+ versions[entry[:rvm]] = true
79
+
80
+ shell_command!(
81
+ [
82
+ "ruby -e 'puts RUBY_VERSION'"
83
+ ],
84
+ entry
85
+ )
86
+ end
87
+ end
88
+
89
+ def self.gemfile_lock_remove!(path)
90
+ path = path + '.lock'
91
+
92
+ if (File.exist?(path))
93
+ File.unlink(path)
94
+ end
95
+
96
+ rescue Errno::ENOENT
97
+ # Already removed for some reason? Ignore.
98
+ end
99
+
100
+ def self.run!
101
+ travis_test = self.new
102
+
103
+ results = { }
104
+
105
+ travis_test.matrix.each do |entry|
106
+ puts "RBENV_VERSION=%{rvm} BUNDLE_GEMFILE=%{gemfile}" % entry
107
+
108
+ gemfile_lock_remove!(entry[:gemfile])
109
+
110
+ shell_command!(
111
+ [
112
+ "bundle install --quiet",
113
+ "rake test"
114
+ ],
115
+ entry
116
+ ) do |code|
117
+ results[entry] = code
118
+ end
119
+ end
120
+
121
+ puts '%-20s %-24s %-6s' % [ 'Ruby', 'Gemfile', 'Status' ]
122
+ puts '-' * 78
123
+
124
+ results.each do |entry, code|
125
+ puts '%-20s %-24s %-6s' % [
126
+ entry[:rvm],
127
+ File.basename(entry[:gemfile]).sub(/\AGemfile\./,''),
128
+ code
129
+ ]
130
+ end
131
+ end
132
+
133
+ def travis_config_path
134
+ @travis_config_path ||= File.expand_path('../.travis.yml', File.dirname(__FILE__))
135
+ end
136
+
137
+ def travis_config
138
+ @travis_config ||= YAML.load(File.open(travis_config_path))
139
+ end
140
+
141
+ def gemfiles
142
+ travis_config['gemfile']
143
+ end
144
+
145
+ def ruby_versions
146
+ travis_config['rvm']
147
+ end
148
+
149
+ def matrix_exclusions
150
+ travis_config['matrix']['exclude'].collect do |entry|
151
+ {
152
+ :rvm => entry['rvm'],
153
+ :gemfile => entry['gemfile']
154
+ }
155
+ end
156
+ end
157
+
158
+ def matrix
159
+ ruby_versions.flat_map do |version|
160
+ gemfiles.collect do |gemfile|
161
+ {
162
+ :rvm => version,
163
+ :gemfile => gemfile
164
+ }
165
+ end
166
+ end - matrix_exclusions
167
+ end
168
+ end
@@ -0,0 +1,27 @@
1
+ module WithEnvironment
2
+ def with_environment(env)
3
+ prev_env = {
4
+ 'PATH' => ENV['PATH']
5
+ }
6
+
7
+ # Remove rbenv version specific paths to restore environment to normal,
8
+ # non-versioned state.
9
+ ENV['PATH'] = ENV['PATH'].split(/:/).reject do |path|
10
+ path.match(%r[/\.rbenv/versions/])
11
+ end.join(':')
12
+
13
+ env.each do |key, value|
14
+ key = key.to_s
15
+
16
+ prev_env[key] = ENV[key]
17
+ ENV[key] = value
18
+ end
19
+
20
+ yield
21
+
22
+ ensure
23
+ prev_env.each do |key, value|
24
+ ENV[key] = value
25
+ end
26
+ end
27
+ end