At 3:15 PM -0400 9/8/11, Stephen Bannasch wrote: >We are migrating an app to Rails 3 and some classes of views need to be >rendered without self-closing tags. > >We have thins in mime_types.rb: > > Mime::Type.register "text/xml", :otml > >We like to have haml use the :xhtml format when rendering a view like this and >the default for the application with other views? > >file: _show_otml.haml > >%OTQuestion{:local_id => ot_local_id_for(open_response)} > %prompt > %OTCompoundDoc > %bodyText= open_response.prompt > >Is this possible?
This problem is strange ... it seems to show up Haml::Template.options[:format]in rspec controller tests but not with curl ??? When I take a look at the response through the whole stack by using curl the returned XML comes back well-formed. Here's a short extract where you can see the <OTCssText> element is self-closed: http://localhost:3000/embeddable/open_responses/3.otml <cssBlocks> <OTCssText local_id='otml_css' src='/stylesheets/otml.css' /> </cssBlocks> I haven't initialized Haml::Template.options[:format] to anything so it's usingthe default value of :html5 But running this: bin/rspec spec/controllers/embeddable/open_responses_controller_spec.rb The <OTCssText> element is not closed and is invalid XML <cssBlocks> <OTCssText local_id='otml_css' src='/stylesheets/otml.css'> </cssBlocks The spec test starts like this: it "renders the requested #{model_ivar_name_lambda.call} as otml without error" do @model_class.stub!(:find).with("37").and_return(@model_ivar) get :show, :id => "37", :format => 'otml' assigns[@model_ivar_name].should equal(@model_ivar) response.should render_template(:show) The response.content_type is 'text/xml' response.header => {"Content-Type"=>"text/xml; charset=utf-8", "ETag"=>"\"91e2be08a38574a4059d1208e69e4ea7\"", "Cache-Control"=>"max-age=0, private, must-revalidate"} However if I specifically set the Haml format to :xhtml in the spec test like this: it "renders the requested #{model_ivar_name_lambda.call} as otml without error" do Haml::Template.options[:format] = :xhtml @model_class.stub!(:find).with("37").and_return(@model_ivar) get :show, :id => "37", :format => 'otml' assigns[@model_ivar_name].should equal(@model_ivar) response.should render_template(:show) Now the response is well-formed XML. It may be a problem with rspec, rspec-rails, haml or the ActionController::TestResponse rspec delagates to ??? I'd like to expect that I'll get the same rendered content running my tests as when the app runs. -- You received this message because you are subscribed to the Google Groups "Haml" group. To post to this group, send email to haml@googlegroups.com. To unsubscribe from this group, send email to haml+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/haml?hl=en.