ryanking-aws-s3 0.5.1.200811101723

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.
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class BucketTest < Test::Unit::TestCase
4
+ def test_bucket_name_validation
5
+ valid_names = %w(123 joe step-one step_two step3 step_4 step-5 step.six)
6
+ invalid_names = ['12', 'jo', 'kevin spacey', 'larry@wall', '', 'a' * 256]
7
+ validate_name = Proc.new {|name| Bucket.send(:validate_name!, name)}
8
+ valid_names.each do |valid_name|
9
+ assert_nothing_raised { validate_name[valid_name] }
10
+ end
11
+
12
+ invalid_names.each do |invalid_name|
13
+ assert_raises(InvalidBucketName) { validate_name[invalid_name] }
14
+ end
15
+ end
16
+
17
+ def test_empty_bucket
18
+ mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.empty_bucket, :code => 200})
19
+ bucket = Bucket.find('marcel_molina')
20
+ assert bucket.empty?
21
+ end
22
+
23
+ def test_bucket_with_one_file
24
+ mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.bucket_with_one_key, :code => 200})
25
+ bucket = Bucket.find('marcel_molina')
26
+ assert !bucket.empty?
27
+ assert_equal 1, bucket.size
28
+ assert_equal %w(tongue_overload.jpg), bucket.objects.map {|object| object.key}
29
+ assert bucket['tongue_overload.jpg']
30
+ end
31
+
32
+ def test_bucket_with_more_than_one_file
33
+ mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.bucket_with_more_than_one_key, :code => 200})
34
+ bucket = Bucket.find('marcel_molina')
35
+ assert !bucket.empty?
36
+ assert_equal 2, bucket.size
37
+ assert_equal %w(beluga_baby.jpg tongue_overload.jpg), bucket.objects.map {|object| object.key}.sort
38
+ assert bucket['tongue_overload.jpg']
39
+ end
40
+
41
+ def test_bucket_path
42
+ assert_equal '/bucket_name?max-keys=2', Bucket.send(:path, 'bucket_name', :max_keys => 2)
43
+ assert_equal '/bucket_name', Bucket.send(:path, 'bucket_name', {})
44
+ end
45
+
46
+ def test_should_not_be_truncated
47
+ mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.bucket_with_more_than_one_key, :code => 200})
48
+ bucket = Bucket.find('marcel_molina')
49
+ assert !bucket.is_truncated
50
+ end
51
+
52
+ def test_should_be_truncated
53
+ mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.truncated_bucket_with_more_than_one_key, :code => 200})
54
+ bucket = Bucket.find('marcel_molina')
55
+ assert bucket.is_truncated
56
+ end
57
+
58
+ def test_bucket_name_should_have_leading_slash_prepended_only_once_when_forcing_a_delete
59
+ # References bug: http://rubyforge.org/tracker/index.php?func=detail&aid=19158&group_id=2409&atid=9356
60
+ bucket_name = 'foo'
61
+ expected_bucket_path = "/#{bucket_name}"
62
+
63
+ mock_bucket = flexmock('Mock bucket') do |mock|
64
+ mock.should_receive(:delete_all).once
65
+ end
66
+ mock_response = flexmock('Mock delete response') do |mock|
67
+ mock.should_receive(:success?).once
68
+ end
69
+
70
+ flexmock(Bucket).should_receive(:find).with(bucket_name).once.and_return(mock_bucket)
71
+ flexmock(Base).should_receive(:delete).with(expected_bucket_path).once.and_return(mock_response)
72
+ Bucket.delete(bucket_name, :force => true)
73
+ end
74
+ end
@@ -0,0 +1,216 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ConnectionTest < Test::Unit::TestCase
4
+ attr_reader :keys
5
+ def setup
6
+ @keys = {:access_key_id => '123', :secret_access_key => 'abc'}
7
+ end
8
+
9
+ def test_creating_a_connection
10
+ connection = Connection.new(keys)
11
+ assert_kind_of Net::HTTP, connection.http
12
+ end
13
+
14
+ def test_use_ssl_option_is_set_in_connection
15
+ connection = Connection.new(keys.merge(:use_ssl => true))
16
+ assert connection.http.use_ssl?
17
+ end
18
+
19
+ def test_setting_port_to_443_implies_use_ssl
20
+ connection = Connection.new(keys.merge(:port => 443))
21
+ assert connection.http.use_ssl?
22
+ end
23
+
24
+ def test_protocol
25
+ connection = Connection.new(keys)
26
+ assert_equal 'http://', connection.protocol
27
+ connection = Connection.new(keys.merge(:use_ssl => true))
28
+ assert_equal 'https://', connection.protocol
29
+ end
30
+
31
+ def test_url_for_honors_use_ssl_option_if_it_is_false_even_if_connection_has_use_ssl_option_set
32
+ # References bug: http://rubyforge.org/tracker/index.php?func=detail&aid=17628&group_id=2409&atid=9356
33
+ connection = Connection.new(keys.merge(:use_ssl => true))
34
+ assert_match %r(^http://), connection.url_for('/pathdoesnotmatter', :authenticated => false, :use_ssl => false)
35
+ end
36
+
37
+ def test_connection_is_not_persistent_by_default
38
+ connection = Connection.new(keys)
39
+ assert !connection.persistent?
40
+
41
+ connection = Connection.new(keys.merge(:persistent => true))
42
+ assert connection.persistent?
43
+ end
44
+
45
+ def test_server_and_port_are_passed_onto_connection
46
+ connection = Connection.new(keys)
47
+ options = connection.instance_variable_get('@options')
48
+ assert_equal connection.http.address, options[:server]
49
+ assert_equal connection.http.port, options[:port]
50
+ end
51
+
52
+ def test_not_including_required_access_keys_raises
53
+ assert_raises(MissingAccessKey) do
54
+ Connection.new
55
+ end
56
+
57
+ assert_raises(MissingAccessKey) do
58
+ Connection.new(:access_key_id => '123')
59
+ end
60
+
61
+ assert_nothing_raised do
62
+ Connection.new(keys)
63
+ end
64
+ end
65
+
66
+ def test_access_keys_extracted
67
+ connection = Connection.new(keys)
68
+ assert_equal '123', connection.access_key_id
69
+ assert_equal 'abc', connection.secret_access_key
70
+ end
71
+
72
+ def test_request_method_class_lookup
73
+ connection = Connection.new(keys)
74
+ expectations = {
75
+ :get => Net::HTTP::Get, :post => Net::HTTP::Post,
76
+ :put => Net::HTTP::Put, :delete => Net::HTTP::Delete,
77
+ :head => Net::HTTP::Head
78
+ }
79
+
80
+ expectations.each do |verb, klass|
81
+ assert_equal klass, connection.send(:request_method, verb)
82
+ end
83
+ end
84
+
85
+ def test_url_for_uses_default_protocol_server_and_port
86
+ connection = Connection.new(:access_key_id => '123', :secret_access_key => 'abc', :port => 80)
87
+ assert_match %r(^http://s3\.amazonaws\.com/foo\?), connection.url_for('/foo')
88
+
89
+ connection = Connection.new(:access_key_id => '123', :secret_access_key => 'abc', :use_ssl => true, :port => 443)
90
+ assert_match %r(^https://s3\.amazonaws\.com/foo\?), connection.url_for('/foo')
91
+ end
92
+
93
+ def test_url_for_remembers_custom_protocol_server_and_port
94
+ connection = Connection.new(:access_key_id => '123', :secret_access_key => 'abc', :server => 'example.org', :port => 555, :use_ssl => true)
95
+ assert_match %r(^https://example\.org:555/foo\?), connection.url_for('/foo')
96
+ end
97
+
98
+ def test_url_for_with_and_without_authenticated_urls
99
+ connection = Connection.new(:access_key_id => '123', :secret_access_key => 'abc', :server => 'example.org')
100
+ authenticated = lambda {|url| url['?AWSAccessKeyId']}
101
+ assert authenticated[connection.url_for('/foo')]
102
+ assert authenticated[connection.url_for('/foo', :authenticated => true)]
103
+ assert !authenticated[connection.url_for('/foo', :authenticated => false)]
104
+ end
105
+
106
+ def test_connecting_through_a_proxy
107
+ connection = nil
108
+ assert_nothing_raised do
109
+ connection = Connection.new(keys.merge(:proxy => sample_proxy_settings))
110
+ end
111
+ assert connection.http.proxy?
112
+ end
113
+
114
+ def test_request_only_escapes_the_path_the_first_time_it_runs_and_not_subsequent_times
115
+ connection = Connection.new(@keys)
116
+ unescaped_path = 'path with spaces'
117
+ escaped_path = 'path%20with%20spaces'
118
+
119
+ flexmock(Connection).should_receive(:prepare_path).with(unescaped_path).once.and_return(escaped_path).ordered
120
+ flexmock(connection.http).should_receive(:request).and_raise(Errno::EPIPE).ordered
121
+ flexmock(connection.http).should_receive(:request).ordered
122
+ connection.request :put, unescaped_path
123
+ end
124
+
125
+ def test_if_request_has_no_body_then_the_content_length_is_set_to_zero
126
+ # References bug: http://rubyforge.org/tracker/index.php?func=detail&aid=13052&group_id=2409&atid=9356
127
+ connection = Connection.new(@keys)
128
+ flexmock(Net::HTTP::Put).new_instances.should_receive(:content_length=).once.with(0).ordered
129
+ flexmock(connection.http).should_receive(:request).once.ordered
130
+ connection.request :put, 'path does not matter'
131
+ end
132
+ end
133
+
134
+ class ConnectionOptionsTest < Test::Unit::TestCase
135
+
136
+ def setup
137
+ @options = generate_options(:server => 'example.org', :port => 555)
138
+ @default_options = generate_options
139
+ end
140
+
141
+ def test_server_extracted
142
+ assert_key_transfered(:server, 'example.org', @options)
143
+ end
144
+
145
+ def test_port_extracted
146
+ assert_key_transfered(:port, 555, @options)
147
+ end
148
+
149
+ def test_server_defaults_to_default_host
150
+ assert_equal DEFAULT_HOST, @default_options[:server]
151
+ end
152
+
153
+ def test_port_defaults_to_80_if_use_ssl_is_false
154
+ assert_equal 80, @default_options[:port]
155
+ end
156
+
157
+ def test_port_is_set_to_443_if_use_ssl_is_true
158
+ options = generate_options(:use_ssl => true)
159
+ assert_equal 443, options[:port]
160
+ end
161
+
162
+ def test_explicit_port_trumps_use_ssl
163
+ options = generate_options(:port => 555, :use_ssl => true)
164
+ assert_equal 555, options[:port]
165
+ end
166
+
167
+ def test_invalid_options_raise
168
+ assert_raises(InvalidConnectionOption) do
169
+ generate_options(:host => 'campfire.s3.amazonaws.com')
170
+ end
171
+ end
172
+
173
+ def test_not_specifying_all_required_proxy_settings_raises
174
+ assert_raises(ArgumentError) do
175
+ generate_options(:proxy => {})
176
+ end
177
+ end
178
+
179
+ def test_not_specifying_proxy_option_at_all_does_not_raise
180
+ assert_nothing_raised do
181
+ generate_options
182
+ end
183
+ end
184
+
185
+ def test_specifying_all_required_proxy_settings
186
+ assert_nothing_raised do
187
+ generate_options(:proxy => sample_proxy_settings)
188
+ end
189
+ end
190
+
191
+ def test_only_host_setting_is_required
192
+ assert_nothing_raised do
193
+ generate_options(:proxy => {:host => 'http://google.com'})
194
+ end
195
+ end
196
+
197
+ def test_proxy_settings_are_extracted
198
+ options = generate_options(:proxy => sample_proxy_settings)
199
+ assert_equal sample_proxy_settings.values.map {|value| value.to_s}.sort, options.proxy_settings.map {|value| value.to_s}.sort
200
+ end
201
+
202
+ def test_recognizing_that_the_settings_want_to_connect_through_a_proxy
203
+ options = generate_options(:proxy => sample_proxy_settings)
204
+ assert options.connecting_through_proxy?
205
+ end
206
+
207
+ private
208
+ def assert_key_transfered(key, value, options)
209
+ assert_equal value, options[key]
210
+ assert !options.instance_variable_get('@options').has_key?(key)
211
+ end
212
+
213
+ def generate_options(options = {})
214
+ Connection::Options.new(options)
215
+ end
216
+ end
@@ -0,0 +1,70 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ErrorTest < Test::Unit::TestCase
4
+ def setup
5
+ @container = AWS::S3
6
+ @error = Error.new(Parsing::XmlParser.new(Fixtures::Errors.access_denied))
7
+ @container.send(:remove_const, :NotImplemented) if @container.const_defined?(:NotImplemented)
8
+ end
9
+
10
+ def test_error_class_is_automatically_generated
11
+ assert !@container.const_defined?('NotImplemented')
12
+ error = Error.new(Parsing::XmlParser.new(Fixtures::Errors.not_implemented))
13
+ assert @container.const_defined?('NotImplemented')
14
+ end
15
+
16
+ def test_error_contains_attributes
17
+ assert_equal 'Access Denied', @error.message
18
+ end
19
+
20
+ def test_error_is_raisable_as_exception
21
+ assert_raises(@container::AccessDenied) do
22
+ @error.raise
23
+ end
24
+ end
25
+
26
+ def test_error_message_is_passed_along_to_exception
27
+ @error.raise
28
+ rescue @container::AccessDenied => e
29
+ assert_equal 'Access Denied', e.message
30
+ end
31
+
32
+ def test_response_is_passed_along_to_exception
33
+ response = Error::Response.new(FakeResponse.new(:code => 409, :body => Fixtures::Errors.access_denied))
34
+ response.error.raise
35
+ rescue @container::ResponseError => e
36
+ assert e.response
37
+ assert_kind_of Error::Response, e.response
38
+ assert_equal response.error, e.response.error
39
+ end
40
+
41
+ def test_exception_class_clash
42
+ assert !@container.const_defined?(:NotImplemented)
43
+ # Create a class that does not inherit from exception that has the same name as the class
44
+ # the Error instance is about to attempt to find or create
45
+ @container.const_set(:NotImplemented, Class.new)
46
+ assert @container.const_defined?(:NotImplemented)
47
+
48
+ assert_raises(ExceptionClassClash) do
49
+ Error.new(Parsing::XmlParser.new(Fixtures::Errors.not_implemented))
50
+ end
51
+ end
52
+
53
+ def test_error_response_handles_attributes_with_no_value
54
+ mock_connection_for(Bucket, :returns => {:body => Fixtures::Errors.error_with_no_message, :code => 500})
55
+
56
+ begin
57
+ Bucket.create('foo', 'invalid-argument' => 'bad juju')
58
+ rescue ResponseError => error
59
+ end
60
+
61
+ assert_nothing_raised do
62
+ error.response.error.message
63
+ end
64
+ assert_nil error.response.error.message
65
+
66
+ assert_raises(NoMethodError) do
67
+ error.response.error.non_existant_method
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,331 @@
1
+ require File.dirname(__FILE__) + '/test_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_utf8?
69
+ assert !"318597/620065/GTL_75\24300_A600_A610.zip".utf8?
70
+ assert "318597/620065/GTL_75£00_A600_A610.zip".utf8?
71
+ end
72
+
73
+ def test_remove_extended
74
+ assert "318597/620065/GTL_75\24300_A600_A610.zip".remove_extended.utf8?
75
+ assert "318597/620065/GTL_75£00_A600_A610.zip".remove_extended.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
143
+
144
+ class ModuleExtensionsTest < Test::Unit::TestCase
145
+ class Foo
146
+ def foo(reload = false)
147
+ memoize(reload) do
148
+ Time.now
149
+ end
150
+ end
151
+
152
+ def bar(reload = false)
153
+ 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.instance_variables.include?('@foo')
170
+ cached_result = @instance.foo
171
+ assert_equal cached_result, @instance.foo
172
+ assert @instance.instance_variables.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.instance_variables.include?('@bar')
181
+ assert !@instance.instance_variables.include?('@baz')
182
+ cached_result = @instance.bar
183
+ assert !@instance.instance_variables.include?('@bar')
184
+ assert @instance.instance_variables.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.instance_variables.include?('@quux')
192
+ cached_result = @instance.quux
193
+ assert_equal cached_result, @instance.quux
194
+ assert @instance.instance_variables.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
+ end
224
+
225
+ class AttributeProxyTest < Test::Unit::TestCase
226
+ class BlindProxyUsingDefaultAttributesHash
227
+ include SelectiveAttributeProxy
228
+ proxy_to :exlusively => false
229
+ end
230
+
231
+ class BlindProxyUsingCustomAttributeHash
232
+ include SelectiveAttributeProxy
233
+ proxy_to :settings
234
+ end
235
+
236
+ class ProxyUsingPassedInAttributeHash
237
+ include SelectiveAttributeProxy
238
+
239
+ def initialize(attributes = {})
240
+ @attributes = attributes
241
+ end
242
+ end
243
+
244
+ class RestrictedProxy
245
+ include SelectiveAttributeProxy
246
+
247
+ private
248
+ def proxiable_attribute?(name)
249
+ %w(foo bar baz).include?(name)
250
+ end
251
+ end
252
+
253
+ class NonExclusiveProxy
254
+ include SelectiveAttributeProxy
255
+ proxy_to :settings, :exclusively => false
256
+ end
257
+
258
+ def test_using_all_defaults
259
+ b = BlindProxyUsingDefaultAttributesHash.new
260
+ assert_nothing_raised do
261
+ b.foo = 'bar'
262
+ end
263
+
264
+ assert_nothing_raised do
265
+ b.foo
266
+ end
267
+
268
+ assert_equal 'bar', b.foo
269
+ end
270
+
271
+ def test_storage_is_autovivified
272
+ b = BlindProxyUsingDefaultAttributesHash.new
273
+ assert_nothing_raised do
274
+ b.send(:attributes)['foo'] = 'bar'
275
+ end
276
+
277
+ assert_nothing_raised do
278
+ b.foo
279
+ end
280
+
281
+ assert_equal 'bar', b.foo
282
+ end
283
+
284
+ def test_limiting_which_attributes_are_proxiable
285
+ r = RestrictedProxy.new
286
+ assert_nothing_raised do
287
+ r.foo = 'bar'
288
+ end
289
+
290
+ assert_nothing_raised do
291
+ r.foo
292
+ end
293
+
294
+ assert_equal 'bar', r.foo
295
+
296
+ assert_raises(NoMethodError) do
297
+ r.quux = 'foo'
298
+ end
299
+
300
+ assert_raises(NoMethodError) do
301
+ r.quux
302
+ end
303
+ end
304
+
305
+ def test_proxying_is_exclusive_by_default
306
+ p = ProxyUsingPassedInAttributeHash.new('foo' => 'bar')
307
+ assert_nothing_raised do
308
+ p.foo
309
+ p.foo = 'baz'
310
+ end
311
+
312
+ assert_equal 'baz', p.foo
313
+
314
+ assert_raises(NoMethodError) do
315
+ p.quux
316
+ end
317
+ end
318
+
319
+ def test_setting_the_proxy_as_non_exclusive
320
+ n = NonExclusiveProxy.new
321
+ assert_nothing_raised do
322
+ n.foo = 'baz'
323
+ end
324
+
325
+ assert_nothing_raised do
326
+ n.foo
327
+ end
328
+
329
+ assert_equal 'baz', n.foo
330
+ end
331
+ end