public
Description: response for lets you decorate your actions respond_to blocks
Homepage: http://blog.ardes.com/response_for
Clone URL: git://github.com/ianwhite/response_for.git
Click here to lend your support to: response_for and make a donation at www.pledgie.com !
Added some specs to bring C2 up to 100%, caught a bug introduced by changes in 
edge
ianwhite (author)
Wed Apr 30 08:43:59 -0700 2008
commit  1b82c3926db29402ab28207f3ac4e9e1c6c8c9b7
tree    135e52e28be0ef98b10c1234dd62b1ccca7ea4fc
parent  8ab63ae5dcbff171a619e5a7c9e2bfe29fcc9085
...
162
163
164
165
 
166
167
168
...
162
163
164
 
165
166
167
168
0
@@ -162,7 +162,7 @@ module Ardes #:nodoc:
0
     # This allows actions without an explicit respond_to block to be decorated
0
     # with response_for
0
     def render_with_response_for(*args, &block)
0
-      if !instance_variable_get('@performed_respond_to') && !block_given? && args.reject(&:nil?) == [] && self.class.send(:action_responses)[action_name]
0
+      if !instance_variable_get('@performed_respond_to') && self.class.send(:action_responses)[action_name] && !block_given? && args.reject{|a| a.nil? || a.empty?}.empty?
0
         respond_to
0
         return if performed?
0
       end
...
11
12
13
 
 
 
 
14
15
16
...
11
12
13
14
15
16
17
18
19
20
0
@@ -11,6 +11,10 @@ class FooController < ApplicationController
0
     respond_to(:json)
0
     erase_render_results
0
   end
0
+  
0
+  def baz
0
+    # no respond_to block in here, but we can still supplu one with response_for
0
+  end
0
 end
0
 
0
 class XmlFooController < FooController
...
5
6
7
 
 
 
 
8
9
10
...
16
17
18
 
19
20
21
 
22
23
24
 
 
 
 
 
25
26
27
...
29
30
31
32
 
33
34
35
...
5
6
7
8
9
10
11
12
13
14
...
20
21
22
23
24
25
 
26
27
28
29
30
31
32
33
34
35
36
37
...
39
40
41
 
42
43
44
45
0
@@ -5,6 +5,10 @@ class FooAController < FooController
0
   response_for :foo do |format|
0
     format.html { a }
0
   end
0
+  
0
+  response_for :baz do |format|
0
+    format.html { bazza }
0
+  end
0
 end
0
 
0
 class FooBController < FooAController
0
@@ -16,12 +20,18 @@ end
0
 describe FooAController do
0
   before do
0
     @controller.stub!(:a)
0
+    @controller.stub!(:bazza)
0
   end
0
   
0
-  it "get :foo should call :b" do
0
+  it "get :foo should call a" do
0
     @controller.should_receive(:a)
0
     get :foo
0
   end
0
+  
0
+  it "get :baz should call bazza (inside the response_for block)" do
0
+    @controller.should_receive(:bazza)
0
+    get :baz
0
+  end
0
 end
0
 
0
 describe FooBController do
0
@@ -29,7 +39,7 @@ describe FooBController do
0
     @controller.stub!(:b)
0
   end
0
   
0
-  it "get :foo should call :b" do
0
+  it "get :foo should call b" do
0
     @controller.should_receive(:b)
0
     get :foo
0
   end

Comments