Changeset 1320
- Timestamp:
- 01/18/08 13:03:46 (9 months ago)
- Files:
-
- trunk/lib/merb/mixins/render.rb (modified) (2 diffs)
- trunk/spec/fixtures/controllers/render_spec_controllers.rb (modified) (1 diff)
- trunk/spec/merb/render_spec.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/merb/mixins/render.rb
r1249 r1320 118 118 # end 119 119 # 120 # This will first check to see if a index.xml.* template extists, if not 121 # it will call @people.to_xml (as defined in the add_mime_type method) on the passed 122 # in object if such a method exists for the current content_type 120 # This will first check to see if a index.xml.* template extists, if not 121 # it will call @people.to_xml (as defined in the add_mime_type method) on the passed 122 # in object if such a method exists for the current content_type 123 # 124 # Conversely, there may be situations where you prefer to be more literal 125 # such as when you desire to render a Hash, for those occasions, the 126 # the following syntax exists: 127 # 128 # class People < Application 129 # provides :xml 130 # 131 # def index 132 # @people = User.all 133 # render :obj => @people 134 # end 135 # end 123 136 # 124 137 # When using multiple calls to render in one action, the context of the render is cached for performance reasons … … 140 153 141 154 # Handles the case where render is called with an object 142 if obj = args.first 155 if obj = args.first || opts[:obj] 143 156 # Check for a template 144 157 unless find_template({:action => action}.merge(opts)) trunk/spec/fixtures/controllers/render_spec_controllers.rb
r1254 r1320 59 59 @foo = FakeModel.new 60 60 render @foo 61 end 62 63 end 64 65 class RenderHashObjectController < Merb::Controller 66 67 def render_object 68 provides :xml,:json 69 @foo = {:foo => 'bar', :baz => 'quuz'} 70 render :obj => @foo 61 71 end 62 72 trunk/spec/merb/render_spec.rb
r1228 r1320 413 413 end 414 414 415 describe "Merb rendering with a hash object calls to_json or to_xml on the object" do 416 417 it "render :obj => @foo should call @foo.to_json when json is requested" do 418 c = new_spec_controller(:format => 'json', :controller => 'RenderHashObjectController') 419 c.dispatch(:render_object) 420 c.body.should == "{\"foo\": \"bar\", \"baz\": \"quuz\"}" 421 end 422 423 it "render @foo should call @foo.to_xml when xml is requested" do 424 c = new_spec_controller(:format => 'xml', :controller => 'RenderHashObjectController') 425 c.dispatch(:render_object) 426 c.body.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <foo>bar</foo>\n <baz>quuz</baz>\n</hash>\n" 427 end 428 429 end 430 415 431 describe "Merb rendering with an object and using a block/lambda for provides" do 416 432
