mongo_mapper 0.13.1 → 0.15.2
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 +61 -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 +4 -0
- data/lib/mongo_mapper/connection.rb +16 -38
- 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/object_id.rb +5 -1
- data/lib/mongo_mapper/extensions/string.rb +13 -5
- data/lib/mongo_mapper/plugins/accessible.rb +13 -12
- data/lib/mongo_mapper/plugins/associations.rb +7 -6
- data/lib/mongo_mapper/plugins/associations/base.rb +23 -14
- data/lib/mongo_mapper/plugins/associations/belongs_to_association.rb +1 -1
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +9 -8
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +18 -11
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +4 -4
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +60 -29
- data/lib/mongo_mapper/plugins/associations/in_foreign_array_proxy.rb +136 -0
- data/lib/mongo_mapper/plugins/associations/many_association.rb +4 -2
- 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 +12 -10
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +27 -26
- data/lib/mongo_mapper/plugins/associations/proxy.rb +38 -27
- data/lib/mongo_mapper/plugins/associations/single_association.rb +5 -4
- 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 +29 -37
- data/lib/mongo_mapper/plugins/document.rb +1 -1
- data/lib/mongo_mapper/plugins/dynamic_querying.rb +10 -9
- data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +18 -17
- data/lib/mongo_mapper/plugins/embedded_callbacks.rb +2 -1
- data/lib/mongo_mapper/plugins/embedded_document.rb +2 -2
- data/lib/mongo_mapper/plugins/identity_map.rb +4 -2
- data/lib/mongo_mapper/plugins/indexes.rb +14 -7
- data/lib/mongo_mapper/plugins/keys.rb +164 -159
- data/lib/mongo_mapper/plugins/keys/key.rb +27 -16
- data/lib/mongo_mapper/plugins/keys/static.rb +45 -0
- data/lib/mongo_mapper/plugins/modifiers.rb +64 -38
- data/lib/mongo_mapper/plugins/partial_updates.rb +86 -0
- data/lib/mongo_mapper/plugins/persistence.rb +13 -8
- data/lib/mongo_mapper/plugins/protected.rb +6 -5
- data/lib/mongo_mapper/plugins/querying.rb +85 -42
- data/lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb +20 -15
- data/lib/mongo_mapper/plugins/safe.rb +10 -4
- data/lib/mongo_mapper/plugins/scopes.rb +94 -7
- data/lib/mongo_mapper/plugins/stats.rb +1 -3
- data/lib/mongo_mapper/plugins/strong_parameters.rb +26 -0
- data/lib/mongo_mapper/plugins/timestamps.rb +1 -0
- data/lib/mongo_mapper/plugins/validations.rb +0 -0
- 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/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/examples.txt +1728 -0
- data/spec/functional/accessible_spec.rb +19 -13
- data/spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb +13 -13
- data/spec/functional/associations/belongs_to_proxy_spec.rb +54 -20
- data/spec/functional/associations/in_array_proxy_spec.rb +145 -10
- 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 +85 -14
- data/spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb +13 -13
- data/spec/functional/associations/many_embedded_proxy_spec.rb +1 -1
- data/spec/functional/associations/many_polymorphic_proxy_spec.rb +4 -4
- data/spec/functional/associations/one_as_proxy_spec.rb +10 -10
- data/spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb +9 -9
- data/spec/functional/associations/one_embedded_proxy_spec.rb +31 -3
- data/spec/functional/associations/one_proxy_spec.rb +21 -11
- data/spec/functional/associations_spec.rb +3 -3
- data/spec/functional/binary_spec.rb +2 -2
- data/spec/functional/caching_spec.rb +8 -15
- data/spec/functional/callbacks_spec.rb +89 -2
- data/spec/functional/counter_cache_spec.rb +89 -0
- data/spec/functional/dirty_spec.rb +84 -46
- data/spec/functional/dirty_with_callbacks_spec.rb +59 -0
- data/spec/functional/document_spec.rb +2 -5
- data/spec/functional/dumpable_spec.rb +1 -1
- data/spec/functional/embedded_document_spec.rb +17 -17
- data/spec/functional/identity_map_spec.rb +29 -16
- data/spec/functional/indexes_spec.rb +19 -18
- data/spec/functional/keys_spec.rb +55 -28
- data/spec/functional/logger_spec.rb +3 -3
- data/spec/functional/modifiers_spec.rb +81 -19
- data/spec/functional/partial_updates_spec.rb +577 -0
- data/spec/functional/protected_spec.rb +14 -14
- data/spec/functional/querying_spec.rb +77 -28
- data/spec/functional/safe_spec.rb +23 -27
- data/spec/functional/sci_spec.rb +9 -9
- data/spec/functional/scopes_spec.rb +323 -2
- data/spec/functional/static_keys_spec.rb +153 -0
- data/spec/functional/stats_spec.rb +28 -16
- data/spec/functional/strong_parameters_spec.rb +49 -0
- data/spec/functional/touch_spec.rb +1 -1
- data/spec/functional/validations_spec.rb +51 -57
- data/spec/quality_spec.rb +2 -2
- data/spec/spec_helper.rb +37 -9
- data/spec/support/matchers.rb +5 -14
- 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 +26 -20
- data/spec/unit/clone_spec.rb +1 -1
- data/spec/unit/document_spec.rb +8 -8
- data/spec/unit/dynamic_finder_spec.rb +8 -8
- data/spec/unit/embedded_document_spec.rb +18 -19
- data/spec/unit/extensions_spec.rb +17 -17
- data/spec/unit/identity_map_middleware_spec.rb +65 -96
- data/spec/unit/key_spec.rb +28 -26
- data/spec/unit/keys_spec.rb +20 -11
- data/spec/unit/mongo_mapper_spec.rb +38 -85
- data/spec/unit/serialization_spec.rb +1 -1
- data/spec/unit/time_zones_spec.rb +2 -2
- data/spec/unit/validations_spec.rb +46 -33
- metadata +56 -32
- data/README.rdoc +0 -59
- data/lib/mongo_mapper/connections/10gen.rb +0 -0
- data/lib/mongo_mapper/connections/moped.rb +0 -0
- data/lib/mongo_mapper/extensions/ordered_hash.rb +0 -23
|
@@ -3,23 +3,28 @@ require 'spec_helper'
|
|
|
3
3
|
class Address; end
|
|
4
4
|
|
|
5
5
|
describe "MongoMapper" do
|
|
6
|
-
it "should be able to write and read connection" do
|
|
7
|
-
conn = Mongo::
|
|
6
|
+
it "should be able to write and read connection", :without_connection do
|
|
7
|
+
conn = Mongo::Client.new(['127.0.0.1:27001'])
|
|
8
8
|
MongoMapper.connection = conn
|
|
9
9
|
MongoMapper.connection.should == conn
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
it "should default connection to new mongo ruby driver" do
|
|
12
|
+
it "should default connection to new mongo ruby driver", :without_connection do
|
|
13
13
|
MongoMapper.connection = nil
|
|
14
|
-
MongoMapper.connection.should be_instance_of(Mongo::
|
|
14
|
+
MongoMapper.connection.should be_instance_of(Mongo::Client)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
it "should be able to
|
|
18
|
-
MongoMapper.database
|
|
19
|
-
MongoMapper.database.should be_instance_of(Mongo::DB)
|
|
17
|
+
it "should be able to read default database" do
|
|
18
|
+
MongoMapper.database.should be_instance_of(Mongo::Database)
|
|
20
19
|
MongoMapper.database.name.should == 'test'
|
|
21
20
|
end
|
|
22
21
|
|
|
22
|
+
it "should be able to write default database", :without_connection do
|
|
23
|
+
MongoMapper.database = 'test-2'
|
|
24
|
+
MongoMapper.database.should be_instance_of(Mongo::Database)
|
|
25
|
+
MongoMapper.database.name.should == 'test-2'
|
|
26
|
+
end
|
|
27
|
+
|
|
23
28
|
it "should have document not found error" do
|
|
24
29
|
lambda {
|
|
25
30
|
MongoMapper::DocumentNotFound
|
|
@@ -35,96 +40,64 @@ describe "MongoMapper" do
|
|
|
35
40
|
MongoMapper.config.should == config
|
|
36
41
|
end
|
|
37
42
|
|
|
38
|
-
context "connecting to environment from config" do
|
|
39
|
-
it "should work without authentication" do
|
|
40
|
-
MongoMapper.config = {
|
|
41
|
-
'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'}
|
|
42
|
-
}
|
|
43
|
-
Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, {})
|
|
44
|
-
MongoMapper.should_receive(:database=).with('test')
|
|
45
|
-
Mongo::DB.any_instance.should_receive(:authenticate).never
|
|
46
|
-
MongoMapper.connect('development')
|
|
47
|
-
end
|
|
43
|
+
context "connecting to environment from config", :without_connection do
|
|
48
44
|
|
|
49
45
|
it "should work without authentication using uri" do
|
|
50
46
|
MongoMapper.config = {
|
|
51
47
|
'development' => {'uri' => 'mongodb://127.0.0.1:27017/test'}
|
|
52
48
|
}
|
|
53
|
-
Mongo::
|
|
54
|
-
MongoMapper.should_receive(:database=).with('test')
|
|
55
|
-
Mongo::DB.any_instance.should_receive(:authenticate).never
|
|
49
|
+
Mongo::Client.should_receive(:new).with('mongodb://127.0.0.1:27017/test', {})
|
|
56
50
|
MongoMapper.connect('development')
|
|
57
51
|
end
|
|
58
52
|
|
|
59
|
-
it "should work
|
|
53
|
+
it "should work without authentication using hosts" do
|
|
60
54
|
MongoMapper.config = {
|
|
61
|
-
'development' => {'
|
|
55
|
+
'development' => {'hosts' => ['127.0.0.1:27017']}
|
|
62
56
|
}
|
|
63
|
-
Mongo::
|
|
64
|
-
MongoMapper.
|
|
65
|
-
Mongo::DB.any_instance.should_receive(:authenticate).never
|
|
66
|
-
MongoMapper.connect(:development)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "should work with options" do
|
|
70
|
-
MongoMapper.config = {
|
|
71
|
-
'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test'}
|
|
72
|
-
}
|
|
73
|
-
connection, logger = double('connection'), double('logger')
|
|
74
|
-
Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, :logger => logger)
|
|
75
|
-
MongoMapper.connect('development', :logger => logger)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "should pass along ssl when true" do
|
|
79
|
-
MongoMapper.config = {
|
|
80
|
-
'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test', 'ssl' => true}
|
|
81
|
-
}
|
|
82
|
-
connection, logger = double('connection'), double('logger')
|
|
83
|
-
Mongo::MongoClient.should_receive(:new).with('127.0.0.1', 27017, :logger => logger, :ssl => true)
|
|
84
|
-
MongoMapper.connect('development', :logger => logger)
|
|
57
|
+
Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], {})
|
|
58
|
+
MongoMapper.connect('development')
|
|
85
59
|
end
|
|
86
60
|
|
|
87
|
-
it "should
|
|
61
|
+
it "should work without authentication using host" do
|
|
88
62
|
MongoMapper.config = {
|
|
89
|
-
'development' => {'host' => '127.0.0.1
|
|
63
|
+
'development' => {'host' => '127.0.0.1:27017'}
|
|
90
64
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
MongoMapper.connect('development', :logger => logger)
|
|
65
|
+
Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], {})
|
|
66
|
+
MongoMapper.connect('development')
|
|
94
67
|
end
|
|
95
68
|
|
|
96
69
|
it "should convert read preferences to symbols" do
|
|
97
70
|
MongoMapper.config = {
|
|
98
|
-
'development' => {'
|
|
71
|
+
'development' => {'hosts' => ['127.0.0.1:27017'], 'database' => 'test', 'read' => 'primary'}
|
|
99
72
|
}
|
|
100
|
-
|
|
101
|
-
Mongo::
|
|
73
|
+
logger = double('logger')
|
|
74
|
+
Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], :logger => logger, :read => :primary, :database => 'test')
|
|
102
75
|
MongoMapper.connect('development', :logger => logger)
|
|
103
76
|
end
|
|
104
77
|
|
|
105
78
|
it "should work with options from config" do
|
|
106
79
|
MongoMapper.config = {
|
|
107
|
-
'development' => {'
|
|
80
|
+
'development' => {'hosts' => ['192.168.1.1:2222'], 'database' => 'test', 'safe' => true}
|
|
108
81
|
}
|
|
109
|
-
|
|
110
|
-
Mongo::
|
|
82
|
+
logger = double('logger')
|
|
83
|
+
Mongo::Client.should_receive(:new).with(['192.168.1.1:2222'], :logger => logger, :safe => true, :database => 'test')
|
|
111
84
|
MongoMapper.connect('development', :logger => logger)
|
|
112
85
|
end
|
|
113
86
|
|
|
114
87
|
it "should work with options using uri" do
|
|
115
88
|
MongoMapper.config = {
|
|
116
|
-
'development' => {'uri' => 'mongodb://127.0.0.1:27017/test'}
|
|
89
|
+
'development' => {'uri' => 'mongodb://127.0.0.1:27017/test', 'options'=> {:foo => 1}}
|
|
117
90
|
}
|
|
118
|
-
|
|
119
|
-
Mongo::
|
|
91
|
+
logger = double('logger')
|
|
92
|
+
Mongo::Client.should_receive(:new).with('mongodb://127.0.0.1:27017/test', :logger => logger, :foo => 1)
|
|
120
93
|
MongoMapper.connect('development', :logger => logger)
|
|
121
94
|
end
|
|
122
95
|
|
|
123
96
|
it "should work with authentication" do
|
|
124
97
|
MongoMapper.config = {
|
|
125
|
-
'development' => {'
|
|
98
|
+
'development' => {'hosts' => ['127.0.0.1:27017'], 'database' => 'test', 'user' => 'john', 'password' => 'secret'}
|
|
126
99
|
}
|
|
127
|
-
Mongo::
|
|
100
|
+
Mongo::Client.should_receive(:new).with(['127.0.0.1:27017'], :database => 'test', :user => 'john', :password => 'secret')
|
|
128
101
|
MongoMapper.connect('development')
|
|
129
102
|
end
|
|
130
103
|
|
|
@@ -132,7 +105,7 @@ describe "MongoMapper" do
|
|
|
132
105
|
MongoMapper.config = {
|
|
133
106
|
'development' => {'uri' => 'mongodb://john:secret@127.0.0.1:27017/test'}
|
|
134
107
|
}
|
|
135
|
-
Mongo::
|
|
108
|
+
Mongo::Client.should_receive(:new).with('mongodb://john:secret@127.0.0.1:27017/test', {})
|
|
136
109
|
MongoMapper.connect('development')
|
|
137
110
|
end
|
|
138
111
|
|
|
@@ -140,36 +113,16 @@ describe "MongoMapper" do
|
|
|
140
113
|
MongoMapper.config = {
|
|
141
114
|
'development' => {'uri' => 'mysql://127.0.0.1:5336/foo'}
|
|
142
115
|
}
|
|
143
|
-
|
|
116
|
+
lambda { MongoMapper.connect('development') }.should raise_error(Mongo::Error::InvalidURI)
|
|
144
117
|
end
|
|
145
118
|
|
|
146
|
-
it
|
|
119
|
+
it 'should forbid use of port' do
|
|
147
120
|
MongoMapper.config = {
|
|
148
|
-
'development' => {
|
|
149
|
-
'hosts' => [ ['127.0.0.1', 27017], ['localhost', 27017] ],
|
|
150
|
-
'database' => 'test'
|
|
151
|
-
}
|
|
121
|
+
'development' => {'host' => '192.168.1.1', 'port' => '27017', 'database' => 'test', 'safe' => true}
|
|
152
122
|
}
|
|
153
|
-
|
|
154
|
-
Mongo::MongoReplicaSetClient.should_receive(:new).with( ['127.0.0.1', 27017], ['localhost', 27017], {'read_secondary' => true} )
|
|
155
|
-
MongoMapper.should_receive(:database=).with('test')
|
|
156
|
-
Mongo::DB.any_instance.should_receive(:authenticate).never
|
|
157
|
-
MongoMapper.connect('development', 'read_secondary' => true)
|
|
123
|
+
lambda { MongoMapper.connect('development') }.should raise_error(RuntimeError)
|
|
158
124
|
end
|
|
159
125
|
|
|
160
|
-
it "should create a replica set connection if config contains multiple hosts in the new format" do
|
|
161
|
-
MongoMapper.config = {
|
|
162
|
-
'development' => {
|
|
163
|
-
'hosts' => ['127.0.0.1:27017', 'localhost:27017'],
|
|
164
|
-
'database' => 'test'
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
Mongo::MongoReplicaSetClient.should_receive(:new).with( ['127.0.0.1:27017', 'localhost:27017'], {'read_secondary' => true} )
|
|
169
|
-
MongoMapper.should_receive(:database=).with('test')
|
|
170
|
-
Mongo::DB.any_instance.should_receive(:authenticate).never
|
|
171
|
-
MongoMapper.connect('development', 'read_secondary' => true)
|
|
172
|
-
end
|
|
173
126
|
end
|
|
174
127
|
|
|
175
128
|
context "setup" do
|
|
@@ -151,7 +151,7 @@ module Serialization
|
|
|
151
151
|
|
|
152
152
|
@instance.name.should == unserialized.name
|
|
153
153
|
@instance.age.should == unserialized.age
|
|
154
|
-
unserialized.awesome.should
|
|
154
|
+
unserialized.awesome.should be_falsey
|
|
155
155
|
unserialized.created_at.should be_nil
|
|
156
156
|
end
|
|
157
157
|
|
|
@@ -25,7 +25,7 @@ describe "TimeZones" do
|
|
|
25
25
|
Time.zone = 'UTC'
|
|
26
26
|
|
|
27
27
|
doc = @document.new(:created_at => "2009-08-15 14:00:00")
|
|
28
|
-
doc.created_at.is_a?(ActiveSupport::TimeWithZone).should
|
|
28
|
+
doc.created_at.is_a?(ActiveSupport::TimeWithZone).should be_truthy
|
|
29
29
|
doc.created_at.should == Time.utc(2009, 8, 15, 14)
|
|
30
30
|
|
|
31
31
|
Time.zone = nil
|
|
@@ -35,7 +35,7 @@ describe "TimeZones" do
|
|
|
35
35
|
Time.zone = 'Hawaii'
|
|
36
36
|
|
|
37
37
|
doc = @document.new(:created_at => "2009-08-15 14:00:00")
|
|
38
|
-
doc.created_at.is_a?(ActiveSupport::TimeWithZone).should
|
|
38
|
+
doc.created_at.is_a?(ActiveSupport::TimeWithZone).should be_truthy
|
|
39
39
|
doc.created_at.should == Time.utc(2009, 8, 16)
|
|
40
40
|
|
|
41
41
|
Time.zone = nil
|
|
@@ -27,7 +27,7 @@ describe "Validations" do
|
|
|
27
27
|
doc = @document.new
|
|
28
28
|
doc.password = 'foobar'
|
|
29
29
|
doc.password_confirmation = 'foobar1'
|
|
30
|
-
doc.should have_error_on(:
|
|
30
|
+
doc.should have_error_on(:password).or(have_error_on(:password_confirmation))
|
|
31
31
|
|
|
32
32
|
doc.password_confirmation = 'foobar'
|
|
33
33
|
doc.should_not have_error_on(:password)
|
|
@@ -157,19 +157,19 @@ describe "Validations" do
|
|
|
157
157
|
end # numericality of
|
|
158
158
|
|
|
159
159
|
context "validating presence of" do
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
160
|
+
it "should work with validates_presence_of macro" do
|
|
161
|
+
@document.key :name, String
|
|
162
|
+
@document.validates_presence_of :name
|
|
163
|
+
doc = @document.new
|
|
164
|
+
doc.should have_error_on(:name)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it "should work with :required shortcut on key definition" do
|
|
168
|
+
@document.key :name, String, :required => true
|
|
169
|
+
doc = @document.new
|
|
170
|
+
doc.should have_error_on(:name)
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
173
|
|
|
174
174
|
context "validating exclusion of" do
|
|
175
175
|
it "should throw error if enumerator not provided" do
|
|
@@ -190,7 +190,8 @@ describe "Validations" do
|
|
|
190
190
|
doc.should_not have_error_on(:action)
|
|
191
191
|
|
|
192
192
|
doc.action = 'kick'
|
|
193
|
-
doc.should have_error_on(:action
|
|
193
|
+
doc.should have_error_on(:action)
|
|
194
|
+
doc.errors[:action].should == ['is reserved']
|
|
194
195
|
end
|
|
195
196
|
|
|
196
197
|
it "should work with :not_in shortcut on key definition" do
|
|
@@ -203,7 +204,8 @@ describe "Validations" do
|
|
|
203
204
|
doc.should_not have_error_on(:action)
|
|
204
205
|
|
|
205
206
|
doc.action = 'kick'
|
|
206
|
-
doc.should have_error_on(:action
|
|
207
|
+
doc.should have_error_on(:action)
|
|
208
|
+
doc.errors[:action].should == ['is reserved']
|
|
207
209
|
end
|
|
208
210
|
|
|
209
211
|
it "should not have error if allow nil is true and value is nil" do
|
|
@@ -236,10 +238,12 @@ describe "Validations" do
|
|
|
236
238
|
@document.validates_inclusion_of :action, :in => %w(kick run)
|
|
237
239
|
|
|
238
240
|
doc = @document.new
|
|
239
|
-
doc.should have_error_on(:action
|
|
241
|
+
doc.should have_error_on(:action)
|
|
242
|
+
doc.errors[:action].should == ['is not included in the list']
|
|
240
243
|
|
|
241
244
|
doc.action = 'fart'
|
|
242
|
-
doc.should have_error_on(:action
|
|
245
|
+
doc.should have_error_on(:action)
|
|
246
|
+
doc.errors[:action].should == ['is not included in the list']
|
|
243
247
|
|
|
244
248
|
doc.action = 'kick'
|
|
245
249
|
doc.should_not have_error_on(:action)
|
|
@@ -249,10 +253,12 @@ describe "Validations" do
|
|
|
249
253
|
@document.key :action, String, :in => %w(kick run)
|
|
250
254
|
|
|
251
255
|
doc = @document.new
|
|
252
|
-
doc.should have_error_on(:action
|
|
256
|
+
doc.should have_error_on(:action)
|
|
257
|
+
doc.errors[:action].should == ['is not included in the list']
|
|
253
258
|
|
|
254
259
|
doc.action = 'fart'
|
|
255
|
-
doc.should have_error_on(:action
|
|
260
|
+
doc.should have_error_on(:action)
|
|
261
|
+
doc.errors[:action].should == ['is not included in the list']
|
|
256
262
|
|
|
257
263
|
doc.action = 'kick'
|
|
258
264
|
doc.should_not have_error_on(:action)
|
|
@@ -262,7 +268,8 @@ describe "Validations" do
|
|
|
262
268
|
@document.key :flag, Boolean, :required => true
|
|
263
269
|
|
|
264
270
|
doc = @document.new
|
|
265
|
-
doc.should have_error_on(:flag
|
|
271
|
+
doc.should have_error_on(:flag)
|
|
272
|
+
doc.errors[:flag].should == ['is not included in the list']
|
|
266
273
|
|
|
267
274
|
doc.flag = true
|
|
268
275
|
doc.should_not have_error_on(:action)
|
|
@@ -313,7 +320,7 @@ describe "Validations" do
|
|
|
313
320
|
doc = @embedded_doc.new
|
|
314
321
|
doc.password = 'foobar'
|
|
315
322
|
doc.password_confirmation = 'foobar1'
|
|
316
|
-
doc.should have_error_on(:password).or(:password_confirmation)
|
|
323
|
+
doc.should have_error_on(:password).or(have_error_on(:password_confirmation))
|
|
317
324
|
doc.password_confirmation = 'foobar'
|
|
318
325
|
doc.should_not have_error_on(:password)
|
|
319
326
|
end
|
|
@@ -429,19 +436,19 @@ describe "Validations" do
|
|
|
429
436
|
end # numericality of
|
|
430
437
|
|
|
431
438
|
context "validating presence of" do
|
|
432
|
-
|
|
439
|
+
it "should work with validates_presence_of macro" do
|
|
433
440
|
@embedded_doc.key :name, String
|
|
434
441
|
@embedded_doc.validates_presence_of :name
|
|
435
442
|
doc = @embedded_doc.new
|
|
436
443
|
doc.should have_error_on(:name)
|
|
437
|
-
|
|
444
|
+
end
|
|
438
445
|
|
|
439
|
-
|
|
446
|
+
it "should work with :required shortcut on key definition" do
|
|
440
447
|
@embedded_doc.key :name, String, :required => true
|
|
441
448
|
doc = @embedded_doc.new
|
|
442
449
|
doc.should have_error_on(:name)
|
|
443
|
-
|
|
444
|
-
|
|
450
|
+
end
|
|
451
|
+
end
|
|
445
452
|
|
|
446
453
|
context "validating exclusion of" do
|
|
447
454
|
it "should throw error if enumerator not provided" do
|
|
@@ -462,7 +469,8 @@ describe "Validations" do
|
|
|
462
469
|
doc.should_not have_error_on(:action)
|
|
463
470
|
|
|
464
471
|
doc.action = 'kick'
|
|
465
|
-
doc.should have_error_on(:action
|
|
472
|
+
doc.should have_error_on(:action)
|
|
473
|
+
doc.errors[:action].should == ['is reserved']
|
|
466
474
|
end
|
|
467
475
|
|
|
468
476
|
it "should work with :not_in shortcut on key definition" do
|
|
@@ -475,7 +483,8 @@ describe "Validations" do
|
|
|
475
483
|
doc.should_not have_error_on(:action)
|
|
476
484
|
|
|
477
485
|
doc.action = 'kick'
|
|
478
|
-
doc.should have_error_on(:action
|
|
486
|
+
doc.should have_error_on(:action)
|
|
487
|
+
doc.errors[:action].should == ['is reserved']
|
|
479
488
|
end
|
|
480
489
|
|
|
481
490
|
it "should not have error if allow nil is true and value is nil" do
|
|
@@ -508,10 +517,12 @@ describe "Validations" do
|
|
|
508
517
|
@embedded_doc.validates_inclusion_of :action, :in => %w(kick run)
|
|
509
518
|
|
|
510
519
|
doc = @embedded_doc.new
|
|
511
|
-
doc.should have_error_on(:action
|
|
520
|
+
doc.should have_error_on(:action)
|
|
521
|
+
doc.errors[:action].should == ['is not included in the list']
|
|
512
522
|
|
|
513
523
|
doc.action = 'fart'
|
|
514
|
-
doc.should have_error_on(:action
|
|
524
|
+
doc.should have_error_on(:action)
|
|
525
|
+
doc.errors[:action].should == ['is not included in the list']
|
|
515
526
|
|
|
516
527
|
doc.action = 'kick'
|
|
517
528
|
doc.should_not have_error_on(:action)
|
|
@@ -521,10 +532,12 @@ describe "Validations" do
|
|
|
521
532
|
@embedded_doc.key :action, String, :in => %w(kick run)
|
|
522
533
|
|
|
523
534
|
doc = @embedded_doc.new
|
|
524
|
-
doc.should have_error_on(:action
|
|
535
|
+
doc.should have_error_on(:action)
|
|
536
|
+
doc.errors[:action].should == ['is not included in the list']
|
|
525
537
|
|
|
526
538
|
doc.action = 'fart'
|
|
527
|
-
doc.should have_error_on(:action
|
|
539
|
+
doc.should have_error_on(:action)
|
|
540
|
+
doc.errors[:action].should == ['is not included in the list']
|
|
528
541
|
|
|
529
542
|
doc.action = 'kick'
|
|
530
543
|
doc.should_not have_error_on(:action)
|
metadata
CHANGED
|
@@ -1,81 +1,99 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mongo_mapper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.15.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Nunemaker
|
|
8
|
-
|
|
8
|
+
- Chris Heald
|
|
9
|
+
- Scott Taylor
|
|
10
|
+
autorequire:
|
|
9
11
|
bindir: bin
|
|
10
12
|
cert_chain: []
|
|
11
|
-
date:
|
|
13
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
|
12
14
|
dependencies:
|
|
13
15
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
16
|
+
name: mongo
|
|
15
17
|
requirement: !ruby/object:Gem::Requirement
|
|
16
18
|
requirements:
|
|
17
|
-
- -
|
|
19
|
+
- - "~>"
|
|
18
20
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
21
|
+
version: '2.0'
|
|
20
22
|
type: :runtime
|
|
21
23
|
prerelease: false
|
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
25
|
requirements:
|
|
24
|
-
- -
|
|
26
|
+
- - "~>"
|
|
25
27
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
28
|
+
version: '2.0'
|
|
29
|
+
- !ruby/object:Gem::Dependency
|
|
30
|
+
name: plucky
|
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
|
32
|
+
requirements:
|
|
33
|
+
- - "~>"
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: 0.8.0
|
|
36
|
+
type: :runtime
|
|
37
|
+
prerelease: false
|
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - "~>"
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: 0.8.0
|
|
27
43
|
- !ruby/object:Gem::Dependency
|
|
28
44
|
name: activesupport
|
|
29
45
|
requirement: !ruby/object:Gem::Requirement
|
|
30
46
|
requirements:
|
|
31
|
-
- -
|
|
47
|
+
- - ">="
|
|
32
48
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
49
|
+
version: '5.0'
|
|
34
50
|
type: :runtime
|
|
35
51
|
prerelease: false
|
|
36
52
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
53
|
requirements:
|
|
38
|
-
- -
|
|
54
|
+
- - ">="
|
|
39
55
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
56
|
+
version: '5.0'
|
|
41
57
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
58
|
+
name: activemodel
|
|
43
59
|
requirement: !ruby/object:Gem::Requirement
|
|
44
60
|
requirements:
|
|
45
|
-
- -
|
|
61
|
+
- - ">="
|
|
46
62
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 0
|
|
63
|
+
version: '5.0'
|
|
48
64
|
type: :runtime
|
|
49
65
|
prerelease: false
|
|
50
66
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
67
|
requirements:
|
|
52
|
-
- -
|
|
68
|
+
- - ">="
|
|
53
69
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 0
|
|
70
|
+
version: '5.0'
|
|
55
71
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
72
|
+
name: activemodel-serializers-xml
|
|
57
73
|
requirement: !ruby/object:Gem::Requirement
|
|
58
74
|
requirements:
|
|
59
|
-
- - ~>
|
|
75
|
+
- - "~>"
|
|
60
76
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '1.
|
|
77
|
+
version: '1.0'
|
|
62
78
|
type: :runtime
|
|
63
79
|
prerelease: false
|
|
64
80
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
81
|
requirements:
|
|
66
|
-
- - ~>
|
|
82
|
+
- - "~>"
|
|
67
83
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '1.
|
|
84
|
+
version: '1.0'
|
|
69
85
|
description: MongoMapper is a Object-Document Mapper for Ruby and Rails
|
|
70
86
|
email:
|
|
71
87
|
- nunemaker@gmail.com
|
|
88
|
+
- cheald@gmail.com
|
|
89
|
+
- scott@railsnewbie.com
|
|
72
90
|
executables:
|
|
73
91
|
- mmconsole
|
|
74
92
|
extensions: []
|
|
75
93
|
extra_rdoc_files: []
|
|
76
94
|
files:
|
|
77
95
|
- LICENSE
|
|
78
|
-
- README.
|
|
96
|
+
- README.md
|
|
79
97
|
- UPGRADES
|
|
80
98
|
- bin/mmconsole
|
|
81
99
|
- examples/attr_accessible.rb
|
|
@@ -93,8 +111,6 @@ files:
|
|
|
93
111
|
- examples/validating/embedded_docs.rb
|
|
94
112
|
- lib/mongo_mapper.rb
|
|
95
113
|
- lib/mongo_mapper/connection.rb
|
|
96
|
-
- lib/mongo_mapper/connections/10gen.rb
|
|
97
|
-
- lib/mongo_mapper/connections/moped.rb
|
|
98
114
|
- lib/mongo_mapper/document.rb
|
|
99
115
|
- lib/mongo_mapper/embedded_document.rb
|
|
100
116
|
- lib/mongo_mapper/exceptions.rb
|
|
@@ -109,7 +125,6 @@ files:
|
|
|
109
125
|
- lib/mongo_mapper/extensions/nil_class.rb
|
|
110
126
|
- lib/mongo_mapper/extensions/object.rb
|
|
111
127
|
- lib/mongo_mapper/extensions/object_id.rb
|
|
112
|
-
- lib/mongo_mapper/extensions/ordered_hash.rb
|
|
113
128
|
- lib/mongo_mapper/extensions/set.rb
|
|
114
129
|
- lib/mongo_mapper/extensions/string.rb
|
|
115
130
|
- lib/mongo_mapper/extensions/symbol.rb
|
|
@@ -127,6 +142,7 @@ files:
|
|
|
127
142
|
- lib/mongo_mapper/plugins/associations/collection.rb
|
|
128
143
|
- lib/mongo_mapper/plugins/associations/embedded_collection.rb
|
|
129
144
|
- lib/mongo_mapper/plugins/associations/in_array_proxy.rb
|
|
145
|
+
- lib/mongo_mapper/plugins/associations/in_foreign_array_proxy.rb
|
|
130
146
|
- lib/mongo_mapper/plugins/associations/many_association.rb
|
|
131
147
|
- lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb
|
|
132
148
|
- lib/mongo_mapper/plugins/associations/many_documents_proxy.rb
|
|
@@ -157,9 +173,11 @@ files:
|
|
|
157
173
|
- lib/mongo_mapper/plugins/inspect.rb
|
|
158
174
|
- lib/mongo_mapper/plugins/keys.rb
|
|
159
175
|
- lib/mongo_mapper/plugins/keys/key.rb
|
|
176
|
+
- lib/mongo_mapper/plugins/keys/static.rb
|
|
160
177
|
- lib/mongo_mapper/plugins/logger.rb
|
|
161
178
|
- lib/mongo_mapper/plugins/modifiers.rb
|
|
162
179
|
- lib/mongo_mapper/plugins/pagination.rb
|
|
180
|
+
- lib/mongo_mapper/plugins/partial_updates.rb
|
|
163
181
|
- lib/mongo_mapper/plugins/persistence.rb
|
|
164
182
|
- lib/mongo_mapper/plugins/protected.rb
|
|
165
183
|
- lib/mongo_mapper/plugins/querying.rb
|
|
@@ -171,6 +189,7 @@ files:
|
|
|
171
189
|
- lib/mongo_mapper/plugins/scopes.rb
|
|
172
190
|
- lib/mongo_mapper/plugins/serialization.rb
|
|
173
191
|
- lib/mongo_mapper/plugins/stats.rb
|
|
192
|
+
- lib/mongo_mapper/plugins/strong_parameters.rb
|
|
174
193
|
- lib/mongo_mapper/plugins/timestamps.rb
|
|
175
194
|
- lib/mongo_mapper/plugins/touch.rb
|
|
176
195
|
- lib/mongo_mapper/plugins/userstamps.rb
|
|
@@ -184,10 +203,12 @@ files:
|
|
|
184
203
|
- lib/rails/generators/mongo_mapper/config/templates/mongo.yml
|
|
185
204
|
- lib/rails/generators/mongo_mapper/model/model_generator.rb
|
|
186
205
|
- lib/rails/generators/mongo_mapper/model/templates/model.rb
|
|
206
|
+
- spec/examples.txt
|
|
187
207
|
- spec/functional/accessible_spec.rb
|
|
188
208
|
- spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb
|
|
189
209
|
- spec/functional/associations/belongs_to_proxy_spec.rb
|
|
190
210
|
- spec/functional/associations/in_array_proxy_spec.rb
|
|
211
|
+
- spec/functional/associations/in_foreign_array_proxy_spec.rb
|
|
191
212
|
- spec/functional/associations/many_documents_as_proxy_spec.rb
|
|
192
213
|
- spec/functional/associations/many_documents_proxy_spec.rb
|
|
193
214
|
- spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb
|
|
@@ -203,6 +224,7 @@ files:
|
|
|
203
224
|
- spec/functional/callbacks_spec.rb
|
|
204
225
|
- spec/functional/counter_cache_spec.rb
|
|
205
226
|
- spec/functional/dirty_spec.rb
|
|
227
|
+
- spec/functional/dirty_with_callbacks_spec.rb
|
|
206
228
|
- spec/functional/document_spec.rb
|
|
207
229
|
- spec/functional/dumpable_spec.rb
|
|
208
230
|
- spec/functional/dynamic_querying_spec.rb
|
|
@@ -215,13 +237,16 @@ files:
|
|
|
215
237
|
- spec/functional/logger_spec.rb
|
|
216
238
|
- spec/functional/modifiers_spec.rb
|
|
217
239
|
- spec/functional/pagination_spec.rb
|
|
240
|
+
- spec/functional/partial_updates_spec.rb
|
|
218
241
|
- spec/functional/protected_spec.rb
|
|
219
242
|
- spec/functional/querying_spec.rb
|
|
220
243
|
- spec/functional/rails_spec.rb
|
|
221
244
|
- spec/functional/safe_spec.rb
|
|
222
245
|
- spec/functional/sci_spec.rb
|
|
223
246
|
- spec/functional/scopes_spec.rb
|
|
247
|
+
- spec/functional/static_keys_spec.rb
|
|
224
248
|
- spec/functional/stats_spec.rb
|
|
249
|
+
- spec/functional/strong_parameters_spec.rb
|
|
225
250
|
- spec/functional/timestamps_spec.rb
|
|
226
251
|
- spec/functional/touch_spec.rb
|
|
227
252
|
- spec/functional/userstamps_spec.rb
|
|
@@ -264,24 +289,23 @@ homepage: http://mongomapper.com
|
|
|
264
289
|
licenses:
|
|
265
290
|
- MIT
|
|
266
291
|
metadata: {}
|
|
267
|
-
post_install_message:
|
|
292
|
+
post_install_message:
|
|
268
293
|
rdoc_options: []
|
|
269
294
|
require_paths:
|
|
270
295
|
- lib
|
|
271
296
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
272
297
|
requirements:
|
|
273
|
-
- -
|
|
298
|
+
- - ">="
|
|
274
299
|
- !ruby/object:Gem::Version
|
|
275
300
|
version: '0'
|
|
276
301
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
277
302
|
requirements:
|
|
278
|
-
- -
|
|
303
|
+
- - ">="
|
|
279
304
|
- !ruby/object:Gem::Version
|
|
280
305
|
version: '0'
|
|
281
306
|
requirements: []
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
signing_key:
|
|
307
|
+
rubygems_version: 3.1.4
|
|
308
|
+
signing_key:
|
|
285
309
|
specification_version: 4
|
|
286
310
|
summary: A Ruby Object Mapper for Mongo
|
|
287
311
|
test_files: []
|