Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8155471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:40:43+00:00 2026-06-06T16:40:43+00:00

This all worked fine in rails 2.3.5, but when a contractor firm upgraded directly

  • 0

This all worked fine in rails 2.3.5, but when a contractor firm upgraded directly to 2.3.14 suddenly all the integration tests were saying:

NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]

I have a before_filter on my ApplicationController that sets a bunch of cookies for some javascript to use, and I found that if I comment out all but one of the lines that sets cookie values, it works fine, and it doesn’t matter which line I leave in.

before_filter :set_cookies

def set_cookies
  cookies['logged_in'] = (logged_in ? 'y' : 'n')
  cookies['gets_premium'] = (gets_premium ? 'y' : 'n')
  cookies['is_admin'] = (is_admin ? 'y' : 'n')
end

If only one of these lines is active, everything is fine in the integration test, otherwise I get the error above. For example, consider the following test / response:

test "foo" do
  get '/'
end


$ ruby -I"lib:test" test/integration/foo_test.rb -n test_foo -v
Loaded suite test/integration/foo_test
Started
test_foo(FooTest): E

Finished in 5.112648 seconds.

  1) Error:
test_foo(FooTest):
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
    test/integration/foo_test.rb:269:in `test_foo'

1 tests, 0 assertions, 0 failures, 1 errors

But if any two of those cookie setting lines are commented out, I get:

$ ruby -I"lib:test" test/integration/foo_test.rb -n test_foo -v
Loaded suite test/integration/foo_test
Started
test_foo(FooTest): .

Finished in 1.780388 seconds.

1 tests, 0 assertions, 0 failures, 0 errors

The website running in development and production mode works fine – this is just a matter of getting the tests passing. Also, with debugging output I have verified that the error does not get thrown in the method where the cookies get set, that all executes fine, it’s somewhere later that the error happens (but the backtrace doesn’t tell me where)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:40:44+00:00Added an answer on June 6, 2026 at 4:40 pm

    This turned out to be a bug in how rack rack writes cookies to the client along with the session cookie. Rack was including double newlines and omitting semi-colons.

    Browsers like firefox can handle mildly malformed cookie data, but the integration test client couldn’t.

    To fix this I had to rewrite the cookie header before sending it to the client.

    In environment.rb:

    require 'rack_rails_cookie_header_hack'
    

    And in lib/rack_rails_cookie_header_hack.rb:

    class RackRailsCookieHeaderHack
    
      def initialize(app)
        @app = app
      end
    
      def call(env)
        status, headers, body = @app.call(env)
        if headers['Set-Cookie']
          cookies = headers['Set-Cookie']
          cookies = cookies.split("\n") if is_str = cookies.is_a?(String)
          if cookies.respond_to?(:collect!)
            cookies.collect! { |h| h.strip }
            cookies.delete_if { |h| h.empty? }
            cookies.collect! { |h| h.include?(';') ? h : h + ';' }
          end
          headers['Set-Cookie'] = is_str ? cookies.join("\n").strip : cookies
        end
        [status, headers, body]
      end
    end
    

    Sorry the sources aren’t articulated, I actually fixed this awhile ago and came across this questions and figured I’d post my patch.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the beginning this worked fine: $ rake cucumber:all But then $ script/plugin install
I'm running into a strange issue.... This all worked fine last night when I
I have installed ImageMagick using brew install imagemagick . This all worked fine and
I was under the impression all this time that .on() worked like .live() with
sorry if this all seem nooby and unclear, but I'm currently learning Netlogo to
rails 2.3.4, sqlite3 I'm trying this Production.find(:all, :conditions => ["time > ?", start_time.utc], :order
I installed ruby 1.9.3 on Mountain Lion using: rvm install 1.9.3 This all worked
So this all stemmed from not wanting to check each POST in a huge
I been at this all day and feel like I'm getting nowhere, I need
I've struggled with this all day, I am trying to get a random number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.