persevere 0.28.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
File without changes
data/Manifest.txt ADDED
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/persevere.rb
6
+ test/test_persevere.rb
data/README.txt CHANGED
@@ -1,89 +1,90 @@
1
- = dm-persevere-adapter
1
+ = ruby persevere client
2
2
 
3
- A DataMapper adapter for Persevere (http://www.persvr.org/)
3
+ * http://github.com/irjudson/persevere
4
4
 
5
- == Usage
5
+ == DESCRIPTION:
6
6
 
7
- DM Persevere Adapter is very simple and very similar to the REST
8
- Adapter, however it has two differences: 1) instead of XML it uses
9
- JSON, and 2) Persevere supports typing using JSON Schema. These
10
- differences make it valuable to have a separate DM adapter
11
- specifically for Persevere so it can leverage richer aspects of
12
- persevere.
7
+ This gem provides a simple ruby wrapper around the persevere JSON document data store available from http://www.persvr.org.
13
8
 
14
- The setup and resource mapping is identical to standard datamapper
15
- objects, as can be seen below.
9
+ == FEATURES/PROBLEMS:
16
10
 
17
- DataMapper.setup(:default, {
18
- :adapter => 'persevere',
19
- :host => 'localhost',
20
- :port => '8080'
21
- })
22
-
23
- # Or,
24
- # DataMapper.setup(:default, "persevere://localhost:8080")
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.
25
12
 
26
- class MyUser
27
- include DataMapper::Resource
13
+ == SYNOPSIS:
28
14
 
29
- property :id, Serial
30
- property :uuid, String
31
- property :name, String
32
- property :first_name, String
33
- property :last_name, String
34
- property :groupid, Integer
35
- property :userid, Integer
36
- property :username, String
37
- property :homedirectory, String
15
+ #!/usr/bin/env ruby
16
+ #
17
+ require 'persevere'
38
18
 
39
- end
19
+ #
20
+ # Create an object to interact with Persevere
21
+ #
22
+ p = Persevere.new('http://localhost:8080')
40
23
 
41
- To use with Rails, you can put this in your environment.rb:
42
- config.gem "dm-core"
43
- config.gem "data_objects"
44
- config.gem "dm-persevere-adapter", :lib => 'persevere_adapter'
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
45
32
 
46
- With a database.yml:
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
47
40
 
48
- development: &defaults
49
- :adapter: persevere
50
- :host: localhost
51
- :port: 8080
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
52
49
 
53
- test:
54
- <<: *defaults
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
55
57
 
56
- production:
57
- <<: *defaults
58
+ == REQUIREMENTS:
58
59
 
59
- == Code
60
+ * Persevere installed somewhere
61
+ * JSON gem
60
62
 
61
- MyUser.auto_migrate!
63
+ == INSTALL:
62
64
 
63
- # Create
64
- user = MyUser.new(:username => "dmtest", :uuid => UUID.random_create().to_s,
65
- :name => "DataMapper Test", :homedirectory => "/home/dmtest",
66
- :first_name => "DataMapperTest", :last_name => "User",
67
- :userid => 3, :groupid => 500)
68
- user.save
65
+ sudo gem install persevere
69
66
 
70
- # Retrieve
71
- user = MyUser.first(:netid => 'dmtest')
72
- puts user
67
+ == LICENSE:
73
68
 
74
- # Modify
75
- if user.update_attributes(:name => 'DM Test')
76
- puts user
77
- else
78
- puts "Failed to update attributes."
79
- end
69
+ (The MIT License)
80
70
 
81
- # Delete
82
- result = user.destroy
83
- puts "Result: #{result}"
71
+ Copyright (c) 2009 Montana State University
84
72
 
85
- == To Do:
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:
86
80
 
87
- - Cleanup Documentation
88
- - Add more negative / failure tests
81
+ The above copyright notice and this permission notice shall be
82
+ included in all copies or substantial portions of the Software.
89
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.
data/Rakefile CHANGED
@@ -1,38 +1,12 @@
1
+ # -*- ruby -*-
2
+
1
3
  require 'rubygems'
