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.
Files changed (105) hide show
  1. data/History.txt +7 -1
  2. data/Manifest.txt +9 -87
  3. data/README.markdown +47 -0
  4. data/README.txt +44 -0
  5. data/Rakefile +5 -5
  6. data/config/database.rb.example +8 -0
  7. data/dm-rest-adapter.gemspec +34 -0
  8. data/lib/rest_adapter.rb +10 -246
  9. data/lib/rest_adapter/adapter.rb +291 -0
  10. data/lib/rest_adapter/connection.rb +76 -0
  11. data/lib/rest_adapter/exceptions.rb +66 -0
  12. data/lib/rest_adapter/formats.rb +16 -0
  13. data/lib/rest_adapter/version.rb +2 -4
  14. data/spec/connection_spec.rb +130 -0
  15. data/spec/crud_spec.rb +250 -0
  16. data/spec/spec_helper.rb +1 -6
  17. data/tasks/spec.rb +1 -1
  18. metadata +16 -94
  19. data/fixtures/book_service/README +0 -256
  20. data/fixtures/book_service/Rakefile +0 -10
  21. data/fixtures/book_service/app/controllers/application.rb +0 -15
  22. data/fixtures/book_service/app/controllers/books_controller.rb +0 -85
  23. data/fixtures/book_service/app/controllers/shelves_controller.rb +0 -89
  24. data/fixtures/book_service/app/helpers/application_helper.rb +0 -3
  25. data/fixtures/book_service/app/helpers/books_helper.rb +0 -2
  26. data/fixtures/book_service/app/helpers/shelf_helper.rb +0 -2
  27. data/fixtures/book_service/app/models/book.rb +0 -6
  28. data/fixtures/book_service/app/models/shelf.rb +0 -5
  29. data/fixtures/book_service/app/views/books/edit.html.erb +0 -20
  30. data/fixtures/book_service/app/views/books/index.html.erb +0 -22
  31. data/fixtures/book_service/app/views/books/new.html.erb +0 -19
  32. data/fixtures/book_service/app/views/books/show.html.erb +0 -13
  33. data/fixtures/book_service/app/views/layouts/books.html.erb +0 -17
  34. data/fixtures/book_service/app/views/shelves/edit.html.erb +0 -16
  35. data/fixtures/book_service/app/views/shelves/index.html.erb +0 -20
  36. data/fixtures/book_service/app/views/shelves/new.html.erb +0 -15
  37. data/fixtures/book_service/app/views/shelves/show.html.erb +0 -7
  38. data/fixtures/book_service/config/boot.rb +0 -109
  39. data/fixtures/book_service/config/database.yml +0 -19
  40. data/fixtures/book_service/config/environment.rb +0 -67
  41. data/fixtures/book_service/config/environments/development.rb +0 -17
  42. data/fixtures/book_service/config/environments/production.rb +0 -22
  43. data/fixtures/book_service/config/environments/test.rb +0 -22
  44. data/fixtures/book_service/config/initializers/inflections.rb +0 -10
  45. data/fixtures/book_service/config/initializers/mime_types.rb +0 -5
  46. data/fixtures/book_service/config/initializers/new_rails_defaults.rb +0 -15
  47. data/fixtures/book_service/config/routes.rb +0 -44
  48. data/fixtures/book_service/db/development.sqlite3 +0 -0
  49. data/fixtures/book_service/db/migrate/20080608165526_create_books.rb +0 -15
  50. data/fixtures/book_service/db/migrate/20080621171551_create_shelves.rb +0 -13
  51. data/fixtures/book_service/db/migrate/20080629143033_create_fake_books_and_shelves.rb +0 -20
  52. data/fixtures/book_service/db/schema.rb +0 -28
  53. data/fixtures/book_service/public/404.html +0 -30
  54. data/fixtures/book_service/public/422.html +0 -30
  55. data/fixtures/book_service/public/500.html +0 -30
  56. data/fixtures/book_service/public/dispatch.cgi +0 -10
  57. data/fixtures/book_service/public/dispatch.fcgi +0 -24
  58. data/fixtures/book_service/public/dispatch.rb +0 -10
  59. data/fixtures/book_service/public/favicon.ico +0 -0
  60. data/fixtures/book_service/public/images/rails.png +0 -0
  61. data/fixtures/book_service/public/index.html +0 -274
  62. data/fixtures/book_service/public/javascripts/application.js +0 -2
  63. data/fixtures/book_service/public/javascripts/controls.js +0 -963
  64. data/fixtures/book_service/public/javascripts/dragdrop.js +0 -972
  65. data/fixtures/book_service/public/javascripts/effects.js +0 -1120
  66. data/fixtures/book_service/public/javascripts/prototype.js +0 -4225
  67. data/fixtures/book_service/public/robots.txt +0 -5
  68. data/fixtures/book_service/public/stylesheets/scaffold.css +0 -53
  69. data/fixtures/book_service/script/about +0 -3
  70. data/fixtures/book_service/script/console +0 -3
  71. data/fixtures/book_service/script/dbconsole +0 -3
  72. data/fixtures/book_service/script/destroy +0 -3
  73. data/fixtures/book_service/script/generate +0 -3
  74. data/fixtures/book_service/script/performance/benchmarker +0 -3
  75. data/fixtures/book_service/script/performance/profiler +0 -3
  76. data/fixtures/book_service/script/performance/request +0 -3
  77. data/fixtures/book_service/script/plugin +0 -3
  78. data/fixtures/book_service/script/process/inspector +0 -3
  79. data/fixtures/book_service/script/process/reaper +0 -3
  80. data/fixtures/book_service/script/process/spawner +0 -3
  81. data/fixtures/book_service/script/runner +0 -3
  82. data/fixtures/book_service/script/server +0 -3
  83. data/fixtures/book_service/test/fixtures/books.yml +0 -9
  84. data/fixtures/book_service/test/fixtures/shelves.yml +0 -7
  85. data/fixtures/book_service/test/functional/books_controller_test.rb +0 -45
  86. data/fixtures/book_service/test/functional/shelf_controller_test.rb +0 -8
  87. data/fixtures/book_service/test/test_helper.rb +0 -38
  88. data/fixtures/book_service/test/unit/book_test.rb +0 -8
  89. data/fixtures/book_service/test/unit/shelf_test.rb +0 -8
  90. data/spec/create_spec.rb +0 -21
  91. data/spec/delete_spec.rb +0 -22
  92. data/spec/read_spec.rb +0 -101
  93. data/spec/update_spec.rb +0 -36
  94. data/stories/all.rb +0 -5
  95. data/stories/crud/create +0 -39
  96. data/stories/crud/delete +0 -9
  97. data/stories/crud/read +0 -36
  98. data/stories/crud/stories.rb +0 -18
  99. data/stories/crud/update +0 -44
  100. data/stories/helper.rb +0 -19
  101. data/stories/resources/helpers/book.rb +0 -7
  102. data/stories/resources/helpers/story_helper.rb +0 -2
  103. data/stories/resources/steps/read.rb +0 -35
  104. data/stories/resources/steps/using_rest_adapter.rb +0 -99
  105. data/tasks/stories.rb +0 -5
