Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.0.0.beta1 --api rendering does not follow status: on certain content types #23142

Closed
bbonamin opened this issue Jan 20, 2016 · 3 comments
Closed

Comments

@bbonamin
Copy link

Sample repo: https://github.com/bbonamin/render-content-type-status-api
(app generated with rails new --api)

In https://github.com/bbonamin/render-content-type-status-api/blob/master/app/controllers/status_controller.rb

render json: {what: 'oops!'}, status: 500
Renders with 500 Internal Server Error √

render plain: 'oops!', status: 500
Renders with status 200 OK (500 is expected)

This also happens with render text: 'foo', status: 500

An app created without --api works as expected, I suspect this behavior might be coming from somewhere related to ActionController::API

Thanks 😄

@rafaelfranca rafaelfranca added this to the 5.0.0 milestone Jan 20, 2016
@maclover7
Copy link
Contributor

Failing reproduction script:

require 'action_controller/railtie'
require 'minitest/autorun'
require 'rack/test'

class TestApp < Rails::Application
  config.root = File.dirname(__FILE__)
  config.session_store :cookie_store, key: 'cookie_store_key'
  secrets.secret_token    = 'secret_token'
  secrets.secret_key_base = 'secret_key_base'

  config.logger = Logger.new($stdout)
  Rails.logger  = config.logger

  routes.draw do
    get '/test500_plain' => 'test#plain'
    get '/test500_text' => 'test#text'
  end
end

ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)

class TestController < ActionController::API
  include Rails.application.routes.url_helpers

  def plain
    render plain: 'Home', status: 500
  end

  def text
    render text: 'Home', status: 500
  end
end

class BugTest < Minitest::Test
  include Rack::Test::Methods

  def test_plain
    get '/test500_plain'
    assert_equal(500, last_response.status)
  end

  def test_text
    get '/test500_text'
    assert_equal(500, last_response.status)
  end

  private
    def app
      Rails.application
    end
end

@maclover7
Copy link
Contributor

Ran a git bisect, broken commit is 38818c9.

maclover7 added a commit to maclover7/rails that referenced this issue Jan 21, 2016
- Fixes bug rails#23142.
- Bug was occurring only with ActionController::API, because `_process_options` wasn't being run for API requests, even though it was being run for normal app requests.
@maclover7
Copy link
Contributor

Opened PR to try and solve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants