dm-persevere-adapter 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +1 -1
- data/Rakefile +12 -3
- data/VERSION +1 -1
- data/lib/persevere.rb +106 -0
- data/lib/persevere_adapter.rb +43 -25
- data/persevere/History.txt +6 -0
- data/persevere/LICENSE.txt +13 -0
- data/persevere/Manifest.txt +6 -0
- data/persevere/README.txt +90 -0
- data/spec/persevere_adapter_spec.rb +76 -21
- data/spec/persevere_spec.rb +119 -0
- data/spec/spec_helper.rb +10 -24
- metadata +9 -15
- data/dm-persevere-adapter.gemspec +0 -73
- data/spec/integration/persevere_adapter_spec.rb +0 -6
data/LICENSE.txt
CHANGED
data/Rakefile
CHANGED
@@ -12,9 +12,20 @@ begin
|
|
12
12
|
gemspec.authors = ["Ivan R. Judson", "The Yogo Data Management Development Team" ]
|
13
13
|
gemspec.rdoc_options = ["--main", "README.txt"]
|
14
14
|
gemspec.add_dependency(%q<dm-core>, [">= 0.10.1"])
|
15
|
-
gemspec.add_dependency(%q<persevere>, [">= 1.1"])
|
16
15
|
gemspec.add_dependency(%q<extlib>)
|
17
16
|
end
|
17
|
+
Jeweler::Tasks.new do |gemspec|
|
18
|
+
gemspec.name = %q{persevere}
|
19
|
+
gemspec.summary = %q{A ruby wrapper for persevere}
|
20
|
+
gemspec.description = %q{A ruby wrapper for persevere}
|
21
|
+
gemspec.email = ["irjudson [a] gmail [d] com"]
|
22
|
+
gemspec.homepage = %q{http://github.com/yogo/persevere}
|
23
|
+
gemspec.authors = ["Ivan R. Judson", "The Yogo Data Management Development Team" ]
|
24
|
+
gemspec.rdoc_options = ["--main", "persevere/README.txt"]
|
25
|
+
gemspec.files = ["LICENSE.txt", "persevere/History.txt", "persevere/README.txt", "Rakefile", "lib/persevere.rb"]
|
26
|
+
gemspec.test_files = ["spec/persevere_spec.rb", "spec/spec.opts", "spec/spec_helper.rb"]
|
27
|
+
end
|
28
|
+
Jeweler::GemcutterTasks.new
|
18
29
|
rescue LoadError
|
19
30
|
puts "Jeweler not available. Install it with: gem install jeweler"
|
20
31
|
end
|
@@ -24,6 +35,4 @@ JRUBY = RUBY_PLATFORM =~ /java/
|
|
24
35
|
WINDOWS = Gem.win_platform?
|
25
36
|
SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
|
26
37
|
|
27
|
-
require ROOT + 'lib/persevere_adapter'
|
28
|
-
|
29
38
|
Pathname.glob(ROOT.join('tasks/**/*.rb').to_s).each { |f| require f }
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.17.0
|
data/lib/persevere.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
#
|
2
|
+
# Yogo Data Management Toolkit : Persevere Wrapper
|
3
|
+
# (c) 2008-2009 Montana State University
|
4
|
+
# Ivan R. Judson
|
5
|
+
#
|
6
|
+
# This provides a relatively simple interface to access the Persevere
|
7
|
+
# JSON data store. More information about Persevere can be found here:
|
8
|
+
# http://www.persvr.org/
|
9
|
+
#
|
10
|
+
require 'net/http'
|
11
|
+
require 'uri'
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
class PersevereResult
|
17
|
+
attr_reader :location, :code, :message, :body
|
18
|
+
|
19
|
+
def PersevereResult.make(response)
|
20
|
+
return PersevereResult.new(response["Location"], response.code,
|
21
|
+
response.msg, response.body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(location, code, message, body)
|
25
|
+
@location = location
|
26
|
+
@code = code
|
27
|
+
@message = message
|
28
|
+
@body = body
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
super + " < Location: #{ @location } Code: #{ @code } Message: #{ @message } >"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Persevere
|
37
|
+
VERSION = '1.1'
|
38
|
+
HEADERS = { 'Accept' => 'application/json',
|
39
|
+
'Content-Type' => 'application/json'
|
40
|
+
}
|
41
|
+
|
42
|
+
attr_accessor :server_url, :pservr
|
43
|
+
|
44
|
+
|
45
|
+
def initialize(url)
|
46
|
+
@server_url = url
|
47
|
+
server = URI.parse(@server_url)
|
48
|
+
@persevere = Net::HTTP.new(server.host, server.port)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Pass in a resource hash
|
52
|
+
def create(path, resource)
|
53
|
+
json_blob = resource.to_json
|
54
|
+
response = nil
|
55
|
+
while response.nil?
|
56
|
+
begin
|
57
|
+
response = @persevere.send_request('POST', path, json_blob, HEADERS)
|
58
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
59
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
60
|
+
puts "Persevere Create Failed: #{e}, Trying again."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
return PersevereResult.make(response)
|
64
|
+
end
|
65
|
+
|
66
|
+
def retrieve(path)
|
67
|
+
response = nil
|
68
|
+
while response.nil?
|
69
|
+
begin
|
70
|
+
response = @persevere.send_request('GET', path, nil, HEADERS)
|
71
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
72
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
73
|
+
puts "Persevere Create Failed: #{e}, Trying again."
|
74
|
+
end
|
75
|
+
end
|
76
|
+
return PersevereResult.make(response)
|
77
|
+
end
|
78
|
+
|
79
|
+
def update(path, resource)
|
80
|
+
json_blob = resource.to_json
|
81
|
+
# puts "JSON to PERSEVERE: #{json_blob}"
|
82
|
+
response = nil
|
83
|
+
while response.nil?
|
84
|
+
begin
|
85
|
+
response = @persevere.send_request('PUT', path, json_blob, HEADERS)
|
86
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
87
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
88
|
+
puts "Persevere Create Failed: #{e}, Trying again."
|
89
|
+
end
|
90
|
+
end
|
91
|
+
return PersevereResult.make(response)
|
92
|
+
end
|
93
|
+
|
94
|
+
def delete(path)
|
95
|
+
response = nil
|
96
|
+
while response.nil?
|
97
|
+
begin
|
98
|
+
response = @persevere.send_request('DELETE', path, nil, HEADERS)
|
99
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
100
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
101
|
+
puts "Persevere Create Failed: #{e}, Trying again."
|
102
|
+
end
|
103
|
+
end
|
104
|
+
return PersevereResult.make(response)
|
105
|
+
end
|
106
|
+
end # class Persevere
|
data/lib/persevere_adapter.rb
CHANGED
@@ -2,6 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'dm-core'
|
3
3
|
require 'extlib'
|
4
4
|
require 'json'
|
5
|
+
|
5
6
|
require 'persevere'
|
6
7
|
|
7
8
|
module DataMapper
|
@@ -26,21 +27,14 @@ module DataMapper
|
|
26
27
|
connect if @persevere.nil?
|
27
28
|
created = 0
|
28
29
|
resources.each do |resource|
|
30
|
+
serial = resource.model.serial(self.name)
|
31
|
+
|
29
32
|
#
|
30
33
|
# This isn't the best solution but for an adapter, it'd be nice
|
31
34
|
# to support objects being in *tables* instead of in one big icky
|
32
35
|
# sort of table.
|
33
36
|
#
|
34
|
-
tblname =
|
35
|
-
|
36
|
-
if ! @classes.include?(tblname)
|
37
|
-
payload = {
|
38
|
-
'id' => tblname,
|
39
|
-
'extends' => { "$ref" => "/Class/Object" }
|
40
|
-
}
|
41
|
-
|
42
|
-
response = @persevere.create("/Class/", payload)
|
43
|
-
end
|
37
|
+
tblname = resource.model.storage_name
|
44
38
|
|
45
39
|
path = "/#{tblname}/"
|
46
40
|
payload = resource.attributes
|
@@ -61,7 +55,7 @@ module DataMapper
|
|
61
55
|
end
|
62
56
|
end
|
63
57
|
|
64
|
-
resource
|
58
|
+
serial.set!(resource, rsrc_hash["id"]) unless serial.nil?
|
65
59
|
|
66
60
|
created += 1
|
67
61
|
else
|
@@ -101,12 +95,12 @@ module DataMapper
|
|
101
95
|
end
|
102
96
|
|
103
97
|
resources.each do |resource|
|
104
|
-
tblname =
|
98
|
+
tblname = resource.model.storage_name
|
105
99
|
path = "/#{tblname}/#{resource.id}"
|
106
100
|
|
107
101
|
result = @persevere.update(path, resource.attributes)
|
108
102
|
|
109
|
-
if result
|
103
|
+
if result.code == "200"
|
110
104
|
updated += 1
|
111
105
|
else
|
112
106
|
return false
|
@@ -153,7 +147,7 @@ module DataMapper
|
|
153
147
|
resources = Array.new
|
154
148
|
json_query = make_json_query(query)
|
155
149
|
|
156
|
-
tblname =
|
150
|
+
tblname = query.model.storage_name
|
157
151
|
path = "/#{tblname}/#{json_query}"
|
158
152
|
|
159
153
|
response = @persevere.retrieve(path)
|
@@ -199,13 +193,15 @@ module DataMapper
|
|
199
193
|
resources = read_many(query)
|
200
194
|
end
|
201
195
|
|
196
|
+
puts resources.inspect
|
197
|
+
|
202
198
|
resources.each do |resource|
|
203
|
-
tblname =
|
199
|
+
tblname = resource.model.storage_name
|
204
200
|
path = "/#{tblname}/#{resource.id}"
|
205
201
|
|
206
202
|
result = @persevere.delete(path)
|
207
203
|
|
208
|
-
if result # ok
|
204
|
+
if result.code == "204" # ok
|
209
205
|
deleted += 1
|
210
206
|
end
|
211
207
|
end
|
@@ -238,6 +234,28 @@ module DataMapper
|
|
238
234
|
end
|
239
235
|
end
|
240
236
|
|
237
|
+
def put_schema(schema_hash, project = nil)
|
238
|
+
path = "/Class/"
|
239
|
+
|
240
|
+
if ! project.nil?
|
241
|
+
if schema_hash.has_key?("id")
|
242
|
+
if ! schema_hash['id'].index(project)
|
243
|
+
schema_hash['id'] = "#{project}/#{schema_hash['id']}"
|
244
|
+
end
|
245
|
+
else
|
246
|
+
puts "You need an id key/value in the hash"
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
response = @persevere.create(path, schema_hash)
|
251
|
+
|
252
|
+
if response.code == "201"
|
253
|
+
return JSON.parse(response.body)
|
254
|
+
else
|
255
|
+
return nil
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
241
259
|
private
|
242
260
|
|
243
261
|
##
|
@@ -345,15 +363,15 @@ module DataMapper
|
|
345
363
|
end
|
346
364
|
|
347
365
|
query_terms << case operator
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
366
|
+
when :eql then "#{property.field()}=#{value}"
|
367
|
+
when :lt then "#{property.field()}<#{value}"
|
368
|
+
when :gt then "#{property.field()}>#{value}"
|
369
|
+
when :lte then "#{property.field()}<=#{value}"
|
370
|
+
when :gte then "#{property.field()}=>#{value}"
|
371
|
+
when :not then "#{property.field()}!=#{value}"
|
372
|
+
when :like then "#{property.field()}~'*#{value}*'"
|
373
|
+
else puts "Unknown condition: #{operator}"
|
374
|
+
end
|
357
375
|
end
|
358
376
|
end
|
359
377
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2009 Montana State University
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
@@ -0,0 +1,90 @@
|
|
1
|
+
= ruby persevere client
|
2
|
+
|
3
|
+
* http://github.com/irjudson/persevere
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This gem provides a simple ruby wrapper around the persevere JSON document data store available from http://www.persvr.org.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
Currently this provides a very simple RESTful interface to persevere. Data to be stored in persevere should be sent as hashes. To make this more robust it should provide some schema/table support, plus validate data against the schema/table. This exists in persevere, but is not exposed by this wrapper.
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
#!/usr/bin/env ruby
|
16
|
+
#
|
17
|
+
require 'persevere'
|
18
|
+
|
19
|
+
#
|
20
|
+
# Create an object to interact with Persevere
|
21
|
+
#
|
22
|
+
p = Persevere.new('http://localhost:8080')
|
23
|
+
|
24
|
+
#
|
25
|
+
# Test POST to create a new class
|
26
|
+
#
|
27
|
+
print "\nTesting POST..."
|
28
|
+
tstObj = { 'id' => 'tstObj', 'extends' => { '$ref' => 'Object' } }
|
29
|
+
result = p.create('/Class/', tstObj)
|
30
|
+
print "Response:\n"
|
31
|
+
puts result
|
32
|
+
|
33
|
+
#
|
34
|
+
# Test GET to retrieve the list of classes from Persvr
|
35
|
+
#
|
36
|
+
print "\nTesting GET..."
|
37
|
+
result = p.retrieve('/Class')
|
38
|
+
print "Response:\n"
|
39
|
+
puts result
|
40
|
+
|
41
|
+
#
|
42
|
+
# Test PUT to modify an existing class
|
43
|
+
#
|
44
|
+
print "\nTesting PUT..."
|
45
|
+
tstObj['tstAttribute'] = 42
|
46
|
+
result = p.update('/Class/tstObj', tstObj)
|
47
|
+
print "Response:\n"
|
48
|
+
puts result
|
49
|
+
|
50
|
+
#
|
51
|
+
# Test DELETE to remove the previously created and modified class
|
52
|
+
#
|
53
|
+
print "\nTesting DELETE..."
|
54
|
+
result = p.delete('/Class/tstObj')
|
55
|
+
print "Response:\n"
|
56
|
+
puts result
|
57
|
+
|
58
|
+
== REQUIREMENTS:
|
59
|
+
|
60
|
+
* Persevere installed somewhere
|
61
|
+
* JSON gem
|
62
|
+
|
63
|
+
== INSTALL:
|
64
|
+
|
65
|
+
sudo gem install persevere
|
66
|
+
|
67
|
+
== LICENSE:
|
68
|
+
|
69
|
+
(The MIT License)
|
70
|
+
|
71
|
+
Copyright (c) 2009 Montana State University
|
72
|
+
|
73
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
74
|
+
a copy of this software and associated documentation files (the
|
75
|
+
'Software'), to deal in the Software without restriction, including
|
76
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
77
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
78
|
+
permit persons to whom the Software is furnished to do so, subject to
|
79
|
+
the following conditions:
|
80
|
+
|
81
|
+
The above copyright notice and this permission notice shall be
|
82
|
+
included in all copies or substantial portions of the Software.
|
83
|
+
|
84
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
85
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
86
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
87
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
88
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
89
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
90
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,34 +1,89 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require 'pathname'
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
gem 'rspec'
|
6
|
+
require 'spec'
|
7
|
+
|
8
|
+
require Pathname(__FILE__).dirname.expand_path.parent + 'lib/persevere_adapter'
|
9
|
+
|
10
|
+
DataMapper.setup(:default, {
|
11
|
+
:adapter => 'persevere',
|
12
|
+
:host => 'localhost',
|
13
|
+
:port => '8080',
|
14
|
+
:uri => 'http://localhost:8080'
|
15
|
+
})
|
16
|
+
|
17
|
+
#
|
18
|
+
# I need to make the Book class for Books to relate to
|
19
|
+
#
|
20
|
+
|
21
|
+
class Book
|
22
|
+
include DataMapper::Resource
|
23
|
+
|
24
|
+
# Persevere only does id's as strings.
|
25
|
+
property :id, String, :serial => true
|
26
|
+
property :author, String
|
27
|
+
property :created_at, DateTime
|
28
|
+
property :title, String
|
29
|
+
end
|
2
30
|
|
31
|
+
require 'dm-core'
|
32
|
+
require 'extlib'
|
3
33
|
|
4
34
|
require DataMapper.root / 'lib' / 'dm-core' / 'spec' / 'adapter_shared_spec'
|
35
|
+
require Pathname(__FILE__).dirname.expand_path.parent + 'lib/persevere_adapter'
|
5
36
|
|
6
37
|
describe DataMapper::Adapters::PersevereAdapter do
|
7
38
|
before :all do
|
8
|
-
# This needs to point to a valid
|
39
|
+
# This needs to point to a valid persevere server
|
9
40
|
@adapter = DataMapper.setup(:default, { :adapter => 'persevere',
|
10
|
-
|
11
|
-
|
12
|
-
|
41
|
+
:host => 'localhost',
|
42
|
+
:port => '8080' }
|
43
|
+
)
|
44
|
+
|
45
|
+
@test_schema_hash = {
|
46
|
+
'id' => 'Vanilla',
|
47
|
+
'properties' => {
|
48
|
+
'cid' => {'type' => 'string' },
|
49
|
+
'parent' => { 'type' => 'string'},
|
50
|
+
'data' => { 'type' => 'string'}
|
51
|
+
}
|
52
|
+
}
|
13
53
|
end
|
14
54
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
55
|
+
it_should_behave_like 'An Adapter'
|
56
|
+
|
57
|
+
describe '#get_schema' do
|
58
|
+
it 'should return all of the schemas (in json) if no name is provided' do
|
59
|
+
@adapter.get_schema()
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should return the json schema of the class specified' do
|
63
|
+
@adapter.get_schema("Object")
|
64
|
+
end
|
21
65
|
|
22
|
-
|
23
|
-
|
66
|
+
it 'should return all of the schemas (in json) for a project if no name is provided' do
|
67
|
+
@adapter.get_schema(nil, "Class")
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should return all of the schemas (in json) if no name is provided' do
|
71
|
+
@adapter.get_schema("Object", "Class")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#put_schema' do
|
76
|
+
it 'should create the json schema for the hash' do
|
77
|
+
@adapter.put_schema(@test_schema_hash)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should create the json schema for the hash under the specified project' do
|
81
|
+
@adapter.put_schema(@test_schema_hash, "test")
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should create the json schema for the hash under the specified project' do
|
85
|
+
@test_schema_hash['id'] = 'test1/Vanilla'
|
86
|
+
@adapter.put_schema(@test_schema_hash)
|
87
|
+
end
|
24
88
|
end
|
25
|
-
|
26
|
-
it 'should return all of the schemas (in json) for a project if no name is provided' do
|
27
|
-
@adapter.get_schema(nil, "Class")
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should return all of the schemas (in json) if no name is provided' do
|
31
|
-
@adapter.get_schema("Object", "Class")
|
32
|
-
end
|
33
89
|
end
|
34
|
-
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require Pathname(__FILE__).dirname.expand_path.parent + 'lib/persevere'
|
3
|
+
|
4
|
+
describe Persevere do
|
5
|
+
#
|
6
|
+
# Create an object to interact with Persevere
|
7
|
+
#
|
8
|
+
before :all do
|
9
|
+
@p = Persevere.new('http://localhost:8080')
|
10
|
+
|
11
|
+
@blobObj = {
|
12
|
+
'id' => 'Yogo',
|
13
|
+
'properties' => {
|
14
|
+
'cid' => {'type' => 'string' },
|
15
|
+
'parent' => { 'type' => 'string'},
|
16
|
+
'data' => { 'type' => 'string'}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
@corruptObj = {
|
21
|
+
'id' => 'Corrupt',
|
22
|
+
'properties' => {
|
23
|
+
'id' => 1234,
|
24
|
+
'parent' => { 'type' => 'string'},
|
25
|
+
'data' => { 'type' => 'string'}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
@mockObj = {
|
30
|
+
'id' => 'Yogo',
|
31
|
+
'properties' => {
|
32
|
+
'cid' => {'type' => 'string' },
|
33
|
+
'parent' => { 'type' => 'string'},
|
34
|
+
'data' => { 'type' => 'string'}
|
35
|
+
},
|
36
|
+
'prototype' => {}
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Test POST to create a new class
|
42
|
+
#
|
43
|
+
describe '#post' do
|
44
|
+
it 'should create a new object in persevere' do
|
45
|
+
result = @p.create('/Class/', @blobObj)
|
46
|
+
result.code.should == "201"
|
47
|
+
JSON.parse(result.body).should == @mockObj
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should not allow posting with a bad object' do
|
51
|
+
result = @p.create('/Class/', @corruptObj)
|
52
|
+
result.code.should == "500"
|
53
|
+
result.body.should == "\"Can not modify queries\""
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should not allow posting to an existing object/id/path' do
|
57
|
+
result = @p.create('/Class/', @blobObj)
|
58
|
+
result.code.should == "201"
|
59
|
+
JSON.parse(result.body).should == @blobObj
|
60
|
+
# result.body.should == "\"Can not modify queries\""
|
61
|
+
# This shouldn't be a 201, it should say something mean.
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# Test GET to retrieve the list of classes from Persvr
|
67
|
+
#
|
68
|
+
describe '#get' do
|
69
|
+
it 'should retrieve the previously created object from persevere' do
|
70
|
+
result = @p.retrieve('/Class/Yogo')
|
71
|
+
result.code.should == "200"
|
72
|
+
JSON.parse(result.body).should == @blobObj
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should 404 on a non-existent object' do
|
76
|
+
result = @p.retrieve('/Class/NotThere')
|
77
|
+
result.code.should == "404"
|
78
|
+
result.message.should == "Not Found"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Test PUT to modify an existing class
|
84
|
+
#
|
85
|
+
describe '#put' do
|
86
|
+
it 'should modify the previously created object in persevere' do
|
87
|
+
@blobObj['properties']['tstAttribute'] = { 'type' => 'string' }
|
88
|
+
result = @p.update('/Class/Yogo', @blobObj)
|
89
|
+
result.code.should == "200"
|
90
|
+
JSON.parse(result.body).should == @blobObj
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should fail to modify a non-existent item' do
|
94
|
+
result = @p.update('/Class/NotThere', @blobObj)
|
95
|
+
result.code.should == "500"
|
96
|
+
result.body.should == "\"id does not match location\""
|
97
|
+
# This should be a 404 and not throw a persevere server exception
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Test DELETE to remove the previously created and modified class
|
103
|
+
#
|
104
|
+
describe '#delete' do
|
105
|
+
it 'should remove the previously created and modified object from persevere' do
|
106
|
+
result = @p.delete('/Class/Yogo')
|
107
|
+
result.code.should == "204"
|
108
|
+
@p.retrieve('/Class/Yogo').code.should == "404"
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should fail to delete a non-existent item' do
|
112
|
+
result = @p.delete('/Class/NotThere')
|
113
|
+
result.code.should == "204"
|
114
|
+
result.message.should == "No Content"
|
115
|
+
result.body.should be_nil
|
116
|
+
# This should be a 404 and not fail silently with a 204
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,28 +1,14 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
require 'rubygems'
|
1
|
+
# require 'pathname'
|
2
|
+
# require 'rubygems'
|
3
|
+
#require 'spec'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
:adapter => 'persevere',
|
11
|
-
:host => 'localhost',
|
12
|
-
:port => '8080',
|
13
|
-
:uri => 'http://localhost:8080'
|
14
|
-
})
|
5
|
+
# DataMapper.setup(:default, {
|
6
|
+
# :adapter => 'persevere',
|
7
|
+
# :host => 'localhost',
|
8
|
+
# :port => '8080',
|
9
|
+
# :uri => 'http://localhost:8080'
|
10
|
+
# })
|
15
11
|
|
16
12
|
#
|
17
13
|
# I need to make the Book class for Books to relate to
|
18
|
-
#
|
19
|
-
|
20
|
-
class Book
|
21
|
-
include DataMapper::Resource
|
22
|
-
|
23
|
-
# Persevere only does id's as strings.
|
24
|
-
property :id, String, :serial => true
|
25
|
-
property :author, String
|
26
|
-
property :created_at, DateTime
|
27
|
-
property :title, String
|
28
|
-
end
|
14
|
+
#
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-persevere-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan R. Judson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-01-
|
13
|
+
date: 2010-01-11 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -23,16 +23,6 @@ dependencies:
|
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: 0.10.1
|
25
25
|
version:
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: persevere
|
28
|
-
type: :runtime
|
29
|
-
version_requirement:
|
30
|
-
version_requirements: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: "1.1"
|
35
|
-
version:
|
36
26
|
- !ruby/object:Gem::Dependency
|
37
27
|
name: extlib
|
38
28
|
type: :runtime
|
@@ -61,10 +51,14 @@ files:
|
|
61
51
|
- README.txt
|
62
52
|
- Rakefile
|
63
53
|
- VERSION
|
64
|
-
-
|
54
|
+
- lib/persevere.rb
|
65
55
|
- lib/persevere_adapter.rb
|
66
|
-
-
|
56
|
+
- persevere/History.txt
|
57
|
+
- persevere/LICENSE.txt
|
58
|
+
- persevere/Manifest.txt
|
59
|
+
- persevere/README.txt
|
67
60
|
- spec/persevere_adapter_spec.rb
|
61
|
+
- spec/persevere_spec.rb
|
68
62
|
- spec/spec.opts
|
69
63
|
- spec/spec_helper.rb
|
70
64
|
- spec/unit/create_spec.rb
|
@@ -103,8 +97,8 @@ specification_version: 3
|
|
103
97
|
summary: A DataMapper Adapter for persevere
|
104
98
|
test_files:
|
105
99
|
- spec/persevere_adapter_spec.rb
|
100
|
+
- spec/persevere_spec.rb
|
106
101
|
- spec/spec_helper.rb
|
107
|
-
- spec/integration/persevere_adapter_spec.rb
|
108
102
|
- spec/unit/create_spec.rb
|
109
103
|
- spec/unit/delete_spec.rb
|
110
104
|
- spec/unit/read_spec.rb
|
@@ -1,73 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{dm-persevere-adapter}
|
8
|
-
s.version = "0.16.0"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Ivan R. Judson", "The Yogo Data Management Development Team"]
|
12
|
-
s.date = %q{2010-01-06}
|
13
|
-
s.description = %q{A DataMapper Adapter for persevere}
|
14
|
-
s.email = ["irjudson [a] gmail [d] com"]
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE.txt",
|
17
|
-
"README.txt"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".gitignore",
|
21
|
-
"History.txt",
|
22
|
-
"LICENSE.txt",
|
23
|
-
"Manifest.txt",
|
24
|
-
"README.txt",
|
25
|
-
"Rakefile",
|
26
|
-
"VERSION",
|
27
|
-
"dm-persevere-adapter.gemspec",
|
28
|
-
"lib/persevere_adapter.rb",
|
29
|
-
"spec/integration/persevere_adapter_spec.rb",
|
30
|
-
"spec/persevere_adapter_spec.rb",
|
31
|
-
"spec/spec.opts",
|
32
|
-
"spec/spec_helper.rb",
|
33
|
-
"spec/unit/create_spec.rb",
|
34
|
-
"spec/unit/delete_spec.rb",
|
35
|
-
"spec/unit/read_spec.rb",
|
36
|
-
"spec/unit/update_spec.rb",
|
37
|
-
"tasks/spec.rb"
|
38
|
-
]
|
39
|
-
s.homepage = %q{http://github.com/yogo/dm-persevere-adapter}
|
40
|
-
s.rdoc_options = ["--main", "README.txt"]
|
41
|
-
s.require_paths = ["lib"]
|
42
|
-
s.rubygems_version = %q{1.3.5}
|
43
|
-
s.summary = %q{A DataMapper Adapter for persevere}
|
44
|
-
s.test_files = [
|
45
|
-
"spec/persevere_adapter_spec.rb",
|
46
|
-
"spec/spec_helper.rb",
|
47
|
-
"spec/integration/persevere_adapter_spec.rb",
|
48
|
-
"spec/unit/create_spec.rb",
|
49
|
-
"spec/unit/delete_spec.rb",
|
50
|
-
"spec/unit/read_spec.rb",
|
51
|
-
"spec/unit/update_spec.rb"
|
52
|
-
]
|
53
|
-
|
54
|
-
if s.respond_to? :specification_version then
|
55
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
56
|
-
s.specification_version = 3
|
57
|
-
|
58
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
59
|
-
s.add_runtime_dependency(%q<dm-core>, [">= 0.10.1"])
|
60
|
-
s.add_runtime_dependency(%q<persevere>, [">= 1.1"])
|
61
|
-
s.add_runtime_dependency(%q<extlib>, [">= 0"])
|
62
|
-
else
|
63
|
-
s.add_dependency(%q<dm-core>, [">= 0.10.1"])
|
64
|
-
s.add_dependency(%q<persevere>, [">= 1.1"])
|
65
|
-
s.add_dependency(%q<extlib>, [">= 0"])
|
66
|
-
end
|
67
|
-
else
|
68
|
-
s.add_dependency(%q<dm-core>, [">= 0.10.1"])
|
69
|
-
s.add_dependency(%q<persevere>, [">= 1.1"])
|
70
|
-
s.add_dependency(%q<extlib>, [">= 0"])
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|