postageapp 1.2.0 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,7 +20,7 @@ class ConfigurationTest < MiniTest::Test
20
20
  assert_equal nil, config.project_root
21
21
  assert_equal 'production', config.environment
22
22
  assert_equal nil, config.logger
23
- assert_equal 'undefined framework', config.framework
23
+ assert_equal 'Ruby', config.framework
24
24
  end
25
25
 
26
26
  def test_initialization_overrides
@@ -8,23 +8,25 @@ class FailedRequestTest < MiniTest::Test
8
8
  end
9
9
 
10
10
  def test_store_and_initialize
11
- assert_match /.*?\/tmp\/postageapp_failed_requests/, PostageApp::FailedRequest.store_path
11
+ assert_match(/.*?\/tmp\/postageapp_failed_requests/, PostageApp::FailedRequest.store_path)
12
12
 
13
13
  request = PostageApp::Request.new(:send_message, {
14
- :headers => {
14
+ headers: {
15
15
  'from' => 'sender@test.test',
16
16
  'subject' => 'Test Message'
17
17
  },
18
- :recipients => 'test@test.test',
19
- :content => {
18
+ recipients: 'test@test.test',
19
+ content: {
20
20
  'text/plain' => 'text content',
21
21
  'text/html' => 'html content'
22
22
  }
23
23
  })
24
24
 
25
25
  assert PostageApp::FailedRequest.store(request)
26
+
26
27
  file_path = File.join(PostageApp::FailedRequest.store_path, request.uid)
27
- assert File.exists?(file_path)
28
+
29
+ assert File.exist?(file_path)
28
30
 
29
31
  stored_request = PostageApp::FailedRequest.initialize_request(request.uid)
30
32
 
@@ -54,6 +56,7 @@ class FailedRequestTest < MiniTest::Test
54
56
 
55
57
  def test_store_with_no_file_path_defined
56
58
  PostageApp.configuration.project_root = nil
59
+
57
60
  assert !PostageApp::FailedRequest.store_path
58
61
  assert !PostageApp::FailedRequest.store('something')
59
62
  end
@@ -62,12 +65,12 @@ class FailedRequestTest < MiniTest::Test
62
65
  mock_failed_send
63
66
 
64
67
  request = PostageApp::Request.new(:send_message, {
65
- :headers => {
68
+ headers: {
66
69
  'from' => 'sender@test.test',
67
70
  'subject' => 'Test Message'
68
71
  },
69
- :recipients => 'test@test.test',
70
- :content => {
72
+ recipients: 'test@test.test',
73
+ content: {
71
74
  'text/plain' => 'text content',
72
75
  'text/html' => 'html content'
73
76
  }
@@ -77,44 +80,56 @@ class FailedRequestTest < MiniTest::Test
77
80
  assert response.fail?
78
81
 
79
82
  file_path = File.join(PostageApp::FailedRequest.store_path, request.uid)
80
- assert File.exists?(file_path)
83
+ assert File.exist?(file_path)
81
84
 
82
85
  mock_successful_send
83
86
 
84
87
  request = PostageApp::Request.new(:get_project_info)
85
88
 
86
- message_receipt_response = stub(:fail? => false, :ok? => false, :not_found? => true)
89
+ message_receipt_response = stub(
90
+ :fail? => false,
91
+ :ok? => false,
92
+ :not_found? => true
93
+ )
94
+
87
95
  message_receipt_request = stub(:send => message_receipt_response)
88
- PostageApp::Request.stubs(:new).with{|a,b| a == :get_message_receipt}.returns(message_receipt_request)
96
+
97
+ PostageApp::Request.stubs(:new).with do |a,b|
98
+ a == :get_message_receipt
99
+ end.returns(message_receipt_request)
89
100
 
90
101
  response = request.send
102
+
91
103
  assert response.ok?
92
104
 
93
- assert !File.exists?(file_path)
105
+ assert !File.exist?(file_path)
94
106
  end
95
107
 
96
108
  def test_resend_all_failure
97
109
  mock_failed_send
98
110
  request = PostageApp::Request.new(:send_message, {
99
- :headers => {
111
+ headers: {
100
112
  'from' => 'sender@test.test',
101
113
  'subject' => 'Test Message'
102
114
  },
103
- :recipients => 'test@test.test',
104
- :content => {
115
+ recipients: 'test@test.test',
116
+ content: {
105
117
  'text/plain' => 'text content',
106
118
  'text/html' => 'html content'
107
119
  }
108
120
  })
109
121
 
110
122
  response = request.send
123
+
111
124
  assert response.fail?
125
+
112
126
  file_path = File.join(PostageApp::FailedRequest.store_path, request.uid)
113
- assert File.exists?(file_path)
127
+
128
+ assert File.exist?(file_path)
114
129
 
115
130
  # Forcing to resend. Should quit right away as we can't connect
116
131
  PostageApp::FailedRequest.resend_all
117
132
 
118
- assert File.exists?(file_path)
133
+ assert File.exist?(file_path)
119
134
  end
120
135
  end
@@ -1,12 +1,16 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
+ # rubygems 1.8.30
4
+
5
+ gem 'rails', '~> 2.3.0'
6
+
3
7
  gem 'json'
4
8
  gem 'mail'
9
+ gem 'mime-types', '2.99.1' # Locked for 1.9 compatibility
5
10
 
6
11
  group :test do
7
12
  gem 'rake'
8
13
  gem 'minitest'
9
14
  gem 'minitest-reporters'
10
- gem 'rails', '~> 2.3.0'
11
15
  gem 'mocha'
12
16
  end
@@ -1,12 +1,17 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
+ # rubygems 1.8.30
4
+
5
+ gem 'bundler', '1.0.22'
6
+ gem 'rails', '~> 3.0.0'
7
+
3
8
  gem 'json'
4
9
  gem 'mail'
10
+ gem 'mime-types', '~> 1.16' # Rails 3.0.x dependency
5
11
 
6
12
  group :test do
7
13
  gem 'rake'
8
14
  gem 'minitest'
9
15
  gem 'minitest-reporters'
10
- gem 'rails', '~> 3.0.0'
11
16
  gem 'mocha'
12
17
  end
@@ -1,5 +1,6 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
+ gem 'rails', '~> 3.1.0'
3
4
  gem 'json'
4
5
  gem 'mail'
5
6
 
@@ -7,6 +8,5 @@ group :test do
7
8
  gem 'rake'
8
9
  gem 'minitest'
9
10
  gem 'minitest-reporters'
10
- gem 'rails', '~> 3.1.0'
11
11
  gem 'mocha'
12
12
  end
@@ -1,5 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
+ gem 'rails', '~> 3.2.0'
4
+
3
5
  gem 'json'
4
6
  gem 'mail'
5
7
 
@@ -7,6 +9,5 @@ group :test do
7
9
  gem 'rake'
8
10
  gem 'minitest'
9
11
  gem 'minitest-reporters'
10
- gem 'rails', '~> 3.2.0'
11
12
  gem 'mocha'
12
13
  end
@@ -1,5 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
+ gem 'rails', '~> 4.0.0'
4
+
3
5
  gem 'json'
4
6
  gem 'mail'
5
7
 
@@ -7,6 +9,5 @@ group :test do
7
9
  gem 'rake'
8
10
  gem 'minitest'
9
11
  gem 'minitest-reporters'
10
- gem 'rails', '~> 4.0.0'
11
12
  gem 'mocha'
12
13
  end
@@ -1,5 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
+ gem 'rails', '~> 4.1.0'
4
+
3
5
  gem 'json'
4
6
  gem 'mail'
5
7
 
@@ -7,6 +9,5 @@ group :test do
7
9
  gem 'rake'
8
10
  gem 'minitest'
9
11
  gem 'minitest-reporters'
10
- gem 'rails', '~> 4.1.0'
11
12
  gem 'mocha'
12
13
  end
@@ -1,5 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
+ gem 'rails', '~> 4.2.0'
4
+
3
5
  gem 'json'
4
6
  gem 'mail'
5
7
 
@@ -7,6 +9,5 @@ group :test do
7
9
  gem 'rake'
8
10
  gem 'minitest'
9
11
  gem 'minitest-reporters'
10
- gem 'rails', '~> 4.2.0'
11
12
  gem 'mocha'
12
13
  end
@@ -2,6 +2,7 @@ source 'http://rubygems.org'
2
2
 
3
3
  gem 'json'
4
4
  gem 'mail'
5
+ gem 'mime-types', '2.99.1' # Locked for 1.9 compatibility
5
6
 
6
7
  group :test do
7
8
  gem 'rake'
@@ -21,6 +21,12 @@ require 'postageapp/mailer'
21
21
  require 'mocha/setup'
22
22
  require 'with_environment'
23
23
 
24
+ # This fixes an issue in Rails 3.2.22.2 where HashWithIndifferentAccess isn't
25
+ # being loaded properly during testing.
26
+ if (defined?(ActiveSupport) and !defined?(HashWithIndifferentAccess))
27
+ require 'active_support/hash_with_indifferent_access'
28
+ end
29
+
24
30
  class MiniTest::Test
25
31
  include WithEnvironment
26
32
 
@@ -67,12 +73,12 @@ class MiniTest::Test
67
73
  def mock_successful_send(status = 'ok')
68
74
  Net::HTTP.any_instance.stubs(:post).returns(Net::HTTPResponse.new(nil, nil, nil))
69
75
  Net::HTTPResponse.any_instance.stubs(:body).returns({
70
- :response => {
71
- :uid => 'sha1hashuid23456789012345678901234567890',
72
- :status => status
76
+ response: {
77
+ uid: 'sha1hashuid23456789012345678901234567890',
78
+ status: status
73
79
  },
74
- :data => {
75
- :message => { :id => 999 }
80
+ data: {
81
+ message: { id: 999 }
76
82
  }
77
83
  }.to_json)
78
84
  end
@@ -84,6 +90,7 @@ class MiniTest::Test
84
90
  # Briefly substitutes a new object in place of an existing constant.
85
91
  def const_replace(name, object)
86
92
  original = Object.const_defined?(name) && Object.const_get(name)
93
+
87
94
  Object.send(:remove_const, name) if (original)
88
95
  Object.const_set(name, object)
89
96
 
@@ -9,9 +9,9 @@ class LiveTest < MiniTest::Test
9
9
  super
10
10
 
11
11
  PostageApp.configure do |config|
12
- config.secure = false
13
- config.host = 'api.postageapp.local'
14
- config.api_key = 'PROJECT_API_KEY'
12
+ config.secure = false
13
+ config.host = 'api.postageapp.local'
14
+ config.api_key = 'PROJECT_API_KEY'
15
15
  end
16
16
  end
17
17
 
@@ -21,55 +21,74 @@ class LiveTest < MiniTest::Test
21
21
 
22
22
  assert_equal 'PostageApp::Response', response.class.name
23
23
  assert_equal 'ok', response.status
24
- assert_match /^\w{40}$/, response.uid
24
+ assert_match(/^\w{40}$/, response.uid)
25
25
  assert_equal nil, response.message
26
- assert_equal ({
27
- 'methods' => 'get_account_info, get_message_receipt, get_method_list, get_project_info, send_message'
28
- }), response.data
26
+ assert_equal(
27
+ {
28
+ 'methods' => 'get_account_info, get_message_receipt, get_method_list, get_project_info, send_message'
29
+ },
30
+ response.data
31
+ )
29
32
  end
30
33
 
31
34
  def test_request_send_message
32
35
  request = PostageApp::Request.new(:send_message, {
33
- :headers => {
36
+ headers: {
34
37
  'from' => 'sender@example.com',
35
38
  'subject' => 'Test Message'
36
39
  },
37
- :recipients => 'recipient@example.net',
38
- :content => {
40
+ recipients: 'recipient@example.net',
41
+ content: {
39
42
  'text/plain' => 'text content',
40
43
  'text/html' => 'html content'
41
44
  }
42
45
  })
46
+
43
47
  response = request.send
48
+
44
49
  assert_equal 'PostageApp::Response', response.class.name
45
50
  assert_equal 'ok', response.status
46
- assert_match /^\w{40}$/, response.uid
51
+
52
+ assert_match(/^\w{40}$/, response.uid)
47
53
  assert_equal nil, response.message
48
- assert_match /\d+/, response.data['message']['id'].to_s
54
+ assert_match(/\d+/, response.data['message']['id'].to_s)
55
+
56
+ receipt = PostageApp::Request.new(
57
+ :get_message_receipt,
58
+ uid: response.uid
59
+ ).send
49
60
 
50
- receipt = PostageApp::Request.new(:get_message_receipt, :uid => response.uid).send
51
61
  assert receipt.ok?
52
62
 
53
- receipt = PostageApp::Request.new(:get_message_receipt, :uid => 'bogus').send
63
+ receipt = PostageApp::Request.new(
64
+ :get_message_receipt,
65
+ uid: 'bogus'
66
+ ).send
67
+
54
68
  assert receipt.not_found?
55
69
  end
56
70
 
57
71
  def test_request_non_existant_method
58
72
  request = PostageApp::Request.new(:non_existant)
73
+
59
74
  response = request.send
75
+
60
76
  assert_equal 'PostageApp::Response', response.class.name
61
77
  assert_equal 'internal_server_error', response.status
62
- assert_match /^\w{40}$/, response.uid
63
- assert_equal 'No action responded to non_existant. Actions: get_account_info, get_message_receipt, get_method_list, get_project_info, and send_message', response.message
78
+ assert_match(/\A\w{40}$/, response.uid)
79
+ assert_match(/\ANo action responded to non_existant/, response.message)
64
80
  assert_equal nil, response.data
65
81
  end
66
82
 
67
83
  # Testable under ruby 1.9.2 Probably OK in production too... Probably
68
84
  # Lunchtime reading: http://ph7spot.com/musings/system-timer
69
85
  def test_request_timeout
70
- PostageApp.configuration.host = 'dead.postageapp.local'
86
+ PostageApp.configuration.host = '127.0.0.254'
87
+
71
88
  request = PostageApp::Request.new(:get_method_list)
89
+
72
90
  response = request.send
91
+
73
92
  assert_equal 'PostageApp::Response', response.class.name
74
93
  assert_equal 'fail', response.status
75
94
  end
@@ -1,6 +1,5 @@
1
1
  require File.expand_path('helper', File.dirname(__FILE__))
2
2
 
3
- # tests for ActionMailer bundled with Rails 2
4
3
  class Mailer2Test < MiniTest::Test
5
4
  require_action_mailer(2) do
6
5
  require File.expand_path('mailer/action_mailer_2/notifier', File.dirname(__FILE__))
@@ -19,7 +18,7 @@ class Mailer2Test < MiniTest::Test
19
18
  assert mail = Notifier.create_with_no_content
20
19
 
21
20
  assert_equal 'recipient@example.net', mail.arguments['recipients']
22
- assert_equal ({ 'from' => 'sender@example.com', 'subject' => 'Test Email' }), mail.arguments['headers']
21
+ assert_equal({ 'from' => 'sender@example.com', 'subject' => 'Test Email' }, mail.arguments['headers'])
23
22
  assert mail.arguments['content'].blank?
24
23
  end
25
24
 
@@ -77,9 +76,9 @@ class Mailer2Test < MiniTest::Test
77
76
  assert_equal 'custom_uid', mail.uid
78
77
  assert_equal 'custom_api_key', mail.api_key
79
78
  assert_equal 'test-template', mail.arguments['template']
80
- assert_equal ({ 'variable' => 'value' }), mail.arguments['variables']
81
- assert_equal ({ 'test2@example.net' => { 'name' => 'Test 2'},
82
- 'test1@example.net' => { 'name' => 'Test 1'}}), mail.arguments['recipients']
79
+ assert_equal({ 'variable' => 'value' }, mail.arguments['variables'])
80
+ assert_equal({ 'test2@example.net' => { 'name' => 'Test 2'},
81
+ 'test1@example.net' => { 'name' => 'Test 1'}}, mail.arguments['recipients'])
83
82
  assert_equal 'text content', mail.arguments['content']['text/plain']
84
83
  assert_equal 'html content', mail.arguments['content']['text/html']
85
84
  end
@@ -1,6 +1,5 @@
1
1
  require File.expand_path('helper', File.dirname(__FILE__))
2
2
 
3
- # tests for ActionMailer bundled with Rails 3
4
3
  class Mailer3Test < MiniTest::Test
5
4
  require_action_mailer(3) do
6
5
  require File.expand_path('mailer/action_mailer_3/notifier', File.dirname(__FILE__))
@@ -72,13 +71,16 @@ class Mailer3Test < MiniTest::Test
72
71
 
73
72
  args = args['arguments']
74
73
 
75
- assert_equal ({
76
- 'test1@example.net' => { 'name' => 'Test 1'},
77
- 'test2@example.net' => { 'name' => 'Test 2'}
78
- }), args['recipients']
74
+ assert_equal(
75
+ {
76
+ 'test1@example.net' => { 'name' => 'Test 1' },
77
+ 'test2@example.net' => { 'name' => 'Test 2' }
78
+ },
79
+ args['recipients']
80
+ )
79
81
 
80
82
  assert_equal 'test-template', args['template']
81
- assert_equal ({ 'variable' => 'value' }), args['variables']
83
+ assert_equal({ 'variable' => 'value' }, args['variables'])
82
84
  assert_equal 'CustomValue1', args['headers']['CustomHeader1']
83
85
  assert_equal 'CustomValue2', args['headers']['CustomHeader2']
84
86
  assert_equal 'text content', args['content']['text/plain']