This project is archived and is in readonly mode.

#1783 ✓resolved
gaffo

Explicitly setting the content type get overriden by respond_to / render

Reported by gaffo | January 20th, 2009 @ 03:51 AM | in 3.0.2

When doing the following, the content type which is explicitly set is being overridden.

class Admin::NotificationsController < Admin::AdminController

def show

@notification = Notification.find(params[:id])
respond_to do |format|
  format.html do
    content = render_to_string :layout => false,
                               :template => 'notification_mailer/notify.text.html.rhtml'
    content = "<head><title>Subject: #{@notification.subject}</title></head>#{content}"
    render :text => content, :content_type => :html
  end
  format.txt do
    content = render_to_string :layout => false,
                               :template => 'notification_mailer/notify.text.plain.rhtml'
    content = "Subject: #{@notification.subject}\n\n\n#{content}"
    render :text => content, :content_type => :text
  end
end

end

end

class Admin::NotificationsControllerTest < ActionController::TestCase def test_html_output_from_html_method

@request.env['HTTP_ACCEPT'] = "text/html"
get(:show, {:format => 'html', :id => "1"}, session_for_user(:admin_user) )
assert_response(:success)
assert_tag :tag => "table"
assert_equal("text/html; charset=utf-8", @response.headers["type"])

end

def test_html_not_output_from_plain_method

get( :show, {:format => 'txt', :id => "1"}, session_for_user(:admin_user) )
assert_response(:success)
assert_no_tag :tag => "html"
assert_equal("text/plain; charset=utf-8", @response.headers["type"])

end end

1) Failure: test_html_not_output_from_plain_method(Admin::NotificationsControllerTest)

[test/functional/admin/notifications_controller_test.rb:24:in `test_html_not_output_from_plain_method'
 /shared/home/mike.gaffney/workspace/git-ruby/vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:94:in `__send__'
 /shared/home/mike.gaffney/workspace/git-ruby/vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:94:in `run']:

<"text/plain; charset=utf-8"> expected but was <"text; charset=utf-8">.

2) Failure: test_html_output_from_html_method(Admin::NotificationsControllerTest)

[test/functional/admin/notifications_controller_test.rb:17:in `test_html_output_from_html_method'
 /shared/home/mike.gaffney/workspace/git-ruby/vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:94:in `__send__'
 /shared/home/mike.gaffney/workspace/git-ruby/vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:94:in `run']:

<"text/html; charset=utf-8"> expected but was <"html; charset=utf-8">.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Tags

Pages