GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Resource-oriented open source Ruby framework for Web apps.
Homepage: http://rubywaves.com/
Clone URL: git://github.com/dyoder/waves.git
anonymous mappings raise when no block is supplied
automatthew (author)
Fri Jul 18 18:40:36 -0700 2008
commit  60daadd2a8407448a4060e69690d9669378e3cc9
tree    b838174a89c53f5b9d1da6a6f82cc2c5bafeee92
parent  7c35e7ef72f8c106e1cae5c755fcd913d7a5f848
...
19
20
21
 
22
23
24
...
19
20
21
22
23
24
25
0
@@ -19,6 +19,7 @@ module Waves
0
       def self.included( app )
0
 
0
         app.instance_eval do
0
+ include Waves::Layers::Inflect::English
0
           include Waves::Layers::Simple
0
         end
0
         
...
26
27
28
 
29
30
31
...
26
27
28
29
30
31
32
0
@@ -26,6 +26,7 @@ module Waves
0
           auto_create_class true, Waves::Configurations::Default
0
           auto_load :Mapping, :directories => [:configurations]
0
           auto_load true, :directories => [:configurations]
0
+ auto_create_module( :Mapping ) { extend Waves::Mapping }
0
         end
0
           
0
         app.auto_create_module( :Resources ) do
...
9
10
11
 
 
 
 
12
13
14
...
27
28
29
 
30
31
32
...
9
10
11
12
13
14
15
16
17
18
...
31
32
33
34
35
36
37
0
@@ -9,6 +9,10 @@ module Waves
0
     
0
     def mappings ; @mappings ||= Hash.new { |h,k| h[k] = [] } ; end
0
     
0
+ def clear
0
+ @mappings = Hash.new { |h,k| h[k] = [] }
0
+ end
0
+
0
     def method_missing( name, *args, &block )
0
       return super unless RULES.include? name
0
       args << block if block_given?
0
@@ -27,6 +31,7 @@ module Waves
0
     end
0
     functor( :map, Symbol, Hash ) { | name, options | options[:name] = name ; map( options ) }
0
     functor( :map, Hash ) do | options |
0
+ raise ArgumentError, "A mapping must have a name or a block" if !options[:name] && !options[:block]
0
       options = ( @options || {} ).merge( options )
0
       options[ :method ] = method = METHODS.find { |method| options[ method ] }
0
       options[ :path ] = options[ method ]
...
13
14
15
 
 
16
17
18
...
13
14
15
16
17
18
19
20
0
@@ -13,6 +13,8 @@ module Waves
0
       
0
       def resource
0
         params['resource'] || params['resources'].singular
0
+ rescue NoMethodError
0
+ :default
0
       end
0
       
0
       def resources
...
1
2
3
4
 
5
6
7
8
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
11
 
12
13
14
15
...
1
2
3
 
4
5
 
 
 
 
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
35
36
37
38
39
0
@@ -1,14 +1,38 @@
0
 # require 'test_helper' because RubyMate needs help
0
 require File.join(File.dirname(__FILE__) , "helpers")
0
 
0
-describe "An anonymous action mapping" do
0
+describe "A named action mapping" do
0
   
0
- it "does things" do
0
- mapping.module_eval do
0
- action( :get => [ :resources ] ) { "Brainy" }
0
- end
0
+ before do
0
+ mapping.clear
0
+ @resource = mock('resource')
0
+ ResourceMappingApp::Resources::Default.stub!(:new).and_return(@resource)
0
+ end
0
+
0
+ it "calls the method with the action name on the Resource" do
0
+ @resource.should.receive(:smurf)
0
+ mapping.action( :smurf, :get => [ "blue_critter" ] )
0
+
0
+ request.get("/blue_critter").status.should == 200
0
+ end
0
+
0
+
0
+end
0
+
0
+describe "An anonymous action mapping" do
0
+
0
+ before do
0
+ mapping.clear
0
+ end
0
+
0
+ it "raises an ArgumentError when no block is supplied" do
0
+ lambda { mapping.action( :get => [ "one" ] ) }.should.raise ArgumentError
0
+ end
0
+
0
+ it "uses the supplied block" do
0
+ mapping.action( :get => [ "two" ] ) { "Brainy" }
0
     
0
- request.get("/smurf").body.should == "Brainy"
0
+ request.get("/two").body.should == "Brainy"
0
   end
0
   
0
 end
0
\ No newline at end of file
...
2
3
4
5
 
6
7
8
9
...
2
3
4
 
5
6
7
8
9
0
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__) , "..", "helpers")
0
 
0
 # define basic app for use in testing
0
 # before methods may add to it using helper methods
0
-module ResourceMappingApp ; include Waves::Foundations::Simple ; end
0
+module ResourceMappingApp ; include Waves::Foundations::Default ; end
0
 Waves << ResourceMappingApp
0
 RMA = ResourceMappingApp
0
 Waves::Console.load( :mode => :development )
0
\ No newline at end of file

Comments

    No one has commented yet.