dm-rest-adapter 0.9.10 → 0.9.11
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -1
- data/Manifest.txt +9 -87
- data/README.markdown +47 -0
- data/README.txt +44 -0
- data/Rakefile +5 -5
- data/config/database.rb.example +8 -0
- data/dm-rest-adapter.gemspec +34 -0
- data/lib/rest_adapter.rb +10 -246
- data/lib/rest_adapter/adapter.rb +291 -0
- data/lib/rest_adapter/connection.rb +76 -0
- data/lib/rest_adapter/exceptions.rb +66 -0
- data/lib/rest_adapter/formats.rb +16 -0
- data/lib/rest_adapter/version.rb +2 -4
- data/spec/connection_spec.rb +130 -0
- data/spec/crud_spec.rb +250 -0
- data/spec/spec_helper.rb +1 -6
- data/tasks/spec.rb +1 -1
- metadata +16 -94
- data/fixtures/book_service/README +0 -256
- data/fixtures/book_service/Rakefile +0 -10
- data/fixtures/book_service/app/controllers/application.rb +0 -15
- data/fixtures/book_service/app/controllers/books_controller.rb +0 -85
- data/fixtures/book_service/app/controllers/shelves_controller.rb +0 -89
- data/fixtures/book_service/app/helpers/application_helper.rb +0 -3
- data/fixtures/book_service/app/helpers/books_helper.rb +0 -2
- data/fixtures/book_service/app/helpers/shelf_helper.rb +0 -2
- data/fixtures/book_service/app/models/book.rb +0 -6
- data/fixtures/book_service/app/models/shelf.rb +0 -5
- data/fixtures/book_service/app/views/books/edit.html.erb +0 -20
- data/fixtures/book_service/app/views/books/index.html.erb +0 -22
- data/fixtures/book_service/app/views/books/new.html.erb +0 -19
- data/fixtures/book_service/app/views/books/show.html.erb +0 -13
- data/fixtures/book_service/app/views/layouts/books.html.erb +0 -17
- data/fixtures/book_service/app/views/shelves/edit.html.erb +0 -16
- data/fixtures/book_service/app/views/shelves/index.html.erb +0 -20
- data/fixtures/book_service/app/views/shelves/new.html.erb +0 -15
- data/fixtures/book_service/app/views/shelves/show.html.erb +0 -7
- data/fixtures/book_service/config/boot.rb +0 -109
- data/fixtures/book_service/config/database.yml +0 -19
- data/fixtures/book_service/config/environment.rb +0 -67
- data/fixtures/book_service/config/environments/development.rb +0 -17
- data/fixtures/book_service/config/environments/production.rb +0 -22
- data/fixtures/book_service/config/environments/test.rb +0 -22
- data/fixtures/book_service/config/initializers/inflections.rb +0 -10
- data/fixtures/book_service/config/initializers/mime_types.rb +0 -5
- data/fixtures/book_service/config/initializers/new_rails_defaults.rb +0 -15
- data/fixtures/book_service/config/routes.rb +0 -44
- data/fixtures/book_service/db/development.sqlite3 +0 -0
- data/fixtures/book_service/db/migrate/20080608165526_create_books.rb +0 -15
- data/fixtures/book_service/db/migrate/20080621171551_create_shelves.rb +0 -13
- data/fixtures/book_service/db/migrate/20080629143033_create_fake_books_and_shelves.rb +0 -20
- data/fixtures/book_service/db/schema.rb +0 -28
- data/fixtures/book_service/public/404.html +0 -30
- data/fixtures/book_service/public/422.html +0 -30
- data/fixtures/book_service/public/500.html +0 -30
- data/fixtures/book_service/public/dispatch.cgi +0 -10
- data/fixtures/book_service/public/dispatch.fcgi +0 -24
- data/fixtures/book_service/public/dispatch.rb +0 -10
- data/fixtures/book_service/public/favicon.ico +0 -0
- data/fixtures/book_service/public/images/rails.png +0 -0
- data/fixtures/book_service/public/index.html +0 -274
- data/fixtures/book_service/public/javascripts/application.js +0 -2
- data/fixtures/book_service/public/javascripts/controls.js +0 -963
- data/fixtures/book_service/public/javascripts/dragdrop.js +0 -972
- data/fixtures/book_service/public/javascripts/effects.js +0 -1120
- data/fixtures/book_service/public/javascripts/prototype.js +0 -4225
- data/fixtures/book_service/public/robots.txt +0 -5
- data/fixtures/book_service/public/stylesheets/scaffold.css +0 -53
- data/fixtures/book_service/script/about +0 -3
- data/fixtures/book_service/script/console +0 -3
- data/fixtures/book_service/script/dbconsole +0 -3
- data/fixtures/book_service/script/destroy +0 -3
- data/fixtures/book_service/script/generate +0 -3
- data/fixtures/book_service/script/performance/benchmarker +0 -3
- data/fixtures/book_service/script/performance/profiler +0 -3
- data/fixtures/book_service/script/performance/request +0 -3
- data/fixtures/book_service/script/plugin +0 -3
- data/fixtures/book_service/script/process/inspector +0 -3
- data/fixtures/book_service/script/process/reaper +0 -3
- data/fixtures/book_service/script/process/spawner +0 -3
- data/fixtures/book_service/script/runner +0 -3
- data/fixtures/book_service/script/server +0 -3
- data/fixtures/book_service/test/fixtures/books.yml +0 -9
- data/fixtures/book_service/test/fixtures/shelves.yml +0 -7
- data/fixtures/book_service/test/functional/books_controller_test.rb +0 -45
- data/fixtures/book_service/test/functional/shelf_controller_test.rb +0 -8
- data/fixtures/book_service/test/test_helper.rb +0 -38
- data/fixtures/book_service/test/unit/book_test.rb +0 -8
- data/fixtures/book_service/test/unit/shelf_test.rb +0 -8
- data/spec/create_spec.rb +0 -21
- data/spec/delete_spec.rb +0 -22
- data/spec/read_spec.rb +0 -101
- data/spec/update_spec.rb +0 -36
- data/stories/all.rb +0 -5
- data/stories/crud/create +0 -39
- data/stories/crud/delete +0 -9
- data/stories/crud/read +0 -36
- data/stories/crud/stories.rb +0 -18
- data/stories/crud/update +0 -44
- data/stories/helper.rb +0 -19
- data/stories/resources/helpers/book.rb +0 -7
- data/stories/resources/helpers/story_helper.rb +0 -2
- data/stories/resources/steps/read.rb +0 -35
- data/stories/resources/steps/using_rest_adapter.rb +0 -99
- data/tasks/stories.rb +0 -5
data/stories/all.rb
DELETED
data/stories/crud/create
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
Story: remote app wants to create a resource
|
2
|
-
As a remote app
|
3
|
-
I want to create a resource
|
4
|
-
So that I can store some data about a particular item
|
5
|
-
|
6
|
-
Scenario: remote app supplies a new valid Resource
|
7
|
-
Given a valid DataMapper::Resource
|
8
|
-
When I try to save the Resource
|
9
|
-
Then the Resource should save
|
10
|
-
|
11
|
-
Scenario: remote app supplies a new invalid Resource
|
12
|
-
Given a valid DataMapper::Resource
|
13
|
-
When I make invalid changes to that Resource
|
14
|
-
When I try to save the Resource
|
15
|
-
Then the Resource should not save
|
16
|
-
|
17
|
-
Scenario: remote app supplies a new valid Resource associated with another new valid Resource
|
18
|
-
Given a new Resource
|
19
|
-
And another new Resource associated with the first
|
20
|
-
When I try to save the first Resource
|
21
|
-
Then both Resources should save
|
22
|
-
|
23
|
-
Scenario: remote app supplies a new invalid Resource associated with another new valid Resource
|
24
|
-
Given a new invalid Resouce
|
25
|
-
And another new Resource associated with the first
|
26
|
-
When I try to save the first Resource
|
27
|
-
Neither Resource should save
|
28
|
-
|
29
|
-
Scenario: remote app supplies a new valid Resource associated with another new invalid Resource
|
30
|
-
Given a new Resource
|
31
|
-
And another new invalid Resource associated with the first
|
32
|
-
When I try to save the first Resource
|
33
|
-
Neither Resource should save
|
34
|
-
|
35
|
-
Scenario: remote app supplies a new invalid Resource associated with another new invalid Resource
|
36
|
-
Given a new invalid Resource
|
37
|
-
And another new invalid Resource associated with the first
|
38
|
-
When I try to save the first Resource
|
39
|
-
Neither Resource should save
|
data/stories/crud/delete
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
Story: remote app wants to delete a Resource
|
2
|
-
As a remote app
|
3
|
-
I want to delete a Resource
|
4
|
-
So that the information will no longer be available
|
5
|
-
|
6
|
-
Scenario: remote app attempts to delete a Resource by ID
|
7
|
-
Given a local representation of a remote Resource
|
8
|
-
When I destroy the Resource
|
9
|
-
Then the Resource will no longer be available
|
data/stories/crud/read
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
Story: remote app wants to access one or more Resources
|
2
|
-
As a remote app
|
3
|
-
I want to get one or more Resources
|
4
|
-
So that I can take an action based upon the information
|
5
|
-
|
6
|
-
Scenario: GET <resource>
|
7
|
-
Given a type of Resource
|
8
|
-
When I request all of the Resources of that type
|
9
|
-
Then I should not receive an empty list
|
10
|
-
|
11
|
-
Scenario: GET <resource>/<id>
|
12
|
-
Given a type of Resource
|
13
|
-
And the ID of an existing Resource
|
14
|
-
When I request the Resource
|
15
|
-
Then I should receive that Resource
|
16
|
-
|
17
|
-
Scenario: GET <resource>/<invalid id>
|
18
|
-
Given a type of Resource
|
19
|
-
And the ID of a nonexistent Resource
|
20
|
-
When I request the Resource
|
21
|
-
Then I should get nothing in return
|
22
|
-
|
23
|
-
Scenario: GET <nested resource>/<id>
|
24
|
-
Given a Resource that returns associated resources
|
25
|
-
And the ID of an existing Resource that has associated Resources
|
26
|
-
And I have all of the necessary class definitions
|
27
|
-
When I GET <nested resource>/<id>
|
28
|
-
Then I should get the Resource
|
29
|
-
And the Resource will have associated Resources
|
30
|
-
|
31
|
-
Scenario: GET <nested resource>/<id> but we are missing some class definitions
|
32
|
-
Given a Resource that returns associated resources
|
33
|
-
And the ID of an existing Resource that has associated Resources
|
34
|
-
And I do not have all of the necessary class definitions
|
35
|
-
When I GET <nested resource>/<id>
|
36
|
-
Then I should get an Exception
|
data/stories/crud/stories.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), *%w[.. helper])
|
2
|
-
|
3
|
-
Dir["#{File.dirname(__FILE__)}/*"].each do |file|
|
4
|
-
unless (file =~ /\.rb$/)
|
5
|
-
file_name = file.split('/').last
|
6
|
-
begin
|
7
|
-
require File.join(File.dirname(__FILE__), "..", "resources", "steps", file_name)
|
8
|
-
rescue LoadError
|
9
|
-
puts "Can't find #{file_name}.rb to define story steps; assuming this is intentional"
|
10
|
-
rescue Exception => e
|
11
|
-
puts e.backtrace
|
12
|
-
exit 1
|
13
|
-
end
|
14
|
-
with_steps_for :using_rest_adapter, file_name.to_sym do
|
15
|
-
run file if File.file?(file)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/stories/crud/update
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
Story: remote app wants to update a resource
|
2
|
-
As a remote app
|
3
|
-
I want to modify a resource
|
4
|
-
So that it's information represents the correct state
|
5
|
-
|
6
|
-
Scenario: remote app updates with changes made to a resource's state
|
7
|
-
Given a local representation of a remote Resource
|
8
|
-
When I make valid changes to that Resource
|
9
|
-
And I try to save the Resource
|
10
|
-
Then the Resource should save
|
11
|
-
|
12
|
-
Scenario: remote app updates with invalid changes to a resource's state
|
13
|
-
Given a local representation of a remote Resource
|
14
|
-
When I make invalid changes to that Resource
|
15
|
-
And I try to save the Resource
|
16
|
-
Then the Resource should not save
|
17
|
-
|
18
|
-
Scenario: remote app updates with changes to an object and one of its children
|
19
|
-
Given a local representation of a remote Resource
|
20
|
-
And a local representation of one of that Resource's child Resources
|
21
|
-
When I make valid changes to the parent Resource
|
22
|
-
And I make valid changes to the child Resource
|
23
|
-
Then both Resources should save
|
24
|
-
|
25
|
-
Scenario: remote app updates with valid changes to an object and invalid changes to one of its children
|
26
|
-
Given a local representation of a remote Resource
|
27
|
-
And a local representation of one of that Resource's child Resources
|
28
|
-
When I make valid changes to the parent Resource
|
29
|
-
And I make invalid changes to the child Resource
|
30
|
-
Then neither Resource should save
|
31
|
-
|
32
|
-
Scenario: remote app updates with invalid changes to an object and valid changes to one of its children
|
33
|
-
Given a local representation of a remote Resource
|
34
|
-
And a local representation of one of that Resource's child Resources
|
35
|
-
When I make invalid changes to the parent Resource
|
36
|
-
And I make valid changes to the child Resource
|
37
|
-
Then neither Resource should save
|
38
|
-
|
39
|
-
Scenario: remote app updates with invalid changes to an object and invalid changes to one of its children
|
40
|
-
Given a local representation of a remote Resource
|
41
|
-
And a local representation of one of that Resource's child Resources
|
42
|
-
When I make invalid changes to the parent Resource
|
43
|
-
And I make invalid changes to the child Resource
|
44
|
-
Then neither Resource should save
|
data/stories/helper.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
require 'rubygems'
|
3
|
-
require 'tempfile'
|
4
|
-
|
5
|
-
gem 'dm-core', '~>0.9.10'
|
6
|
-
require 'dm-core'
|
7
|
-
|
8
|
-
gem 'rspec', '~>1.1.11'
|
9
|
-
require 'spec'
|
10
|
-
|
11
|
-
ROOT = Pathname(__FILE__).dirname.parent.expand_path
|
12
|
-
|
13
|
-
# use local dm-serializer if running from dm-more directly
|
14
|
-
lib = ROOT.parent.parent.join('dm-serializer', 'lib').expand_path
|
15
|
-
$LOAD_PATH.unshift(lib) if lib.directory?
|
16
|
-
|
17
|
-
require ROOT + 'lib/rest_adapter'
|
18
|
-
require ROOT + 'stories/resources/helpers/story_helper'
|
19
|
-
require ROOT + 'stories/resources/steps/using_rest_adapter'
|
@@ -1,35 +0,0 @@
|
|
1
|
-
steps_for :read do
|
2
|
-
Given "a Resource that returns associated resources" do
|
3
|
-
class Shelf
|
4
|
-
include DataMapper::Resource
|
5
|
-
property :id, Integer, :serial => true
|
6
|
-
property :name, String
|
7
|
-
has n, :books
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
Given "the ID of an existing Resource that has associated Resources" do
|
12
|
-
# Assuming that resource 1 is there.
|
13
|
-
# @type.first would do a GET; that's what we're testing
|
14
|
-
@resource_id = 1
|
15
|
-
end
|
16
|
-
|
17
|
-
Given "I have all of the necessary class definitions" do
|
18
|
-
# NO-OP because defined above
|
19
|
-
end
|
20
|
-
|
21
|
-
When "I GET <nested resource>/<id>" do
|
22
|
-
@resource = Shelf.get(@resource_id)
|
23
|
-
end
|
24
|
-
|
25
|
-
Then "I should get the Resource" do
|
26
|
-
@resource.should_not be_nil
|
27
|
-
@resource.should be_an_instance_of(Shelf)
|
28
|
-
@resource.id.should == 1
|
29
|
-
end
|
30
|
-
|
31
|
-
Then "the Resource will have associated Resources" do
|
32
|
-
@resource.books.should_not be_empty
|
33
|
-
@resource.books.first.should be_an_instance_of(Book)
|
34
|
-
end
|
35
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
require 'dm-core'
|
2
|
-
|
3
|
-
steps_for :using_rest_adapter do
|
4
|
-
#To run these specs, you must have a REST Application running on port 3001 on your localhost
|
5
|
-
#The app is expected to implement the REST API for CRUD operations on a Book
|
6
|
-
|
7
|
-
DataMapper.setup(:default, {
|
8
|
-
:adapter => 'rest',
|
9
|
-
:format => 'xml',
|
10
|
-
:host => 'localhost',
|
11
|
-
:port => '3001'
|
12
|
-
})
|
13
|
-
|
14
|
-
Given("a valid DataMapper::Resource") do
|
15
|
-
# TODO refactor
|
16
|
-
require File.join(File.dirname(__FILE__), '..', 'helpers', 'book')
|
17
|
-
@resource = new_book
|
18
|
-
end
|
19
|
-
|
20
|
-
Given("a type of Resource") do
|
21
|
-
# TODO refactor
|
22
|
-
# require File.join(File.dirname(__FILE__), '..', 'helpers', 'book')
|
23
|
-
# Book = Book
|
24
|
-
end
|
25
|
-
|
26
|
-
Given("the ID of an existing Resource") do
|
27
|
-
# TODO refactor
|
28
|
-
require File.join(File.dirname(__FILE__), '..', 'helpers', 'book')
|
29
|
-
@resource_id = Book.first.id
|
30
|
-
end
|
31
|
-
|
32
|
-
Given("the ID of a nonexistent Resource") do
|
33
|
-
@resource_id = 42 ** 3
|
34
|
-
end
|
35
|
-
|
36
|
-
Given("a local representation of a remote Resource") do
|
37
|
-
# TODO refactor
|
38
|
-
require File.join(File.dirname(__FILE__), '..', 'helpers', 'book')
|
39
|
-
@resource = Book.first
|
40
|
-
@resource_id = @resource.id
|
41
|
-
end
|
42
|
-
|
43
|
-
When("I try to save the Resource") do
|
44
|
-
@result = @resource.save
|
45
|
-
end
|
46
|
-
|
47
|
-
When("I request all of the Resources of that type") do
|
48
|
-
require File.join(File.dirname(__FILE__), '..', 'helpers', 'book')
|
49
|
-
@resources = Book.all
|
50
|
-
end
|
51
|
-
|
52
|
-
When("I request the Resource") do
|
53
|
-
require File.join(File.dirname(__FILE__), '..', 'helpers', 'book')
|
54
|
-
@resource = Book.get(@resource_id)
|
55
|
-
end
|
56
|
-
|
57
|
-
When("I make valid changes to that Resource") do
|
58
|
-
@resource.title = "Mary had a little lamb"
|
59
|
-
end
|
60
|
-
|
61
|
-
When("I make invalid changes to that Resource") do
|
62
|
-
@resource.title = nil
|
63
|
-
end
|
64
|
-
|
65
|
-
When("I destroy the Resource") do
|
66
|
-
@resource.destroy
|
67
|
-
end
|
68
|
-
|
69
|
-
Then("the Resource should save") do
|
70
|
-
@result.should be_true
|
71
|
-
end
|
72
|
-
|
73
|
-
Then("the Resource should not save") do
|
74
|
-
@result.should be_false
|
75
|
-
end
|
76
|
-
|
77
|
-
Then("I should not receive an empty list") do
|
78
|
-
@resources.should_not be_empty
|
79
|
-
end
|
80
|
-
|
81
|
-
Then("I should receive that Resource") do
|
82
|
-
@resource.should_not be_nil
|
83
|
-
@resource.id.should == @resource_id
|
84
|
-
end
|
85
|
-
|
86
|
-
Then("I should get nothing in return") do
|
87
|
-
@resource.should be_nil
|
88
|
-
end
|
89
|
-
|
90
|
-
Then("the Resource will no longer be available") do
|
91
|
-
# TODO refactor
|
92
|
-
require File.join(File.dirname(__FILE__), '..', 'helpers', 'book')
|
93
|
-
Book.get(@resource_id).should be_nil
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def new_book(options={})
|
98
|
-
Book.new(options.merge({:title => "Hello, World!", :author => "Some dude"}))
|
99
|
-
end
|