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/lib/rest_adapter/version.rb
CHANGED
@@ -0,0 +1,130 @@
|
|
1
|
+
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'A Connection instance' do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@username = "admin"
|
8
|
+
@password = "tot@ls3crit"
|
9
|
+
@uri = DataObjects::URI.parse(Addressable::URI.new(
|
10
|
+
:scheme => 'http',
|
11
|
+
:adapter => 'rest',
|
12
|
+
:user => @username,
|
13
|
+
:password => @password,
|
14
|
+
:host => 'localhost',
|
15
|
+
:port => '4000',
|
16
|
+
:query => nil
|
17
|
+
))
|
18
|
+
@connection = DataMapperRest::Connection.new(@uri, "xml")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should construct a valid uri" do
|
22
|
+
@connection.uri.to_s.should == "http://#{@username}:#{@password}@localhost:4000"
|
23
|
+
@connection.uri.host.should == "localhost"
|
24
|
+
@connection.uri.port.should == 4000
|
25
|
+
@connection.uri.user.should == @username
|
26
|
+
@connection.uri.password.should == @password
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return the correct extension and mime type for xml" do
|
30
|
+
@connection.format.header.should == {'Content-Type' => "application/xml"}
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return the correct extension and mime type for json" do
|
34
|
+
connection = DataMapperRest::Connection.new(@uri, "json")
|
35
|
+
connection.format.header.should == {'Content-Type' => "application/json"}
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'when running the verb methods' do
|
39
|
+
|
40
|
+
it 'should make an HTTP Post' do
|
41
|
+
@connection.should_receive(:run_verb).with("post", "<somexml>")
|
42
|
+
@connection.http_post("foobars", "<somexml>")
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should make an HTTP Get' do
|
46
|
+
@connection.should_receive(:run_verb).with("get", "<somexml>")
|
47
|
+
@connection.http_get("foobars", "<somexml>")
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should make an HTTP Put' do
|
51
|
+
@connection.should_receive(:run_verb).with("put", "<somexml>")
|
52
|
+
@connection.http_put("foobars", "<somexml>")
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should make an HTTP Delete' do
|
56
|
+
@connection.should_receive(:run_verb).with("delete", "<somexml>")
|
57
|
+
@connection.http_delete("foobars", "<somexml>")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should only accept the listed verbs" do
|
61
|
+
@connection.should_not_receive(:run_verb).with("delete", "<somexml>")
|
62
|
+
@connection.http_explode("foobars", "<somexml>")
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "when receiving error response codes" do
|
68
|
+
|
69
|
+
before do
|
70
|
+
@mock_http = mock("http")
|
71
|
+
Net::HTTP.should_receive(:start).with(@connection.uri.host, @connection.uri.port).and_yield @mock_http
|
72
|
+
@mock_resp = mock("response")
|
73
|
+
@mock_resp.stub!(:body).and_return ""
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should raise 404" do
|
77
|
+
@mock_http.should_receive(:request).and_return Net::HTTPResponse.new(1, 404, "oops")
|
78
|
+
lambda {@connection.http_post("foobars", "<somexml>")}.should raise_error(DataMapperRest::ResourceNotFound, "Resource action failed with code: 404, message: oops")
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should redirect on 301" do
|
82
|
+
@mock_http.should_receive(:request).and_return Net::HTTPResponse.new(1, 301, "moved")
|
83
|
+
lambda {@connection.http_post("foobars", "<somexml>")}.should raise_error(DataMapperRest::Redirection, "Resource action failed with code: 301, message: moved")
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should redirect on 302" do
|
87
|
+
@mock_http.should_receive(:request).and_return Net::HTTPResponse.new(1, 302, "moved")
|
88
|
+
lambda {@connection.http_post("foobars", "<somexml>")}.should raise_error(DataMapperRest::Redirection, "Resource action failed with code: 302, message: moved")
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should raise bad request on 400" do
|
92
|
+
@mock_http.should_receive(:request).and_return Net::HTTPResponse.new(1, 400, "bad mojo")
|
93
|
+
|
94
|
+
lambda {@connection.http_post("foobars", "<somexml>")}.should raise_error(DataMapperRest::BadRequest, "Resource action failed with code: 400, message: bad mojo")
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should raise MethodNotAllowed on 405" do
|
98
|
+
@mock_http.should_receive(:request).and_return Net::HTTPResponse.new(1, 405, "nope zero")
|
99
|
+
|
100
|
+
lambda {@connection.http_post("foobars", "<somexml>")}.should raise_error(DataMapperRest::MethodNotAllowed, "Resource action failed with code: 405, message: nope zero")
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should raise ResourceConflict on 409" do
|
104
|
+
@mock_http.should_receive(:request).and_return Net::HTTPResponse.new(1, 409, "should I stay or should I go")
|
105
|
+
|
106
|
+
lambda {@connection.http_post("foobars", "<somexml>")}.should raise_error(DataMapperRest::ResourceConflict, "Resource action failed with code: 409, message: should I stay or should I go")
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should raise ResourceInvalid on 422" do
|
110
|
+
@mock_resp.should_receive(:code).twice.and_return 422
|
111
|
+
@mock_resp.should_receive(:message).and_return "WTF"
|
112
|
+
@mock_http.should_receive(:request).and_return @mock_resp
|
113
|
+
|
114
|
+
lambda {@connection.http_post("foobars", "<somexml>")}.should raise_error(DataMapperRest::ResourceInvalid, "Resource action failed with code: 422, message: WTF")
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should raise ClientError on 401" do
|
118
|
+
@mock_http.should_receive(:request).and_return Net::HTTPResponse.new(1, 401, "no idea")
|
119
|
+
|
120
|
+
lambda {@connection.http_post("foobars", "<somexml>")}.should raise_error(DataMapperRest::ClientError, "Resource action failed with code: 401, message: no idea")
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should raise ServerError on 500" do
|
124
|
+
@mock_http.should_receive(:request).and_return Net::HTTPResponse.new(1, 500, "I broken")
|
125
|
+
|
126
|
+
lambda {@connection.http_post("foobars", "<somexml>")}.should raise_error(DataMapperRest::ServerError, "Resource action failed with code: 500, message: I broken")
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
data/spec/crud_spec.rb
ADDED
@@ -0,0 +1,250 @@
|
|
1
|
+
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'A REST adapter' do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@book = Book.new(:title => 'Hello, World!', :author => 'Anonymous')
|
8
|
+
@adapter = DataMapper::Repository.adapters[:default]
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'when saving a new resource' do
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
@mock_resp = mock("response")
|
15
|
+
|
16
|
+
@book.id = 1
|
17
|
+
@mock_resp.should_receive(:body).and_return @book.to_xml
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should create a book" do
|
21
|
+
@mock_http = mock("http")
|
22
|
+
Net::HTTP.should_receive(:start).and_yield @mock_http
|
23
|
+
|
24
|
+
@mock_resp.should_receive(:code).and_return 200
|
25
|
+
|
26
|
+
@mock_http.should_receive(:request).and_return @mock_resp
|
27
|
+
|
28
|
+
@book.save.should eql(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should make an HTTP POST' do
|
32
|
+
@adapter.connection.should_receive(:http_post).with('books', @book.to_xml).and_return @mock_resp
|
33
|
+
@book.save
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should call run_verb with POST' do
|
37
|
+
@adapter.connection.should_receive(:run_verb).with('post', @book.to_xml).and_return @mock_resp
|
38
|
+
@book.save
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'when returning incorrect xml from a save' do
|
44
|
+
before(:all) do
|
45
|
+
@mock_resp = mock("response")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should raise error on missing root element in xml" do
|
49
|
+
@mock_resp.should_receive(:body).and_return ""
|
50
|
+
@adapter.connection.should_receive(:run_verb).with('post', @book.to_xml).and_return @mock_resp
|
51
|
+
|
52
|
+
lambda {@book.save}.should raise_error(RuntimeError, "No root element matching book in xml")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should not raise an error if the root xml is empty" do
|
56
|
+
@mock_resp.should_receive(:body).and_return "<book></book>"
|
57
|
+
@adapter.connection.should_receive(:run_verb).with('post', @book.to_xml).and_return @mock_resp
|
58
|
+
|
59
|
+
lambda {@book.save}.should_not raise_error(RuntimeError)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'when deleting an existing resource' do
|
64
|
+
before do
|
65
|
+
@book.stub!(:new_record?).and_return(false)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should do an HTTP DELETE' do
|
69
|
+
@adapter.connection.should_receive(:http_delete)
|
70
|
+
@book.destroy
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should raise NotImplementedError if is not a single resource query" do
|
74
|
+
@adapter.should_receive(:is_single_resource_query?).and_return(false)
|
75
|
+
lambda {@book.destroy}.should raise_error(NotImplementedError)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should call run_verb with DELETE and no data' do
|
79
|
+
@adapter.connection.should_receive(:run_verb).with('delete', nil)
|
80
|
+
@book.destroy
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should return false if the record does not exist in the repository" do
|
84
|
+
@book.should_receive(:new_record?).and_return(true)
|
85
|
+
@book.destroy.should eql(false)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'when getting one resource' do
|
90
|
+
|
91
|
+
describe 'if the resource exists' do
|
92
|
+
|
93
|
+
before do
|
94
|
+
book_xml = <<-BOOK
|
95
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
96
|
+
<book>
|
97
|
+
<author>Stephen King</author>
|
98
|
+
<created-at type='datetime'>2008-06-08T17:03:07Z</created-at>
|
99
|
+
<id type='integer'>1</id>
|
100
|
+
<title>The Shining</title>
|
101
|
+
<updated-at type='datetime'>2008-06-08T17:03:07Z</updated-at>
|
102
|
+
</book>
|
103
|
+
BOOK
|
104
|
+
@id = 1
|
105
|
+
@response = mock(Net::HTTPResponse)
|
106
|
+
@response.stub!(:body).and_return(book_xml)
|
107
|
+
@adapter.connection.stub!(:http_get).and_return(@response)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should return the resource' do
|
111
|
+
book = Book.get(@id)
|
112
|
+
book.should_not be_nil
|
113
|
+
book.id.should be_an_instance_of(Fixnum)
|
114
|
+
book.id.should == 1
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should have its attributes well formed" do
|
118
|
+
book = Book.get(@id)
|
119
|
+
book.author.should == 'Stephen King'
|
120
|
+
book.title.should == 'The Shining'
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should do an HTTP GET' do
|
124
|
+
@adapter.connection.should_receive(:http_get).with('books/1').and_return(@response)
|
125
|
+
Book.get(@id)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should be equal to itself" do
|
129
|
+
Book.get(@id).should == Book.get(@id)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should return its cached version when it was already fetched" do
|
133
|
+
book = mock(Book, :kind_of? => Book)
|
134
|
+
repo = mock(DataMapper::Repository)
|
135
|
+
ident_map = mock(DataMapper::IdentityMap)
|
136
|
+
|
137
|
+
Book.should_receive(:repository).and_return(repo)
|
138
|
+
repo.should_receive(:identity_map).and_return(ident_map)
|
139
|
+
ident_map.stub!(:get).with([@id]).and_return(book)
|
140
|
+
|
141
|
+
# The remote resource won't be called when a cached object exists
|
142
|
+
Book.should_receive(:first).never
|
143
|
+
Book.get(@id).should be_a_kind_of(Book)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should call read_one method" do
|
147
|
+
@adapter.should_receive(:read_one)
|
148
|
+
Book.get(@id)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe 'if the resource does not exist' do
|
153
|
+
it 'should raise DataMapperRest::ResourceNotFound' do
|
154
|
+
@mock_resp = mock("response")
|
155
|
+
@mock_http = mock("http")
|
156
|
+
Net::HTTP.should_receive(:start).and_yield @mock_http
|
157
|
+
|
158
|
+
@mock_resp.should_receive(:code).and_return 404
|
159
|
+
@mock_http.should_receive(:request).and_return @mock_resp
|
160
|
+
|
161
|
+
lambda{ Book.get(5000) }.should raise_error(DataMapperRest::ResourceNotFound)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe 'when getting all resource of a particular type' do
|
167
|
+
before do
|
168
|
+
books_xml = <<-BOOK
|
169
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
170
|
+
<books type='array'>
|
171
|
+
<book>
|
172
|
+
<author>Ursula K LeGuin</author>
|
173
|
+
<created-at type='datetime'>2008-06-08T17:02:28Z</created-at>
|
174
|
+
<id type='integer'>1</id>
|
175
|
+
<title>The Dispossed</title>
|
176
|
+
<updated-at type='datetime'>2008-06-08T17:02:28Z</updated-at>
|
177
|
+
</book>
|
178
|
+
<book>
|
179
|
+
<author>Stephen King</author>
|
180
|
+
<created-at type='datetime'>2008-06-08T17:03:07Z</created-at>
|
181
|
+
<id type='integer'>2</id>
|
182
|
+
<title>The Shining</title>
|
183
|
+
<updated-at type='datetime'>2008-06-08T17:03:07Z</updated-at>
|
184
|
+
</book>
|
185
|
+
</books>
|
186
|
+
BOOK
|
187
|
+
@response = mock(Net::HTTPResponse)
|
188
|
+
@response.stub!(:body).and_return(books_xml)
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'should get a non-empty list' do
|
192
|
+
@adapter.connection.stub!(:http_get).and_return(@response)
|
193
|
+
Book.all.should_not be_empty
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'should receive one Resource for each entity in the XML' do
|
197
|
+
@adapter.connection.stub!(:http_get).and_return(@response)
|
198
|
+
Book.all.size.should == 2
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should call read_many method" do
|
202
|
+
@adapter.connection.stub!(:http_get).and_return(@response)
|
203
|
+
@adapter.should_receive(:read_many)
|
204
|
+
Book.all
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should raise NotImplementedError if conditions are specified" do
|
208
|
+
# Have to find a way to set an expectation for a method call inside a block
|
209
|
+
# Book.all(:title => "NonExistentTitle")
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe 'when updating an existing resource' do
|
214
|
+
before do
|
215
|
+
@books_xml = <<-XML
|
216
|
+
<book>
|
217
|
+
<id type='integer'>42</id>
|
218
|
+
<title>Starship Troopers</title>
|
219
|
+
<author>Robert Heinlein</author>
|
220
|
+
<created-at type='datetime'>2008-06-08T17:02:28Z</created-at>
|
221
|
+
</book>
|
222
|
+
XML
|
223
|
+
repository do |repo|
|
224
|
+
@repository = repo
|
225
|
+
@book = Book.new(:id => 42,
|
226
|
+
:title => 'Starship Troopers',
|
227
|
+
:author => 'Robert Heinlein',
|
228
|
+
:created_at => DateTime.parse('2008-06-08T17:02:28Z'))
|
229
|
+
@book.instance_eval { @new_record = false }
|
230
|
+
@repository.identity_map(Book)[@book.key] = @book
|
231
|
+
@book.title = "Mary Had a Little Lamb"
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'should do an HTTP PUT' do
|
236
|
+
@adapter.connection.should_receive(:http_put).with('books/42', @book.to_xml)
|
237
|
+
@repository.scope do
|
238
|
+
@book.save
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should not do an HTTP PUT for non-dirty resources" do
|
243
|
+
@book.should_receive(:dirty_attributes).and_return({})
|
244
|
+
@adapter.connection.should_receive(:http_put).never
|
245
|
+
@repository.scope do
|
246
|
+
@book.save
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,12 +9,7 @@ $LOAD_PATH.unshift(lib) if lib.directory?
|
|
9
9
|
|
10
10
|
require ROOT + 'lib/rest_adapter'
|
11
11
|
|
12
|
-
|
13
|
-
:adapter => 'rest',
|
14
|
-
:format => 'xml',
|
15
|
-
:host => 'localhost',
|
16
|
-
:port => '3001'
|
17
|
-
})
|
12
|
+
load ROOT + 'config/database.rb.example'
|
18
13
|
|
19
14
|
class Book
|
20
15
|
include DataMapper::Resource
|
data/tasks/spec.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-rest-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Scott Burton @ Joyent Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-03-29 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -18,13 +18,13 @@ dependencies:
|
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- -
|
21
|
+
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.
|
23
|
+
version: 0.9.11
|
24
24
|
version:
|
25
25
|
description: REST Adapter for DataMapper
|
26
26
|
email:
|
27
|
-
-
|
27
|
+
- scott.burton [a] joyent [d] com
|
28
28
|
executables: []
|
29
29
|
|
30
30
|
extensions: []
|
@@ -38,105 +38,27 @@ files:
|
|
38
38
|
- History.txt
|
39
39
|
- LICENSE
|
40
40
|
- Manifest.txt
|
41
|
+
- README.markdown
|
41
42
|
- README.txt
|
42
43
|
- Rakefile
|
43
44
|
- TODO
|
44
|
-
-
|
45
|
-
-
|
46
|
-
- fixtures/book_service/app/controllers/application.rb
|
47
|
-
- fixtures/book_service/app/controllers/books_controller.rb
|
48
|
-
- fixtures/book_service/app/controllers/shelves_controller.rb
|
49
|
-
- fixtures/book_service/app/helpers/application_helper.rb
|
50
|
-
- fixtures/book_service/app/helpers/books_helper.rb
|
51
|
-
- fixtures/book_service/app/helpers/shelf_helper.rb
|
52
|
-
- fixtures/book_service/app/models/book.rb
|
53
|
-
- fixtures/book_service/app/models/shelf.rb
|
54
|
-
- fixtures/book_service/app/views/books/edit.html.erb
|
55
|
-
- fixtures/book_service/app/views/books/index.html.erb
|
56
|
-
- fixtures/book_service/app/views/books/new.html.erb
|
57
|
-
- fixtures/book_service/app/views/books/show.html.erb
|
58
|
-
- fixtures/book_service/app/views/layouts/books.html.erb
|
59
|
-
- fixtures/book_service/app/views/shelves/edit.html.erb
|
60
|
-
- fixtures/book_service/app/views/shelves/index.html.erb
|
61
|
-
- fixtures/book_service/app/views/shelves/new.html.erb
|
62
|
-
- fixtures/book_service/app/views/shelves/show.html.erb
|
63
|
-
- fixtures/book_service/config/boot.rb
|
64
|
-
- fixtures/book_service/config/database.yml
|
65
|
-
- fixtures/book_service/config/environment.rb
|
66
|
-
- fixtures/book_service/config/environments/development.rb
|
67
|
-
- fixtures/book_service/config/environments/production.rb
|
68
|
-
- fixtures/book_service/config/environments/test.rb
|
69
|
-
- fixtures/book_service/config/initializers/inflections.rb
|
70
|
-
- fixtures/book_service/config/initializers/mime_types.rb
|
71
|
-
- fixtures/book_service/config/initializers/new_rails_defaults.rb
|
72
|
-
- fixtures/book_service/config/routes.rb
|
73
|
-
- fixtures/book_service/db/development.sqlite3
|
74
|
-
- fixtures/book_service/db/migrate/20080608165526_create_books.rb
|
75
|
-
- fixtures/book_service/db/migrate/20080621171551_create_shelves.rb
|
76
|
-
- fixtures/book_service/db/migrate/20080629143033_create_fake_books_and_shelves.rb
|
77
|
-
- fixtures/book_service/db/schema.rb
|
78
|
-
- fixtures/book_service/public/404.html
|
79
|
-
- fixtures/book_service/public/422.html
|
80
|
-
- fixtures/book_service/public/500.html
|
81
|
-
- fixtures/book_service/public/dispatch.cgi
|
82
|
-
- fixtures/book_service/public/dispatch.fcgi
|
83
|
-
- fixtures/book_service/public/dispatch.rb
|
84
|
-
- fixtures/book_service/public/favicon.ico
|
85
|
-
- fixtures/book_service/public/images/rails.png
|
86
|
-
- fixtures/book_service/public/index.html
|
87
|
-
- fixtures/book_service/public/javascripts/application.js
|
88
|
-
- fixtures/book_service/public/javascripts/controls.js
|
89
|
-
- fixtures/book_service/public/javascripts/dragdrop.js
|
90
|
-
- fixtures/book_service/public/javascripts/effects.js
|
91
|
-
- fixtures/book_service/public/javascripts/prototype.js
|
92
|
-
- fixtures/book_service/public/robots.txt
|
93
|
-
- fixtures/book_service/public/stylesheets/scaffold.css
|
94
|
-
- fixtures/book_service/script/about
|
95
|
-
- fixtures/book_service/script/console
|
96
|
-
- fixtures/book_service/script/dbconsole
|
97
|
-
- fixtures/book_service/script/destroy
|
98
|
-
- fixtures/book_service/script/generate
|
99
|
-
- fixtures/book_service/script/performance/benchmarker
|
100
|
-
- fixtures/book_service/script/performance/profiler
|
101
|
-
- fixtures/book_service/script/performance/request
|
102
|
-
- fixtures/book_service/script/plugin
|
103
|
-
- fixtures/book_service/script/process/inspector
|
104
|
-
- fixtures/book_service/script/process/reaper
|
105
|
-
- fixtures/book_service/script/process/spawner
|
106
|
-
- fixtures/book_service/script/runner
|
107
|
-
- fixtures/book_service/script/server
|
108
|
-
- fixtures/book_service/test/fixtures/books.yml
|
109
|
-
- fixtures/book_service/test/fixtures/shelves.yml
|
110
|
-
- fixtures/book_service/test/functional/books_controller_test.rb
|
111
|
-
- fixtures/book_service/test/functional/shelf_controller_test.rb
|
112
|
-
- fixtures/book_service/test/test_helper.rb
|
113
|
-
- fixtures/book_service/test/unit/book_test.rb
|
114
|
-
- fixtures/book_service/test/unit/shelf_test.rb
|
45
|
+
- config/database.rb.example
|
46
|
+
- dm-rest-adapter.gemspec
|
115
47
|
- lib/rest_adapter.rb
|
48
|
+
- lib/rest_adapter/adapter.rb
|
49
|
+
- lib/rest_adapter/connection.rb
|
50
|
+
- lib/rest_adapter/exceptions.rb
|
51
|
+
- lib/rest_adapter/formats.rb
|
116
52
|
- lib/rest_adapter/version.rb
|
117
|
-
- spec/
|
118
|
-
- spec/
|
119
|
-
- spec/read_spec.rb
|
53
|
+
- spec/connection_spec.rb
|
54
|
+
- spec/crud_spec.rb
|
120
55
|
- spec/ruby_forker.rb
|
121
56
|
- spec/spec.opts
|
122
57
|
- spec/spec_helper.rb
|
123
|
-
- spec/update_spec.rb
|
124
|
-
- stories/all.rb
|
125
|
-
- stories/crud/create
|
126
|
-
- stories/crud/delete
|
127
|
-
- stories/crud/read
|
128
|
-
- stories/crud/stories.rb
|
129
|
-
- stories/crud/update
|
130
|
-
- stories/helper.rb
|
131
|
-
- stories/resources/helpers/book.rb
|
132
|
-
- stories/resources/helpers/story_helper.rb
|
133
|
-
- stories/resources/steps/read.rb
|
134
|
-
- stories/resources/steps/using_rest_adapter.rb
|
135
58
|
- tasks/install.rb
|
136
59
|
- tasks/spec.rb
|
137
|
-
- tasks/stories.rb
|
138
60
|
has_rdoc: true
|
139
|
-
homepage: http://github.com/
|
61
|
+
homepage: http://github.com/datamapper/dm-more/tree/master/adapters/dm-rest-adapter
|
140
62
|
post_install_message:
|
141
63
|
rdoc_options:
|
142
64
|
- --main
|