persistence 0.0.1.alpha → 0.0.1

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.
Files changed (138) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/README.md +260 -17
  3. data/lib/namespaces.rb +55 -0
  4. data/lib/persistence.rb +38 -3
  5. data/lib/persistence/adapter/abstract.rb +22 -0
  6. data/lib/persistence/adapter/abstract/enable_disable.rb +107 -0
  7. data/lib/persistence/adapter/abstract/primary_key/id_property_string.rb +33 -0
  8. data/lib/persistence/adapter/abstract/primary_key/simple.rb +29 -0
  9. data/lib/persistence/adapter/mock.rb +9 -0
  10. data/lib/persistence/adapter/mock/adapter_interface.rb +102 -0
  11. data/lib/persistence/adapter/mock/bucket.rb +9 -0
  12. data/lib/persistence/adapter/mock/bucket/bucket_interface.rb +260 -0
  13. data/lib/persistence/adapter/mock/bucket/index.rb +9 -0
  14. data/lib/persistence/adapter/mock/bucket/index/index_interface.rb +155 -0
  15. data/lib/persistence/adapter/mock/cursor.rb +9 -0
  16. data/lib/persistence/adapter/mock/cursor/cursor_interface.rb +238 -0
  17. data/lib/persistence/cursor.rb +11 -0
  18. data/lib/persistence/cursor/atomic.rb +110 -0
  19. data/lib/persistence/cursor/cursor_interface.rb +337 -0
  20. data/lib/persistence/exception/block_required.rb +7 -0
  21. data/lib/persistence/exception/conflicting_index_already_declared.rb +7 -0
  22. data/lib/persistence/exception/duplicate_violates_unique_index.rb +7 -0
  23. data/lib/persistence/exception/explicit_index_required.rb +7 -0
  24. data/lib/persistence/exception/indexing_block_failed_to_generate_keys.rb +7 -0
  25. data/lib/persistence/exception/indexing_object_requires_keys.rb +7 -0
  26. data/lib/persistence/exception/key_value_required.rb +7 -0
  27. data/lib/persistence/exception/no_port_enabled.rb +7 -0
  28. data/lib/persistence/object.rb +21 -0
  29. data/lib/persistence/object/autodetermine.rb +74 -0
  30. data/lib/persistence/object/class_instance.rb +1884 -0
  31. data/lib/persistence/object/complex.rb +17 -0
  32. data/lib/persistence/object/complex/array.rb +14 -0
  33. data/lib/persistence/object/complex/array/class_instance.rb +37 -0
  34. data/lib/persistence/object/complex/array/object_instance.rb +54 -0
  35. data/lib/persistence/object/complex/attributes.rb +1808 -0
  36. data/lib/persistence/object/complex/attributes/attributes_array.rb +32 -0
  37. data/lib/persistence/object/complex/attributes/attributes_hash.rb +187 -0
  38. data/lib/persistence/object/complex/attributes/default_atomic_non_atomic.rb +102 -0
  39. data/lib/persistence/object/complex/attributes/hash_to_port.rb +40 -0
  40. data/lib/persistence/object/complex/class_and_object_instance.rb +132 -0
  41. data/lib/persistence/object/complex/class_instance.rb +267 -0
  42. data/lib/persistence/object/complex/complex_object.rb +111 -0
  43. data/lib/persistence/object/complex/hash.rb +14 -0
  44. data/lib/persistence/object/complex/hash/class_instance.rb +40 -0
  45. data/lib/persistence/object/complex/hash/object_instance.rb +63 -0
  46. data/lib/persistence/object/complex/index/attribute_index.rb +10 -0
  47. data/lib/persistence/object/complex/index/attribute_index/attribute_index_interface.rb +43 -0
  48. data/lib/persistence/object/complex/object_instance.rb +469 -0
  49. data/lib/persistence/object/flat.rb +17 -0
  50. data/lib/persistence/object/flat/class_instance.rb +34 -0
  51. data/lib/persistence/object/flat/file.rb +14 -0
  52. data/lib/persistence/object/flat/file/class_instance.rb +122 -0
  53. data/lib/persistence/object/flat/file/contents.rb +7 -0
  54. data/lib/persistence/object/flat/file/file_persistence.rb +147 -0
  55. data/lib/persistence/object/flat/file/object_instance.rb +116 -0
  56. data/lib/persistence/object/flat/file/path.rb +9 -0
  57. data/lib/persistence/object/flat/object_instance.rb +24 -0
  58. data/lib/persistence/object/index.rb +479 -0
  59. data/lib/persistence/object/index/block_index.rb +10 -0
  60. data/lib/persistence/object/index/block_index/block_index_interface.rb +110 -0
  61. data/lib/persistence/object/index/explicit_index.rb +10 -0
  62. data/lib/persistence/object/index/explicit_index/explicit_index_interface.rb +57 -0
  63. data/lib/persistence/object/index_hash.rb +40 -0
  64. data/lib/persistence/object/object_instance.rb +322 -0
  65. data/lib/persistence/object/parse_persistence_args.rb +145 -0
  66. data/lib/persistence/port.rb +9 -0
  67. data/lib/persistence/port/bucket.rb +9 -0
  68. data/lib/persistence/port/bucket/bucket_index.rb +9 -0
  69. data/lib/persistence/port/bucket/bucket_interface.rb +685 -0
  70. data/lib/persistence/port/controller.rb +263 -0
  71. data/lib/persistence/port/port_interface.rb +417 -0
  72. data/lib/requires.rb +146 -0
  73. data/spec/Integration_spec.rb +53 -0
  74. data/spec/Persistence_spec.rb +175 -0
  75. data/spec/example_objects.rb +6 -0
  76. data/spec/example_objects/complex_object.rb +7 -0
  77. data/spec/example_objects/complex_object/array_object.rb +7 -0
  78. data/spec/example_objects/complex_object/hash_object.rb +7 -0
  79. data/spec/example_objects/flat_object.rb +7 -0
  80. data/spec/example_objects/flat_object/file_object.rb +7 -0
  81. data/spec/persistence/adapter/enable_disable_spec.rb +29 -0
  82. data/spec/persistence/adapter/mock/cursor_spec.rb +64 -0
  83. data/spec/persistence/adapter/mock_helpers.rb +27 -0
  84. data/spec/persistence/adapter/mock_helpers/bucket.rb +10 -0
  85. data/spec/persistence/adapter/mock_helpers/integration/dictionary_hash.rb +4 -0
  86. data/spec/persistence/adapter/mock_helpers/integration/note.rb +18 -0
  87. data/spec/persistence/adapter/mock_helpers/integration/notes_array.rb +4 -0
  88. data/spec/persistence/adapter/mock_helpers/integration/user.rb +44 -0
  89. data/spec/persistence/adapter/mock_helpers/integration/user/address.rb +18 -0
  90. data/spec/persistence/adapter/mock_helpers/integration/user/dictionary_entry.rb +12 -0
  91. data/spec/persistence/adapter/mock_helpers/integration/user/sub_account.rb +15 -0
  92. data/spec/persistence/adapter/mock_helpers/object.rb +87 -0
  93. data/spec/persistence/adapter/mock_helpers/port.rb +21 -0
  94. data/spec/persistence/adapter/mock_spec.rb +211 -0
  95. data/spec/persistence/adapter/primary_key/id_property_string_spec.rb +27 -0
  96. data/spec/persistence/adapter/primary_key/simple_spec.rb +19 -0
  97. data/spec/persistence/adapter/spec_abstract/adapter_spec.rb +223 -0
  98. data/spec/persistence/adapter/spec_abstract/cursor_spec.rb +116 -0
  99. data/spec/persistence/cursor/atomic_spec.rb +86 -0
  100. data/spec/persistence/cursor/object_and_class_instance_spec.rb +73 -0
  101. data/spec/persistence/cursor_spec.rb +128 -0
  102. data/spec/persistence/object/complex/attributes/persistence_hash/array_instance_spec.rb +51 -0
  103. data/spec/persistence/object/complex/attributes/persistence_hash/hash_instance_spec.rb +56 -0
  104. data/spec/persistence/object/complex/attributes_spec.rb +1717 -0
  105. data/spec/persistence/object/complex/complex_spec.rb +922 -0
  106. data/spec/persistence/object/complex/index/attribute_index_spec.rb +76 -0
  107. data/spec/persistence/object/flat/bignum_spec.rb +33 -0
  108. data/spec/persistence/object/flat/class_instance_spec.rb +30 -0
  109. data/spec/persistence/object/flat/class_spec.rb +38 -0
  110. data/spec/persistence/object/flat/complex_spec.rb +36 -0
  111. data/spec/persistence/object/flat/false_class_spec.rb +34 -0
  112. data/spec/persistence/object/flat/file/class_instance_spec.rb +54 -0
  113. data/spec/persistence/object/flat/file/object_instance_spec.rb +143 -0
  114. data/spec/persistence/object/flat/file_spec.rb +64 -0
  115. data/spec/persistence/object/flat/fixnum_spec.rb +32 -0
  116. data/spec/persistence/object/flat/float_spec.rb +32 -0
  117. data/spec/persistence/object/flat/indexing_spec.rb +38 -0
  118. data/spec/persistence/object/flat/rational_spec.rb +33 -0
  119. data/spec/persistence/object/flat/regexp_spec.rb +32 -0
  120. data/spec/persistence/object/flat/string_spec.rb +34 -0
  121. data/spec/persistence/object/flat/symbol_spec.rb +32 -0
  122. data/spec/persistence/object/flat/true_class_spec.rb +32 -0
  123. data/spec/persistence/object/indexes/block_index_spec.rb +119 -0
  124. data/spec/persistence/object/indexes/explicit_index_spec.rb +112 -0
  125. data/spec/persistence/object/parse_persistence_args_spec.rb +65 -0
  126. data/spec/persistence/object_spec.rb +310 -0
  127. data/spec/persistence/port/bucket/bucket_interface_spec.rb +146 -0
  128. data/spec/persistence/port/bucket/index/bucket_index_spec.rb +67 -0
  129. data/spec/persistence/port/bucket_spec.rb +20 -0
  130. data/spec/persistence/port/controller_spec.rb +60 -0
  131. data/spec/persistence/port/port_interface_spec.rb +105 -0
  132. metadata +178 -21
  133. data/.gitignore +0 -17
  134. data/Gemfile +0 -4
  135. data/LICENSE +0 -22
  136. data/Rakefile +0 -2
  137. data/lib/persistence/version.rb +0 -3
  138. data/persistence.gemspec +0 -17
