mongo_mapper 0.14.0 → 0.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/README.md +72 -0
- data/examples/keys.rb +1 -1
- data/examples/modifiers/set.rb +1 -1
- data/examples/querying.rb +1 -1
- data/examples/safe.rb +2 -2
- data/examples/scopes.rb +1 -1
- data/lib/mongo_mapper.rb +19 -17
- data/lib/mongo_mapper/connection.rb +16 -38
- data/lib/mongo_mapper/extensions/array.rb +1 -1
- data/lib/mongo_mapper/extensions/binary.rb +1 -1
- data/lib/mongo_mapper/extensions/date.rb +1 -1
- data/lib/mongo_mapper/extensions/float.rb +1 -1
- data/lib/mongo_mapper/extensions/hash.rb +1 -1
- data/lib/mongo_mapper/extensions/nil_class.rb +2 -2
- data/lib/mongo_mapper/extensions/object.rb +1 -1
- data/lib/mongo_mapper/extensions/object_id.rb +6 -2
- data/lib/mongo_mapper/extensions/set.rb +1 -1
- data/lib/mongo_mapper/extensions/string.rb +1 -1
- data/lib/mongo_mapper/plugins/accessible.rb +1 -1
- data/lib/mongo_mapper/plugins/associations/base.rb +10 -2
- data/lib/mongo_mapper/plugins/associations/belongs_to_association.rb +1 -1
- data/lib/mongo_mapper/plugins/associations/many_association.rb +6 -5
- data/lib/mongo_mapper/plugins/associations/{belongs_to_polymorphic_proxy.rb → proxy/belongs_to_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{belongs_to_proxy.rb → proxy/belongs_to_proxy.rb} +6 -0
- data/lib/mongo_mapper/plugins/associations/proxy/collection.rb +55 -0
- data/lib/mongo_mapper/plugins/associations/{embedded_collection.rb → proxy/embedded_collection.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{in_array_proxy.rb → proxy/in_array_proxy.rb} +36 -6
- data/lib/mongo_mapper/plugins/associations/proxy/in_foreign_array_proxy.rb +136 -0
- data/lib/mongo_mapper/plugins/associations/{many_documents_as_proxy.rb → proxy/many_documents_as_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{many_documents_proxy.rb → proxy/many_documents_proxy.rb} +0 -4
- data/lib/mongo_mapper/plugins/associations/{many_embedded_polymorphic_proxy.rb → proxy/many_embedded_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{many_embedded_proxy.rb → proxy/many_embedded_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{many_polymorphic_proxy.rb → proxy/many_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{one_as_proxy.rb → proxy/one_as_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{one_embedded_polymorphic_proxy.rb → proxy/one_embedded_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{one_embedded_proxy.rb → proxy/one_embedded_proxy.rb} +3 -1
- data/lib/mongo_mapper/plugins/associations/{one_proxy.rb → proxy/one_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/proxy/proxy.rb +164 -0
- data/lib/mongo_mapper/plugins/associations/single_association.rb +5 -13
- data/lib/mongo_mapper/plugins/dirty.rb +29 -37
- data/lib/mongo_mapper/plugins/document.rb +1 -1
- data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +1 -1
- data/lib/mongo_mapper/plugins/embedded_callbacks.rb +1 -0
- data/lib/mongo_mapper/plugins/embedded_document.rb +2 -2
- data/lib/mongo_mapper/plugins/identity_map.rb +3 -1
- data/lib/mongo_mapper/plugins/indexes.rb +13 -6
- data/lib/mongo_mapper/plugins/keys.rb +12 -7
- data/lib/mongo_mapper/plugins/keys/key.rb +21 -13
- data/lib/mongo_mapper/plugins/modifiers.rb +39 -14
- data/lib/mongo_mapper/plugins/persistence.rb +6 -2
- data/lib/mongo_mapper/plugins/querying.rb +9 -3
- data/lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb +6 -6
- data/lib/mongo_mapper/plugins/safe.rb +10 -4
- data/lib/mongo_mapper/plugins/scopes.rb +19 -3
- data/lib/mongo_mapper/plugins/stats.rb +1 -3
- data/lib/mongo_mapper/plugins/strong_parameters.rb +26 -0
- data/lib/mongo_mapper/plugins/validations.rb +1 -1
- data/lib/mongo_mapper/railtie.rb +1 -0
- data/lib/mongo_mapper/utils.rb +2 -2
- data/lib/mongo_mapper/version.rb +1 -1
- data/spec/examples.txt +1731 -0
- data/spec/functional/accessible_spec.rb +7 -1
- data/spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb +2 -2
- data/spec/functional/associations/belongs_to_proxy_spec.rb +55 -5
- data/spec/functional/associations/in_array_proxy_spec.rb +149 -14
- data/spec/functional/associations/in_foreign_array_proxy_spec.rb +321 -0
- data/spec/functional/associations/many_documents_as_proxy_spec.rb +6 -6
- data/spec/functional/associations/many_documents_proxy_spec.rb +22 -22
- data/spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb +2 -2
- data/spec/functional/associations/many_polymorphic_proxy_spec.rb +4 -4
- data/spec/functional/associations/one_as_proxy_spec.rb +8 -8
- data/spec/functional/associations/one_embedded_proxy_spec.rb +28 -0
- data/spec/functional/associations/one_proxy_spec.rb +19 -9
- data/spec/functional/associations_spec.rb +3 -3
- data/spec/functional/binary_spec.rb +2 -2
- data/spec/functional/caching_spec.rb +15 -22
- data/spec/functional/callbacks_spec.rb +2 -2
- data/spec/functional/counter_cache_spec.rb +10 -10
- data/spec/functional/dirty_spec.rb +48 -10
- data/spec/functional/dirty_with_callbacks_spec.rb +59 -0
- data/spec/functional/document_spec.rb +5 -8
- data/spec/functional/dumpable_spec.rb +1 -1
- data/spec/functional/embedded_document_spec.rb +5 -5
- data/spec/functional/identity_map_spec.rb +8 -8
- data/spec/functional/indexes_spec.rb +19 -18
- data/spec/functional/keys_spec.rb +64 -33
- data/spec/functional/logger_spec.rb +2 -2
- data/spec/functional/modifiers_spec.rb +81 -19
- data/spec/functional/partial_updates_spec.rb +8 -8
- data/spec/functional/protected_spec.rb +1 -1
- data/spec/functional/querying_spec.rb +70 -22
- data/spec/functional/safe_spec.rb +23 -27
- data/spec/functional/sci_spec.rb +7 -7
- data/spec/functional/scopes_spec.rb +89 -1
- data/spec/functional/static_keys_spec.rb +2 -2
- data/spec/functional/stats_spec.rb +28 -12
- data/spec/functional/strong_parameters_spec.rb +49 -0
- data/spec/functional/validations_spec.rb +8 -16
- data/spec/quality_spec.rb +1 -1
- data/spec/spec_helper.rb +39 -8
- data/spec/support/matchers.rb +1 -1
- data/spec/unit/associations/proxy_spec.rb +18 -10
- data/spec/unit/clone_spec.rb +1 -1
- data/spec/unit/document_spec.rb +3 -3
- data/spec/unit/embedded_document_spec.rb +4 -5
- data/spec/unit/extensions_spec.rb +12 -7
- data/spec/unit/identity_map_middleware_spec.rb +65 -96
- data/spec/unit/inspect_spec.rb +1 -1
- data/spec/unit/key_spec.rb +23 -18
- data/spec/unit/keys_spec.rb +17 -8
- data/spec/unit/mongo_mapper_spec.rb +41 -88
- data/spec/unit/rails_spec.rb +2 -2
- data/spec/unit/validations_spec.rb +18 -18
- metadata +70 -38
- data/README.rdoc +0 -56
- data/lib/mongo_mapper/extensions/ordered_hash.rb +0 -23
- data/lib/mongo_mapper/plugins/associations/collection.rb +0 -29
- data/lib/mongo_mapper/plugins/associations/proxy.rb +0 -141
data/spec/quality_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -2,10 +2,21 @@ $:.unshift(File.expand_path('../../lib', __FILE__))
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'bundler/setup'
|
5
|
+
|
6
|
+
# workaround for https://github.com/jruby/jruby/issues/6547
|
7
|
+
if RUBY_PLATFORM == 'java'
|
8
|
+
require 'i18n/backend'
|
9
|
+
require 'i18n/backend/simple'
|
10
|
+
end
|
11
|
+
|
12
|
+
Bundler.require(:default)
|
5
13
|
require 'fileutils'
|
6
14
|
require 'timecop'
|
7
15
|
require "generator_spec/test_case"
|
8
|
-
|
16
|
+
|
17
|
+
if RUBY_ENGINE == "ruby" && RUBY_VERSION >= '2.3'
|
18
|
+
require 'byebug'
|
19
|
+
end
|
9
20
|
|
10
21
|
if RUBY_PLATFORM != "java"
|
11
22
|
if ENV['TRAVIS']
|
@@ -40,7 +51,7 @@ def Doc(name='Class', &block)
|
|
40
51
|
end
|
41
52
|
|
42
53
|
klass.class_eval(&block) if block_given?
|
43
|
-
klass.collection.
|
54
|
+
klass.collection.drop
|
44
55
|
klass
|
45
56
|
end
|
46
57
|
|
@@ -59,21 +70,28 @@ def EDoc(name='Class', &block)
|
|
59
70
|
end
|
60
71
|
|
61
72
|
def drop_indexes(klass)
|
62
|
-
klass.collection.
|
73
|
+
klass.collection.indexes.drop_all if klass.database.collection_names.include?(klass.collection.name)
|
63
74
|
end
|
64
75
|
|
65
76
|
log_dir = File.expand_path('../../log', __FILE__)
|
66
77
|
FileUtils.mkdir_p(log_dir) unless File.exist?(log_dir)
|
67
78
|
logger = Logger.new(log_dir + '/test.log')
|
68
79
|
|
69
|
-
|
70
|
-
|
71
|
-
MongoMapper.
|
80
|
+
Mongo::Logger.logger = logger
|
81
|
+
|
82
|
+
MongoMapper.connection = Mongo::Client.new(['127.0.0.1:27017'], :database => 'test')
|
83
|
+
MongoMapper.database.collections.each { |c| c.indexes.drop_all }
|
72
84
|
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
73
85
|
|
74
86
|
RSpec.configure do |config|
|
87
|
+
config.example_status_persistence_file_path = "./spec/examples.txt"
|
88
|
+
|
75
89
|
config.expect_with :rspec do |c|
|
76
|
-
c.syntax =
|
90
|
+
c.syntax = :should
|
91
|
+
end
|
92
|
+
|
93
|
+
config.mock_with :rspec do |mocks|
|
94
|
+
mocks.syntax = :should
|
77
95
|
end
|
78
96
|
|
79
97
|
config.around(:each, :without_connection) do |example|
|
@@ -81,5 +99,18 @@ RSpec.configure do |config|
|
|
81
99
|
example.run
|
82
100
|
MongoMapper.connection = old
|
83
101
|
end
|
84
|
-
end
|
85
102
|
|
103
|
+
def suppress_stderr
|
104
|
+
begin
|
105
|
+
original_stderr = $stderr.clone
|
106
|
+
$stderr.reopen(File.new('/dev/null', 'w'))
|
107
|
+
retval = yield
|
108
|
+
rescue Exception => e
|
109
|
+
$stderr.reopen(original_stderr)
|
110
|
+
raise e
|
111
|
+
ensure
|
112
|
+
$stderr.reopen(original_stderr)
|
113
|
+
end
|
114
|
+
retval
|
115
|
+
end
|
116
|
+
end
|
data/spec/support/matchers.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class FakeNilProxy < MongoMapper::Plugins::Associations::Proxy
|
4
|
-
def
|
4
|
+
def load_target; @target ||= nil end
|
5
5
|
end
|
6
6
|
|
7
7
|
class FakeBlankProxy < MongoMapper::Plugins::Associations::Proxy
|
8
|
-
def
|
8
|
+
def load_target; @target ||= '' end
|
9
9
|
end
|
10
10
|
|
11
11
|
class FakeNumberProxy < MongoMapper::Plugins::Associations::Proxy
|
12
|
-
def
|
12
|
+
def load_target; @target ||= 17 end
|
13
13
|
end
|
14
14
|
|
15
15
|
class FakeProxy < MongoMapper::Plugins::Associations::Proxy
|
16
|
-
def
|
16
|
+
def load_target; @target ||= [1, 2] end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "Proxy" do
|
@@ -32,7 +32,7 @@ describe "Proxy" do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should be able to inspect the proxy" do
|
35
|
-
@proxy.inspect.should ==
|
35
|
+
@proxy.inspect.should == "#<FakeProxy:#{@proxy.object_id} [1, 2]>"
|
36
36
|
end
|
37
37
|
|
38
38
|
context "nil?" do
|
@@ -77,10 +77,6 @@ describe "Proxy" do
|
|
77
77
|
@proxy.proxy_owner.should == @owner
|
78
78
|
end
|
79
79
|
|
80
|
-
it "should alias proxy target to target" do
|
81
|
-
@proxy.proxy_target.should == @target
|
82
|
-
end
|
83
|
-
|
84
80
|
context "send" do
|
85
81
|
it "should work if proxy responds to method" do
|
86
82
|
@proxy.send(:reset)
|
@@ -92,12 +88,24 @@ describe "Proxy" do
|
|
92
88
|
end
|
93
89
|
|
94
90
|
it "should not work if neither the proxy or target respond to method" do
|
95
|
-
lambda { @proxy.send(:gsub) }.should raise_error
|
91
|
+
lambda { @proxy.send(:gsub) }.should raise_error(NoMethodError)
|
96
92
|
end
|
97
93
|
|
98
94
|
it "should work if a proc is passed" do
|
99
95
|
p = Proc.new {|x| x+1}
|
100
96
|
@proxy.send(:collect, &p).should == [2,3]
|
101
97
|
end
|
98
|
+
|
99
|
+
it "should not respond to private method" do
|
100
|
+
@proxy.reload # To load @proxy.target
|
101
|
+
@proxy.target.extend(Module.new do
|
102
|
+
private
|
103
|
+
|
104
|
+
def private_foo
|
105
|
+
end
|
106
|
+
end)
|
107
|
+
|
108
|
+
lambda { @proxy.private_foo }.should raise_error(NoMethodError, /private method `private_foo' called/)
|
109
|
+
end
|
102
110
|
end
|
103
111
|
end
|
data/spec/unit/clone_spec.rb
CHANGED
data/spec/unit/document_spec.rb
CHANGED
@@ -21,11 +21,11 @@ describe "Document" do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should have a connection" do
|
24
|
-
@document.connection.should be_instance_of(Mongo::
|
24
|
+
@document.connection.should be_instance_of(Mongo::Client)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should allow setting different connection without affecting the default" do
|
28
|
-
conn = Mongo::
|
28
|
+
conn = Mongo::Client.new(['127.0.0.1:27001'])
|
29
29
|
@document.connection conn
|
30
30
|
@document.connection.should == conn
|
31
31
|
@document.connection.should_not == MongoMapper.connection
|
@@ -152,7 +152,7 @@ describe "Document" do
|
|
152
152
|
|
153
153
|
it "should be true if id but using custom id and not saved yet" do
|
154
154
|
@document.key :_id, String
|
155
|
-
doc =
|
155
|
+
doc = suppress_stderr { @document.new }
|
156
156
|
doc.id = '1234'
|
157
157
|
doc.new?.should be_truthy
|
158
158
|
end
|
@@ -210,7 +210,7 @@ describe "EmbeddedDocument" do
|
|
210
210
|
end
|
211
211
|
|
212
212
|
it "should not include descendant keys" do
|
213
|
-
lambda { Parent.new.other_child }.should raise_error
|
213
|
+
lambda { Parent.new.other_child }.should raise_error(NoMethodError)
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
@@ -308,7 +308,7 @@ describe "EmbeddedDocument" do
|
|
308
308
|
end
|
309
309
|
|
310
310
|
it "should not throw error if initialized with nil" do
|
311
|
-
|
311
|
+
lambda { @document.new(nil) }.should_not raise_error
|
312
312
|
end
|
313
313
|
end
|
314
314
|
|
@@ -661,16 +661,15 @@ describe "EmbeddedDocument" do
|
|
661
661
|
|
662
662
|
it "should should raise errors when invalid" do
|
663
663
|
@doc.name = ''
|
664
|
-
|
664
|
+
lambda { @doc.save! }.should raise_error(MongoMapper::DocumentNotValid)
|
665
665
|
end
|
666
666
|
|
667
667
|
it "should should raise errors when root document is invalid" do
|
668
668
|
@root.name = ''
|
669
669
|
@root.save(:validate => false)
|
670
|
-
|
670
|
+
lambda { @doc.save! }.should raise_error(MongoMapper::DocumentNotValid)
|
671
671
|
end
|
672
672
|
end
|
673
673
|
end # instance of a embedded document
|
674
674
|
end
|
675
675
|
end
|
676
|
-
|
@@ -192,22 +192,28 @@ describe "Support" do
|
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
195
|
-
context "NilClass
|
195
|
+
context "NilClass.from_mongo" do
|
196
196
|
it "should return nil" do
|
197
|
-
|
197
|
+
NilClass.from_mongo(nil).should be_nil
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context "NilClass.to_mongo" do
|
202
|
+
it "should return nil" do
|
203
|
+
NilClass.to_mongo(nil).should be_nil
|
198
204
|
end
|
199
205
|
end
|
200
206
|
|
201
207
|
context "NilClass#to_mongo" do
|
202
208
|
it "should return nil" do
|
203
|
-
nil.to_mongo
|
209
|
+
nil.to_mongo.should be_nil
|
204
210
|
end
|
205
211
|
end
|
206
212
|
|
207
213
|
context "ObjectId#to_mongo" do
|
208
214
|
it "should call class to_mongo with self" do
|
209
215
|
object = Object.new
|
210
|
-
|
216
|
+
object.class.should_receive(:to_mongo).with(object)
|
211
217
|
object.to_mongo
|
212
218
|
end
|
213
219
|
end
|
@@ -300,8 +306,7 @@ describe "Support" do
|
|
300
306
|
end
|
301
307
|
|
302
308
|
it "should be time in utc if time" do
|
303
|
-
|
304
|
-
Time.to_mongo(Time.local(2009, 8, 15, 0, 0, 0)).zone.should == utc_str
|
309
|
+
Time.to_mongo(Time.local(2009, 8, 15, 0, 0, 0)).zone.should == 'UTC'
|
305
310
|
end
|
306
311
|
|
307
312
|
it "should be nil if blank string" do
|
@@ -388,7 +393,7 @@ describe "Support" do
|
|
388
393
|
|
389
394
|
it "should support ruby driver syntax also" do
|
390
395
|
id = BSON::ObjectId.new
|
391
|
-
id.original_to_json.should == %Q({"$oid":
|
396
|
+
id.original_to_json.should == %Q({"$oid":"#{id}"})
|
392
397
|
end
|
393
398
|
end
|
394
399
|
end
|
@@ -19,116 +19,85 @@ module IdentityMapSpec
|
|
19
19
|
end.to_app
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
22
|
+
before do
|
23
|
+
@enabled = MongoMapper::Plugins::IdentityMap.enabled
|
24
|
+
MongoMapper::Plugins::IdentityMap.enabled = false
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
after do
|
28
|
+
MongoMapper::Plugins::IdentityMap.enabled = @enabled
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
31
|
+
it "should delegate" do
|
32
|
+
called = false
|
33
|
+
mw = MongoMapper::Middleware::IdentityMap.new lambda { |env|
|
34
|
+
called = true
|
35
|
+
[200, {}, nil]
|
36
|
+
}
|
37
|
+
mw.call({})
|
38
|
+
called.should be_truthy
|
39
|
+
end
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
it "should enable identity map during delegation" do
|
42
|
+
mw = MongoMapper::Middleware::IdentityMap.new lambda { |env|
|
43
|
+
MongoMapper::Plugins::IdentityMap.should be_enabled
|
44
|
+
[200, {}, nil]
|
45
|
+
}
|
46
|
+
mw.call({})
|
47
|
+
end
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
49
|
+
class Enum < Struct.new(:iter)
|
50
|
+
def each(&b)
|
51
|
+
iter.call(&b)
|
54
52
|
end
|
53
|
+
end
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
55
|
+
it "should enable IM for body each" do
|
56
|
+
mw = MongoMapper::Middleware::IdentityMap.new lambda { |env|
|
57
|
+
[200, {}, Enum.new(lambda { |&b|
|
58
|
+
MongoMapper::Plugins::IdentityMap.should be_enabled
|
59
|
+
b.call "hello"
|
60
|
+
})]
|
61
|
+
}
|
62
|
+
body = mw.call({}).last
|
63
|
+
body.each { |x| x.should eql('hello') }
|
64
|
+
end
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
66
|
+
it "should disable IM after body close" do
|
67
|
+
mw = MongoMapper::Middleware::IdentityMap.new lambda { |env| [200, {}, []] }
|
68
|
+
body = mw.call({}).last
|
69
|
+
MongoMapper::Plugins::IdentityMap.should be_enabled
|
70
|
+
body.close
|
71
|
+
MongoMapper::Plugins::IdentityMap.should_not be_enabled
|
72
|
+
end
|
74
73
|
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
it "should clear IM after body close" do
|
75
|
+
mw = MongoMapper::Middleware::IdentityMap.new lambda { |env| [200, {}, []] }
|
76
|
+
body = mw.call({}).last
|
78
77
|
|
79
|
-
|
80
|
-
|
78
|
+
MongoMapper::Plugins::IdentityMap.repository['hello'] = 'world'
|
79
|
+
MongoMapper::Plugins::IdentityMap.repository.should_not be_empty
|
81
80
|
|
82
|
-
|
81
|
+
body.close
|
83
82
|
|
84
|
-
|
85
|
-
|
83
|
+
MongoMapper::Plugins::IdentityMap.repository.should be_empty
|
84
|
+
end
|
86
85
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
86
|
+
context "with a successful request" do
|
87
|
+
it "should clear the identity map" do
|
88
|
+
# for some reason, body.close gets called twice - once in rack-2.2.3/lib/rack/response.rb:281
|
89
|
+
# the other time rack-test-0.8.3/lib/rack/mock_session.rb:32
|
90
|
+
# use at_least(:twice) here to handle the error happening more than twice
|
91
|
+
MongoMapper::Plugins::IdentityMap.should_receive(:clear).at_least(:twice)
|
92
|
+
get '/'
|
92
93
|
end
|
94
|
+
end
|
93
95
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
96
|
+
context "when the request raises an error" do
|
97
|
+
it "should clear the identity map" do
|
98
|
+
MongoMapper::Plugins::IdentityMap.should_receive(:clear).once
|
99
|
+
get '/fail' rescue nil
|
99
100
|
end
|
100
101
|
end
|
101
102
|
end
|
102
|
-
|
103
|
-
# describe "IdentityMapMiddleware" do
|
104
|
-
# include Rack::Test::Methods
|
105
|
-
|
106
|
-
# def app
|
107
|
-
# @app ||= Rack::Builder.new do
|
108
|
-
# use MongoMapper::Middleware::IdentityMap
|
109
|
-
# map "/" do
|
110
|
-
# run lambda {|env| [200, {}, []] }
|
111
|
-
# end
|
112
|
-
# map "/fail" do
|
113
|
-
# run lambda {|env| raise "FAIL!" }
|
114
|
-
# end
|
115
|
-
# end.to_app
|
116
|
-
# end
|
117
|
-
|
118
|
-
# context "with a successful request" do
|
119
|
-
# it "should clear the identity map" do
|
120
|
-
# expect(MongoMapper::Plugins::IdentityMap).to receive(:clear).twice
|
121
|
-
# get '/'
|
122
|
-
# end
|
123
|
-
# end
|
124
|
-
|
125
|
-
# context "when the request raises an error" do
|
126
|
-
# it "should clear the identity map" do
|
127
|
-
# expect(MongoMapper::Plugins::IdentityMap).to receive(:clear).twice
|
128
|
-
# get '/fail' rescue nil
|
129
|
-
# end
|
130
|
-
# end
|
131
|
-
|
132
|
-
|
133
|
-
# end
|
134
|
-
end
|
103
|
+
end
|