mongo_mapper 0.13.1 → 0.14.0.rc1
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 +13 -5
- data/README.rdoc +3 -6
- data/lib/mongo_mapper.rb +1 -0
- data/lib/mongo_mapper/document.rb +2 -0
- data/lib/mongo_mapper/extensions/array.rb +14 -6
- data/lib/mongo_mapper/extensions/hash.rb +15 -3
- data/lib/mongo_mapper/extensions/object.rb +4 -0
- data/lib/mongo_mapper/extensions/string.rb +13 -5
- data/lib/mongo_mapper/plugins/accessible.rb +12 -11
- data/lib/mongo_mapper/plugins/associations.rb +7 -6
- data/lib/mongo_mapper/plugins/associations/base.rb +13 -12
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +9 -8
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +12 -11
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +4 -4
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +24 -23
- data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +18 -16
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +55 -48
- data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +14 -13
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +7 -6
- data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +7 -5
- data/lib/mongo_mapper/plugins/associations/one_as_proxy.rb +14 -11
- data/lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb +14 -13
- data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +9 -9
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +27 -26
- data/lib/mongo_mapper/plugins/associations/proxy.rb +29 -26
- data/lib/mongo_mapper/plugins/callbacks.rb +13 -0
- data/lib/mongo_mapper/plugins/counter_cache.rb +23 -4
- data/lib/mongo_mapper/plugins/dirty.rb +2 -2
- data/lib/mongo_mapper/plugins/dynamic_querying.rb +10 -9
- data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +17 -16
- data/lib/mongo_mapper/plugins/embedded_callbacks.rb +1 -1
- data/lib/mongo_mapper/plugins/identity_map.rb +1 -1
- data/lib/mongo_mapper/plugins/indexes.rb +1 -1
- data/lib/mongo_mapper/plugins/keys.rb +158 -158
- data/lib/mongo_mapper/plugins/keys/key.rb +16 -10
- data/lib/mongo_mapper/plugins/keys/static.rb +45 -0
- data/lib/mongo_mapper/plugins/modifiers.rb +27 -26
- data/lib/mongo_mapper/plugins/partial_updates.rb +86 -0
- data/lib/mongo_mapper/plugins/persistence.rb +7 -6
- data/lib/mongo_mapper/plugins/protected.rb +6 -5
- data/lib/mongo_mapper/plugins/querying.rb +80 -43
- data/lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb +14 -9
- data/lib/mongo_mapper/plugins/scopes.rb +78 -7
- data/lib/mongo_mapper/plugins/timestamps.rb +1 -0
- data/lib/mongo_mapper/plugins/validations.rb +0 -0
- data/lib/mongo_mapper/version.rb +1 -1
- data/lib/rails/generators/mongo_mapper/config/config_generator.rb +12 -13
- data/lib/rails/generators/mongo_mapper/model/model_generator.rb +9 -9
- data/spec/functional/accessible_spec.rb +12 -12
- data/spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb +11 -11
- data/spec/functional/associations/belongs_to_proxy_spec.rb +14 -15
- data/spec/functional/associations/in_array_proxy_spec.rb +6 -6
- data/spec/functional/associations/many_documents_proxy_spec.rb +89 -18
- data/spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb +11 -11
- data/spec/functional/associations/many_embedded_proxy_spec.rb +1 -1
- data/spec/functional/associations/one_as_proxy_spec.rb +14 -14
- data/spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb +9 -9
- data/spec/functional/associations/one_embedded_proxy_spec.rb +3 -3
- data/spec/functional/associations/one_proxy_spec.rb +14 -14
- data/spec/functional/caching_spec.rb +8 -8
- data/spec/functional/callbacks_spec.rb +87 -0
- data/spec/functional/counter_cache_spec.rb +89 -0
- data/spec/functional/dirty_spec.rb +41 -41
- data/spec/functional/document_spec.rb +3 -3
- data/spec/functional/embedded_document_spec.rb +18 -18
- data/spec/functional/identity_map_spec.rb +28 -15
- data/spec/functional/indexes_spec.rb +4 -4
- data/spec/functional/keys_spec.rb +12 -3
- data/spec/functional/logger_spec.rb +1 -1
- data/spec/functional/modifiers_spec.rb +2 -2
- data/spec/functional/partial_updates_spec.rb +577 -0
- data/spec/functional/protected_spec.rb +13 -13
- data/spec/functional/querying_spec.rb +11 -10
- data/spec/functional/safe_spec.rb +2 -2
- data/spec/functional/sci_spec.rb +3 -3
- data/spec/functional/scopes_spec.rb +234 -1
- data/spec/functional/static_keys_spec.rb +153 -0
- data/spec/functional/stats_spec.rb +0 -4
- data/spec/functional/touch_spec.rb +1 -1
- data/spec/functional/validations_spec.rb +59 -57
- data/spec/quality_spec.rb +1 -1
- data/spec/spec_helper.rb +7 -3
- data/spec/support/matchers.rb +4 -13
- data/spec/unit/associations/base_spec.rb +12 -12
- data/spec/unit/associations/belongs_to_association_spec.rb +2 -2
- data/spec/unit/associations/many_association_spec.rb +2 -2
- data/spec/unit/associations/one_association_spec.rb +2 -2
- data/spec/unit/associations/proxy_spec.rb +13 -15
- data/spec/unit/document_spec.rb +5 -5
- data/spec/unit/dynamic_finder_spec.rb +8 -8
- data/spec/unit/embedded_document_spec.rb +14 -14
- data/spec/unit/extensions_spec.rb +17 -17
- data/spec/unit/identity_map_middleware_spec.rb +5 -5
- data/spec/unit/key_spec.rb +24 -21
- data/spec/unit/keys_spec.rb +5 -5
- data/spec/unit/mongo_mapper_spec.rb +26 -26
- data/spec/unit/rails_spec.rb +2 -2
- data/spec/unit/serialization_spec.rb +1 -1
- data/spec/unit/time_zones_spec.rb +2 -2
- data/spec/unit/validations_spec.rb +28 -15
- metadata +16 -14
- data/lib/mongo_mapper/connections/10gen.rb +0 -0
- data/lib/mongo_mapper/connections/moped.rb +0 -0
data/spec/support/matchers.rb
CHANGED
@@ -1,19 +1,10 @@
|
|
1
1
|
RSpec::Matchers.define :have_error_on do |*args|
|
2
|
-
@message = nil
|
3
|
-
@attributes = [args]
|
4
|
-
|
5
|
-
chain :or do |*args|
|
6
|
-
@attributes << args
|
7
|
-
end
|
8
|
-
|
9
2
|
match do |model|
|
3
|
+
field = args.dup.shift
|
4
|
+
error_messages = args
|
5
|
+
|
10
6
|
model.valid?
|
11
|
-
|
12
|
-
if @message
|
13
|
-
!!@has_errors && model.errors[@has_errors[0]].include?(@has_errors[1])
|
14
|
-
else
|
15
|
-
!!@has_errors
|
16
|
-
end
|
7
|
+
model.errors[field].any?
|
17
8
|
end
|
18
9
|
end
|
19
10
|
|
@@ -12,7 +12,7 @@ module AssociationSpec
|
|
12
12
|
|
13
13
|
it "should also allow options when initializing" do
|
14
14
|
base = ManyAssociation.new(:foos, :polymorphic => true)
|
15
|
-
base.options[:polymorphic].should
|
15
|
+
base.options[:polymorphic].should be_truthy
|
16
16
|
end
|
17
17
|
|
18
18
|
context "klass" do
|
@@ -28,31 +28,31 @@ module AssociationSpec
|
|
28
28
|
|
29
29
|
context "polymorphic?" do
|
30
30
|
it "should be true if polymorphic" do
|
31
|
-
ManyAssociation.new(:foos, :polymorphic => true).polymorphic?.should
|
31
|
+
ManyAssociation.new(:foos, :polymorphic => true).polymorphic?.should be_truthy
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should be false if not polymorphic" do
|
35
|
-
ManyAssociation.new(:bars).polymorphic?.should
|
35
|
+
ManyAssociation.new(:bars).polymorphic?.should be_falsey
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
context "as?" do
|
40
40
|
it "should be true if one" do
|
41
|
-
OneAssociation.new(:foo, :as => :commentable).as?.should
|
41
|
+
OneAssociation.new(:foo, :as => :commentable).as?.should be_truthy
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should be false if not one" do
|
45
|
-
ManyAssociation.new(:foo).as?.should
|
45
|
+
ManyAssociation.new(:foo).as?.should be_falsey
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
context "in_array?" do
|
50
50
|
it "should be true if one" do
|
51
|
-
OneAssociation.new(:foo, :in => :list_ids).in_array?.should
|
51
|
+
OneAssociation.new(:foo, :in => :list_ids).in_array?.should be_truthy
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should be false if not one" do
|
55
|
-
ManyAssociation.new(:foo).in_array?.should
|
55
|
+
ManyAssociation.new(:foo).in_array?.should be_falsey
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -98,15 +98,15 @@ module AssociationSpec
|
|
98
98
|
context "embeddable?" do
|
99
99
|
it "should be true if class is embeddable" do
|
100
100
|
base = ManyAssociation.new(:medias)
|
101
|
-
base.embeddable?.should
|
101
|
+
base.embeddable?.should be_truthy
|
102
102
|
end
|
103
103
|
|
104
104
|
it "should be false if class is not embeddable" do
|
105
105
|
base = ManyAssociation.new(:statuses)
|
106
|
-
base.embeddable?.should
|
106
|
+
base.embeddable?.should be_falsey
|
107
107
|
|
108
108
|
base = BelongsToAssociation.new(:project)
|
109
|
-
base.embeddable?.should
|
109
|
+
base.embeddable?.should be_falsey
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
@@ -134,11 +134,11 @@ module AssociationSpec
|
|
134
134
|
|
135
135
|
context "touch?" do
|
136
136
|
it "should be true if touch" do
|
137
|
-
BelongsToAssociation.new(:car, :touch => true).touch?.should
|
137
|
+
BelongsToAssociation.new(:car, :touch => true).touch?.should be_truthy
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should be false if not touch" do
|
141
|
-
BelongsToAssociation.new(:car).touch?.should
|
141
|
+
BelongsToAssociation.new(:car).touch?.should be_falsey
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
@@ -18,12 +18,12 @@ module BelongsToAssociation
|
|
18
18
|
context "embeddable?" do
|
19
19
|
it "should be false even if class is embeddable" do
|
20
20
|
base = BelongsToAssociation.new(:address)
|
21
|
-
base.embeddable?.should
|
21
|
+
base.embeddable?.should be_falsey
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should be false if class is not embeddable" do
|
25
25
|
base = BelongsToAssociation.new(:project)
|
26
|
-
base.embeddable?.should
|
26
|
+
base.embeddable?.should be_falsey
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -25,12 +25,12 @@ module ManyAssociationSpec
|
|
25
25
|
context "embeddable?" do
|
26
26
|
it "should be true if class is embeddable" do
|
27
27
|
base = ManyAssociation.new(:medias)
|
28
|
-
base.embeddable?.should
|
28
|
+
base.embeddable?.should be_truthy
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should be false if class is not embeddable" do
|
32
32
|
base = ManyAssociation.new(:statuses)
|
33
|
-
base.embeddable?.should
|
33
|
+
base.embeddable?.should be_falsey
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -14,12 +14,12 @@ module OneAssociationSpec
|
|
14
14
|
context "embeddable?" do
|
15
15
|
it "should be true if class is embeddable" do
|
16
16
|
base = OneAssociation.new(:media)
|
17
|
-
base.embeddable?.should
|
17
|
+
base.embeddable?.should be_truthy
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should be false if class is not embeddable" do
|
21
21
|
base = OneAssociation.new(:project)
|
22
|
-
base.embeddable?.should
|
22
|
+
base.embeddable?.should be_falsey
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -18,10 +18,8 @@ end
|
|
18
18
|
|
19
19
|
describe "Proxy" do
|
20
20
|
before do
|
21
|
-
@owner = double('owner')
|
22
|
-
@
|
23
|
-
@association = double('association')
|
24
|
-
@association.stub(:options).and_return({:extend => []})
|
21
|
+
@owner = double('owner', :new? => false)
|
22
|
+
@association = double('association', :options => {:extend => []})
|
25
23
|
|
26
24
|
@proxy = FakeProxy.new(@owner, @association)
|
27
25
|
@nil_proxy = FakeNilProxy.new(@owner, @association)
|
@@ -39,40 +37,40 @@ describe "Proxy" do
|
|
39
37
|
|
40
38
|
context "nil?" do
|
41
39
|
it "should be true if nil" do
|
42
|
-
@nil_proxy.nil?.should
|
40
|
+
@nil_proxy.nil?.should be_truthy
|
43
41
|
end
|
44
42
|
|
45
43
|
it "should be false if not nil" do
|
46
|
-
@proxy.nil?.should
|
44
|
+
@proxy.nil?.should be_falsey
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|
50
48
|
context "blank?" do
|
51
49
|
it "should be true if blank" do
|
52
|
-
@blank_proxy.blank?.should
|
53
|
-
@nil_proxy.blank?.should
|
50
|
+
@blank_proxy.blank?.should be_truthy
|
51
|
+
@nil_proxy.blank?.should be_truthy
|
54
52
|
end
|
55
53
|
|
56
54
|
it "should be false if not blank" do
|
57
|
-
@proxy.blank?.should
|
55
|
+
@proxy.blank?.should be_falsey
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
61
59
|
context "present?" do
|
62
60
|
it "should be true if present" do
|
63
|
-
@proxy.present?.should
|
61
|
+
@proxy.present?.should be_truthy
|
64
62
|
end
|
65
63
|
|
66
64
|
it "should be false if not present" do
|
67
|
-
@blank_proxy.present?.should
|
68
|
-
@nil_proxy.present?.should
|
65
|
+
@blank_proxy.present?.should be_falsey
|
66
|
+
@nil_proxy.present?.should be_falsey
|
69
67
|
end
|
70
68
|
end
|
71
69
|
|
72
70
|
it "should delegate respond_to? to target" do
|
73
|
-
@proxy.respond_to?(:each).should
|
74
|
-
@proxy.respond_to?(:size).should
|
75
|
-
@proxy.respond_to?(:gsub).should
|
71
|
+
@proxy.respond_to?(:each).should be_truthy
|
72
|
+
@proxy.respond_to?(:size).should be_truthy
|
73
|
+
@proxy.respond_to?(:gsub).should be_falsey
|
76
74
|
end
|
77
75
|
|
78
76
|
it "should alias proxy owner to owner" do
|
data/spec/unit/document_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe "Document" do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should return false for embeddable" do
|
11
|
-
Doc().embeddable?.should
|
11
|
+
Doc().embeddable?.should be_falsey
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should have logger method" do
|
@@ -122,8 +122,8 @@ describe "Document" do
|
|
122
122
|
it "should use default values if defined for keys" do
|
123
123
|
@document.key :active, Boolean, :default => true
|
124
124
|
|
125
|
-
@document.new.active.should
|
126
|
-
@document.new(:active => false).active.should
|
125
|
+
@document.new.active.should be_truthy
|
126
|
+
@document.new(:active => false).active.should be_falsey
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should use default values if defined even when custom data type" do
|
@@ -147,14 +147,14 @@ describe "Document" do
|
|
147
147
|
|
148
148
|
context "new?" do
|
149
149
|
it "should be true if no id" do
|
150
|
-
@document.new.new?.should
|
150
|
+
@document.new.new?.should be_truthy
|
151
151
|
end
|
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
155
|
doc = silence_stderr { @document.new }
|
156
156
|
doc.id = '1234'
|
157
|
-
doc.new?.should
|
157
|
+
doc.new?.should be_truthy
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
@@ -10,28 +10,28 @@ describe "DynamicFinder" do
|
|
10
10
|
|
11
11
|
context "found?" do
|
12
12
|
it "should be true for find_by" do
|
13
|
-
DynamicFinder.new(:find_by_foo).found?.should
|
13
|
+
DynamicFinder.new(:find_by_foo).found?.should be_truthy
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should be true for find_by with !" do
|
17
|
-
DynamicFinder.new(:find_by_foo!).found?.should
|
17
|
+
DynamicFinder.new(:find_by_foo!).found?.should be_truthy
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should be true for find_all_by" do
|
21
|
-
DynamicFinder.new(:find_all_by_foo).found?.should
|
21
|
+
DynamicFinder.new(:find_all_by_foo).found?.should be_truthy
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should be true for find_or_initialize_by" do
|
25
|
-
DynamicFinder.new(:find_or_initialize_by_foo).found?.should
|
25
|
+
DynamicFinder.new(:find_or_initialize_by_foo).found?.should be_truthy
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should be true for find_or_create_by" do
|
29
|
-
DynamicFinder.new(:find_or_create_by_foo).found?.should
|
29
|
+
DynamicFinder.new(:find_or_create_by_foo).found?.should be_truthy
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should be false for anything else" do
|
33
33
|
[:foobar, :bazwick].each do |method|
|
34
|
-
DynamicFinder.new(method).found?.should
|
34
|
+
DynamicFinder.new(method).found?.should be_falsey
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -65,7 +65,7 @@ describe "DynamicFinder" do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should set bang to false" do
|
68
|
-
DynamicFinder.new(:find_by_foo).bang.should
|
68
|
+
DynamicFinder.new(:find_by_foo).bang.should be_falsey
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -83,7 +83,7 @@ describe "DynamicFinder" do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should set bang to true" do
|
86
|
-
DynamicFinder.new(:find_by_foo!).bang.should
|
86
|
+
DynamicFinder.new(:find_by_foo!).bang.should be_truthy
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -66,12 +66,12 @@ describe "EmbeddedDocument" do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should know it is using object id" do
|
69
|
-
@klass.using_object_id?.should
|
69
|
+
@klass.using_object_id?.should be_truthy
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should know it is not using object id if _id type is changed" do
|
73
73
|
@klass.key :_id, String
|
74
|
-
@klass.using_object_id?.should
|
74
|
+
@klass.using_object_id?.should be_falsey
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -83,7 +83,7 @@ describe "EmbeddedDocument" do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should return false for embeddable" do
|
86
|
-
EDoc().embeddable?.should
|
86
|
+
EDoc().embeddable?.should be_truthy
|
87
87
|
end
|
88
88
|
|
89
89
|
context "#to_mongo" do
|
@@ -96,7 +96,7 @@ describe "EmbeddedDocument" do
|
|
96
96
|
it "should convert to_mongo for other values" do
|
97
97
|
doc = @klass.new(:foo => 'bar')
|
98
98
|
to_mongo = @klass.to_mongo(doc)
|
99
|
-
to_mongo.is_a?(Hash).should
|
99
|
+
to_mongo.is_a?(Hash).should be_truthy
|
100
100
|
to_mongo['foo'].should == 'bar'
|
101
101
|
end
|
102
102
|
end
|
@@ -115,7 +115,7 @@ describe "EmbeddedDocument" do
|
|
115
115
|
|
116
116
|
it "should be instance if hash of attributes" do
|
117
117
|
doc = @klass.from_mongo({:foo => 'bar'})
|
118
|
-
doc.instance_of?(@klass).should
|
118
|
+
doc.instance_of?(@klass).should be_truthy
|
119
119
|
doc.foo.should == 'bar'
|
120
120
|
end
|
121
121
|
end
|
@@ -140,13 +140,13 @@ describe "EmbeddedDocument" do
|
|
140
140
|
key = @document.key(:name, String, :required => true)
|
141
141
|
key.name.should == 'name'
|
142
142
|
key.type.should == String
|
143
|
-
key.options[:required].should
|
143
|
+
key.options[:required].should be_truthy
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should work with name and options" do
|
147
147
|
key = @document.key(:name, :required => true)
|
148
148
|
key.name.should == 'name'
|
149
|
-
key.options[:required].should
|
149
|
+
key.options[:required].should be_truthy
|
150
150
|
end
|
151
151
|
|
152
152
|
it "should be tracked per document" do
|
@@ -206,7 +206,7 @@ describe "EmbeddedDocument" do
|
|
206
206
|
end
|
207
207
|
|
208
208
|
it "should not add anonymous objects to the ancestor tree" do
|
209
|
-
OtherChild.ancestors.any? { |a| a.name.blank? }.should
|
209
|
+
OtherChild.ancestors.any? { |a| a.name.blank? }.should be_falsey
|
210
210
|
end
|
211
211
|
|
212
212
|
it "should not include descendant keys" do
|
@@ -422,7 +422,7 @@ describe "EmbeddedDocument" do
|
|
422
422
|
it "should create key and write value for missing key" do
|
423
423
|
doc = @document.new
|
424
424
|
doc[:foo] = 'string'
|
425
|
-
doc.class.keys.include?('foo').should
|
425
|
+
doc.class.keys.include?('foo').should be_truthy
|
426
426
|
doc[:foo].should == 'string'
|
427
427
|
end
|
428
428
|
|
@@ -550,9 +550,9 @@ describe "EmbeddedDocument" do
|
|
550
550
|
context "checking if a keys value is present" do
|
551
551
|
it "should work for defined keys" do
|
552
552
|
doc = @document.new
|
553
|
-
doc.name?.should
|
553
|
+
doc.name?.should be_falsey
|
554
554
|
doc.name = 'John'
|
555
|
-
doc.name?.should
|
555
|
+
doc.name?.should be_truthy
|
556
556
|
end
|
557
557
|
|
558
558
|
it "should raise no method error for undefined keys" do
|
@@ -590,16 +590,16 @@ describe "EmbeddedDocument" do
|
|
590
590
|
end
|
591
591
|
|
592
592
|
it "should be equal if id and class are the same" do
|
593
|
-
(@document.new('_id' => @oid) == @document.new('_id' => @oid)).should
|
593
|
+
(@document.new('_id' => @oid) == @document.new('_id' => @oid)).should be_truthy
|
594
594
|
end
|
595
595
|
|
596
596
|
it "should not be equal if class same but id different" do
|
597
|
-
(@document.new('_id' => @oid) == @document.new('_id' => BSON::ObjectId.new)).should
|
597
|
+
(@document.new('_id' => @oid) == @document.new('_id' => BSON::ObjectId.new)).should be_falsey
|
598
598
|
end
|
599
599
|
|
600
600
|
it "should not be equal if id same but class different" do
|
601
601
|
another_document = Doc()
|
602
|
-
(@document.new('_id' => @oid) == another_document.new('_id' => @oid)).should
|
602
|
+
(@document.new('_id' => @oid) == another_document.new('_id' => @oid)).should be_falsey
|
603
603
|
end
|
604
604
|
end
|
605
605
|
|
@@ -21,11 +21,11 @@ describe "Support" do
|
|
21
21
|
|
22
22
|
context "Binary.to_mongo" do
|
23
23
|
it "should convert to binary if not binary" do
|
24
|
-
Binary.to_mongo('asdfsadasdfs').is_a?(BSON::Binary).should
|
24
|
+
Binary.to_mongo('asdfsadasdfs').is_a?(BSON::Binary).should be_truthy
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should be binary if binary" do
|
28
|
-
Binary.to_mongo(BSON::Binary.new('asdfsadasdfs')).is_a?(BSON::Binary).should
|
28
|
+
Binary.to_mongo(BSON::Binary.new('asdfsadasdfs')).is_a?(BSON::Binary).should be_truthy
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should be nil if nil" do
|
@@ -42,23 +42,23 @@ describe "Support" do
|
|
42
42
|
|
43
43
|
context "Boolean.to_mongo" do
|
44
44
|
it "should be true for true" do
|
45
|
-
Boolean.to_mongo(true).should
|
45
|
+
Boolean.to_mongo(true).should be_truthy
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should be false for false" do
|
49
|
-
Boolean.to_mongo(false).should
|
49
|
+
Boolean.to_mongo(false).should be_falsey
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should handle odd assortment of other values" do
|
53
|
-
Boolean.to_mongo('true').should
|
54
|
-
Boolean.to_mongo('t').should
|
55
|
-
Boolean.to_mongo('1').should
|
56
|
-
Boolean.to_mongo(1).should
|
53
|
+
Boolean.to_mongo('true').should be_truthy
|
54
|
+
Boolean.to_mongo('t').should be_truthy
|
55
|
+
Boolean.to_mongo('1').should be_truthy
|
56
|
+
Boolean.to_mongo(1).should be_truthy
|
57
57
|
|
58
|
-
Boolean.to_mongo('false').should
|
59
|
-
Boolean.to_mongo('f').should
|
60
|
-
Boolean.to_mongo('0').should
|
61
|
-
Boolean.to_mongo(0).should
|
58
|
+
Boolean.to_mongo('false').should be_falsey
|
59
|
+
Boolean.to_mongo('f').should be_falsey
|
60
|
+
Boolean.to_mongo('0').should be_falsey
|
61
|
+
Boolean.to_mongo(0).should be_falsey
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should be nil for nil" do
|
@@ -68,11 +68,11 @@ describe "Support" do
|
|
68
68
|
|
69
69
|
context "Boolean.from_mongo" do
|
70
70
|
it "should be true for true" do
|
71
|
-
Boolean.from_mongo(true).should
|
71
|
+
Boolean.from_mongo(true).should be_truthy
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should be false for false" do
|
75
|
-
Boolean.from_mongo(false).should
|
75
|
+
Boolean.from_mongo(false).should be_falsey
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should be nil for nil" do
|
@@ -153,7 +153,7 @@ describe "Support" do
|
|
153
153
|
it "should be hash if nil" do
|
154
154
|
hash = Hash.from_mongo(nil)
|
155
155
|
hash.should == {}
|
156
|
-
hash.is_a?(HashWithIndifferentAccess).should
|
156
|
+
hash.is_a?(HashWithIndifferentAccess).should be_truthy
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
@@ -207,7 +207,7 @@ describe "Support" do
|
|
207
207
|
context "ObjectId#to_mongo" do
|
208
208
|
it "should call class to_mongo with self" do
|
209
209
|
object = Object.new
|
210
|
-
object.class.
|
210
|
+
expect(object.class).to receive(:to_mongo).with(object)
|
211
211
|
object.to_mongo
|
212
212
|
end
|
213
213
|
end
|
@@ -359,7 +359,7 @@ describe "Support" do
|
|
359
359
|
|
360
360
|
time = Time.from_mongo(Time.utc(2009, 10, 1))
|
361
361
|
time.should == Time.zone.local(2009, 9, 30, 14)
|
362
|
-
time.is_a?(ActiveSupport::TimeWithZone).should
|
362
|
+
time.is_a?(ActiveSupport::TimeWithZone).should be_truthy
|
363
363
|
|
364
364
|
Time.zone = nil
|
365
365
|
end
|