@@ -0,0 +1,112 @@
1
+
2
+ require_relative '../../../../lib/persistence.rb'
3
+
4
+ describe ::Persistence::Object::Index::ExplicitIndex do
5
+
6
+ before :all do
7
+ # Port enabled during index test
8
+ ::Persistence.disable_port( :mock )
9
+ end
10
+
11
+ after :all do
12
+ ::Persistence.disable_port( :mock )
13
+ end
14
+
15
+ ####################################
16
+ # explicit_index #
17
+ # explicit_index_with_duplicates #
18
+ # has_explicit_index? #
19
+ # index #
20
+ ####################################
21
+
22
+ it 'can declare an arbitrary key/value index on an object' do
23
+ class ::Persistence::Object::Index::ExplicitIndex::Mock
24
+
25
+ include ::Persistence::Object::Complex
26
+
27
+ explicit_index :explicit_index
28
+ explicit_index_with_duplicates :explicit_index_with_duplicates
29
+
30
+ has_explicit_index?( :explicit_index ).should == true
31
+ has_index?( :explicit_index ).should == true
32
+ has_explicit_index?( :explicit_index_with_duplicates ).should == true
33
+ has_index?( :explicit_index_with_duplicates ).should == true
34
+ index( :explicit_index ).is_a?( ::Persistence::Object::Index ).should == true
35
+ index( :explicit_index_with_duplicates ).is_a?( ::Persistence::Object::Index ).should == true
36
+
37
+ end
38
+ end
39
+
40
+ ################################
41
+ # index_object #
42
+ # persisted? #
43
+ # get_object_id #
44
+ # index_object #
45
+ # delete_keys_for_object_id! #
46
+ # delete_object #
47
+ ################################
48
+
49
+ it 'interfaces with an adapter instance' do
50
+
51
+ class ::Persistence::Object::Index::ExplicitIndex::Mock
52
+ include ::Persistence::Object::Complex
53
+ end
54
+
55
+ object = ::Persistence::Object::Index::ExplicitIndex::Mock.new
56
+
57
+ bucket = object.persistence_bucket
58
+
59
+ bucket.index( :explicit_index ).should == nil
60
+
61
+ # before port
62
+ index_instance = ::Persistence::Object::Index::ExplicitIndex.new( :explicit_index, bucket, false )
63
+ Proc.new { bucket.create_index( :explicit_index, true ) }.should raise_error
64
+ index_instance.is_a?( ::Persistence::Object::Index::ExplicitIndex ).should == true
65
+ index_instance.permits_duplicates?.should == false
66
+ Proc.new { index_instance.adapter_index }.should raise_error
67
+ Proc.new { index_instance.index_object( object ) }.should raise_error
68
+ Proc.new { index_instance.persisted?( :any_key ) }.should raise_error
69
+ Proc.new { index_instance.get_object_id( :any_key ) }.should raise_error
70
+ Proc.new { index_instance.index_object_id( any_id = 0, :any_key ) }.should raise_error
71
+ Proc.new { index_instance.delete_keys_for_object_id!( any_id = 0 ) }.should raise_error
72
+
73
+ # after port
74
+ ::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
75
+
76
+ index_instance.adapter_index.should_not == nil
77
+
78
+ bucket.index( :other_explicit_index ).should == nil
79
+ index_instance_two = ::Persistence::Object::Index::ExplicitIndex.new( :other_explicit_index, bucket, true )
80
+ index_instance_two.is_a?( ::Persistence::Object::Index::ExplicitIndex ).should == true
81
+ index_instance_two.adapter_index.should_not == nil
82
+ index_instance_two.permits_duplicates?.should == true
83
+ index_instance_two_conflicting_settings = Proc.new { bucket.create_index( :other_explicit_index, false ) }.should raise_error
84
+
85
+ index_instance.persisted?( :any_key ).should == false
86
+ index_instance.get_object_id( :any_key ).should == nil
87
+
88
+ # put object
89
+ object.persist!
90
+
91
+ # create arbitrary index value for object
92
+ index_instance.index_object( object, :some_key )
93
+
94
+ # test retrieval of ID for index value
95
+ index_instance.persisted?( :some_key ).should == true
96
+ index_instance.get_object_id( :some_key ).should == object.persistence_id
97
+
98
+ # delete keys
99
+ index_instance.delete_keys_for_object_id!( object.persistence_id )
100
+ index_instance.get_object_id( :some_key ).should == nil
101
+
102
+ # delete object
103
+ index_instance.index_object( object, :some_key )
104
+ index_instance.get_object_id( :some_key ).should == object.persistence_id
105
+ index_instance.delete_keys_for_object!( object )
106
+ index_instance.get_object_id( :some_key ).should == nil
107
+
108
+ ::Persistence.disable_port( :mock )
109
+
110
+ end
111
+
112
+ end
@@ -0,0 +1,65 @@
1
+
2
+ require_relative '../../../lib/persistence.rb'
3
+
4
+ describe ::Persistence::Object::ParsePersistenceArgs do
5
+
6
+ before :all do
7
+ ::Persistence.enable_port( :mock1, ::Persistence::Adapter::Mock.new )
8
+ class ::Persistence::Object::ParsePersistenceArgs::Mock
9
+ include ::Persistence::Object::Flat::File
10
+ attr_accessor :indexes
11
+ class IndexMock
12
+ end
13
+ def indexes
14
+ return { :index => IndexMock }
15
+ end
16
+ end
17
+ end
18
+
19
+ after :all do
20
+ ::Persistence.disable_port( :mock1 )
21
+ end
22
+
23
+ ######################
24
+ # process_file_key #
25
+ ######################
26
+
27
+ it 'can process a file key for flat persistence' do
28
+ file_instance = File.open( __FILE__ )
29
+ instance = ::Persistence::Object::ParsePersistenceArgs::Mock.new
30
+ instance.persistence_port.persist_files_by_path!
31
+ instance.process_file_key( file_instance ).should == file_instance.path
32
+ instance.persistence_port.persists_files_by_content!
33
+ instance.process_file_key( file_instance ).should == file_instance.readlines.join
34
+ end
35
+
36
+ #########################################
37
+ # parse_args_for_index_value_no_value #
38
+ #########################################
39
+
40
+ it 'can parse args for indexed or non-indexed processing' do
41
+ instance = ::Persistence::Object::ParsePersistenceArgs::Mock.new
42
+ lambda { instance.parse_args_for_index_value_no_value( [], true ) }.should raise_error( ::Persistence::Exception::KeyValueRequired )
43
+ # 0 args
44
+ args = []
45
+ instance.parse_args_for_index_value_no_value( args ).should == [ nil, nil, true ]
46
+ # 1 arg: index
47
+ args = [ :index ]
48
+ instance.parse_args_for_index_value_no_value( args ).should == [ ::Persistence::Object::ParsePersistenceArgs::Mock::IndexMock, nil, true ]
49
+ # 2 args: index, key
50
+ args = [ :index, :key ]
51
+ instance.parse_args_for_index_value_no_value( args ).should == [ ::Persistence::Object::ParsePersistenceArgs::Mock::IndexMock, :key, false ]
52
+ # 2 args: no index, global id
53
+ args = [ nil, 0 ]
54
+ instance.parse_args_for_index_value_no_value( args ).should == [ nil, 0, false ]
55
+ # test special case: file key
56
+ file_instance = File.open( __FILE__ )
57
+ args = [ :index, file_instance ]
58
+ instance.persistence_port.persist_files_by_path!
59
+ instance.parse_args_for_index_value_no_value( args ).should == [ ::Persistence::Object::ParsePersistenceArgs::Mock::IndexMock, ::Persistence::Object::Flat::File::Path.new( file_instance.path ), false ]
60
+ instance.persistence_port.persists_files_by_content!
61
+ instance.parse_args_for_index_value_no_value( args ).should == [ ::Persistence::Object::ParsePersistenceArgs::Mock::IndexMock, ::Persistence::Object::Flat::File::Contents.new( file_instance.readlines.join ), false ]
62
+ end
63
+
64
+ end
65
+
@@ -0,0 +1,310 @@
1
+
2
+ require_relative '../../lib/persistence.rb'
3
+
4
+ describe ::Persistence::Object do
5
+
6
+ before :all do
7
+ ::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
8
+ end
9
+
10
+ after :all do
11
+ ::Persistence.disable_port( :mock )
12
+ end
13
+
14
+ ################
15
+ # persist! #
16
+ # persisted? #
17
+ # persist #
18
+ # count #
19
+ ################
20
+
21
+ it 'can persist an object and test whether it has been persisted' do
22
+ module ::Persistence::Object::PersistMock
23
+
24
+ class ClassInstanceMock
25
+
26
+ include ::Persistence::Object::Complex
27
+
28
+ self.instance_persistence_port = ::Persistence.port( :mock )
29
+
30
+ end
31
+
32
+ instance = ClassInstanceMock.new
33
+
34
+ ClassInstanceMock.count.should == 0
35
+
36
+ instance.persistence_port.put_object!( instance )
37
+ instance.persistence_id.nil?.should == false
38
+ ClassInstanceMock.persisted?( 0 ).should == true
39
+ ClassInstanceMock.persist( 0 ).should == instance
40
+ ClassInstanceMock.count.should == 1
41
+
42
+ class ObjectInstanceMock
43
+
44
+ include ::Persistence::Object::Complex
45
+
46
+ self.instance_persistence_port = ::Persistence.port( :mock )
47
+
48
+ end
49
+
50
+ instance = ObjectInstanceMock.new
51
+ instance.persistence_id.should == nil
52
+ instance.persist!
53
+ instance.persistence_id.nil?.should == false
54
+ instance.persisted?.should == true
55
+
56
+ end
57
+ end
58
+
59
+ ############
60
+ # cease! #
61
+ ############
62
+
63
+ it 'can persist an object and test whether it has been persisted' do
64
+ module ::Persistence::Object::CeaseMock
65
+
66
+ class ClassInstanceMock
67
+
68
+ include ::Persistence::Object::Complex
69
+
70
+ self.instance_persistence_port = ::Persistence.port( :mock )
71
+
72
+ end
73
+
74
+ instance = ClassInstanceMock.new
75
+ instance.persistence_port.put_object!( instance )
76
+ instance.persistence_id.nil?.should == false
77
+ ClassInstanceMock.cease!( 0 )
78
+ ( instance.persistence_port.get_bucket_name_for_object_id( 0 ) ? true : false ).should == false
79
+
80
+ class ObjectInstanceMock
81
+
82
+ include ::Persistence::Object::Complex
83
+
84
+ self.instance_persistence_port = ::Persistence.port( :mock )
85
+
86
+ end
87
+
88
+ instance = ObjectInstanceMock.new
89
+ instance.persistence_port.put_object!( instance )
90
+ global_id = instance.persistence_id
91
+ instance.persistence_id.nil?.should == false
92
+ instance.cease!
93
+ instance.persistence_id.should == nil
94
+ ( instance.persistence_port.get_bucket_name_for_object_id( global_id ) ? true : false ).should == false
95
+
96
+ end
97
+ end
98
+
99
+ #####################
100
+ # persistence_id= #
101
+ # persistence_id #
102
+ #####################
103
+
104
+ it 'can set and get a persistence id that uniquely identifies the object instance' do
105
+ module ::Persistence::Object::PersistenceIDMock
106
+
107
+ class ObjectInstance
108
+ include ::Persistence::Object::Complex
109
+ end
110
+
111
+ instance = ObjectInstance.new
112
+
113
+ instance.persistence_id.should == nil
114
+ instance.persistence_id = 1
115
+ instance.persistence_id.should == 1
116
+
117
+ end
118
+ end
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+ ################
134
+ # persist! #
135
+ # persisted? #
136
+ # persist #
137
+ ################
138
+
139
+ it 'can persist with an index and explicit key' do
140
+ module ::Persistence::Object::PersistMock
141
+
142
+ class ObjectIndexMock
143
+
144
+ include ::Persistence::Object::Complex
145
+
146
+ explicit_index :explicit_index
147
+
148
+ end
149
+
150
+ encapsulation = ::CascadingConfiguration::Core::Encapsulation.encapsulation( :default )
151
+
152
+ ObjectIndexMock.count.should == 0
153
+ ObjectIndexMock.count( :explicit_index ).should == 0
154
+ instance_one = ObjectIndexMock.new.persist!
155
+ instance_one.persistence_id.should_not == nil
156
+ ObjectIndexMock.count.should == 1
157
+ ObjectIndexMock.count( :explicit_index ).should == 0
158
+
159
+ instance_two = ObjectIndexMock.new.persist!( :explicit_index, :some_key )
160
+ instance_two.persistence_id.should_not == nil
161
+ ObjectIndexMock.count.should == 2
162
+ ObjectIndexMock.count( :explicit_index ).should == 1
163
+ persisted_instance_two_a = ObjectIndexMock.persist( instance_two.persistence_id )
164
+ persisted_instance_two_a.should == instance_two
165
+ persisted_instance_two_b = ObjectIndexMock.persist( :explicit_index, :some_key )
166
+ persisted_instance_two_b.should == instance_two
167
+
168
+ end
169
+ end
170
+
171
+ ############
172
+ # cease! #
173
+ ############
174
+
175
+ it 'can persist with an index and explicit key' do
176
+ module ::Persistence::Object::CeaseMock
177
+
178
+ class ObjectIndexMock
179
+
180
+ include ::Persistence::Object::Complex
181
+
182
+ explicit_index :explicit_index
183
+
184
+ # mock - not relevant to explicit indexing
185
+ def self.non_atomic_attribute_readers
186
+ return [ ]
187
+ end
188
+
189
+ def persistence_hash_to_port
190
+ end
191
+
192
+ end
193
+ instance_one = ObjectIndexMock.new.persist!
194
+ instance_one.persistence_id.should_not == nil
195
+ instance_one.cease!
196
+ ObjectIndexMock.persist( instance_one.persistence_id ).should == nil
197
+ instance_two = ObjectIndexMock.new.persist!
198
+ instance_two.persistence_id.should_not == nil
199
+ ObjectIndexMock.cease!( instance_two.persistence_id )
200
+ ObjectIndexMock.persist( instance_two.persistence_id ).should == nil
201
+ instance_three = ObjectIndexMock.new.persist!( :explicit_index, :some_key )
202
+ instance_three.persistence_id.should_not == nil
203
+ instance_three.cease!
204
+ index = ObjectIndexMock.index( :explicit_index )
205
+ index.get_object_id( :some_key ).should == nil
206
+ ObjectIndexMock.persist( :explicit_index, :some_key ).should == nil
207
+ ObjectIndexMock.persist( instance_three.persistence_id ).should == nil
208
+ instance_four = ObjectIndexMock.new.persist!( :explicit_index, :some_key )
209
+ instance_four.persistence_id.should_not == nil
210
+ ObjectIndexMock.cease!( :explicit_index, :some_key )
211
+ index = ObjectIndexMock.index( :explicit_index )
212
+ index.get_object_id( :some_key ).should == nil
213
+ ObjectIndexMock.persist( :explicit_index, :some_key ).should == nil
214
+ ObjectIndexMock.persist( instance_four.persistence_id ).should == nil
215
+
216
+ end
217
+ end
218
+
219
+ ##################################
220
+ # instance_persistence_bucket #
221
+ # instance_persistence_bucket= #
222
+ # store_as #
223
+ # persists_in #
224
+ ##################################
225
+
226
+ it 'can set and return a persistence bucket to be used for instances' do
227
+ class ::Persistence::Port::Bucket::ClassInstance::Mock
228
+ include ::Persistence::Object
229
+ method( :instance_persistence_bucket= ).should == method( :store_as )
230
+ method( :instance_persistence_bucket= ).should == method( :persists_in )
231
+ instance_persistence_bucket.name.to_s.should == ::Persistence::Port::Bucket::ClassInstance::Mock.to_s
232
+ self.instance_persistence_bucket = 'some other bucket'
233
+ instance_persistence_bucket.name.to_s.should == 'some other bucket'
234
+ end
235
+ ::Persistence::Port::Bucket::ClassInstance::Mock.instance_persistence_bucket = ::Persistence::Port::Bucket::ClassInstance::Mock.to_s
236
+ ::Persistence::Port::Bucket::ClassInstance::Mock.instance_persistence_bucket.name.to_s.should == ::Persistence::Port::Bucket::ClassInstance::Mock.to_s
237
+ end
238
+
239
+ #########################
240
+ # persistence_bucket #
241
+ # persistence_bucket= #
242
+ #########################
243
+
244
+ it 'can set and return a persistence bucket to be used for instances' do
245
+ class ::Persistence::Object::PersistenceBucketMock
246
+ include ::Persistence::Object
247
+ def self.instance_persistence_port
248
+ @persistence_port ||= ::Persistence::Port.new( :mock_port, ::Persistence::Adapter::Mock.new )
249
+ end
250
+ def persistence_port
251
+ return self.class.instance_persistence_port
252
+ end
253
+ # mock function
254
+ def self.instance_persistence_bucket
255
+ return instance_persistence_port.persistence_bucket( to_s )
256
+ end
257
+ end
258
+ object_instance = ::Persistence::Object::PersistenceBucketMock.new
259
+ object_instance.persistence_bucket.name.to_s.should == ::Persistence::Object::PersistenceBucketMock.to_s
260
+ object_instance.persistence_bucket = 'mock bucket'
261
+ object_instance.persistence_bucket.name.to_s.should == 'mock bucket'
262
+ end
263
+
264
+ ################################
265
+ # instance_persistence_port= #
266
+ # instance_persistence_port #
267
+ # store_using #
268
+ # persists_using #
269
+ ################################
270
+
271
+ it 'can set and return a persistence port to be used for instances' do
272
+ class ::Persistence::Object::InstancePersistencePortMock
273
+ include ::Persistence::Object
274
+ method( :instance_persistence_port= ).should == method( :store_using )
275
+ method( :instance_persistence_port= ).should == method( :persists_using )
276
+ mock_port = ::Persistence.port( :mock )
277
+ self.instance_persistence_port = mock_port
278
+ instance_persistence_port.should == mock_port
279
+ self.instance_persistence_port = nil
280
+ ::Persistence.disable_port( :mock )
281
+ instance_persistence_port.should == nil
282
+ self.instance_persistence_port = nil
283
+ instance_persistence_port.should == nil
284
+ self.instance_persistence_port = :mock
285
+ instance_persistence_port.should == mock_port
286
+ ::Persistence.enable_port( :mock )
287
+ end
288
+ end
289
+
290
+ #######################
291
+ # persistence_port= #
292
+ # persistence_port #
293
+ #######################
294
+
295
+ it "it can set and return a persistence port, either from an instance, a name, or another instance's persistence port, or from its class's instance persistence port by default" do
296
+ class ::Persistence::Object::PersistencePortMock
297
+ include ::Persistence::Object
298
+ end
299
+ rspec = self
300
+ ::Persistence::Object::PersistencePortMock.new.instance_eval do
301
+ persistence_port.name.should == :mock
302
+ ::Proc.new { self.persistence_port = :another_mock }.should rspec.raise_error
303
+ ::Persistence.enable_port( :another_mock, ::Persistence::Adapter::Mock.new )
304
+ self.persistence_port = :another_mock
305
+ persistence_port.name.should == :another_mock
306
+ ::Persistence.disable_port( :another_mock )
307
+ end
308
+ end
309
+
310
+ end