persistence 0.0.1.alpha → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/README.md +260 -17
- data/lib/namespaces.rb +55 -0
- data/lib/persistence.rb +38 -3
- data/lib/persistence/adapter/abstract.rb +22 -0
- data/lib/persistence/adapter/abstract/enable_disable.rb +107 -0
- data/lib/persistence/adapter/abstract/primary_key/id_property_string.rb +33 -0
- data/lib/persistence/adapter/abstract/primary_key/simple.rb +29 -0
- data/lib/persistence/adapter/mock.rb +9 -0
- data/lib/persistence/adapter/mock/adapter_interface.rb +102 -0
- data/lib/persistence/adapter/mock/bucket.rb +9 -0
- data/lib/persistence/adapter/mock/bucket/bucket_interface.rb +260 -0
- data/lib/persistence/adapter/mock/bucket/index.rb +9 -0
- data/lib/persistence/adapter/mock/bucket/index/index_interface.rb +155 -0
- data/lib/persistence/adapter/mock/cursor.rb +9 -0
- data/lib/persistence/adapter/mock/cursor/cursor_interface.rb +238 -0
- data/lib/persistence/cursor.rb +11 -0
- data/lib/persistence/cursor/atomic.rb +110 -0
- data/lib/persistence/cursor/cursor_interface.rb +337 -0
- data/lib/persistence/exception/block_required.rb +7 -0
- data/lib/persistence/exception/conflicting_index_already_declared.rb +7 -0
- data/lib/persistence/exception/duplicate_violates_unique_index.rb +7 -0
- data/lib/persistence/exception/explicit_index_required.rb +7 -0
- data/lib/persistence/exception/indexing_block_failed_to_generate_keys.rb +7 -0
- data/lib/persistence/exception/indexing_object_requires_keys.rb +7 -0
- data/lib/persistence/exception/key_value_required.rb +7 -0
- data/lib/persistence/exception/no_port_enabled.rb +7 -0
- data/lib/persistence/object.rb +21 -0
- data/lib/persistence/object/autodetermine.rb +74 -0
- data/lib/persistence/object/class_instance.rb +1884 -0
- data/lib/persistence/object/complex.rb +17 -0
- data/lib/persistence/object/complex/array.rb +14 -0
- data/lib/persistence/object/complex/array/class_instance.rb +37 -0
- data/lib/persistence/object/complex/array/object_instance.rb +54 -0
- data/lib/persistence/object/complex/attributes.rb +1808 -0
- data/lib/persistence/object/complex/attributes/attributes_array.rb +32 -0
- data/lib/persistence/object/complex/attributes/attributes_hash.rb +187 -0
- data/lib/persistence/object/complex/attributes/default_atomic_non_atomic.rb +102 -0
- data/lib/persistence/object/complex/attributes/hash_to_port.rb +40 -0
- data/lib/persistence/object/complex/class_and_object_instance.rb +132 -0
- data/lib/persistence/object/complex/class_instance.rb +267 -0
- data/lib/persistence/object/complex/complex_object.rb +111 -0
- data/lib/persistence/object/complex/hash.rb +14 -0
- data/lib/persistence/object/complex/hash/class_instance.rb +40 -0
- data/lib/persistence/object/complex/hash/object_instance.rb +63 -0
- data/lib/persistence/object/complex/index/attribute_index.rb +10 -0
- data/lib/persistence/object/complex/index/attribute_index/attribute_index_interface.rb +43 -0
- data/lib/persistence/object/complex/object_instance.rb +469 -0
- data/lib/persistence/object/flat.rb +17 -0
- data/lib/persistence/object/flat/class_instance.rb +34 -0
- data/lib/persistence/object/flat/file.rb +14 -0
- data/lib/persistence/object/flat/file/class_instance.rb +122 -0
- data/lib/persistence/object/flat/file/contents.rb +7 -0
- data/lib/persistence/object/flat/file/file_persistence.rb +147 -0
- data/lib/persistence/object/flat/file/object_instance.rb +116 -0
- data/lib/persistence/object/flat/file/path.rb +9 -0
- data/lib/persistence/object/flat/object_instance.rb +24 -0
- data/lib/persistence/object/index.rb +479 -0
- data/lib/persistence/object/index/block_index.rb +10 -0
- data/lib/persistence/object/index/block_index/block_index_interface.rb +110 -0
- data/lib/persistence/object/index/explicit_index.rb +10 -0
- data/lib/persistence/object/index/explicit_index/explicit_index_interface.rb +57 -0
- data/lib/persistence/object/index_hash.rb +40 -0
- data/lib/persistence/object/object_instance.rb +322 -0
- data/lib/persistence/object/parse_persistence_args.rb +145 -0
- data/lib/persistence/port.rb +9 -0
- data/lib/persistence/port/bucket.rb +9 -0
- data/lib/persistence/port/bucket/bucket_index.rb +9 -0
- data/lib/persistence/port/bucket/bucket_interface.rb +685 -0
- data/lib/persistence/port/controller.rb +263 -0
- data/lib/persistence/port/port_interface.rb +417 -0
- data/lib/requires.rb +146 -0
- data/spec/Integration_spec.rb +53 -0
- data/spec/Persistence_spec.rb +175 -0
- data/spec/example_objects.rb +6 -0
- data/spec/example_objects/complex_object.rb +7 -0
- data/spec/example_objects/complex_object/array_object.rb +7 -0
- data/spec/example_objects/complex_object/hash_object.rb +7 -0
- data/spec/example_objects/flat_object.rb +7 -0
- data/spec/example_objects/flat_object/file_object.rb +7 -0
- data/spec/persistence/adapter/enable_disable_spec.rb +29 -0
- data/spec/persistence/adapter/mock/cursor_spec.rb +64 -0
- data/spec/persistence/adapter/mock_helpers.rb +27 -0
- data/spec/persistence/adapter/mock_helpers/bucket.rb +10 -0
- data/spec/persistence/adapter/mock_helpers/integration/dictionary_hash.rb +4 -0
- data/spec/persistence/adapter/mock_helpers/integration/note.rb +18 -0
- data/spec/persistence/adapter/mock_helpers/integration/notes_array.rb +4 -0
- data/spec/persistence/adapter/mock_helpers/integration/user.rb +44 -0
- data/spec/persistence/adapter/mock_helpers/integration/user/address.rb +18 -0
- data/spec/persistence/adapter/mock_helpers/integration/user/dictionary_entry.rb +12 -0
- data/spec/persistence/adapter/mock_helpers/integration/user/sub_account.rb +15 -0
- data/spec/persistence/adapter/mock_helpers/object.rb +87 -0
- data/spec/persistence/adapter/mock_helpers/port.rb +21 -0
- data/spec/persistence/adapter/mock_spec.rb +211 -0
- data/spec/persistence/adapter/primary_key/id_property_string_spec.rb +27 -0
- data/spec/persistence/adapter/primary_key/simple_spec.rb +19 -0
- data/spec/persistence/adapter/spec_abstract/adapter_spec.rb +223 -0
- data/spec/persistence/adapter/spec_abstract/cursor_spec.rb +116 -0
- data/spec/persistence/cursor/atomic_spec.rb +86 -0
- data/spec/persistence/cursor/object_and_class_instance_spec.rb +73 -0
- data/spec/persistence/cursor_spec.rb +128 -0
- data/spec/persistence/object/complex/attributes/persistence_hash/array_instance_spec.rb +51 -0
- data/spec/persistence/object/complex/attributes/persistence_hash/hash_instance_spec.rb +56 -0
- data/spec/persistence/object/complex/attributes_spec.rb +1717 -0
- data/spec/persistence/object/complex/complex_spec.rb +922 -0
- data/spec/persistence/object/complex/index/attribute_index_spec.rb +76 -0
- data/spec/persistence/object/flat/bignum_spec.rb +33 -0
- data/spec/persistence/object/flat/class_instance_spec.rb +30 -0
- data/spec/persistence/object/flat/class_spec.rb +38 -0
- data/spec/persistence/object/flat/complex_spec.rb +36 -0
- data/spec/persistence/object/flat/false_class_spec.rb +34 -0
- data/spec/persistence/object/flat/file/class_instance_spec.rb +54 -0
- data/spec/persistence/object/flat/file/object_instance_spec.rb +143 -0
- data/spec/persistence/object/flat/file_spec.rb +64 -0
- data/spec/persistence/object/flat/fixnum_spec.rb +32 -0
- data/spec/persistence/object/flat/float_spec.rb +32 -0
- data/spec/persistence/object/flat/indexing_spec.rb +38 -0
- data/spec/persistence/object/flat/rational_spec.rb +33 -0
- data/spec/persistence/object/flat/regexp_spec.rb +32 -0
- data/spec/persistence/object/flat/string_spec.rb +34 -0
- data/spec/persistence/object/flat/symbol_spec.rb +32 -0
- data/spec/persistence/object/flat/true_class_spec.rb +32 -0
- data/spec/persistence/object/indexes/block_index_spec.rb +119 -0
- data/spec/persistence/object/indexes/explicit_index_spec.rb +112 -0
- data/spec/persistence/object/parse_persistence_args_spec.rb +65 -0
- data/spec/persistence/object_spec.rb +310 -0
- data/spec/persistence/port/bucket/bucket_interface_spec.rb +146 -0
- data/spec/persistence/port/bucket/index/bucket_index_spec.rb +67 -0
- data/spec/persistence/port/bucket_spec.rb +20 -0
- data/spec/persistence/port/controller_spec.rb +60 -0
- data/spec/persistence/port/port_interface_spec.rb +105 -0
- metadata +178 -21
- data/.gitignore +0 -17
- data/Gemfile +0 -4
- data/LICENSE +0 -22
- data/Rakefile +0 -2
- data/lib/persistence/version.rb +0 -3
- data/persistence.gemspec +0 -17
data/lib/requires.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
|
2
|
+
basepath = 'persistence'
|
3
|
+
|
4
|
+
files = [ ]
|
5
|
+
|
6
|
+
# Abstract Adapter
|
7
|
+
files.concat [
|
8
|
+
|
9
|
+
'adapter/abstract',
|
10
|
+
'adapter/abstract/enable_disable',
|
11
|
+
'adapter/abstract/primary_key/id_property_string',
|
12
|
+
'adapter/abstract/primary_key/simple'
|
13
|
+
|
14
|
+
]
|
15
|
+
|
16
|
+
# Mock Adapter
|
17
|
+
files.concat [
|
18
|
+
|
19
|
+
'adapter/mock/bucket/index/index_interface',
|
20
|
+
'adapter/mock/bucket/index',
|
21
|
+
'adapter/mock/bucket/bucket_interface',
|
22
|
+
'adapter/mock/bucket',
|
23
|
+
'adapter/mock/cursor/cursor_interface',
|
24
|
+
'adapter/mock/cursor',
|
25
|
+
'adapter/mock/adapter_interface',
|
26
|
+
'adapter/mock'
|
27
|
+
|
28
|
+
]
|
29
|
+
|
30
|
+
# Object
|
31
|
+
files.concat [
|
32
|
+
|
33
|
+
'object/parse_persistence_args',
|
34
|
+
|
35
|
+
'object/index',
|
36
|
+
|
37
|
+
'object/index_hash',
|
38
|
+
|
39
|
+
'object/index/block_index/block_index_interface',
|
40
|
+
'object/index/block_index',
|
41
|
+
'object/index/explicit_index/explicit_index_interface',
|
42
|
+
'object/index/explicit_index',
|
43
|
+
|
44
|
+
'object/flat/file/file_persistence',
|
45
|
+
|
46
|
+
'object/flat/file/contents',
|
47
|
+
'object/flat/file/path',
|
48
|
+
|
49
|
+
'object/flat/file/class_instance',
|
50
|
+
'object/flat/file/object_instance',
|
51
|
+
|
52
|
+
'object/class_instance',
|
53
|
+
'object/object_instance',
|
54
|
+
|
55
|
+
'object/flat/class_instance',
|
56
|
+
'object/flat/object_instance',
|
57
|
+
|
58
|
+
'object/complex/attributes/attributes_array',
|
59
|
+
'object/complex/attributes/attributes_hash',
|
60
|
+
'object/complex/attributes/default_atomic_non_atomic',
|
61
|
+
'object/complex/attributes/hash_to_port',
|
62
|
+
'object/complex/attributes',
|
63
|
+
|
64
|
+
'object/complex/complex_object',
|
65
|
+
|
66
|
+
'object/complex/class_and_object_instance',
|
67
|
+
'object/complex/class_instance',
|
68
|
+
'object/complex/object_instance',
|
69
|
+
|
70
|
+
'object/complex/array/class_instance',
|
71
|
+
'object/complex/array/object_instance',
|
72
|
+
|
73
|
+
'object/complex/hash/class_instance',
|
74
|
+
'object/complex/hash/object_instance',
|
75
|
+
|
76
|
+
'object/complex',
|
77
|
+
'object/complex/array',
|
78
|
+
'object/complex/hash',
|
79
|
+
|
80
|
+
'object/flat',
|
81
|
+
'object/flat/file',
|
82
|
+
|
83
|
+
'object/autodetermine',
|
84
|
+
'object',
|
85
|
+
|
86
|
+
]
|
87
|
+
|
88
|
+
# Port
|
89
|
+
files.concat [
|
90
|
+
|
91
|
+
'port/controller',
|
92
|
+
|
93
|
+
'port/port_interface',
|
94
|
+
|
95
|
+
'port/bucket/bucket_interface',
|
96
|
+
'port/bucket',
|
97
|
+
|
98
|
+
'port'
|
99
|
+
|
100
|
+
]
|
101
|
+
|
102
|
+
# Cursor
|
103
|
+
files.concat [
|
104
|
+
|
105
|
+
'cursor/cursor_interface',
|
106
|
+
'cursor/atomic',
|
107
|
+
|
108
|
+
'cursor'
|
109
|
+
|
110
|
+
]
|
111
|
+
|
112
|
+
# Complex Index
|
113
|
+
files.concat [
|
114
|
+
|
115
|
+
'object/complex/index/attribute_index/attribute_index_interface',
|
116
|
+
'object/complex/index/attribute_index'
|
117
|
+
|
118
|
+
]
|
119
|
+
|
120
|
+
# Port Index
|
121
|
+
files.concat [
|
122
|
+
|
123
|
+
'port/bucket/bucket_index'
|
124
|
+
|
125
|
+
]
|
126
|
+
|
127
|
+
# Exceptions
|
128
|
+
files.concat [
|
129
|
+
|
130
|
+
'exception/block_required',
|
131
|
+
'exception/conflicting_index_already_declared',
|
132
|
+
'exception/duplicate_violates_unique_index',
|
133
|
+
'exception/indexing_block_failed_to_generate_keys',
|
134
|
+
'exception/indexing_object_requires_keys',
|
135
|
+
|
136
|
+
'exception/no_port_enabled',
|
137
|
+
'exception/explicit_index_required',
|
138
|
+
'exception/key_value_required'
|
139
|
+
|
140
|
+
]
|
141
|
+
|
142
|
+
files.each do |this_file|
|
143
|
+
require_relative( File.join( basepath, this_file ) + '.rb' )
|
144
|
+
end
|
145
|
+
|
146
|
+
require_relative( basepath + '.rb' )
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
require_relative '../lib/persistence.rb'
|
3
|
+
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
require_relative 'persistence/adapter/mock_helpers.rb'
|
7
|
+
|
8
|
+
# FIX - Date needs to be treated as a string in and out
|
9
|
+
|
10
|
+
describe ::Persistence do
|
11
|
+
|
12
|
+
it 'can create some objects with sub-objects and get them back' do
|
13
|
+
|
14
|
+
::Persistence.enable_port( :mock, ::Persistence::Adapter::Mock.new )
|
15
|
+
|
16
|
+
user = ::Persistence::Adapter::Abstract::Mock::User.new.persist!
|
17
|
+
user.populate
|
18
|
+
|
19
|
+
user.persistence_bucket.should == ::Persistence::Adapter::Abstract::Mock::User.instance_persistence_bucket
|
20
|
+
user.persistence_bucket.name.should == ::Persistence::Adapter::Abstract::Mock::User.to_s.to_sym
|
21
|
+
|
22
|
+
user.address.persistence_bucket.should == ::Persistence::Adapter::Abstract::Mock::User::Address.instance_persistence_bucket
|
23
|
+
user.address.persistence_bucket.name.should == ::Persistence::Adapter::Abstract::Mock::User::Address.to_s.to_sym
|
24
|
+
|
25
|
+
user.alternate_address.persistence_bucket.should == ::Persistence::Adapter::Abstract::Mock::User::Address.instance_persistence_bucket
|
26
|
+
user.alternate_address.persistence_bucket.name.should == ::Persistence::Adapter::Abstract::Mock::User::Address.to_s.to_sym
|
27
|
+
|
28
|
+
user.notes.persistence_bucket.should == ::Persistence::Adapter::Abstract::Mock::NotesArray.instance_persistence_bucket
|
29
|
+
user.notes.persistence_bucket.name.should == ::Persistence::Adapter::Abstract::Mock::NotesArray.to_s.to_sym
|
30
|
+
|
31
|
+
user.dictionary.persistence_bucket.should == ::Persistence::Adapter::Abstract::Mock::DictionaryHash.instance_persistence_bucket
|
32
|
+
user.dictionary.persistence_bucket.name.should == ::Persistence::Adapter::Abstract::Mock::DictionaryHash.to_s.to_sym
|
33
|
+
|
34
|
+
user.notes[0].persistence_bucket.should == ::Persistence::Adapter::Abstract::Mock::Note.instance_persistence_bucket
|
35
|
+
user.notes[0].persistence_bucket.name.should == ::Persistence::Adapter::Abstract::Mock::Note.to_s.to_sym
|
36
|
+
|
37
|
+
notes_array = ::Persistence::Adapter::Abstract::Mock::NotesArray.persist( user.notes.persistence_id )
|
38
|
+
notes_array.should == user.notes
|
39
|
+
|
40
|
+
dictionary_hash = ::Persistence::Adapter::Abstract::Mock::DictionaryHash.persist( user.dictionary.persistence_id )
|
41
|
+
dictionary_hash.should == user.dictionary
|
42
|
+
|
43
|
+
persisted_user = ::Persistence::Adapter::Abstract::Mock::User.persist( user.persistence_id )
|
44
|
+
persisted_user.class.should == ::Persistence::Adapter::Abstract::Mock::User
|
45
|
+
|
46
|
+
persisted_user.should == user
|
47
|
+
|
48
|
+
::Persistence.disable_port( :mock )
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,175 @@
|
|
1
|
+
|
2
|
+
require_relative '../lib/persistence.rb'
|
3
|
+
|
4
|
+
describe ::Persistence 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
|
+
it "can persist an object to and from a default bucket with an arbitrary key method" do
|
15
|
+
class ::Persistence::MockUserObject3
|
16
|
+
include ::Persistence
|
17
|
+
attr_accessor :username, :firstname, :lastname
|
18
|
+
attr_index :username
|
19
|
+
end
|
20
|
+
user = ::Persistence::MockUserObject3.new
|
21
|
+
user.username = 'user'
|
22
|
+
user.firstname = 'first'
|
23
|
+
user.lastname = 'last'
|
24
|
+
user.persist!
|
25
|
+
::Persistence::MockUserObject3.persist( :username => 'user' ).should == user
|
26
|
+
end
|
27
|
+
|
28
|
+
it "can persist an object to and from a default bucket with an arbitrary key variable" do
|
29
|
+
class ::Persistence::MockUserObject4
|
30
|
+
include ::Persistence
|
31
|
+
attr_accessor :username, :firstname, :lastname
|
32
|
+
attr_index :username
|
33
|
+
end
|
34
|
+
user = ::Persistence::MockUserObject4.new
|
35
|
+
user.username = 'user'
|
36
|
+
user.firstname = 'first'
|
37
|
+
user.lastname = 'last'
|
38
|
+
user.persist!
|
39
|
+
::Persistence::MockUserObject4.persist( :username => 'user' ).should == user
|
40
|
+
end
|
41
|
+
|
42
|
+
it "can persist an object with other objects as members" do
|
43
|
+
class ::Persistence::MockUserObject5
|
44
|
+
include ::Persistence
|
45
|
+
attr_accessor :username, :firstname, :lastname, :address, :alternate_address
|
46
|
+
attr_index :username
|
47
|
+
end
|
48
|
+
class ::Persistence::MockAddress1
|
49
|
+
include ::Persistence
|
50
|
+
attr_accessor :number, :street, :city, :state, :zipcode
|
51
|
+
end
|
52
|
+
|
53
|
+
user = ::Persistence::MockUserObject5.new
|
54
|
+
user.username = 'user'
|
55
|
+
user.firstname = 'first'
|
56
|
+
user.lastname = 'last'
|
57
|
+
|
58
|
+
user.address = ::Persistence::MockAddress1.new
|
59
|
+
user.address.number = 42
|
60
|
+
user.address.street = 'Street'
|
61
|
+
user.address.city = 'Some City'
|
62
|
+
user.address.state = 'GA'
|
63
|
+
user.address.zipcode = '30003'
|
64
|
+
|
65
|
+
user.alternate_address = ::Persistence::MockAddress1.new
|
66
|
+
user.alternate_address.number = 37
|
67
|
+
user.alternate_address.street = 'Another Street'
|
68
|
+
user.alternate_address.city = 'Some Other City'
|
69
|
+
user.alternate_address.state = 'TX'
|
70
|
+
user.alternate_address.zipcode = '70004'
|
71
|
+
user.persist!
|
72
|
+
|
73
|
+
# here we should be looking for:
|
74
|
+
# * username => 'user' => looks for 'user' with bucket (should find it and replace it)
|
75
|
+
# * address => should get ID from existing user if user exists => needs to check if existing user address is same ID
|
76
|
+
# * alternate_ddress => should also get ID from existing user if user exists => needs to check if existing alternate address is same ID
|
77
|
+
|
78
|
+
::Persistence::MockUserObject5.persist( :username => 'user' ).should == user
|
79
|
+
|
80
|
+
user.alternate_address.number = 48
|
81
|
+
|
82
|
+
user.alternate_address.persist!
|
83
|
+
|
84
|
+
::Persistence::MockUserObject5.persist( :username => 'user' ).should == user
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
it "can persist an object with other objects as members that have atomic properties" do
|
89
|
+
class ::Persistence::MockUserObject6
|
90
|
+
include ::Persistence
|
91
|
+
attr_accessor :username, :firstname, :lastname, :address, :alternate_address
|
92
|
+
attr_index :username
|
93
|
+
end
|
94
|
+
class ::Persistence::MockAddress1
|
95
|
+
include ::Persistence
|
96
|
+
attr_accessor :number, :street, :city, :state, :zipcode
|
97
|
+
attr_atomic_accessor :number
|
98
|
+
attrs_atomic!
|
99
|
+
end
|
100
|
+
|
101
|
+
::Persistence::MockAddress1.atomic_attribute?( :number ).should == true
|
102
|
+
|
103
|
+
user = ::Persistence::MockUserObject6.new
|
104
|
+
user.username = 'user'
|
105
|
+
user.firstname = 'first'
|
106
|
+
user.lastname = 'last'
|
107
|
+
|
108
|
+
user.persist!
|
109
|
+
|
110
|
+
user.address = ::Persistence::MockAddress1.new
|
111
|
+
user.address.number = 42
|
112
|
+
user.address.street = 'Street'
|
113
|
+
user.address.city = 'Some City'
|
114
|
+
user.address.state = 'GA'
|
115
|
+
user.address.zipcode = '30003'
|
116
|
+
|
117
|
+
user.alternate_address = ::Persistence::MockAddress1.new
|
118
|
+
user.alternate_address.number = 37
|
119
|
+
user.alternate_address.street = 'Another Street'
|
120
|
+
user.alternate_address.city = 'Some Other City'
|
121
|
+
user.alternate_address.state = 'TX'
|
122
|
+
user.alternate_address.zipcode = '70004'
|
123
|
+
|
124
|
+
persisted_user = ::Persistence::MockUserObject6.persist( :username => 'user' )
|
125
|
+
persisted_user.should == user
|
126
|
+
|
127
|
+
user.alternate_address.number = 48
|
128
|
+
|
129
|
+
::Persistence::MockUserObject6.persist( :username => 'user' ).should == user
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
it "can persist an object with hash members" do
|
134
|
+
class ::Persistence::MockHashContainerClass1
|
135
|
+
include ::Persistence
|
136
|
+
attr_accessor :some_hash, :storage_key
|
137
|
+
attr_index :storage_key
|
138
|
+
end
|
139
|
+
class ::Persistence::MockHash < Hash
|
140
|
+
include ::Persistence
|
141
|
+
end
|
142
|
+
|
143
|
+
hash_container = ::Persistence::MockHashContainerClass1.new
|
144
|
+
hash_container.storage_key = :hash_container
|
145
|
+
hash_container.some_hash = ::Persistence::MockHash.new
|
146
|
+
hash_container.some_hash[ :hash_key ] = :hash_data
|
147
|
+
|
148
|
+
hash_container.persist!
|
149
|
+
::Persistence::MockHashContainerClass1.persist( :storage_key => :hash_container ).should == hash_container
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
it "can persist an object with array members" do
|
154
|
+
class ::Persistence::MockArrayContainerClass1
|
155
|
+
include ::Persistence
|
156
|
+
attr_accessor :array, :storage_key
|
157
|
+
attr_index :storage_key
|
158
|
+
end
|
159
|
+
class ::Persistence::MockSubArray < Array
|
160
|
+
include ::Persistence
|
161
|
+
end
|
162
|
+
|
163
|
+
storage_key = :array_container
|
164
|
+
array_data = :array_data
|
165
|
+
array_container = ::Persistence::MockArrayContainerClass1.new
|
166
|
+
array_container.storage_key = storage_key
|
167
|
+
array_container.array = ::Persistence::MockSubArray.new
|
168
|
+
array_container.array.push( array_data )
|
169
|
+
|
170
|
+
array_container.persist!
|
171
|
+
::Persistence::MockArrayContainerClass1.persist( :storage_key => storage_key ).should == array_container
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../lib/persistence.rb'
|
3
|
+
|
4
|
+
describe ::Persistence::Adapter::Abstract::EnableDisable do
|
5
|
+
|
6
|
+
################
|
7
|
+
# initialize #
|
8
|
+
################
|
9
|
+
|
10
|
+
it 'can initialize with a home directory specified' do
|
11
|
+
class ::Persistence::Adapter::Abstract::EnableDisable::Mock
|
12
|
+
include ::Persistence::Adapter::Abstract::EnableDisable
|
13
|
+
end
|
14
|
+
home_directory_location = '/tmp/persistence_spec_home_directory'
|
15
|
+
::Persistence::Adapter::Abstract::EnableDisable::Mock.new( home_directory_location ).instance_eval do
|
16
|
+
enabled?.should == false
|
17
|
+
enable
|
18
|
+
enabled?.should == true
|
19
|
+
disable
|
20
|
+
enabled?.should == false
|
21
|
+
enable
|
22
|
+
File.exists?( home_directory_location ).should == true
|
23
|
+
self.home_directory.should == home_directory_location
|
24
|
+
Dir.delete( home_directory_location )
|
25
|
+
File.exists?( home_directory_location ).should == false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|