@@ -1,5 +0,0 @@
1
- # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
- #
3
- # To ban all spiders from the entire site uncomment the next two lines:
4
- # User-Agent: *
5
- # Disallow: /
@@ -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,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
3
- require 'commands/about'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
3
- require 'commands/console'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
3
- require 'commands/dbconsole'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
3
- require 'commands/destroy'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
3
- require 'commands/generate'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../../config/boot'
3
- require 'commands/performance/benchmarker'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../../config/boot'
3
- require 'commands/performance/profiler'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../../config/boot'
3
- require 'commands/performance/request'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
3
- require 'commands/plugin'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../../config/boot'
3
- require 'commands/process/inspector'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../../config/boot'
3
- require 'commands/process/reaper'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../../config/boot'
3
- require 'commands/process/spawner'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
3
- require 'commands/runner'
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
3
- require 'commands/server'
@@ -1,9 +0,0 @@
1
- # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
-
3
- one:
4
- title: MyString
5
- author: MyString
6
-
7
- two:
8
- title: MyString
9
- author: MyString
@@ -1,7 +0,0 @@
1
- # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
-
3
- # one:
4
- # column: value
5
- #
6
- # two:
7
- # column: value
@@ -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,8 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ShelfControllerTest < ActionController::TestCase
4
- # Replace this with your real tests.
5
- def test_truth
6
- assert true
7
- end
8
- 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
@@ -1,8 +0,0 @@
1
- require 'test_helper'
2
-
3
- class BookTest < ActiveSupport::TestCase
4
- # Replace this with your real tests.
5
- def test_truth
6
- assert true
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ShelfTest < ActiveSupport::TestCase
4
- # Replace this with your real tests.
5
- def test_truth
6
- assert true
7
- end
8
- 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