Created
June 14, 2009 22:49
-
-
Save cloudhead/129852 to your computer and use it in GitHub Desktop.
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
require 'spec_helper' | |
Journey.map :Cow | |
module Cow | |
class Glass < Journey::Resource | |
def show id | |
["milk", @input["milk"], "glass", id].join '/' | |
end | |
def create | |
"opacity=#{@input['opacity']}&milk=#{@input['milk']}" | |
end | |
end | |
class Milk < Journey::Resource | |
def create | |
return 201 => @input['colour'] | |
end | |
def show id | |
id | |
end | |
def index | |
return 200 => "index" | |
end | |
def new | |
'new' | |
end | |
def destroy id | |
ok | |
end | |
def update id | |
"#{id} is #{@input['colour']}" | |
end | |
end | |
end | |
describe Journey do | |
before(:each) do | |
@req = Rack::MockRequest.new Journey.begin | |
end | |
it "should respond to valid requests" do | |
@req.get('/milk').status.should == Journey::HTTP::OK | |
@req.get('/milk').body.should == "index" | |
@req.get('/milk/1').body.should == "1" | |
@req.post('/milk', {input: 'colour=white'}).status.should == Journey::HTTP::Created | |
@req.post('/milk', {input: 'colour=white'}).body.should == 'white' | |
@req.put('/milk/1', {input: 'colour=white'}).body.should == '1 is white' | |
@req.delete('/milk/1').status.should == Journey::HTTP::OK | |
@req.get('/milk/new').body.should == 'new' | |
end | |
it "should respond to nested requests" do | |
@req.get('/milk/1/glass/3').body.should == 'milk/1/glass/3' | |
@req.post('/milk/1/glass/', {input: "opacity=0"}).body.should == "opacity=0&milk=1" | |
end | |
it "should report invalid requests" do | |
@req.get( '/banana').status.should == Journey::HTTP::NotFound | |
@req.get( '/').status.should == Journey::HTTP::BadRequest | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment