Skip to content

Commit

Permalink
Revert back to original middleware [ #2445 ]
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Nov 10, 2012
1 parent 565ad46 commit 403bf9a
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 85 deletions.
6 changes: 1 addition & 5 deletions lib/mongoid/railtie.rb
Expand Up @@ -118,11 +118,7 @@ def self.rescue_responses

# Need to include the Mongoid identity map middleware.
initializer "include the identity map" do |app|
if ::Mongoid.running_with_passenger?
app.config.middleware.use "Rack::Mongoid::Middleware::IdentityMap::Passenger"
else
app.config.middleware.use "Rack::Mongoid::Middleware::IdentityMap"
end
app.config.middleware.use "Rack::Mongoid::Middleware::IdentityMap"
end

# Instantitate any registered observers after Rails initialization and
Expand Down
1 change: 0 additions & 1 deletion lib/rack/mongoid.rb
@@ -1,3 +1,2 @@
# encoding: utf-8
require "rack/mongoid/proxy"
require "rack/mongoid/middleware/identity_map"
43 changes: 1 addition & 42 deletions lib/rack/mongoid/middleware/identity_map.rb
Expand Up @@ -31,48 +31,7 @@ def initialize(app)
#
# @since 2.1.0
def call(env)
begin
response = @app.call(env)
response[2] = ::Rack::Mongoid::Proxy.new(response[2]) do
::Mongoid::IdentityMap.clear
end
rescue
::Mongoid::IdentityMap.clear
raise
end
response
end

# Passenger 3 does not execute the block provided to a Rack::BodyProxy
# so the identity map never gets cleared. Since there's no streaming
# support in it anyways we do not need the proxy functionality.
class Passenger

# Initialize the new middleware.
#
# @example Init the middleware.
# IdentityMap.new(app)
#
# @param [ Object ] app The application.
#
# @since 3.0.11
def initialize(app)
@app = app
end

# Make the request with the provided environment.
#
# @example Make the request.
# identity_map.call(env)
#
# @param [ Object ] env The environment.
#
# @return [ Array ] The status, headers, and response.
#
# @since 3.0.11
def call(env)
::Mongoid.unit_of_work { @app.call(env) }
end
::Mongoid.unit_of_work { @app.call(env) }
end
end
end
Expand Down
38 changes: 1 addition & 37 deletions spec/rack/mongoid/middleware/identity_map_spec.rb
Expand Up @@ -20,42 +20,6 @@

describe "#call" do

module Rack
class BodyProxy
def initialize(body, &block)
@body, @block, @closed = body, block, false
end

def respond_to?(*args)
return false if args.first.to_s =~ /^to_ary$/
super or @body.respond_to?(*args)
end

def close
return if @closed
@closed = true
begin
@body.close if @body.respond_to? :close
ensure
@block.call
end
end

def closed?
@closed
end

def each(*args, &block)
@body.each(*args, &block)
end

def method_missing(*args, &block)
super if args.first.to_s =~ /^to_ary$/
@body.__send__(*args, &block)
end
end
end

let(:middleware) do
klass.new(app)
end
Expand All @@ -79,7 +43,7 @@ def method_missing(*args, &block)
end

it "returns the call with the body proxy" do
result[2].should be_a(Rack::BodyProxy)
result.should eq([])
end

it "clears out the identity map" do
Expand Down

0 comments on commit 403bf9a

Please sign in to comment.