0
@@ -7,64 +7,73 @@ require File.join(File.dirname(__FILE__) , "helpers")
0
describe "A mapping declaration" do
0
handle( Waves::Dispatchers::NotFoundError ) { response.status = 404 }
0
- @resource = mock('resource')
0
@default = MappingApp::Resources::Default
0
- it "operates on app::Resources::Default when a resource is not specified" do
0
- mapping.response( :mapping_name, :get => [ "somewhere"] ) do
0
+ it "operates on the default resource when a resource is not specified" do
0
+ on( :get => [ "somewhere"] ) { resource }
0
- mock_request.get("/somewhere").body.should == "
MappingApp::Resources::Default"
0
+ mock_request.get("/somewhere").body.should == "
default"
0
it "may specify a resource in the options with a key of :resource" do
0
- mapping.response( :mapping_name, :resource => :smurf, :get => [ "somewhere"] ) do
0
+ on( :get => [ "somewhere"], :resource => :smurf ) { self.class.inspect }
0
mock_request.get("/somewhere").body.should == "MappingApp::Resources::Smurf"
0
it "may determine the resource using a parameter match in the path pattern" do
0
- mapping.response( :mapping_name, :get => [ :resources ]) { self.class.inspect }
0
- mapping.response( :mapping_name, :get => [ :resource ]) { self.class.inspect }
0
- mock_request.get("/blankets").body.should == "MappingApp::Resources::Blanket"
0
- mock_request.get("/blanket").body.should == "MappingApp::Resources::Blanket"
0
+ on( :get => [ :resource ]) { resources }
0
+ on( :get => [ "some", :resources ]) { singular }
0
+ mock_request.get("/blanket").body.should == "blankets"
0
+ mock_request.get("/some/blankets").body.should == "blanket"
0
-describe "A mapping
given a name as the first argument" do
0
+describe "A mapping
with an :as param" do
0
handle( Waves::Dispatchers::NotFoundError ) { response.status = 404 }
0
@resource = mock('resource')
0
@default = MappingApp::Resources::Default
0
- it "calls the method with the action name on the Resource
" do
0
+ it "calls the method with the action name on the Resource
when no block is supplied" do
0
@default.stub!(:new).and_return(@resource)
0
- @resource.should.receive(:smurf)
0
- mapping.response( :smurf, :get => [ "blue_critter" ] )
0
+ @resource.should.receive(:smurf).and_return("Smurfy")
0
+ on( :get => [ "blue_critter" ], :as => :smurf )
0
- mock_request.get("/blue_critter").status.should == 200
0
- it "defines a method on the Resource when a block is given" do
0
- mapping.response( :wizard, :get => [ :wizard ] ) { "Kill Smurfs!" }
0
+ mock_request.get("/blue_critter").body.should == "Smurfy"
0
- @default.new( mock('request') ).should.respond_to :wizard
0
+ @resource.should.not.receive(:leprechaun)
0
+ on( :get => [ "green_critter" ], :as => :leprechaun ) { "Gold!" }
0
+ mock_request.get("/green_critter").body.should == "Gold!"
0
it "defines a path generator on the Resource's Paths object" do
0
- mapping.response( :wizard, :get => [ :wizard ] ) { "Kill Smurfs!" }
0
+ on( :get => [ :wizard ], :as => :wizard ) { "Kill Smurfs!" }
0
paths = @default.new( mock('request') ).paths
0
paths.should.respond_to :wizard
0
describe "A mapping without a name" do
0
handle( Waves::Dispatchers::NotFoundError ) { response.status = 404 }
0
it "raises an ArgumentError when no block is supplied" do
0
- lambda { mapping.response( :get => [ "one" ] ) }.should.raise ArgumentError
0
+ mappings { on( :get => [ "one" ] ) }
0
+ end.should.raise ArgumentError
0
it "evaluates the supplied block instead of calling a resource method" do
0
- mapping.response( :get => [ "two" ] ) { "Brainy" }
0
+ on( :get => [ "two" ] ) { "Brainy" }
0
mock_request.get("/two").body.should == "Brainy"
Comments
No one has commented yet.