aws-ses 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ module AWS
2
+ module SES
3
+ module VERSION #:nodoc:
4
+ MAJOR = '0'
5
+ MINOR = '1'
6
+ TINY = '0'
7
+ BETA = Time.now.to_i.to_s
8
+ end
9
+
10
+ Version = [VERSION::MAJOR, VERSION::MINOR, VERSION::TINY, VERSION::BETA].compact * '.'
11
+ end
12
+ end
data/test/base_test.rb ADDED
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class BaseTest < Test::Unit::TestCase
4
+ def test_connection_established
5
+ instance = Base.new(:access_key_id => '123', :secret_access_key => 'abc')
6
+
7
+ assert_not_nil instance.instance_variable_get("@http")
8
+ end
9
+ end
@@ -0,0 +1,340 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class HashExtensionsTest < Test::Unit::TestCase
4
+ def test_to_query_string
5
+ # Because hashes aren't ordered, I'm mostly testing against hashes with just one key
6
+ symbol_keys = {:one => 1}
7
+ string_keys = {'one' => 1}
8
+ expected = '?one=1'
9
+ [symbol_keys, string_keys].each do |hash|
10
+ assert_equal expected, hash.to_query_string
11
+ end
12
+ end
13
+
14
+ def test_empty_hash_returns_no_query_string
15
+ assert_equal '', {}.to_query_string
16
+ end
17
+
18
+ def test_include_question_mark
19
+ hash = {:one => 1}
20
+ assert_equal '?one=1', hash.to_query_string
21
+ assert_equal 'one=1', hash.to_query_string(false)
22
+ end
23
+
24
+ def test_elements_joined_by_ampersand
25
+ hash = {:one => 1, :two => 2}
26
+ qs = hash.to_query_string
27
+ assert qs['one=1&two=2'] || qs['two=2&one=1']
28
+ end
29
+
30
+ def test_normalized_options
31
+ expectations = [
32
+ [{:foo_bar => 1}, {'foo-bar' => '1'}],
33
+ [{'foo_bar' => 1}, {'foo-bar' => '1'}],
34
+ [{'foo-bar' => 1}, {'foo-bar' => '1'}],
35
+ [{}, {}]
36
+ ]
37
+
38
+ expectations.each do |(before, after)|
39
+ assert_equal after, before.to_normalized_options
40
+ end
41
+ end
42
+ end
43
+
44
+ class StringExtensionsTest < Test::Unit::TestCase
45
+ def test_previous
46
+ expectations = {'abc' => 'abb', '123' => '122', '1' => '0'}
47
+ expectations.each do |before, after|
48
+ assert_equal after, before.previous
49
+ end
50
+ end
51
+
52
+ def test_to_header
53
+ transformations = {
54
+ 'foo' => 'foo',
55
+ :foo => 'foo',
56
+ 'foo-bar' => 'foo-bar',
57
+ 'foo_bar' => 'foo-bar',
58
+ :foo_bar => 'foo-bar',
59
+ 'Foo-Bar' => 'foo-bar',
60
+ 'Foo_Bar' => 'foo-bar'
61
+ }
62
+
63
+ transformations.each do |before, after|
64
+ assert_equal after, before.to_header
65
+ end
66
+ end
67
+
68
+ def test_valid_utf8?
69
+ assert !"318597/620065/GTL_75\24300_A600_A610.zip".valid_utf8?
70
+ assert "318597/620065/GTL_75£00_A600_A610.zip".valid_utf8?
71
+ end
72
+
73
+ def test_remove_extended
74
+ assert "318597/620065/GTL_75\24300_A600_A610.zip".remove_extended.valid_utf8?
75
+ assert "318597/620065/GTL_75£00_A600_A610.zip".remove_extended.valid_utf8?
76
+ end
77
+ end
78
+
79
+ class CoercibleStringTest < Test::Unit::TestCase
80
+
81
+ def test_coerce
82
+ coercions = [
83
+ ['1', 1],
84
+ ['false', false],
85
+ ['true', true],
86
+ ['2006-10-29T23:14:47.000Z', Time.parse('2006-10-29T23:14:47.000Z')],
87
+ ['Hello!', 'Hello!'],
88
+ ['false23', 'false23'],
89
+ ['03 1-2-3-Apple-Tree.mp3', '03 1-2-3-Apple-Tree.mp3'],
90
+ ['0815', '0815'] # This number isn't coerced because the leading zero would be lost
91
+ ]
92
+
93
+ coercions.each do |before, after|
94
+ assert_nothing_raised do
95
+ assert_equal after, CoercibleString.coerce(before)
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ class KerneltExtensionsTest < Test::Unit::TestCase
102
+ class Foo
103
+ def foo
104
+ __method__
105
+ end
106
+
107
+ def bar
108
+ foo
109
+ end
110
+
111
+ def baz
112
+ bar
113
+ end
114
+ end
115
+
116
+ class Bar
117
+ def foo
118
+ calling_method
119
+ end
120
+
121
+ def bar
122
+ calling_method
123
+ end
124
+
125
+ def calling_method
126
+ __method__(1)
127
+ end
128
+ end
129
+
130
+ def test___method___works_regardless_of_nesting
131
+ f = Foo.new
132
+ [:foo, :bar, :baz].each do |method|
133
+ assert_equal 'foo', f.send(method)
134
+ end
135
+ end
136
+
137
+ def test___method___depth
138
+ b = Bar.new
139
+ assert_equal 'foo', b.foo
140
+ assert_equal 'bar', b.bar
141
+ end
142
+ end if RUBY_VERSION <= '1.8.7'
143
+
144
+ class ModuleExtensionsTest < Test::Unit::TestCase
145
+ class Foo
146
+ def foo(reload = false)
147
+ expirable_memoize(reload) do
148
+ Time.now
149
+ end
150
+ end
151
+
152
+ def bar(reload = false)
153
+ expirable_memoize(reload, :baz) do
154
+ Time.now
155
+ end
156
+ end
157
+
158
+ def quux
159
+ Time.now
160
+ end
161
+ memoized :quux
162
+ end
163
+
164
+ def setup
165
+ @instance = Foo.new
166
+ end
167
+
168
+ def test_memoize
169
+ assert !instance_variables_of(@instance).include?('@foo')
170
+ cached_result = @instance.foo
171
+ assert_equal cached_result, @instance.foo
172
+ assert instance_variables_of(@instance).include?('@foo')
173
+ assert_equal cached_result, @instance.send(:instance_variable_get, :@foo)
174
+ assert_not_equal cached_result, new_cache = @instance.foo(:reload)
175
+ assert_equal new_cache, @instance.foo
176
+ assert_equal new_cache, @instance.send(:instance_variable_get, :@foo)
177
+ end
178
+
179
+ def test_customizing_memoize_storage
180
+ assert !instance_variables_of(@instance).include?('@bar')
181
+ assert !instance_variables_of(@instance).include?('@baz')
182
+ cached_result = @instance.bar
183
+ assert !instance_variables_of(@instance).include?('@bar')
184
+ assert instance_variables_of(@instance).include?('@baz')
185
+ assert_equal cached_result, @instance.bar
186
+ assert_equal cached_result, @instance.send(:instance_variable_get, :@baz)
187
+ assert_nil @instance.send(:instance_variable_get, :@bar)
188
+ end
189
+
190
+ def test_memoized
191
+ assert !instance_variables_of(@instance).include?('@quux')
192
+ cached_result = @instance.quux
193
+ assert_equal cached_result, @instance.quux
194
+ assert instance_variables_of(@instance).include?('@quux')
195
+ assert_equal cached_result, @instance.send(:instance_variable_get, :@quux)
196
+ assert_not_equal cached_result, new_cache = @instance.quux(:reload)
197
+ assert_equal new_cache, @instance.quux
198
+ assert_equal new_cache, @instance.send(:instance_variable_get, :@quux)
199
+ end
200
+
201
+ def test_constant_setting
202
+ some_module = Module.new
203
+ assert !some_module.const_defined?(:FOO)
204
+ assert_nothing_raised do
205
+ some_module.constant :FOO, 'bar'
206
+ end
207
+
208
+ assert some_module.const_defined?(:FOO)
209
+ assert_nothing_raised do
210
+ some_module::FOO
211
+ some_module.foo
212
+ end
213
+ assert_equal 'bar', some_module::FOO
214
+ assert_equal 'bar', some_module.foo
215
+
216
+ assert_nothing_raised do
217
+ some_module.constant :FOO, 'baz'
218
+ end
219
+
220
+ assert_equal 'bar', some_module::FOO
221
+ assert_equal 'bar', some_module.foo
222
+ end
223
+
224
+ private
225
+ # For 1.9 compatibility
226
+ def instance_variables_of(object)
227
+ object.instance_variables.map do |instance_variable|
228
+ instance_variable.to_s
229
+ end
230
+ end
231
+
232
+ end
233
+
234
+ class AttributeProxyTest < Test::Unit::TestCase
235
+ class BlindProxyUsingDefaultAttributesHash
236
+ include SelectiveAttributeProxy
237
+ proxy_to :exlusively => false
238
+ end
239
+
240
+ class BlindProxyUsingCustomAttributeHash
241
+ include SelectiveAttributeProxy
242
+ proxy_to :settings
243
+ end
244
+
245
+ class ProxyUsingPassedInAttributeHash
246
+ include SelectiveAttributeProxy
247
+
248
+ def initialize(attributes = {})
249
+ @attributes = attributes
250
+ end
251
+ end
252
+
253
+ class RestrictedProxy
254
+ include SelectiveAttributeProxy
255
+
256
+ private
257
+ def proxiable_attribute?(name)
258
+ %w(foo bar baz).include?(name)
259
+ end
260
+ end
261
+
262
+ class NonExclusiveProxy
263
+ include SelectiveAttributeProxy
264
+ proxy_to :settings, :exclusively => false
265
+ end
266
+
267
+ def test_using_all_defaults
268
+ b = BlindProxyUsingDefaultAttributesHash.new
269
+ assert_nothing_raised do
270
+ b.foo = 'bar'
271
+ end
272
+
273
+ assert_nothing_raised do
274
+ b.foo
275
+ end
276
+
277
+ assert_equal 'bar', b.foo
278
+ end
279
+
280
+ def test_storage_is_autovivified
281
+ b = BlindProxyUsingDefaultAttributesHash.new
282
+ assert_nothing_raised do
283
+ b.send(:attributes)['foo'] = 'bar'
284
+ end
285
+
286
+ assert_nothing_raised do
287
+ b.foo
288
+ end
289
+
290
+ assert_equal 'bar', b.foo
291
+ end
292
+
293
+ def test_limiting_which_attributes_are_proxiable
294
+ r = RestrictedProxy.new
295
+ assert_nothing_raised do
296
+ r.foo = 'bar'
297
+ end
298
+
299
+ assert_nothing_raised do
300
+ r.foo
301
+ end
302
+
303
+ assert_equal 'bar', r.foo
304
+
305
+ assert_raises(NoMethodError) do
306
+ r.quux = 'foo'
307
+ end
308
+
309
+ assert_raises(NoMethodError) do
310
+ r.quux
311
+ end
312
+ end
313
+
314
+ def test_proxying_is_exclusive_by_default
315
+ p = ProxyUsingPassedInAttributeHash.new('foo' => 'bar')
316
+ assert_nothing_raised do
317
+ p.foo
318
+ p.foo = 'baz'
319
+ end
320
+
321
+ assert_equal 'baz', p.foo
322
+
323
+ assert_raises(NoMethodError) do
324
+ p.quux
325
+ end
326
+ end
327
+
328
+ def test_setting_the_proxy_as_non_exclusive
329
+ n = NonExclusiveProxy.new
330
+ assert_nothing_raised do
331
+ n.foo = 'baz'
332
+ end
333
+
334
+ assert_nothing_raised do
335
+ n.foo
336
+ end
337
+
338
+ assert_equal 'baz', n.foo
339
+ end
340
+ end
data/test/fixtures.rb ADDED
@@ -0,0 +1,89 @@
1
+ require 'yaml'
2
+
3
+ module AWS
4
+ module SES
5
+ # When this file is loaded, for each fixture file, a module is created within the Fixtures module
6
+ # with the same name as the fixture file. For each fixture in that fixture file, a singleton method is
7
+ # added to the module with the name of the given fixture, returning the value of the fixture.
8
+ #
9
+ # For example:
10
+ #
11
+ # A fixture in <tt>buckets.yml</tt> named <tt>empty_bucket_list</tt> with value <tt><foo>hi!</foo></tt>
12
+ # would be made available like so:
13
+ #
14
+ # Fixtures::Buckets.empty_bucket_list
15
+ # => "<foo>hi!</foo>"
16
+ #
17
+ # Alternatively you can treat the fixture module like a hash
18
+ #
19
+ # Fixtures::Buckets[:empty_bucket_list]
20
+ # => "<foo>hi!</foo>"
21
+ #
22
+ # You can find out all available fixtures by calling
23
+ #
24
+ # Fixtures.fixtures
25
+ # => ["Buckets"]
26
+ #
27
+ # And all the fixtures contained in a given fixture by calling
28
+ #
29
+ # Fixtures::Buckets.fixtures
30
+ # => ["bucket_list_with_more_than_one_bucket", "bucket_list_with_one_bucket", "empty_bucket_list"]
31
+ module Fixtures
32
+ class << self
33
+ def create_fixtures
34
+ files.each do |file|
35
+ create_fixture_for(file)
36
+ end
37
+ end
38
+
39
+ def create_fixture_for(file)
40
+ fixtures = YAML.load_file(path(file))
41
+ fixture_module = Module.new
42
+
43
+ fixtures.each do |name, value|
44
+ fixture_module.module_eval(<<-EVAL, __FILE__, __LINE__)
45
+ def #{name}
46
+ #{value.inspect}
47
+ end
48
+ module_function :#{name}
49
+ EVAL
50
+ end
51
+
52
+ fixture_module.module_eval(<<-EVAL, __FILE__, __LINE__)
53
+ module_function
54
+
55
+ def fixtures
56
+ #{fixtures.keys.sort.inspect}
57
+ end
58
+
59
+ def [](name)
60
+ send(name) if fixtures.include?(name.to_s)
61
+ end
62
+ EVAL
63
+
64
+ const_set(module_name(file), fixture_module)
65
+ end
66
+
67
+ def fixtures
68
+ constants.sort
69
+ end
70
+
71
+ private
72
+
73
+ def files
74
+ Dir.glob(File.dirname(__FILE__) + '/fixtures/*.yml').map {|fixture| File.basename(fixture)}
75
+ end
76
+
77
+ def module_name(file_name)
78
+ File.basename(file_name, '.*').capitalize
79
+ end
80
+
81
+ def path(file_name)
82
+ File.join(File.dirname(__FILE__), 'fixtures', file_name)
83
+ end
84
+ end
85
+
86
+ create_fixtures
87
+ end
88
+ end
89
+ end