Permalink
Browse files

start new way to do integration test with rails app proxying the restbuy

xml/json
  • Loading branch information...
cairesvs committed Dec 29, 2010
1 parent 3dccaef commit 7c4ec1e2defc700a7f1554d6abe44bb46a92bac8
Showing with 22,439 additions and 160 deletions.
  1. +1 −0 .gitignore
  2. +12 −12 client/lib/restfulie.js
  3. +13 −139 client/spec/unit/spec.js
  4. +4 −0 proxyfier/.gitignore
  5. +33 −0 proxyfier/Gemfile
  6. +90 −0 proxyfier/Gemfile.lock
  7. +256 −0 proxyfier/README
  8. +7 −0 proxyfier/Rakefile
  9. +3 −0 proxyfier/app/controllers/application_controller.rb
  10. +13 −0 proxyfier/app/controllers/proxy_controller.rb
  11. +2 −0 proxyfier/app/helpers/application_helper.rb
  12. +2 −0 proxyfier/app/helpers/proxy_helper.rb
  13. +14 −0 proxyfier/app/views/layouts/application.html.erb
  14. +26 −0 proxyfier/app/views/proxy/index.html.erb
  15. +4 −0 proxyfier/config.ru
  16. +42 −0 proxyfier/config/application.rb
  17. +13 −0 proxyfier/config/boot.rb
  18. +22 −0 proxyfier/config/database.yml
  19. +5 −0 proxyfier/config/environment.rb
  20. +26 −0 proxyfier/config/environments/development.rb
  21. +49 −0 proxyfier/config/environments/production.rb
  22. +35 −0 proxyfier/config/environments/test.rb
  23. +7 −0 proxyfier/config/initializers/backtrace_silencers.rb
  24. +10 −0 proxyfier/config/initializers/inflections.rb
  25. +5 −0 proxyfier/config/initializers/mime_types.rb
  26. +7 −0 proxyfier/config/initializers/secret_token.rb
  27. +8 −0 proxyfier/config/initializers/session_store.rb
  28. +5 −0 proxyfier/config/locales/en.yml
  29. +5 −0 proxyfier/config/routes.rb
  30. +7 −0 proxyfier/db/seeds.rb
  31. +2 −0 proxyfier/doc/README_FOR_APP
  32. 0 proxyfier/lib/tasks/.gitkeep
  33. +26 −0 proxyfier/public/404.html
  34. +26 −0 proxyfier/public/422.html
  35. +26 −0 proxyfier/public/500.html
  36. 0 proxyfier/public/favicon.ico
  37. BIN proxyfier/public/images/rails.png
  38. +2 −0 proxyfier/public/javascripts/application.js
  39. +965 −0 proxyfier/public/javascripts/controls.js
  40. +974 −0 proxyfier/public/javascripts/dragdrop.js
  41. +1,123 −0 proxyfier/public/javascripts/effects.js
  42. +167 −0 proxyfier/public/javascripts/jquery.min.js
  43. +175 −0 proxyfier/public/javascripts/rails.js
  44. +1,008 −0 proxyfier/public/javascripts/restfulie.js
  45. +5 −0 proxyfier/public/robots.txt
  46. +19 −0 proxyfier/public/spec/commands/example_command.rb
  47. +1 −0 proxyfier/public/spec/fixtures/page.html
  48. BIN proxyfier/public/spec/lib/images/bg.png
  49. BIN proxyfier/public/spec/lib/images/hr.png
  50. BIN proxyfier/public/spec/lib/images/loading.gif
  51. BIN proxyfier/public/spec/lib/images/sprites.bg.png
  52. BIN proxyfier/public/spec/lib/images/sprites.png
  53. BIN proxyfier/public/spec/lib/images/vr.png
  54. +149 −0 proxyfier/public/spec/lib/jspec.css
  55. +115 −0 proxyfier/public/spec/lib/jspec.growl.js
  56. +79 −0 proxyfier/public/spec/lib/jspec.jquery.js
  57. +1,893 −0 proxyfier/public/spec/lib/jspec.js
  58. +18 −0 proxyfier/public/spec/lib/jspec.nodejs.js
  59. +39 −0 proxyfier/public/spec/lib/jspec.shell.js
  60. +90 −0 proxyfier/public/spec/lib/jspec.timers.js
  61. +210 −0 proxyfier/public/spec/lib/jspec.xhr.js
  62. +17 −0 proxyfier/public/spec/rhino.js
  63. +23 −0 proxyfier/public/spec/server.html
  64. +4 −0 proxyfier/public/spec/server.rb
  65. +10,118 −0 proxyfier/public/spec/support/env.js
  66. +4,376 −0 proxyfier/public/spec/support/jquery.js
  67. BIN proxyfier/public/spec/support/js.jar
  68. 0 proxyfier/public/spec/unit/spec.helper.js
  69. +11 −0 proxyfier/public/spec/unit/spec.js
  70. 0 proxyfier/public/stylesheets/.gitkeep
  71. +6 −0 proxyfier/script/rails
  72. +8 −0 proxyfier/test/functional/proxy_controller_test.rb
  73. +9 −0 proxyfier/test/performance/browsing_test.rb
  74. +13 −0 proxyfier/test/test_helper.rb
  75. +4 −0 proxyfier/test/unit/helpers/proxy_helper_test.rb
  76. 0 proxyfier/vendor/plugins/.gitkeep
  77. +10 −7 restfulie.js
  78. +1 −1 restfulie.min.js
  79. +1 −1 server