2
- require 'pathname'
4
+ require 'hoe'
5
+ require './lib/persevere.rb'
3
6
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gemspec|
7
- gemspec.name = %q{dm-persevere-adapter}
8
- gemspec.summary = %q{A DataMapper Adapter for persevere}
9
- gemspec.description = %q{A DataMapper Adapter for persevere}
10
- gemspec.email = ["irjudson [a] gmail [d] com"]
11
- gemspec.homepage = %q{http://github.com/yogo/dm-persevere-adapter}
12
- gemspec.authors = ["Ivan R. Judson", "The Yogo Data Management Development Team" ]
13
- gemspec.rdoc_options = ["--main", "README.txt"]
14
- gemspec.add_dependency(%q<dm-core>, [">= 0.10.1"])
15
- gemspec.add_dependency(%q<extlib>)
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
29
- rescue LoadError
30
- puts "Jeweler not available. Install it with: gem install jeweler"
7
+ Hoe.spec('persevere') do |p|
8
+ # p.rubyforge_name = 'perseverex' # if different than lowercase project name
9
+ p.developer('Ivan R. Judson', 'irjudson@gmail.com')
31
10
  end
32
11
 
33
- ROOT = Pathname(__FILE__).dirname.expand_path
34
- JRUBY = RUBY_PLATFORM =~ /java/
35
- WINDOWS = Gem.win_platform?
36
- SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
37
-
38
- Pathname.glob(ROOT.join('tasks/**/*.rb').to_s).each { |f| require f }
12
+ # vim: syntax=Ruby
data/lib/persevere.rb CHANGED
@@ -13,23 +13,6 @@ require 'uri'
13
13
  require 'rubygems'
14
14
  require 'json'
15
15
 
16
- # Ugly Monkey patching because Persever uses non-standard content-range headers.
17
- module Net
18
- module HTTPHeader
19
- alias old_content_range content_range
20
- # Returns a Range object which represents Content-Range: header field.
21
- # This indicates, for a partial entity body, where this fragment
22
- # fits inside the full entity body, as range of byte offsets.
23
- def content_range
24
- return nil unless @header['content-range']
25
- m = %r<bytes\s+(\d+)-(\d+)/(\d+|\*)>i.match(self['Content-Range']) or
26
- return nil
27
- m[1].to_i .. m[2].to_i + 1
28
- end
29
-
30
- end
31
- end
32
-
33
16
  class PersevereResult
34
17
  attr_reader :location, :code, :message, :body
35
18
 
@@ -51,9 +34,8 @@ class PersevereResult
51
34
  end
52
35
 
53
36
  class Persevere
54
- HEADERS = { 'Accept' => 'application/json',
55
- 'Content-Type' => 'application/json'
56
- } unless defined?(HEADERS)
37
+ VERSION = '1.1'
38
+ ACCEPT = { 'Accept' => 'application/json' }
57
39
 
58
40
  attr_accessor :server_url, :pservr
59
41
 
@@ -65,57 +47,25 @@ class Persevere
65
47
  end
66
48
 
67
49
  # Pass in a resource hash
68
- def create(path, resource, headers = {})
69
- json_blob = resource.reject{|key,value| value.nil? }.to_json
70
- response = nil
71
- while response.nil?
72
- begin
73
- response = @persevere.send_request('POST', path, json_blob, HEADERS.merge(headers))
74
- rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
75
- Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
76
- puts "Persevere Create Failed: #{e}, Trying again."
77
- end
78
- end
50
+ def create(path, resource)
51
+ json_blob = resource.to_json
52
+ response = @persevere.send_request('POST', path, json_blob, ACCEPT)
79
53
  return PersevereResult.make(response)
80
54
  end
81
55
 
82
- def retrieve(path, headers = {})
83
- response = nil
84
- while response.nil?
85
- begin
86
- response = @persevere.send_request('GET', path, nil, HEADERS.merge(headers))
87
- rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
88
- Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
89
- puts "Persevere Retrieve Failed: #{e}, Trying again."
90
- end
91
- end
56
+ def retrieve(path)
57
+ response = @persevere.send_request('GET', path, nil, ACCEPT)
92
58
  return PersevereResult.make(response)
93
59
  end
94
60
 
95
- def update(path, resource, headers = {})
61
+ def update(path, resource)
96
62
  json_blob = resource.to_json
97
- response = nil
98
- while response.nil?
99
- begin
100
- response = @persevere.send_request('PUT', path, json_blob, HEADERS.merge(headers))
101
- rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
102
- Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
103
- puts "Persevere Create Failed: #{e}, Trying again."
104
- end
105
- end
63
+ response = @persevere.send_request('PUT', path, json_blob, ACCEPT)
106
64
  return PersevereResult.make(response)
107
65
  end
108
66
 
109
- def delete(path, headers = {})
110
- response = nil
111
- while response.nil?
112
- begin
113
- response = @persevere.send_request('DELETE', path, nil, HEADERS.merge(headers))
114
- rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
115
- Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
116
- puts "Persevere Create Failed: #{e}, Trying again."
117
- end
118
- end
67
+ def delete(path)
68
+ response = @persevere.send_request('DELETE', path, nil, ACCEPT)
119
69
  return PersevereResult.make(response)
120
70
  end
121
71
  end # class Persevere
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ require 'rubygems'
4
+ require 'persevere'
5
+
6
+ #
7
+ # Create an object to interact with Persevere
8
+ #
9
+ p = Persevere.new('http://localhost:8080')
10
+
11
+ #
12
+ # Test POST to create a new class
13
+ #
14
+ print "\nTesting POST..."
15
+ blobObj = {
16
+ 'id' => 'Blob',
17
+ 'extends' => { '$ref' => 'Object' },
18
+ 'properties' => {
19
+ 'id' => { },
20
+ 'cid' => { },
21
+ 'parent' => { },
22
+ 'data' => { }
23
+ }
24
+ }
25
+ result = p.create('/Class/', blobObj)
26
+ print "Response:\n"
27
+ puts result.inspect
28
+
29
+ #
30
+ # Test GET to retrieve the list of classes from Persvr
31
+ #
32
+ print "\nTesting GET..."
33
+ result = p.retrieve('/Class')
34
+ print "Response:\n"
35
+ puts result.inspect
36
+
37
+ #
38
+ # Test PUT to modify an existing class
39
+ #
40
+ print "\nTesting PUT..."
41
+ blobObj['tstAttribute'] = 42
42
+ result = p.update('/Class/Blob', blobObj)
43
+ print "Response:\n"
44
+ puts result.inspect
45
+
46
+ #
47
+ # Test DELETE to remove the previously created and modified class
48
+ #
49
+ #print "\nTesting DELETE..."
50
+ #result = p.delete('/Class/Blob')
51
+ #print "Response:\n"
52
+ #puts result
metadata CHANGED
@@ -1,44 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: persevere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.0
4
+ version: "1.1"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan R. Judson
8
- - The Yogo Data Management Development Team
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2010-01-25 00:00:00 -07:00
12
+ date: 2009-10-15 00:00:00 -06:00
14
13
  default_executable:
15
- dependencies: []
16
-
17
- description: A ruby wrapper for persevere
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.3
24
+ version:
25
+ description: This gem provides a simple ruby wrapper around the persevere JSON document data store available from http://www.persvr.org.
18
26
  email:
19
- - irjudson [a] gmail [d] com
27
+ - irjudson@gmail.com
20
28
  executables: []
21
29
 
22
30
  extensions: []
23
31
 
24
32
  extra_rdoc_files:
25
- - LICENSE.txt
33
+ - History.txt
34
+ - Manifest.txt
26
35
  - README.txt
27
36
  files:
28
- - LICENSE.txt
37
+ - History.txt
38
+ - Manifest.txt
39
+ - README.txt
29
40
  - Rakefile
30
41
  - lib/persevere.rb
31
- - persevere/History.txt
32
- - persevere/README.txt
33
- - README.txt
42
+ - test/test_persevere.rb
34
43
  has_rdoc: true
35
- homepage: http://github.com/yogo/persevere
44
+ homepage: http://github.com/irjudson/persevere
36
45
  licenses: []
37
46
 
38
47
  post_install_message:
39
48
  rdoc_options:
40
49
  - --main
41
- - persevere/README.txt
50
+ - README.txt
42
51
  require_paths:
43
52
  - lib
44
53
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -55,12 +64,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
64
  version:
56
65
  requirements: []
57
66
 
58
- rubyforge_project:
67
+ rubyforge_project: persevere
59
68
  rubygems_version: 1.3.5
60
69
  signing_key:
61
70
  specification_version: 3
62
- summary: A ruby wrapper for persevere
71
+ summary: This gem provides a simple ruby wrapper around the persevere JSON document data store available from http://www.persvr.org.
63
72
  test_files:
64
- - spec/persevere_spec.rb
65
- - spec/spec.opts
66
- - spec/spec_helper.rb
73
+ - test/test_persevere.rb
data/LICENSE.txt DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009-2010 Montana State University
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/persevere/README.txt DELETED
@@ -1,90 +0,0 @@
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,201 +0,0 @@
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', 'optional' => true },
15
- 'parent' => { 'type' => 'string', 'optional' => true},
16
- 'data' => { 'type' => 'string', 'optional' => true}
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', 'optional' => true },
33
- 'parent' => { 'type' => 'string', 'optional' => true},
34
- 'data' => { 'type' => 'string', 'optional' => true}
35
- },
36
- 'prototype' => {}
37
- }
38
-
39
- @object = {
40
- 'cid' => '123',
41
- 'parent' => 'none',
42
- 'data' => 'A Chunk Of Data'
43
- }
44
-
45
- end
46
-
47
-
48
- # Test POST to create a new class
49
-
50
- describe '#post' do
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
150
- end
151
-
152
- it "should only retrieve all objects" do
153
- result = @p.retrieve('/Yogo/')
154
- result.code.should == "200"
155
- JSON.parse(result.body).length.should == 100
156
- end
157
-
158
- it "should retrieve the first objects" do
159
- result = @p.retrieve('/Yogo/1')
160
- result.code.should == "200"
161
- JSON.parse(result.body)['id'].should == '1'
162
- end
163
-
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
168
- end
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'
186
- end
187
-
188
- it "should return objects with id's 11 - 15" do
189
- result = @p.retrieve('/Yogo/', {'Range' => 'items=10-14'})
190
- result.code.should == '206'
191
- json = JSON.parse(result.body)
192
- json.length.should == 5
193
- json[0]['id'].should == '11'
194
- json[-1]['id'].should == '15'
195
- end
196
-
197
- after(:all) do
198
- @p.delete('/Class/Yogo')
199
- end
200
- end
201
- end
data/spec/spec.opts DELETED
@@ -1 +0,0 @@
1
- --colour
data/spec/spec_helper.rb DELETED
@@ -1,15 +0,0 @@
1
- require 'pathname'
2
- require 'rubygems'
3
- require 'addressable/uri'
4
- require 'spec'
5
-
6
- require 'dm-core'
7
-
8
- def path_to(gem_name, version=nil)
9
- version = version ? Gem::Requirement.create(version) : Gem::Requirement.default
10
- specs = Gem.source_index.find_name(gem_name, version)
11
- paths = specs.map do |spec|
12
- spec_path = spec.loaded_from
13
- expanded_path = File.join(File.dirname(spec_path), '..', 'gems', "#{spec.name}-#{spec.version}")
14
- end
15
- end