dm-persevere-adapter 0.13.0 → 0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +0 -1
- data/Rakefile +30 -21
- data/lib/persevere_adapter.rb +7 -34
- data/tasks/install.rb +13 -0
- metadata +71 -74
- data/.gitignore +0 -3
- data/VERSION +0 -1
- data/dm-persevere-adapter.gemspec +0 -73
- data/spec/persevere_adapter_spec.rb +0 -34
- data/spec/unit/create_spec.rb +0 -22
- data/spec/unit/delete_spec.rb +0 -23
- data/spec/unit/read_spec.rb +0 -102
- data/spec/unit/update_spec.rb +0 -37
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -1,29 +1,38 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'pathname'
|
3
|
-
|
4
|
-
|
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<persevere>, [">= 1.1"])
|
16
|
-
gemspec.add_dependency(%q<extlib>)
|
17
|
-
end
|
18
|
-
rescue LoadError
|
19
|
-
puts "Jeweler not available. Install it with: gem install jeweler"
|
20
|
-
end
|
2
|
+
require 'rubygems'
|
3
|
+
require 'hoe'
|
21
4
|
|
22
5
|
ROOT = Pathname(__FILE__).dirname.expand_path
|
23
6
|
JRUBY = RUBY_PLATFORM =~ /java/
|
24
7
|
WINDOWS = Gem.win_platform?
|
25
8
|
SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
|
26
9
|
|
27
|
-
require ROOT + 'lib/persevere_adapter'
|
10
|
+
#require ROOT + 'lib/persevere_adapter/version'
|
11
|
+
|
12
|
+
# define some constants to help with task files
|
13
|
+
GEM_NAME = 'dm-persevere-adapter'
|
14
|
+
#GEM_VERSION = DataMapper::PersevereAdapter::VERSION
|
15
|
+
GEM_VERSION = "0.14"
|
16
|
+
|
17
|
+
Hoe.spec(GEM_NAME) do |p|
|
18
|
+
p.developer('Ivan R. Judson', 'irjudson [a] gmail [d] com')
|
19
|
+
|
20
|
+
p.description = 'A DataMapper Adapter for persevere'
|
21
|
+
p.summary = 'A DataMapper Adapter for persevere'
|
22
|
+
p.url = 'http://github.com/USERNAME/dm-persevere-adapter'
|
23
|
+
|
24
|
+
p.clean_globs |= %w[ log pkg coverage ]
|
25
|
+
p.spec_extras = {
|
26
|
+
:has_rdoc => true,
|
27
|
+
:extra_rdoc_files => %w[ README.txt LICENSE.txt History.txt ]
|
28
|
+
}
|
29
|
+
|
30
|
+
p.extra_deps = [
|
31
|
+
['dm-core', "~> 0.9.10"],
|
32
|
+
['extlib', "~> 0.9.10"],
|
33
|
+
['persevere', "~> 1.0"]
|
34
|
+
]
|
35
|
+
|
36
|
+
end
|
28
37
|
|
29
|
-
Pathname.glob(ROOT.join('tasks/**/*.rb').to_s).each { |f| require f }
|
38
|
+
Pathname.glob(ROOT.join('tasks/**/*.rb').to_s).each { |f| require f }
|
data/lib/persevere_adapter.rb
CHANGED
@@ -7,6 +7,7 @@ require 'persevere'
|
|
7
7
|
module DataMapper
|
8
8
|
module Adapters
|
9
9
|
class PersevereAdapter < AbstractAdapter
|
10
|
+
VERSION='0.14'
|
10
11
|
##
|
11
12
|
# Used by DataMapper to put records into a data-store: "INSERT"
|
12
13
|
# in SQL-speak. It takes an array of the resources (model
|
@@ -153,7 +154,7 @@ module DataMapper
|
|
153
154
|
resources = Array.new
|
154
155
|
json_query = make_json_query(query)
|
155
156
|
|
156
|
-
tblname = Extlib::Inflection.classify(query.model)
|
157
|
+
tblname = Extlib::Inflection.classify(query.model).pluralize
|
157
158
|
path = "/#{tblname}/#{json_query}"
|
158
159
|
|
159
160
|
response = @persevere.retrieve(path)
|
@@ -171,6 +172,8 @@ module DataMapper
|
|
171
172
|
end
|
172
173
|
|
173
174
|
resources = query.model.load(results, query)
|
175
|
+
else
|
176
|
+
return false
|
174
177
|
end
|
175
178
|
|
176
179
|
query.filter_records(resources)
|
@@ -212,32 +215,6 @@ module DataMapper
|
|
212
215
|
return deleted
|
213
216
|
end
|
214
217
|
|
215
|
-
##
|
216
|
-
#
|
217
|
-
# Other methods for the Yogo Data Management Toolkit
|
218
|
-
#
|
219
|
-
##
|
220
|
-
def get_schema(name = nil, project = nil)
|
221
|
-
path = nil
|
222
|
-
if name.nil? & project.nil?
|
223
|
-
path = "/Class/"
|
224
|
-
elsif project.nil?
|
225
|
-
path = "/Class/#{name}"
|
226
|
-
elsif name.nil?
|
227
|
-
path = "/Class/#{project}/"
|
228
|
-
else
|
229
|
-
path = "/Class/#{project}/#{name}"
|
230
|
-
end
|
231
|
-
|
232
|
-
response = @persevere.retrieve(path)
|
233
|
-
|
234
|
-
if response.code == "200"
|
235
|
-
return JSON.parse(response.body)
|
236
|
-
else
|
237
|
-
return nil
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
218
|
private
|
242
219
|
|
243
220
|
##
|
@@ -277,16 +254,12 @@ module DataMapper
|
|
277
254
|
@classes = []
|
278
255
|
@persevere = nil
|
279
256
|
@prepped = false
|
280
|
-
|
281
|
-
connect
|
282
257
|
end
|
283
258
|
|
284
259
|
def connect
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
prep_persvr unless @prepped
|
289
|
-
end
|
260
|
+
uri = URI::HTTP.build(@options).to_s
|
261
|
+
@persevere = Persevere.new(uri)
|
262
|
+
prep_persvr unless @prepped
|
290
263
|
end
|
291
264
|
|
292
265
|
def prep_persvr
|
data/tasks/install.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
def sudo_gem(cmd)
|
2
|
+
sh "#{SUDO} #{RUBY} -S gem #{cmd}", :verbose => false
|
3
|
+
end
|
4
|
+
|
5
|
+
desc "Install #{GEM_NAME} #{GEM_VERSION}"
|
6
|
+
task :install => [ :package ] do
|
7
|
+
sudo_gem "install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Uninstall #{GEM_NAME} #{GEM_VERSION}"
|
11
|
+
task :uninstall => [ :clobber ] do
|
12
|
+
sudo_gem "uninstall #{GEM_NAME} -v#{GEM_VERSION} -Ix"
|
13
|
+
end
|
metadata
CHANGED
@@ -1,111 +1,108 @@
|
|
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.14"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
|
8
|
-
- The Yogo Data Management Development Team
|
7
|
+
- Ivan R. Judson
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
11
|
|
13
|
-
date:
|
12
|
+
date: 2009-10-15 00:00:00 -06:00
|
14
13
|
default_executable:
|
15
14
|
dependencies:
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: dm-core
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.9.10
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: extlib
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.10
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: persevere
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "1.0"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: hoe
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.3.3
|
54
|
+
version:
|
46
55
|
description: A DataMapper Adapter for persevere
|
47
56
|
email:
|
48
|
-
|
57
|
+
- irjudson [a] gmail [d] com
|
49
58
|
executables: []
|
50
59
|
|
51
60
|
extensions: []
|
52
61
|
|
53
62
|
extra_rdoc_files:
|
54
|
-
|
55
|
-
|
63
|
+
- README.txt
|
64
|
+
- LICENSE.txt
|
65
|
+
- History.txt
|
56
66
|
files:
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
- spec/spec.opts
|
69
|
-
- spec/spec_helper.rb
|
70
|
-
- spec/unit/create_spec.rb
|
71
|
-
- spec/unit/delete_spec.rb
|
72
|
-
- spec/unit/read_spec.rb
|
73
|
-
- spec/unit/update_spec.rb
|
74
|
-
- tasks/spec.rb
|
67
|
+
- History.txt
|
68
|
+
- LICENSE.txt
|
69
|
+
- Manifest.txt
|
70
|
+
- README.txt
|
71
|
+
- Rakefile
|
72
|
+
- lib/persevere_adapter.rb
|
73
|
+
- spec/integration/persevere_adapter_spec.rb
|
74
|
+
- spec/spec.opts
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
- tasks/install.rb
|
77
|
+
- tasks/spec.rb
|
75
78
|
has_rdoc: true
|
76
|
-
homepage: http://github.com/
|
79
|
+
homepage: http://github.com/USERNAME/dm-persevere-adapter
|
77
80
|
licenses: []
|
78
81
|
|
79
82
|
post_install_message:
|
80
83
|
rdoc_options:
|
81
|
-
|
82
|
-
|
84
|
+
- --main
|
85
|
+
- README.txt
|
83
86
|
require_paths:
|
84
|
-
|
87
|
+
- lib
|
85
88
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
89
|
requirements:
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: "0"
|
90
93
|
version:
|
91
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
95
|
requirements:
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: "0"
|
96
99
|
version:
|
97
100
|
requirements: []
|
98
101
|
|
99
|
-
rubyforge_project:
|
102
|
+
rubyforge_project: dm-persevere-adapter
|
100
103
|
rubygems_version: 1.3.5
|
101
104
|
signing_key:
|
102
105
|
specification_version: 3
|
103
106
|
summary: A DataMapper Adapter for persevere
|
104
|
-
test_files:
|
105
|
-
|
106
|
-
- spec/spec_helper.rb
|
107
|
-
- spec/integration/persevere_adapter_spec.rb
|
108
|
-
- spec/unit/create_spec.rb
|
109
|
-
- spec/unit/delete_spec.rb
|
110
|
-
- spec/unit/read_spec.rb
|
111
|
-
- spec/unit/update_spec.rb
|
107
|
+
test_files: []
|
108
|
+
|
data/.gitignore
DELETED
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.13.0
|
@@ -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.13.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
|
-
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
require DataMapper.root / 'lib' / 'dm-core' / 'spec' / 'adapter_shared_spec'
|
5
|
-
|
6
|
-
describe DataMapper::Adapters::PersevereAdapter do
|
7
|
-
before :all do
|
8
|
-
# This needs to point to a valid ldap server
|
9
|
-
@adapter = DataMapper.setup(:default, { :adapter => 'persevere',
|
10
|
-
:host => 'localhost',
|
11
|
-
:port => '8080' }
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
it_should_behave_like 'An Adapter'
|
16
|
-
|
17
|
-
describe '#schema' do
|
18
|
-
it 'should return all of the schemas (in json) if no name is provided' do
|
19
|
-
@adapter.get_schema()
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should return the json schema of the class specified' do
|
23
|
-
@adapter.get_schema("Object")
|
24
|
-
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
|
-
end
|
34
|
-
end
|
data/spec/unit/create_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
4
|
-
|
5
|
-
describe 'A Persevere adapter' do
|
6
|
-
|
7
|
-
before do
|
8
|
-
@adapter = DataMapper::Repository.adapters[:default]
|
9
|
-
end
|
10
|
-
|
11
|
-
describe 'when saving a resource' do
|
12
|
-
|
13
|
-
before do
|
14
|
-
@book = Book.new(:title => 'Hello, World!', :author => 'Anonymous')
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should call the adapter create method' do
|
18
|
-
#@adapter.should_receive(:create).with([@book])
|
19
|
-
@book.save
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/spec/unit/delete_spec.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# $LOAD_PATH << File.dirname(__FILE__)
|
2
|
-
#
|
3
|
-
# require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
4
|
-
#
|
5
|
-
# describe 'A Persevere adapter' do
|
6
|
-
#
|
7
|
-
# before do
|
8
|
-
# @adapter = DataMapper::Repository.adapters[:default]
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# describe 'when deleting an existing resource' do
|
12
|
-
# before do
|
13
|
-
# @book = Book.new(:title => 'Hello, World!', :author => 'Anonymous')
|
14
|
-
# @book.stub!(:new_record?).and_return(false)
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# it 'should do an HTTP DELETE' do
|
18
|
-
# @adapter.should_receive(:delete)
|
19
|
-
# @book.destroy
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
# end
|
23
|
-
# end
|
data/spec/unit/read_spec.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
4
|
-
|
5
|
-
describe 'A Persevere adapter' do
|
6
|
-
|
7
|
-
before do
|
8
|
-
@adapter = DataMapper::Repository.adapters[:default]
|
9
|
-
end
|
10
|
-
|
11
|
-
# describe 'when getting one resource' do
|
12
|
-
#
|
13
|
-
# describe 'if the resource exists' do
|
14
|
-
#
|
15
|
-
# before do
|
16
|
-
# book_xml = <<-BOOK
|
17
|
-
# <?xml version='1.0' encoding='UTF-8'?>
|
18
|
-
# <book>
|
19
|
-
# <author>Stephen King</author>
|
20
|
-
# <created-at type='datetime'>2008-06-08T17:03:07Z</created-at>
|
21
|
-
# <id type='integer'>1</id>
|
22
|
-
# <title>The Shining</title>
|
23
|
-
# <updated-at type='datetime'>2008-06-08T17:03:07Z</updated-at>
|
24
|
-
# </book>
|
25
|
-
# BOOK
|
26
|
-
# @id = 1
|
27
|
-
# @response = mock(Net::HTTPResponse)
|
28
|
-
# @response.stub!(:body).and_return(book_xml)
|
29
|
-
# @adapter.stub!(:http_get).and_return(@response)
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# it 'should return the resource' do
|
33
|
-
# book = Book.get(@id)
|
34
|
-
# book.should_not be_nil
|
35
|
-
# book.id.should be_an_instance_of(Fixnum)
|
36
|
-
# book.id.should == 1
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# it 'should do an HTTP GET' do
|
40
|
-
# @adapter.should_receive(:http_get).with('/books/1.xml').and_return(@response)
|
41
|
-
# Book.get(@id)
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
# it "it be equal to itself" do
|
45
|
-
# Book.get(@id).should == Book.get(@id)
|
46
|
-
# end
|
47
|
-
# end
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# describe 'if the resource does not exist' do
|
51
|
-
# it 'should return nil' do
|
52
|
-
# @id = 1
|
53
|
-
# @response = mock(Net::HTTPNotFound)
|
54
|
-
# @response.stub!(:content_type).and_return('text/html')
|
55
|
-
# @response.stub!(:body).and_return('<html></html>')
|
56
|
-
# @adapter.stub!(:http_get).and_return(@response)
|
57
|
-
# id = 4200
|
58
|
-
# Book.get(id).should be_nil
|
59
|
-
# end
|
60
|
-
# end
|
61
|
-
# end
|
62
|
-
#
|
63
|
-
# describe 'when getting all resource of a particular type' do
|
64
|
-
# before do
|
65
|
-
# books_xml = <<-BOOK
|
66
|
-
# <?xml version='1.0' encoding='UTF-8'?>
|
67
|
-
# <books type='array'>
|
68
|
-
# <book>
|
69
|
-
# <author>Ursula K LeGuin</author>
|
70
|
-
# <created-at type='datetime'>2008-06-08T17:02:28Z</created-at>
|
71
|
-
# <id type='integer'>1</id>
|
72
|
-
# <title>The Dispossed</title>
|
73
|
-
# <updated-at type='datetime'>2008-06-08T17:02:28Z</updated-at>
|
74
|
-
# </book>
|
75
|
-
# <book>
|
76
|
-
# <author>Stephen King</author>
|
77
|
-
# <created-at type='datetime'>2008-06-08T17:03:07Z</created-at>
|
78
|
-
# <id type='integer'>2</id>
|
79
|
-
# <title>The Shining</title>
|
80
|
-
# <updated-at type='datetime'>2008-06-08T17:03:07Z</updated-at>
|
81
|
-
# </book>
|
82
|
-
# </books>
|
83
|
-
# BOOK
|
84
|
-
# @response = mock(Net::HTTPResponse)
|
85
|
-
# @response.stub!(:body).and_return(books_xml)
|
86
|
-
# @adapter.stub!(:http_get).and_return(@response)
|
87
|
-
# end
|
88
|
-
#
|
89
|
-
# it 'should get a non-empty list' do
|
90
|
-
# Book.all.should_not be_empty
|
91
|
-
# end
|
92
|
-
#
|
93
|
-
# it 'should receive one Resource for each entity in the XML' do
|
94
|
-
# Book.all.size.should == 2
|
95
|
-
# end
|
96
|
-
#
|
97
|
-
# it 'should do an HTTP GET' do
|
98
|
-
# @adapter.should_receive(:http_get).and_return(@response)
|
99
|
-
# Book.first
|
100
|
-
# end
|
101
|
-
# end
|
102
|
-
end
|
data/spec/unit/update_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# $LOAD_PATH << File.dirname(__FILE__)
|
2
|
-
#
|
3
|
-
# require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
4
|
-
#
|
5
|
-
# describe 'A Persevere adapter' do
|
6
|
-
#
|
7
|
-
# describe 'when updating an existing resource' do
|
8
|
-
# # before do
|
9
|
-
# # @books_xml = <<-XML
|
10
|
-
# # <book>
|
11
|
-
# # <id type='integer'>42</id>
|
12
|
-
# # <title>Starship Troopers</title>
|
13
|
-
# # <author>Robert Heinlein</author>
|
14
|
-
# # <created-at type='datetime'>2008-06-08T17:02:28Z</created-at>
|
15
|
-
# # </book>
|
16
|
-
# # XML
|
17
|
-
# # repository do |repo|
|
18
|
-
# # @repository = repo
|
19
|
-
# # @book = Book.new(:id => 42,
|
20
|
-
# # :title => 'Starship Troopers',
|
21
|
-
# # :author => 'Robert Heinlein',
|
22
|
-
# # :created_at => DateTime.parse('2008-06-08T17:02:28Z'))
|
23
|
-
# # @book.instance_eval { @new_record = false }
|
24
|
-
# # @repository.identity_map(Book)[@book.key] = @book
|
25
|
-
# # @book.title = "Mary Had a Little Lamb"
|
26
|
-
# # end
|
27
|
-
# # end
|
28
|
-
# #
|
29
|
-
# # it 'should do an HTTP PUT' do
|
30
|
-
# # adapter = @repository.adapter #DataMapper::Repository.adapters[:default]
|
31
|
-
# # adapter.should_receive(:http_put).with('/books/42.xml', @book.to_xml)
|
32
|
-
# # @repository.scope do
|
33
|
-
# # @book.save
|
34
|
-
# # end
|
35
|
-
# # end
|
36
|
-
# end
|
37
|
-
# end
|