Question

I am upgrading a Rails 3.2 app to Rails 4 and am running into an issue with some rack middleware:

I am getting the following error: DEPRECATION WARNING: Hash#diff is no longer used inside of Rails, and is being deprecated with no replacement. If you're using it to compare hashes for the purpose of testing, please use MiniTest's assert_equal instead.

The line that appears to be triggering it is @app.call(env) from the below:

 class NoWww

  def initialize(app)
    @app = app
  end

  def call(env)

    request = Rack::Request.new(env)

    if request.host =~ /^[^.]+\.[^.]+$/
      [301, {"Location" => request.url.sub("//","//www.")}, self]
    else
      @app.call(env)
    end

  end


  def each(&block)
  end

end

Note sure how the @app.call(env) is triggering this Hash#Diff Deprecation warning...?


UPDATE

My Middleware Stack is as follows:

use Rack::Sendfile
use ActionDispatch::Static
use Rack::Rewrite
use Rack::Lock
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x0000010369c180>
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use BetterErrors::Middleware
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use ActionDispatch::ParamsParser
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
use NoWww
use OmniAuth::Builder
run JobBoard::Application.routes
Was it helpful?

Solution

Monkey-patch Hash#diff so to add

puts caller.join("\n")

at the beginning of the method, this will let you know what exactly invokes the method and triggers the deprecation warning (http://www.ruby-doc.org/core-2.1.0/Kernel.html#method-i-caller). Then, if the issue is in your code, fix it (by using a different approach or by adding Hash#diff through the initializer as suggested by @PaulFioravanti), and if issue is not in your code, file a bug report on github to the appropriate project.

Let me know if you get stuck at some point with details on how you got stuck and I'll expand this answer

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top