-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start new way to do integration test with rails app proxying the restbuy
xml/json
- Loading branch information
Showing
79 changed files
with
22,439 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
*.swp | ||
.rvmrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.bundle | ||
db/*.sqlite3 | ||
log/*.log | ||
tmp/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.