View
@@ -1 +1,2 @@
*.swp
+.rvmrc
View
@@ -34,10 +34,10 @@ var Restfulie = {};
};
// Default accepts should add all known media types
- for (var format in Converters.mediaTypes)
+ for (var format in Converters.mediaTypes){
if ("register getMediaType".indexOf(format)==-1)
this.headers["Accept"] += (this.headers["Accept"]=='' ? '':', ') +format;
-
+ }
// configure accept
this.accepts = function(accept){
@@ -131,7 +131,7 @@ var Restfulie = {};
return addResponseXHR(resource,xhr);
},
"200" : function(xhr,entryPoint){
- var resource = {};
+ var resource = {};
return addResponseXHR(resource, xhr);
},
"201" : function(xhr,entryPoint){
@@ -142,17 +142,17 @@ var Restfulie = {};
}
function getResponseHeadersFrom(xhr) {
- headers = {};
- headerLinks = {};
- responseHeaders = xhr.getAllResponseHeaders().split("\n");
+ var headers = {};
+ var headerLinks = {};
+ var responseHeaders = xhr.getAllResponseHeaders().split("\n");
for(headerName in responseHeaders){
- headerData = responseHeaders[headerName].split(':');
- header = headerData[0];
- value = headerData[1];
+ var headerData = responseHeaders[headerName].split(':');
+ var header = headerData[0];
+ var value = headerData[1];
if (header == 'Link'){
- linkData = value.split(";");
- url = linkData[0].trim().replace(/<|>/g, '');
- rel = linkData[1].split('=')[1].replace(/"+/g, '').trim();
+ var linkData = value.split(";");
+ var url = linkData[0].trim().replace(/<|>/g, '');
+ var rel = linkData[1].split('=')[1].replace(/"+/g, '').trim();
headerLinks[rel] = Restfulie.at(url).accepts(xhr.getResponseHeader("Content-Type").split(";")[0]);
}else{
if (value){
View
@@ -1,140 +1,14 @@
-
-describe 'Restfulie for javascript'
- describe 'core'
- it 'should unmarshall when response was successful'
- r = Restfulie.at("http://localhost:3000/items").accepts('application/xml').get();
- r.items.item[0].price.should.equal 10
- r.response.body.should.not.be_null
- r.response.code.should.equal 200
- end
-
- it 'should work with 4** error codes'
- r = Restfulie.at("http://localhost:3000/notfound").get();
- r.response.code.should.equal 404
- end
-
- it 'should follow 201 responses'
- r = Restfulie.at("http://localhost:3000/items/1").get();
- r.item.price = 20;
- result = Restfulie.at("http://localhost:3000/items").post(r);
- result.item.id.should.not.equal r.item.id
- end
-
- it 'should allow media type registration through a registry'
- type = {
- marshal : function(object){},
- unmarshal : function(request){}
- };
- Restfulie.media_types.register("application/amf",type);
- Restfulie.media_types['application/amf'].should.equal type
- end
-
- it 'should support xml retrieval'
- r = Restfulie.at("http://localhost:3000/items").accepts("application/xml").get();
- r.items.item[0].price.should.equal 10
- r.response.body.should.not.be_null
- r.response.code.should.equal 200
- end
-
- it 'should support xml marshalling'
- r = Restfulie.at("http://localhost:3000/items/1").accepts("application/xml").get();
- r.item.price.should.equal 10
- r.response.body.should.not.be_null
- r.response.code.should.equal 200
- r.item.price = 500
- rn = Restfulie.at("http://localhost:3000/items").as("application/xml").post(r);
- rn.response.body.should.not.be_null
- rn.response.code.should.equal 200
- rn.item.price.should.equal 500
- end
-
- it 'should post the content if its a string'
- rn = Restfulie.at("http://localhost:3000/items").as("application/xml").post("<item><name>Calpis</name><price>500</price></item>");
- rn.response.body.should.not.be_null
- rn.response.code.should.equal 200
- rn.item.price.should.equal 500
- end
-
- it 'should add all known media types as default accepts'
- entryPoint = Restfulie.at("http://localhost:3000/items");
- entryPoint.headers['Accept'].indexOf("application/xml").should.not.equal -1
- entryPoint.headers['Accept'].indexOf("application/json").should.not.equal -1
- end
-
- it 'should allow the representation to follow those links'
- resource = Restfulie.at("http://localhost:3000/items").accepts("application/xml").get();
- itemForList = resource.items.item[0];
- itemForLink = itemForList.links["self"].get();
- itemForLink.item.id.should.equal itemForList.id
- end
-
- it 'Support link following for json'
- resource = Restfulie.at("http://localhost:3000/items").accepts("application/json").get();
- itemForList = resource.items[0];
- itemForLink = itemForList.links["self"].get();
- itemForLink.item.id.should.equal itemForList.id
- end
-
- it 'should follow header links'
- json_one = '{"item":{"price":10.0,"name":"Calpis","created_at":"2010-04-20T14:19:25Z","updated_at":"2010-04-20T14:19:25Z","id":1}}';
- json_two = '{"item":{"price":10.0,"name":"Calpis","created_at":"2010-04-20T14:19:25Z","updated_at":"2010-04-20T14:19:25Z","id":2}}';
-
- mock_request().and_return(json_one, 'application/json', 200,{Link: ' </items/two>; rel="two"'});
- h_one = Restfulie.at("http://restfulie.js/items/one").accepts("application/json").get();
-
- mock_request().and_return(json_two, 'application/json', 200, {Link: ' </items/one>; rel="one"'});
- h_two = h_one.response.headers.links['two'].get();
-
- h_two.item.id.should.equal 2
- end
-
- end
-
- describe 'Rest from scratch examples'
- describe 'Part 1'
- it 'should get items with default response format'
- h = Restfulie.at('http://localhost:3000/items').get();
-
- h.items.length.should.be_greater_than 0
- h.items[0].name.should.equal "Calpis"
- h.items[0].price.should.equal 10
- end
-
- it 'should get items when I request specific format, in this case json'
- h = Restfulie.at('http://localhost:3000/items').accepts("application/json").get();
-
- h.items.length.should.be_greater_than 0
- h.items[0].name.should.equal "Calpis"
- h.items[0].price.should.equal 10
-
- h.response.code.should.equal 200
- h.response.headers['Content-Type'].indexOf('application/json').should.equal 0
- end
-
- it 'should create an item using a xml representation of an item'
- xml = {
- item: {
- name:'calpis_xml',
- price:3
- }
- };
- h = Restfulie.at("http://localhost:3000/items").as("application/xml").post(xml);
- h.item.price.should.equal 3
- h.item.name.should.equal 'calpis_xml'
- end
-
- it 'should create an item using a json representation of an item'
- json = {
- item: {
- name:'calpis_json',
- price:3
- }
- };
- h = Restfulie.at("http://localhost:3000/items").as("application/json").post(json);
- h.item.price.should.equal 3
- h.item.name.should.equal 'calpis_json'
- end
- end
- end
-end
+function search (what) {
+ var description = Restfulie.at("http://localhost:3000/products/opensearch.xml").accepts('application/opensearchdescription+xml').get().resource();
+}
+
+JSpec.describe('Restfulie for Javascript', function(){
+ describe('when searching', function(){
+ it('should be able to search', function(){
+ var description = Restfulie.at("http://localhost:3000/products/opensearch.xml").accepts('application/opensearchdescription+xml').get().resource();
+ //var items = description.use("application/atom+xml").search({searchTerms : "20", startPage : 1});
+ //items.resource.entries.size.should.equal 2
+ });
+ });
+});
View
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
View
@@ -0,0 +1,33 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.0'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3-ruby', :require => 'sqlite3'
+gem 'restfulie', "= 1.0.0.beta1"
+gem 'debuggie'
+gem 'respondie'
+
+# Use unicorn as the web server
+gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug'
+
+# Bundle the extra gems:
+# gem 'bj'
+# gem 'nokogiri'
+# gem 'sqlite3-ruby', :require => 'sqlite3'
+# gem 'aws-s3', :require => 'aws/s3'
+
+# Bundle gems for the local environment. Make sure to
+# put test-only gems in this group so their generators
+# and rake tasks are available in development mode:
+# group :development, :test do
+# gem 'webrat'
+# end
View
@@ -0,0 +1,90 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.0)
+ actionpack (= 3.0.0)
+ mail (~> 2.2.5)
+ actionpack (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4.1)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.12)
+ rack-test (~> 0.5.4)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.0)
+ activesupport (= 3.0.0)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activerecord (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ arel (~> 1.0.0)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.0)
+ activemodel (= 3.0.0)
+ activesupport (= 3.0.0)
+ activesupport (3.0.0)
+ arel (1.0.1)
+ activesupport (~> 3.0.0)
+ builder (2.1.2)
+ debuggie (0.9.0)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.4.1)
+ json_pure (1.4.6)
+ kgio (2.1.1)
+ mail (2.2.5)
+ activesupport (>= 2.3.6)
+ mime-types
+ treetop (>= 1.4.5)
+ mime-types (1.16)
+ nokogiri (1.4.4)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.6)
+ rack (>= 1.0)
+ rails (3.0.0)
+ actionmailer (= 3.0.0)
+ actionpack (= 3.0.0)
+ activerecord (= 3.0.0)
+ activeresource (= 3.0.0)
+ activesupport (= 3.0.0)
+ bundler (~> 1.0.0)
+ railties (= 3.0.0)
+ railties (3.0.0)
+ actionpack (= 3.0.0)
+ activesupport (= 3.0.0)
+ rake (>= 0.8.4)
+ thor (~> 0.14.0)
+ rake (0.8.7)
+ respondie (0.9.0)
+ restfulie (1.0.0.beta1)
+ actionpack (>= 2.3.2)
+ activesupport (>= 2.3.2)
+ json_pure (>= 1.2.4)
+ nokogiri (>= 1.4.2)
+ sqlite3-ruby (1.3.1)
+ thor (0.14.0)
+ treetop (1.4.8)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.23)
+ unicorn (3.2.1)
+ kgio (~> 2.1)
+ rack
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ debuggie
+ rails (= 3.0.0)
+ respondie
+ restfulie (= 1.0.0.beta1)
+ sqlite3-ruby
+ unicorn
Oops, something went wrong.

0 comments on commit 7c4ec1e

Please sign in to comment.