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
@@ -1,53 +0,0 @@
|
|
1
|
-
body { background-color: #fff; color: #333; }
|
2
|
-
|
3
|
-
body, p, ol, ul, td {
|
4
|
-
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
-
font-size: 13px;
|
6
|
-
line-height: 18px;
|
7
|
-
}
|
8
|
-
|
9
|
-
pre {
|
10
|
-
background-color: #eee;
|
11
|
-
padding: 10px;
|
12
|
-
font-size: 11px;
|
13
|
-
}
|
14
|
-
|
15
|
-
a { color: #000; }
|
16
|
-
a:visited { color: #666; }
|
17
|
-
a:hover { color: #fff; background-color:#000; }
|
18
|
-
|
19
|
-
.fieldWithErrors {
|
20
|
-
padding: 2px;
|
21
|
-
background-color: red;
|
22
|
-
display: table;
|
23
|
-
}
|
24
|
-
|
25
|
-
#errorExplanation {
|
26
|
-
width: 400px;
|
27
|
-
border: 2px solid red;
|
28
|
-
padding: 7px;
|
29
|
-
padding-bottom: 12px;
|
30
|
-
margin-bottom: 20px;
|
31
|
-
background-color: #f0f0f0;
|
32
|
-
}
|
33
|
-
|
34
|
-
#errorExplanation h2 {
|
35
|
-
text-align: left;
|
36
|
-
font-weight: bold;
|
37
|
-
padding: 5px 5px 5px 15px;
|
38
|
-
font-size: 12px;
|
39
|
-
margin: -7px;
|
40
|
-
background-color: #c00;
|
41
|
-
color: #fff;
|
42
|
-
}
|
43
|
-
|
44
|
-
#errorExplanation p {
|
45
|
-
color: #333;
|
46
|
-
margin-bottom: 0;
|
47
|
-
padding: 5px;
|
48
|
-
}
|
49
|
-
|
50
|
-
#errorExplanation ul li {
|
51
|
-
font-size: 12px;
|
52
|
-
list-style: square;
|
53
|
-
}
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class BooksControllerTest < ActionController::TestCase
|
4
|
-
def test_should_get_index
|
5
|
-
get :index
|
6
|
-
assert_response :success
|
7
|
-
assert_not_nil assigns(:books)
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_should_get_new
|
11
|
-
get :new
|
12
|
-
assert_response :success
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_should_create_book
|
16
|
-
assert_difference('Book.count') do
|
17
|
-
post :create, :book => { }
|
18
|
-
end
|
19
|
-
|
20
|
-
assert_redirected_to book_path(assigns(:book))
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_should_show_book
|
24
|
-
get :show, :id => books(:one).id
|
25
|
-
assert_response :success
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_should_get_edit
|
29
|
-
get :edit, :id => books(:one).id
|
30
|
-
assert_response :success
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_should_update_book
|
34
|
-
put :update, :id => books(:one).id, :book => { }
|
35
|
-
assert_redirected_to book_path(assigns(:book))
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_should_destroy_book
|
39
|
-
assert_difference('Book.count', -1) do
|
40
|
-
delete :destroy, :id => books(:one).id
|
41
|
-
end
|
42
|
-
|
43
|
-
assert_redirected_to books_path
|
44
|
-
end
|
45
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] = "test"
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
-
require 'test_help'
|
4
|
-
|
5
|
-
class Test::Unit::TestCase
|
6
|
-
# Transactional fixtures accelerate your tests by wrapping each test method
|
7
|
-
# in a transaction that's rolled back on completion. This ensures that the
|
8
|
-
# test database remains unchanged so your fixtures don't have to be reloaded
|
9
|
-
# between every test method. Fewer database queries means faster tests.
|
10
|
-
#
|
11
|
-
# Read Mike Clark's excellent walkthrough at
|
12
|
-
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
13
|
-
#
|
14
|
-
# Every Active Record database supports transactions except MyISAM tables
|
15
|
-
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
16
|
-
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
17
|
-
# is recommended.
|
18
|
-
#
|
19
|
-
# The only drawback to using transactional fixtures is when you actually
|
20
|
-
# need to test transactions. Since your test is bracketed by a transaction,
|
21
|
-
# any transactions started in your code will be automatically rolled back.
|
22
|
-
self.use_transactional_fixtures = true
|
23
|
-
|
24
|
-
# Instantiated fixtures are slow, but give you @david where otherwise you
|
25
|
-
# would need people(:david). If you don't want to migrate your existing
|
26
|
-
# test cases which use the @david style and don't mind the speed hit (each
|
27
|
-
# instantiated fixtures translates to a database query per test method),
|
28
|
-
# then set this back to true.
|
29
|
-
self.use_instantiated_fixtures = false
|
30
|
-
|
31
|
-
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
32
|
-
#
|
33
|
-
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
34
|
-
# -- they do not yet inherit this setting
|
35
|
-
fixtures :all
|
36
|
-
|
37
|
-
# Add more helper methods to be used by all tests here...
|
38
|
-
end
|
data/spec/create_spec.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe 'A REST adapter' do
|
5
|
-
|
6
|
-
before do
|
7
|
-
@adapter = DataMapper::Repository.adapters[:default]
|
8
|
-
end
|
9
|
-
|
10
|
-
describe 'when saving a resource' do
|
11
|
-
|
12
|
-
before do
|
13
|
-
@book = Book.new(:title => 'Hello, World!', :author => 'Anonymous')
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should make an HTTP Post' do
|
17
|
-
@adapter.should_receive(:http_post).with('/books.xml', @book.to_xml)
|
18
|
-
@book.save
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/spec/delete_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe 'A REST adapter' do
|
5
|
-
|
6
|
-
before do
|
7
|
-
@adapter = DataMapper::Repository.adapters[:default]
|
8
|
-
end
|
9
|
-
|
10
|
-
describe 'when deleting an existing resource' do
|
11
|
-
before do
|
12
|
-
@book = Book.new(:title => 'Hello, World!', :author => 'Anonymous')
|
13
|
-
@book.stub!(:new_record?).and_return(false)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should do an HTTP DELETE' do
|
17
|
-
@adapter.should_receive(:http_delete)
|
18
|
-
@book.destroy
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
data/spec/read_spec.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe 'A REST adapter' do
|
5
|
-
|
6
|
-
before do
|
7
|
-
@adapter = DataMapper::Repository.adapters[:default]
|
8
|
-
end
|
9
|
-
|
10
|
-
describe 'when getting one resource' do
|
11
|
-
|
12
|
-
describe 'if the resource exists' do
|
13
|
-
|
14
|
-
before do
|
15
|
-
book_xml = <<-BOOK
|
16
|
-
<?xml version='1.0' encoding='UTF-8'?>
|
17
|
-
<book>
|
18
|
-
<author>Stephen King</author>
|
19
|
-
<created-at type='datetime'>2008-06-08T17:03:07Z</created-at>
|
20
|
-
<id type='integer'>1</id>
|
21
|
-
<title>The Shining</title>
|
22
|
-
<updated-at type='datetime'>2008-06-08T17:03:07Z</updated-at>
|
23
|
-
</book>
|
24
|
-
BOOK
|
25
|
-
@id = 1
|
26
|
-
@response = mock(Net::HTTPResponse)
|
27
|
-
@response.stub!(:body).and_return(book_xml)
|
28
|
-
@adapter.stub!(:http_get).and_return(@response)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should return the resource' do
|
32
|
-
book = Book.get(@id)
|
33
|
-
book.should_not be_nil
|
34
|
-
book.id.should be_an_instance_of(Fixnum)
|
35
|
-
book.id.should == 1
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should do an HTTP GET' do
|
39
|
-
@adapter.should_receive(:http_get).with('/books/1.xml').and_return(@response)
|
40
|
-
Book.get(@id)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "it be equal to itself" do
|
44
|
-
Book.get(@id).should == Book.get(@id)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
describe 'if the resource does not exist' do
|
50
|
-
it 'should return nil' do
|
51
|
-
@id = 1
|
52
|
-
@response = mock(Net::HTTPNotFound)
|
53
|
-
@response.stub!(:content_type).and_return('text/html')
|
54
|
-
@response.stub!(:body).and_return('<html></html>')
|
55
|
-
@adapter.stub!(:http_get).and_return(@response)
|
56
|
-
id = 4200
|
57
|
-
Book.get(id).should be_nil
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe 'when getting all resource of a particular type' do
|
63
|
-
before do
|
64
|
-
books_xml = <<-BOOK
|
65
|
-
<?xml version='1.0' encoding='UTF-8'?>
|
66
|
-
<books type='array'>
|
67
|
-
<book>
|
68
|
-
<author>Ursula K LeGuin</author>
|
69
|
-
<created-at type='datetime'>2008-06-08T17:02:28Z</created-at>
|
70
|
-
<id type='integer'>1</id>
|
71
|
-
<title>The Dispossed</title>
|
72
|
-
<updated-at type='datetime'>2008-06-08T17:02:28Z</updated-at>
|
73
|
-
</book>
|
74
|
-
<book>
|
75
|
-
<author>Stephen King</author>
|
76
|
-
<created-at type='datetime'>2008-06-08T17:03:07Z</created-at>
|
77
|
-
<id type='integer'>2</id>
|
78
|
-
<title>The Shining</title>
|
79
|
-
<updated-at type='datetime'>2008-06-08T17:03:07Z</updated-at>
|
80
|
-
</book>
|
81
|
-
</books>
|
82
|
-
BOOK
|
83
|
-
@response = mock(Net::HTTPResponse)
|
84
|
-
@response.stub!(:body).and_return(books_xml)
|
85
|
-
@adapter.stub!(:http_get).and_return(@response)
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'should get a non-empty list' do
|
89
|
-
Book.all.should_not be_empty
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'should receive one Resource for each entity in the XML' do
|
93
|
-
Book.all.size.should == 2
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'should do an HTTP GET' do
|
97
|
-
@adapter.should_receive(:http_get).and_return(@response)
|
98
|
-
Book.first
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
data/spec/update_spec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe 'A REST adapter' do
|
5
|
-
|
6
|
-
describe 'when updating an existing resource' do
|
7
|
-
before do
|
8
|
-
@books_xml = <<-XML
|
9
|
-
<book>
|
10
|
-
<id type='integer'>42</id>
|
11
|
-
<title>Starship Troopers</title>
|
12
|
-
<author>Robert Heinlein</author>
|
13
|
-
<created-at type='datetime'>2008-06-08T17:02:28Z</created-at>
|
14
|
-
</book>
|
15
|
-
XML
|
16
|
-
repository do |repo|
|
17
|
-
@repository = repo
|
18
|
-
@book = Book.new(:id => 42,
|
19
|
-
:title => 'Starship Troopers',
|
20
|
-
:author => 'Robert Heinlein',
|
21
|
-
:created_at => DateTime.parse('2008-06-08T17:02:28Z'))
|
22
|
-
@book.instance_eval { @new_record = false }
|
23
|
-
@repository.identity_map(Book)[@book.key] = @book
|
24
|
-
@book.title = "Mary Had a Little Lamb"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should do an HTTP PUT' do
|
29
|
-
adapter = @repository.adapter #DataMapper::Repository.adapters[:default]
|
30
|
-
adapter.should_receive(:http_put).with('/books/42.xml', @book.to_xml)
|
31
|
-
@repository.scope do
|
32
|
-
@book.save
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|