This project is archived and is in readonly mode.

#1572 ✓invalid
Patrick

undefined method `server_name' for #<ActionController::TestRequest

Reported by Patrick | December 14th, 2008 @ 06:20 PM | in 2.x

Hi, while starting to setup functional tests for my application I received the following error:

NoMethodError: undefined method server_name' for

<ActionController::TestRequest

which is coming from an instance variable I'm setting up in my application controller.

@domain = Domain.find_or_create_by_name(request.server_name)

I'm using rails 2.0.2, any guidance would be appreciated.

Comments and changes to this ticket

  • Patrick

    Patrick December 15th, 2008 @ 07:46 PM

    • Assigned user set to “Frederick Cheung”
  • Roger

    Roger December 16th, 2008 @ 09:20 PM

    I assume that this is for a "related" database [connected] and should work [and normally does?]

  • Frederick Cheung

    Frederick Cheung December 16th, 2008 @ 11:58 PM

    the server_name method just isn't defined on the fake requests that passed in. It should be hard to add this, similar to how user_agent or host are set (in test_process.rb).

    Alternatively you could always stick

    
    def setup
      def @request.server_name
        "foo.bar"
      end
    end
    

    in the relevant test cases

  • Patrick

    Patrick December 17th, 2008 @ 03:53 PM

    Thanks for getting back to me, I appreciate it.

    Yes, it works fine outside the normal "testing" context.

    Regarding Fredricks's response. I thought I tried that inside my functional test, but still received the error. Let me try it again though.

  • Patrick

    Patrick December 17th, 2008 @ 04:54 PM

    The other thing is that this test is relevant in all my test cases, but let me try the work around out again.

  • Patrick

    Patrick December 18th, 2008 @ 03:17 PM

    I still get the same error:

    NoMethodError: undefined method server_name' for <ActionController::TestRequest

    when defining

    def setup def @request.server_name

    "127.0.0.1"
    
    

    end end

    in the test case specifically.

  • Patrick

    Patrick January 13th, 2009 @ 02:12 AM

    Any other recommendations for this one?

  • Pratik

    Pratik March 13th, 2009 @ 11:01 AM

    • State changed from “new” to “incomplete”

    Is this still an issue on edge ? A failing test case would be great ! http://guides.rails.info/contrib... should be helpful.

    Thanks

  • Ryan Bigg

    Ryan Bigg April 11th, 2010 @ 10:38 PM

    • State changed from “incomplete” to “invalid”

    This is working on 2.3.5 and latest Rails for me.

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>

Pages