Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

NoMethodError on formats= when using ActionController::TestCase to test a direct subclass of ActionController::Metal

#5393

When using ActionController::TestCase to test a direct subclass of ActionController::Metal, the test case raises a NoMethodError on formats=. To see this in action:

  1. Type the following in a shell:
rails new example
cd example
rake db:migrate
  1. Add test/functional/widgets_controller_test.rb with the following code:
require 'test_helper'

class WidgetsControllerTest < ActionController::TestCase
  test "GET index" do
    get :index
  end
end
  1. Add app/controllers/widgets_controller.rb with the following code:
class WidgetsController < ActionController::Metal
  def index
  end
end
  1. Run the test:
rake test:functionals
...
  1) Error:
test_GET_index(WidgetsControllerTest):
NoMethodError: undefined method `formats=' for #<WidgetsController:0x101e601e8>
    /test/functional/widgets_controller_test.rb:5:in `test_GET_index'

Reported by David Chelimsky · August 17th, 2010 @ 01:15 PM

State: stale
Milestone: 3.1
Assigned to: Santiago Pastorino Santiago Pastorino
Importance: Low

Activity

  1. David Chelimsky
    David Chelimsky
    • Assigned user set to José Valim

    August 17th, 2010 @ 01:15 PM

  2. Santiago Pastorino
    Santiago Pastorino
    • Milestone cleared.
    • State changed from new to open
    • Assigned user changed from José Valim to Santiago Pastorino
    • Importance changed from to Low

    Hey David can you add a test case

    August 19th, 2010 @ 08:07 PM

  3. Rohit Arondekar
    Rohit Arondekar

    I'm sorry if this is a silly question, but why would you want to call get :index in a functional test?

    From what I gather, the docs say that AC::Metal is for obtaining Rack app for an action.

    ActionController::Metal provides an #action method that returns a valid Rack application for a given action.

    From the AC::Metal docs

    Also the line that's causing the error is in actionpack/lib/action_controller/metal/rendering:10

        def process_action(*) #:nodoc:
          self.formats = request.formats.map { |x| x.to_sym }
          super
        end
    

    But in the whole of Actionpack there is only one formats= method defined in lib/action_view/lookup_context.rb so why was this line added in Metal?

    Again I apologize if I have missed something obvious.

    August 25th, 2010 @ 04:10 AM

  4. Jeremy Kemper
  5. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 11th, 2010 @ 12:09 PM

  6. Jeremy Kemper
  7. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 19th, 2010 @ 08:35 AM

  8. Jeff Kreeftmeijer
  9. Repository
  10. Santiago Pastorino
    Santiago Pastorino
    • State changed from committed to open
    • Milestone changed from 3.0.2 to 3.1

    November 6th, 2010 @ 11:20 PM

  11. Jeff Kreeftmeijer
  12. Santiago Pastorino
    Santiago Pastorino

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 9th, 2011 @ 12:31 AM

  13. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 9th, 2011 @ 12:32 AM