Sha256: fe95b4516750597acea7b88ef76c50a62c4f2de4c9644ca9a008e67b988e41f0

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

require "spec_helper"

describe "Rack::Mongoid::Middleware::IdentityMap" do

  before(:all) do
    require "rack/mongoid"
  end

  let(:app) do
    double
  end

  let(:env) do
    double
  end

  let(:klass) do
    Rack::Mongoid::Middleware::IdentityMap
  end

  describe "#call" do

    let(:middleware) do
      klass.new(app)
    end

    let(:document) do
      Person.new
    end

    before do
      Mongoid::IdentityMap.set(document)
    end

    describe "when no exception is raised" do

      before do
        app.should_receive(:call).with(env).and_return([])
      end

      let!(:result) do
        middleware.call(env)
      end

      it "returns the call with the body proxy" do
        expect(result).to eq([])
      end

      it "clears out the identity map" do
        expect(Mongoid::Threaded.identity_map).to be_empty
      end
    end

    describe "when an exception is raised" do

      before do
        app.should_receive(:call).with(env).and_raise(RuntimeError)
      end

      let!(:result) do
        begin
          middleware.call(env)
        rescue
        end
      end

      it "clears out the identity map" do
        expect(Mongoid::Threaded.identity_map).to be_empty
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
sepastian-mongoid-rails4-4.0.1.alpha spec/rack/mongoid/middleware/identity_map_spec.rb
sepastian-mongoid-rails4-4.0.0.alpha spec/rack/mongoid/middleware/identity_map_spec.rb
mongoid_heroku_stable-4.0.0 spec/rack/mongoid/middleware/identity_map_spec.rb
mongoid_rails4-4.0.0 spec/rack/mongoid/middleware/identity_map_spec.rb