odba 1.0.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.
@@ -0,0 +1,226 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../lib/', File.dirname(__FILE__))
4
+ $: << File.dirname(__FILE__)
5
+
6
+ require 'odba/stub'
7
+ require 'odba/persistable'
8
+ require 'odba/odba'
9
+ require 'test/unit'
10
+ require 'flexmock'
11
+ require 'yaml'
12
+
13
+ module ODBA
14
+ class Stub
15
+ attr_accessor :receiver, :odba_class
16
+ end
17
+ class TestStub < Test::Unit::TestCase
18
+ include FlexMock::TestCase
19
+ def setup
20
+ @odba_container = flexmock("odba_container")
21
+ @cache = ODBA.cache = flexmock("cache")
22
+ @receiver = flexmock("receiver")
23
+ @stub = Stub.new(9, @odba_container, @receiver)
24
+ end
25
+ def test_method_missing
26
+ receiver = flexmock
27
+ @cache.mock_handle(:fetch) { |id, caller|
28
+ assert_equal(9, id)
29
+ receiver
30
+ }
31
+ receiver.mock_handle(:foo_method){ |number|
32
+ assert_equal(3, number)
33
+ }
34
+ @odba_container.mock_handle(:odba_replace_stubs) { |id, rec|
35
+ assert_equal(receiver, rec)
36
+ }
37
+ @stub.foo_method(3)
38
+ receiver.mock_verify
39
+ @odba_container.mock_verify
40
+ end
41
+ def test_method_missing_receiver_nil
42
+ @stub.receiver = nil
43
+ cache = ODBA.cache
44
+ receiver = flexmock
45
+ cache.mock_handle(:fetch) { |odba_id, odba_container|
46
+ receiver
47
+ }
48
+ receiver.mock_handle(:foo_method) { |number|
49
+ assert_equal(3, number)
50
+ }
51
+ @odba_container.mock_handle(:odba_replace_stubs) { |id,receiver| }
52
+ assert_nothing_raised { @stub.foo_method(3) }
53
+ @odba_container.mock_verify
54
+ cache.mock_verify
55
+ end
56
+ def test_method_missing__odba_class_nil # backward-compatibility
57
+ @stub.odba_class = nil
58
+ receiver = flexmock
59
+ @cache.mock_handle(:fetch) { |odba_id, odba_container|
60
+ receiver
61
+ }
62
+ receiver.mock_handle(:foo_method) { |number|
63
+ assert_equal(3, number)
64
+ }
65
+ @odba_container.mock_handle(:odba_replace_stubs) { |id, receiver| }
66
+ assert_nothing_raised { @stub.foo_method(3) }
67
+ @odba_container.mock_verify
68
+ ODBA.cache.mock_verify
69
+ end
70
+ def test_odba_receiver
71
+ @cache.should_receive(:fetch).with(9, @odba_container)\
72
+ .and_return('odba_instance')
73
+ @odba_container.should_receive(:odba_replace_stubs)\
74
+ .with(@stub.odba_id, 'odba_instance').and_return { assert(true) }
75
+ @stub.odba_receiver
76
+ end
77
+ def test_send_instance_methods
78
+ receiver = 'odba_instance'
79
+ @odba_container.should_ignore_missing
80
+ @cache.mock_handle(:fetch).with(9, @odba_container)\
81
+ .and_return(receiver)
82
+ @stub.taint
83
+ assert_equal(true, receiver.tainted?)
84
+ end
85
+ def test_instance_method_not_sent
86
+ assert_equal(true, @stub.is_a?(Persistable))
87
+ end
88
+ def test_send_class
89
+ receiver = flexmock
90
+ @odba_container.mock_handle(:odba_replace_stubs) { |id, rec|}
91
+ @cache.mock_handle(:fetch) { |id,container|
92
+ receiver
93
+ }
94
+ assert_equal(FlexMock, @stub.class)
95
+ end
96
+ def test_respond_to
97
+ receiver = flexmock('receiver')
98
+ @odba_container.mock_handle(:odba_replace_stubs) { |id, rec|}
99
+ @cache.mock_handle(:fetch) { |id,container|
100
+ receiver
101
+ }
102
+ receiver.mock_verify
103
+ assert_equal(false, @stub.respond_to?(:odba_replace))
104
+ end
105
+ def test_array_methods
106
+ stub = Stub.new(9, [], [])
107
+ @cache.mock_handle(:fetch) { |odba_id, container| [] }
108
+ assert_equal([], stub)
109
+ stub = Stub.new(9, [], [])
110
+ @cache.mock_handle(:fetch) { |odba_id, container| [] }
111
+ assert([] == stub)
112
+ [
113
+ "&", "+", "-", "<=>", "==",
114
+ "concat", "equal?", "replace", "|"
115
+ ].each { |method|
116
+ @cache.mock_handle(:fetch) { |odba_id, container| [] }
117
+ stub = Stub.new(9, [], [])
118
+ assert_nothing_raised("failed method: #{method}") {
119
+ [].send(method, stub)
120
+ }
121
+ }
122
+ end
123
+ def test_hash_methods
124
+ stub = Stub.new(9, [], {})
125
+ @cache.mock_handle(:fetch) { |odba_id, container| {} }
126
+ assert_equal({}, stub)
127
+ stub = Stub.new(9, [], {})
128
+ @cache.mock_handle(:fetch) { |odba_id, container| {} }
129
+ assert({} == stub)
130
+ [
131
+ "merge", "merge!", "replace",
132
+ ].each { |method|
133
+ @cache.mock_handle(:fetch) { |odba_id, container| {} }
134
+ stub = Stub.new(9, [], {})
135
+ assert_nothing_raised("failed method: #{method}") {
136
+ {}.send(method, stub)
137
+ }
138
+ }
139
+ end
140
+ def test_hash__fetch
141
+ stub = Stub.new(9, [], {})
142
+ @cache.mock_handle(:include?) { |odba_id|
143
+ assert_equal(9, odba_id)
144
+ false
145
+ }
146
+ @cache.mock_handle(:fetch_collection_element) { |odba_id, key|
147
+ assert_equal(9, odba_id)
148
+ assert_equal('bar', key)
149
+ 'foo'
150
+ }
151
+ assert_equal('foo', stub['bar'])
152
+ end
153
+ def test_hash__fetch__2
154
+ stub = Stub.new(9, [], {})
155
+ @cache.mock_handle(:include?) { |odba_id|
156
+ assert_equal(9, odba_id)
157
+ false
158
+ }
159
+ @cache.mock_handle(:fetch_collection_element) { |odba_id, key|
160
+ assert_equal(9, odba_id)
161
+ assert_equal('bar', key)
162
+ nil
163
+ }
164
+ @cache.mock_handle(:fetch) { |odba_id, caller|
165
+ assert_equal(9, odba_id)
166
+ assert_equal([], caller)
167
+ {'bar' => 'foo'}
168
+ }
169
+ assert_equal('foo', stub['bar'])
170
+ end
171
+ def test_hash__fetch__already_in_cache
172
+ stub = Stub.new(9, [], {})
173
+ @cache.mock_handle(:include?) { |odba_id|
174
+ assert_equal(9, odba_id)
175
+ true
176
+ }
177
+ @cache.mock_handle(:fetch) { |odba_id, fetcher|
178
+ assert_equal(9, odba_id)
179
+ {'bar' => 'foo'}
180
+ }
181
+ assert_equal('foo', stub['bar'])
182
+ end
183
+ def test_hash_key__1
184
+ stub = Stub.new(9, nil, nil)
185
+ @cache.should_receive(:fetch).with(9, nil).and_return(@receiver)
186
+ @cache.should_receive(:fetch).with(9, @odba_container)\
187
+ .and_return(@receiver)
188
+ @cache.should_receive(:fetch).with(8, nil).and_return('other')
189
+ @odba_container.should_ignore_missing
190
+ hash = {stub => 'success'}
191
+ assert_equal('success', hash[@stub])
192
+ other = Stub.new(8, nil, nil)
193
+ assert_nil(hash[other])
194
+ end
195
+ def test_to_yaml
196
+ yaml = ''
197
+ assert_nothing_raised {
198
+ yaml = @stub.odba_isolated_stub.to_yaml
199
+ }
200
+ loaded = YAML.load(yaml)
201
+ assert(loaded.is_a?(Stub))
202
+ assert_equal(9, loaded.odba_id)
203
+ end
204
+ def test_odba_clear_receiver
205
+ @stub.instance_variable_set('@receiver', flexmock)
206
+ @stub.odba_clear_receiver
207
+ assert_nil(@stub.instance_variable_get('@receiver'))
208
+ end
209
+ def test_odba_unsaved
210
+ assert_equal(false, @stub.odba_unsaved?)
211
+ end
212
+ def test_hash_key__2
213
+ receiver = Object.new
214
+ receiver.extend(Persistable)
215
+ receiver.instance_variable_set('@odba_id', 9)
216
+ stub = Stub.new(9, nil, nil)
217
+ @cache.mock_handle(:fetch) { |odba_id, caller|
218
+ assert_equal(9, odba_id)
219
+ receiver
220
+ }
221
+ hash = {stub => 'success'}
222
+ assert_equal('success', hash[stub])
223
+ assert_equal('success', hash[receiver])
224
+ end
225
+ end
226
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: odba
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Masaomi Hatakeyama, Zeno R.R. Davatz
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-20 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: hoe
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 47
30
+ segments:
31
+ - 2
32
+ - 8
33
+ - 0
34
+ version: 2.8.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: Object Database Access - Ruby Software for ODDB.org Memory Management
38
+ email:
39
+ - mhatakeyama@ywesee.com, zdavatz@ywesee.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - History.txt
46
+ - Manifest.txt
47
+ - README.txt
48
+ files:
49
+ - History.txt
50
+ - LICENSE
51
+ - Manifest.txt
52
+ - README.txt
53
+ - Rakefile
54
+ - install.rb
55
+ - lib/odba.rb
56
+ - lib/odba/18_19_loading_compatibility.rb
57
+ - lib/odba/cache.rb
58
+ - lib/odba/cache_entry.rb
59
+ - lib/odba/connection_pool.rb
60
+ - lib/odba/drbwrapper.rb
61
+ - lib/odba/id_server.rb
62
+ - lib/odba/index.rb
63
+ - lib/odba/index_definition.rb
64
+ - lib/odba/marshal.rb
65
+ - lib/odba/odba.rb
66
+ - lib/odba/odba_error.rb
67
+ - lib/odba/persistable.rb
68
+ - lib/odba/storage.rb
69
+ - lib/odba/stub.rb
70
+ - sql/collection.sql
71
+ - sql/create_tables.sql
72
+ - sql/object.sql
73
+ - sql/object_connection.sql
74
+ - test/suite.rb
75
+ - test/test_array.rb
76
+ - test/test_cache.rb
77
+ - test/test_cache_entry.rb
78
+ - test/test_connection_pool.rb
79
+ - test/test_drbwrapper.rb
80
+ - test/test_hash.rb
81
+ - test/test_id_server.rb
82
+ - test/test_index.rb
83
+ - test/test_marshal.rb
84
+ - test/test_persistable.rb
85
+ - test/test_storage.rb
86
+ - test/test_stub.rb
87
+ has_rdoc: true
88
+ homepage: http://scm.ywesee.com/?p=odba/.git;a=summary
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options:
93
+ - --main
94
+ - README.txt
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project: odba
118
+ rubygems_version: 1.3.7
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Object Database Access - Ruby Software for ODDB.org Memory Management
122
+ test_files:
123
+ - test/test_array.rb
124
+ - test/test_cache.rb
125
+ - test/test_cache_entry.rb
126
+ - test/test_connection_pool.rb
127
+ - test/test_drbwrapper.rb
128
+ - test/test_hash.rb
129
+ - test/test_id_server.rb
130
+ - test/test_index.rb
131
+ - test/test_marshal.rb
132
+ - test/test_persistable.rb
133
+ - test/test_storage.rb
134
+ - test/test_stub.rb