public
Rubygem
Description: RSpec extension library for Ruby on Rails
Homepage:
Clone URL: git://github.com/dchelimsky/rspec-rails.git
reduce monkey patching of rails in code example for render :partial => array
David Chelimsky (author)
Sun Aug 24 08:18:14 -0700 2008
commit  b408c45fbf4369f528bf1ed8c2ae66e5b703dfe0
tree    37e0576bfb9c3d5ac50d1fbc1c6491cf15f8403b
parent  f909c0d9af01a33ab5a842715e195b3c3b8e7fcd
...
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
 
 
 
181
182
183
 
184
185
 
186
187
188
...
151
152
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
155
156
157
158
 
159
160
 
161
162
163
164
0
@@ -151,38 +151,14 @@ end
0
 
0
 describe "A view that includes a partial using an array as partial_path", :type => :view do
0
   before(:each) do
0
-    module ActionView::Partials
0
-      def render_template_with_partial_with_array_support(partial_path, local_assigns = nil, deprecated_local_assigns = nil)
0
-        if partial_path.is_a?(Array)
0
-          "Array Partial"
0
-        else
0
-          begin
0
-            render_partial_without_array_support(partial_path, local_assigns, deprecated_local_assigns)
0
-          rescue ArgumentError
0
-            render_partial_without_array_support(partial_path)
0
-          end
0
-        end
0
-      end
0
-
0
-      alias :render_partial_without_array_support :render_partial
0
-      alias :render_partial :render_template_with_partial_with_array_support
0
-    end
0
-
0
-    @array = ['Alice', 'Bob']
0
-    assigns[:array] = @array
0
-  end
0
-
0
-  after(:each) do
0
-    module ActionView::Partials
0
-      alias :render_template_with_partial_with_array_support :render_partial
0
-      alias :render_partial :render_partial_without_array_support
0
-      undef render_template_with_partial_with_array_support
0
-    end
0
+    renderable_object = Object.new
0
+    renderable_object.stub!(:name).and_return("Renderable Object")
0
+    assigns[:array] = [renderable_object]
0
   end
0
 
0
-  it "should render have the array passed through to render_partial without modification" do
0
+  it "should render the array passed through to render_partial without modification" do
0
     render "view_spec/template_with_partial_with_array" 
0
-    response.body.should match(/^Array Partial$/)
0
+    response.body.should match(/^Renderable Object$/)
0
   end
0
 end
0
 

Comments