dm-persevere-adapter 0.18.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.txt +7 -3
- data/VERSION +1 -1
- data/lib/model_json_support.rb +9 -28
- data/lib/persevere.rb +20 -2
- data/lib/persevere_adapter.rb +331 -130
- data/spec/persevere_adapter_spec.rb +132 -84
- data/spec/persevere_spec.rb +143 -69
- data/spec/spec_helper.rb +7 -44
- metadata +66 -70
- data/spec/adapter_shared_spec.rb +0 -311
- data/spec/lib/adapter_helpers.rb +0 -105
@@ -2,25 +2,28 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
gem 'rspec'
|
3
3
|
require 'spec'
|
4
4
|
|
5
|
-
require 'ruby-debug'
|
6
5
|
require DataMapper.root / 'lib' / 'dm-core' / 'spec' / 'adapter_shared_spec'
|
6
|
+
agg_dir = path_to("dm-aggregates", "0.10.2")[0]
|
7
|
+
require agg_dir / 'spec' / 'public' / 'shared' / 'aggregate_shared_spec'
|
8
|
+
|
7
9
|
require Pathname(__FILE__).dirname.expand_path.parent + 'lib/persevere_adapter'
|
8
10
|
|
9
11
|
describe DataMapper::Adapters::PersevereAdapter do
|
10
12
|
before :all do
|
11
13
|
# This needs to point to a valid persevere server
|
12
14
|
@adapter = DataMapper.setup(:default, { :adapter => 'persevere', :host => 'localhost', :port => '8080' })
|
15
|
+
@repository = DataMapper.repository(@adapter.name)
|
13
16
|
|
14
|
-
class Bozon
|
17
|
+
class ::Bozon
|
15
18
|
include DataMapper::Resource
|
16
|
-
|
19
|
+
|
17
20
|
# Persevere only does id's as strings.
|
18
21
|
property :id, String, :serial => true
|
19
22
|
property :author, String
|
20
23
|
property :created_at, DateTime
|
21
24
|
property :title, String
|
22
25
|
end
|
23
|
-
|
26
|
+
|
24
27
|
@test_schema_hash = {
|
25
28
|
'id' => 'Vanilla',
|
26
29
|
'properties' => {
|
@@ -29,7 +32,7 @@ describe DataMapper::Adapters::PersevereAdapter do
|
|
29
32
|
'data' => { 'type' => 'string'}
|
30
33
|
}
|
31
34
|
}
|
32
|
-
|
35
|
+
|
33
36
|
@test_schema_hash_alt = {
|
34
37
|
'id' => 'test1/Vanilla',
|
35
38
|
'properties' => {
|
@@ -45,7 +48,7 @@ describe DataMapper::Adapters::PersevereAdapter do
|
|
45
48
|
'newdata' => { 'type' => 'any'}
|
46
49
|
}
|
47
50
|
}
|
48
|
-
|
51
|
+
|
49
52
|
@test_schema_hash_alt_mod = {
|
50
53
|
'id' => 'test1/Vanilla',
|
51
54
|
'properties' => {
|
@@ -54,95 +57,140 @@ describe DataMapper::Adapters::PersevereAdapter do
|
|
54
57
|
}
|
55
58
|
}
|
56
59
|
end
|
57
|
-
|
58
|
-
describe 'migrations' do
|
59
|
-
it 'should create the Bozon storage' do
|
60
|
-
Bozon.auto_migrate!
|
61
|
-
Bozon.auto_migrate_down!
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should destroy Create then Remove the Bozon Storage" do
|
65
|
-
@adapter.get_schema(Bozon.storage_name).should == false
|
66
|
-
Bozon.auto_migrate_up!
|
67
|
-
@adapter.get_schema(Bozon.storage_name).should_not == false
|
68
|
-
Bozon.auto_migrate_down!
|
69
|
-
@adapter.get_schema(Bozon.storage_name).should == false
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
it_should_behave_like 'An Adapter Foo'
|
74
|
-
|
75
|
-
describe '#put_schema' do
|
76
|
-
it 'should create the json schema for the hash' do
|
77
|
-
@adapter.put_schema(@test_schema_hash).should_not == false
|
78
|
-
end
|
79
60
|
|
80
|
-
|
81
|
-
|
61
|
+
it_should_behave_like 'An Adapter'
|
62
|
+
|
63
|
+
describe 'migrations' do
|
64
|
+
it 'should create the Bozon storage' do
|
65
|
+
Bozon.auto_migrate!
|
66
|
+
Bozon.auto_migrate_down!
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should destroy Create then Remove the Bozon Storage" do
|
70
|
+
@adapter.get_schema(Bozon.storage_name).should == false
|
71
|
+
Bozon.auto_migrate_up!
|
72
|
+
@adapter.get_schema(Bozon.storage_name).should_not == false
|
73
|
+
Bozon.auto_migrate_down!
|
74
|
+
@adapter.get_schema(Bozon.storage_name).should == false
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#put_schema' do
|
78
|
+
it 'should create the json schema for the hash' do
|
79
|
+
@adapter.put_schema(@test_schema_hash).should_not == false
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should create the json schema for the hash under the specified project' do
|
83
|
+
@adapter.put_schema(@test_schema_hash, "test").should_not == false
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should create the json schema for the hash under the specified project' do
|
87
|
+
@adapter.put_schema(@test_schema_hash_alt).should_not == false
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#get_schema' do
|
92
|
+
it 'should return all of the schemas (in json) if no name is provided' do
|
93
|
+
result = @adapter.get_schema()
|
94
|
+
result.should_not == false
|
95
|
+
JSON.parse(result).class.should == Array
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should return the json schema of the class specified' do
|
99
|
+
result = @adapter.get_schema("Object")
|
100
|
+
result.should_not == false
|
101
|
+
JSON.parse(result)["id"].should == "Object"
|
102
|
+
end
|
103
|
+
|
104
|
+
# I don't think we need these tests.
|
105
|
+
# it 'should return all of the schemas (in json) for a project if no name is provided' do
|
106
|
+
# result = @adapter.get_schema(nil, "Class")
|
107
|
+
# debugger
|
108
|
+
# result
|
109
|
+
# end
|
110
|
+
#
|
111
|
+
# it 'should return all of the schemas (in json) if no name is provided' do
|
112
|
+
# @adapter.get_schema("Object", "Class")
|
113
|
+
# end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#update_schema' do
|
117
|
+
it 'should update a previously existing schema' do
|
118
|
+
result = @adapter.update_schema(@test_schema_hash_mod)
|
119
|
+
result.should_not == false
|
120
|
+
|
121
|
+
@test_schema_hash_mod['id'].should match(JSON.parse(result)['id'])
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should update a previously created schema under the specified project' do
|
125
|
+
result = @adapter.update_schema(@test_schema_hash_mod, "test")
|
126
|
+
result.should_not == false
|
127
|
+
@test_schema_hash_mod['id'].should match(JSON.parse(result)['id'])
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should update a previously created schema under the specified project' do
|
131
|
+
result = @adapter.update_schema(@test_schema_hash_alt_mod)
|
132
|
+
result.should_not == false
|
133
|
+
@test_schema_hash_alt_mod['id'].should match(JSON.parse(result)['id'])
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#delete_schema' do
|
138
|
+
it 'should delete the specified schema' do
|
139
|
+
@adapter.delete_schema(@test_schema_hash).should == true
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should delete the specified schema in the specified project' do
|
143
|
+
@adapter.delete_schema(@test_schema_hash, "test").should == true
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should delete the specified schema in the specified project' do
|
147
|
+
@adapter.delete_schema(@test_schema_hash_alt).should == true
|
148
|
+
end
|
82
149
|
end
|
83
|
-
|
84
|
-
it 'should create the json schema for the hash under the specified project' do
|
85
|
-
@adapter.put_schema(@test_schema_hash_alt).should_not == false
|
86
|
-
end
|
87
150
|
end
|
88
151
|
|
89
|
-
describe '
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'should return the json schema of the class specified' do
|
97
|
-
result = @adapter.get_schema("Object")
|
98
|
-
result.should_not == false
|
99
|
-
JSON.parse(result)["id"].should == "Object"
|
152
|
+
describe 'aggregates' do
|
153
|
+
it_should_behave_like 'It Has Setup Resources'
|
154
|
+
before :all do
|
155
|
+
@dragons = Dragon.all
|
156
|
+
@countries = Country.all
|
100
157
|
end
|
101
|
-
|
102
|
-
# I don't think we need these tests.
|
103
|
-
# it 'should return all of the schemas (in json) for a project if no name is provided' do
|
104
|
-
# result = @adapter.get_schema(nil, "Class")
|
105
|
-
# debugger
|
106
|
-
# result
|
107
|
-
# end
|
108
|
-
#
|
109
|
-
# it 'should return all of the schemas (in json) if no name is provided' do
|
110
|
-
# @adapter.get_schema("Object", "Class")
|
111
|
-
# end
|
158
|
+
it_should_behave_like 'An Aggregatable Class'
|
112
159
|
end
|
113
160
|
|
114
|
-
describe '
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
@test_schema_hash_mod['id'].should match(JSON.parse(result)['id'])
|
161
|
+
describe 'limiting and offsets' do
|
162
|
+
before(:all) do
|
163
|
+
Bozon.auto_migrate!
|
164
|
+
(0..99).each{|i| Bozon.create!(:author => i, :title => i)}
|
120
165
|
end
|
121
|
-
|
122
|
-
it
|
123
|
-
result =
|
124
|
-
result.
|
125
|
-
@test_schema_hash_mod['id'].should match(JSON.parse(result)['id'])
|
166
|
+
|
167
|
+
it "should limit" do
|
168
|
+
result = Bozon.all(:limit => 2)
|
169
|
+
result.length.should == 2
|
126
170
|
end
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
result.should_not == false
|
131
|
-
@test_schema_hash_alt_mod['id'].should match(JSON.parse(result)['id'])
|
171
|
+
|
172
|
+
after(:all) do
|
173
|
+
Bozon.auto_migrate_down!
|
132
174
|
end
|
133
175
|
end
|
134
|
-
|
135
|
-
describe '#delete_schema' do
|
136
|
-
it 'should delete the specified schema' do
|
137
|
-
@adapter.delete_schema(@test_schema_hash).should == true
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'should delete the specified schema in the specified project' do
|
141
|
-
@adapter.delete_schema(@test_schema_hash, "test").should == true
|
142
|
-
end
|
143
176
|
|
144
|
-
|
145
|
-
|
146
|
-
|
177
|
+
describe "is reflective" do
|
178
|
+
it "should be able to fetch json model descriptions" # do
|
179
|
+
# @return_hash = @test_schema_hash.clone
|
180
|
+
# @return_hash['prototype'] = {}
|
181
|
+
# @adapter.fetch_models.should_not include(@return_hash)
|
182
|
+
# @adapter.put_schema(@test_schema_hash)
|
183
|
+
# models = @adapter.fetch_models
|
184
|
+
# models.should include(@return_hash)
|
185
|
+
# @adapter.delete_schema(@test_schema_hash)
|
186
|
+
# end
|
187
|
+
|
188
|
+
it "should reflect existing schemas into DM models with reflect!" # do
|
189
|
+
# @adapter.put_schema(@test_schema_hash)
|
190
|
+
# @adapter.reflect!
|
191
|
+
# Vanilla.should_not be_nil
|
192
|
+
# end
|
147
193
|
end
|
194
|
+
|
195
|
+
|
148
196
|
end
|
data/spec/persevere_spec.rb
CHANGED
@@ -11,9 +11,9 @@ describe Persevere do
|
|
11
11
|
@blobObj = {
|
12
12
|
'id' => 'Yogo',
|
13
13
|
'properties' => {
|
14
|
-
'cid' => {'type' => 'string' },
|
15
|
-
'parent' => { 'type' => 'string'},
|
16
|
-
'data' => { 'type' => 'string'}
|
14
|
+
'cid' => {'type' => 'string', 'optional' => true },
|
15
|
+
'parent' => { 'type' => 'string', 'optional' => true},
|
16
|
+
'data' => { 'type' => 'string', 'optional' => true}
|
17
17
|
}
|
18
18
|
}
|
19
19
|
|
@@ -29,90 +29,164 @@ describe Persevere do
|
|
29
29
|
@mockObj = {
|
30
30
|
'id' => 'Yogo',
|
31
31
|
'properties' => {
|
32
|
-
'cid' => {'type' => 'string' },
|
33
|
-
'parent' => { 'type' => 'string'},
|
34
|
-
'data' => { 'type' => 'string'}
|
32
|
+
'cid' => {'type' => 'string', 'optional' => true },
|
33
|
+
'parent' => { 'type' => 'string', 'optional' => true},
|
34
|
+
'data' => { 'type' => 'string', 'optional' => true}
|
35
35
|
},
|
36
36
|
'prototype' => {}
|
37
37
|
}
|
38
|
+
|
39
|
+
@object = {
|
40
|
+
'cid' => '123',
|
41
|
+
'parent' => 'none',
|
42
|
+
'data' => 'A Chunk Of Data'
|
43
|
+
}
|
44
|
+
|
38
45
|
end
|
39
46
|
|
40
|
-
|
47
|
+
|
41
48
|
# Test POST to create a new class
|
42
|
-
|
49
|
+
|
43
50
|
describe '#post' do
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
51
|
+
it 'should create a new object in persevere' do
|
52
|
+
result = @p.create('/Class/', @blobObj)
|
53
|
+
result.code.should == "201"
|
54
|
+
JSON.parse(result.body).should == @mockObj
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should not allow posting with a bad object' do
|
58
|
+
result = @p.create('/Class/', @corruptObj)
|
59
|
+
result.code.should == "500"
|
60
|
+
result.body.should == "\"Can not modify queries\""
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should not allow posting to an existing object/id/path' do
|
64
|
+
result = @p.create('/Class/', @blobObj)
|
65
|
+
result.code.should == "201"
|
66
|
+
JSON.parse(result.body).should == @blobObj
|
67
|
+
# This shouldn't be a 201, it should say something mean.
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# Test GET to retrieve the list of classes from Persvr
|
73
|
+
#
|
74
|
+
describe '#get' do
|
75
|
+
it 'should retrieve the previously created object from persevere' do
|
76
|
+
result = @p.retrieve('/Class/Yogo')
|
77
|
+
result.code.should == "200"
|
78
|
+
JSON.parse(result.body).should == @blobObj
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should 404 on a non-existent object' do
|
82
|
+
result = @p.retrieve('/Class/GetNotThere')
|
83
|
+
result.code.should == "404"
|
84
|
+
result.message.should == "Not Found"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# Test PUT to modify an existing class
|
90
|
+
#
|
91
|
+
describe '#put' do
|
92
|
+
it 'should modify the previously created object in persevere' do
|
93
|
+
@blobObj['properties']['tstAttribute'] = { 'type' => 'string' }
|
94
|
+
result = @p.update('/Class/Yogo', @blobObj)
|
95
|
+
result.code.should == "200"
|
96
|
+
JSON.parse(result.body).should == @blobObj
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should fail to modify a non-existent item' do
|
100
|
+
result = @p.update('/Class/NonExistent', @blobObj)
|
101
|
+
result.code.should == "500"
|
102
|
+
result.body.should == "\"id does not match location\""
|
103
|
+
@p.delete('/Class/NonExistent') # A bug(?) in Persevere makes a broken NonExistent class.
|
104
|
+
# This should be a 404 and not throw a persevere server exception
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Test DELETE to remove the previously created and modified class
|
110
|
+
#
|
111
|
+
describe '#delete' do
|
112
|
+
it 'should remove the previously created and modified object from persevere' do
|
113
|
+
result = @p.delete('/Class/Yogo')
|
114
|
+
result.code.should == "204"
|
115
|
+
@p.retrieve('/Class/Yogo').code.should == "404"
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should fail to delete a non-existent item' do
|
119
|
+
result = @p.delete('/Class/NotThere')
|
120
|
+
result.code.should == "404"
|
121
|
+
result.message.should == "Not Found"
|
122
|
+
result.body.should == "\"Class/NotThere not found\""
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "POSTing objects" do
|
127
|
+
before(:all) do
|
128
|
+
@p.create('/Class/', @blobObj)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should not allow nil fields to be posted" do
|
132
|
+
obj_with_nil = @object.merge({'cid' => nil})
|
133
|
+
result = @p.create('/Yogo', obj_with_nil)
|
134
|
+
result.code.should == "201"
|
135
|
+
JSON.parse(result.body).reject{|key,value| key == 'id' }.should ==
|
136
|
+
obj_with_nil.reject{|key,value| value.nil?}
|
137
|
+
end
|
138
|
+
|
139
|
+
after(:all) do
|
140
|
+
@p.delete('/Class/Yogo')
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "GETting limits and offsets" do
|
145
|
+
before(:all) do
|
146
|
+
@p.create('/Class/', @blobObj)
|
147
|
+
(0..99).each do |i|
|
148
|
+
@p.create('/Yogo/', @object.merge({'cid' => "#{i}"}))
|
149
|
+
end
|
61
150
|
end
|
62
|
-
end
|
63
151
|
|
64
|
-
|
65
|
-
|
66
|
-
#
|
67
|
-
describe '#get' do
|
68
|
-
it 'should retrieve the previously created object from persevere' do
|
69
|
-
result = @p.retrieve('/Class/Yogo')
|
152
|
+
it "should only retrieve all objects" do
|
153
|
+
result = @p.retrieve('/Yogo/')
|
70
154
|
result.code.should == "200"
|
71
|
-
JSON.parse(result.body).should ==
|
155
|
+
JSON.parse(result.body).length.should == 100
|
72
156
|
end
|
73
157
|
|
74
|
-
it
|
75
|
-
result = @p.retrieve('/
|
76
|
-
result.code.should == "404"
|
77
|
-
result.message.should == "Not Found"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
#
|
82
|
-
# Test PUT to modify an existing class
|
83
|
-
#
|
84
|
-
describe '#put' do
|
85
|
-
it 'should modify the previously created object in persevere' do
|
86
|
-
@blobObj['properties']['tstAttribute'] = { 'type' => 'string' }
|
87
|
-
result = @p.update('/Class/Yogo', @blobObj)
|
158
|
+
it "should retrieve the first objects" do
|
159
|
+
result = @p.retrieve('/Yogo/1')
|
88
160
|
result.code.should == "200"
|
89
|
-
JSON.parse(result.body).should ==
|
161
|
+
JSON.parse(result.body)['id'].should == '1'
|
90
162
|
end
|
91
163
|
|
92
|
-
it
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
@p.delete('/Class/NonExistent') # A bug(?) in Persevere makes a broken NonExistent class.
|
97
|
-
# This should be a 404 and not throw a persevere server exception
|
164
|
+
it "should retrieve a 10 of the objects" do
|
165
|
+
result = @p.retrieve('/Yogo/', {'Range' => "items=1-10"})
|
166
|
+
result.code.should == '206'
|
167
|
+
JSON.parse(result.body).length.should == 10
|
98
168
|
end
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
169
|
+
|
170
|
+
it "should return the first 2 objects" do
|
171
|
+
result = @p.retrieve('/Yogo/', {'Range' => "items=0-1"})
|
172
|
+
result.code.should == '206'
|
173
|
+
json = JSON.parse(result.body)
|
174
|
+
json.length.should == 2
|
175
|
+
json[0]['id'].should == '1'
|
176
|
+
json[1]['id'].should == '2'
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should return 21 and up objects" do
|
180
|
+
result = @p.retrieve('/Yogo/', {'Range' => 'items=20-'})
|
181
|
+
result.code.should == '206'
|
182
|
+
json = JSON.parse(result.body)
|
183
|
+
json.length.should == 80
|
184
|
+
json[0]['id'].should == '21'
|
185
|
+
json[-1]['id'].should == '100'
|
109
186
|
end
|
110
187
|
|
111
|
-
|
112
|
-
|
113
|
-
result.code.should == "404"
|
114
|
-
result.message.should == "Not Found"
|
115
|
-
result.body.should == "\"Class/NotThere not found\""
|
188
|
+
after(:all) do
|
189
|
+
@p.delete('/Class/Yogo')
|
116
190
|
end
|
117
191
|
end
|
118
192
|
end
|