mongo_mapper-unstable 2010.3.8 → 2010.06.23
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -8
- data/bin/mmconsole +1 -1
- data/examples/keys.rb +37 -0
- data/examples/plugins.rb +41 -0
- data/examples/querying.rb +35 -0
- data/examples/scopes.rb +52 -0
- data/lib/mongo_mapper/connection.rb +83 -0
- data/lib/mongo_mapper/document.rb +11 -329
- data/lib/mongo_mapper/embedded_document.rb +9 -38
- data/lib/mongo_mapper/exceptions.rb +30 -0
- data/lib/mongo_mapper/extensions/array.rb +19 -0
- data/lib/mongo_mapper/extensions/binary.rb +22 -0
- data/lib/mongo_mapper/extensions/boolean.rb +44 -0
- data/lib/mongo_mapper/extensions/date.rb +25 -0
- data/lib/mongo_mapper/extensions/float.rb +14 -0
- data/lib/mongo_mapper/extensions/hash.rb +14 -0
- data/lib/mongo_mapper/extensions/integer.rb +19 -0
- data/lib/mongo_mapper/extensions/kernel.rb +9 -0
- data/lib/mongo_mapper/extensions/nil_class.rb +18 -0
- data/lib/mongo_mapper/extensions/object.rb +27 -0
- data/lib/mongo_mapper/extensions/object_id.rb +30 -0
- data/lib/mongo_mapper/extensions/set.rb +20 -0
- data/lib/mongo_mapper/extensions/string.rb +18 -0
- data/lib/mongo_mapper/extensions/time.rb +29 -0
- data/lib/mongo_mapper/plugins/accessible.rb +44 -0
- data/lib/mongo_mapper/plugins/associations/base.rb +7 -6
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +5 -6
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +5 -6
- data/lib/mongo_mapper/plugins/associations/collection.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +2 -1
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +25 -39
- data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +4 -4
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +36 -46
- data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +5 -4
- data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +40 -0
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +7 -7
- data/lib/mongo_mapper/plugins/associations/proxy.rb +16 -8
- data/lib/mongo_mapper/plugins/associations.rb +14 -22
- data/lib/mongo_mapper/plugins/caching.rb +21 -0
- data/lib/mongo_mapper/plugins/callbacks.rb +17 -5
- data/lib/mongo_mapper/plugins/clone.rb +10 -4
- data/lib/mongo_mapper/plugins/descendants.rb +3 -2
- data/lib/mongo_mapper/plugins/dirty.rb +1 -0
- data/lib/mongo_mapper/plugins/document.rb +41 -0
- data/lib/mongo_mapper/{support/find.rb → plugins/dynamic_querying/dynamic_finder.rb} +3 -36
- data/lib/mongo_mapper/plugins/dynamic_querying.rb +43 -0
- data/lib/mongo_mapper/plugins/embedded_document.rb +49 -0
- data/lib/mongo_mapper/plugins/equality.rb +4 -10
- data/lib/mongo_mapper/plugins/identity_map.rb +29 -23
- data/lib/mongo_mapper/plugins/indexes.rb +12 -0
- data/lib/mongo_mapper/plugins/inspect.rb +1 -0
- data/lib/mongo_mapper/plugins/keys/key.rb +55 -0
- data/lib/mongo_mapper/plugins/keys.rb +85 -110
- data/lib/mongo_mapper/plugins/logger.rb +1 -0
- data/lib/mongo_mapper/plugins/modifiers.rb +41 -16
- data/lib/mongo_mapper/plugins/pagination.rb +5 -15
- data/lib/mongo_mapper/plugins/persistence.rb +69 -0
- data/lib/mongo_mapper/plugins/protected.rb +9 -1
- data/lib/mongo_mapper/plugins/querying/decorator.rb +46 -0
- data/lib/mongo_mapper/plugins/querying/plucky_methods.rb +15 -0
- data/lib/mongo_mapper/plugins/querying.rb +176 -0
- data/lib/mongo_mapper/plugins/rails.rb +6 -1
- data/lib/mongo_mapper/plugins/safe.rb +28 -0
- data/lib/mongo_mapper/plugins/sci.rb +32 -0
- data/lib/mongo_mapper/plugins/scopes.rb +21 -0
- data/lib/mongo_mapper/plugins/serialization.rb +5 -4
- data/lib/mongo_mapper/plugins/timestamps.rb +2 -1
- data/lib/mongo_mapper/plugins/userstamps.rb +1 -0
- data/lib/mongo_mapper/plugins/validations.rb +9 -5
- data/lib/mongo_mapper/plugins.rb +1 -20
- data/lib/mongo_mapper/support/descendant_appends.rb +5 -6
- data/lib/mongo_mapper/version.rb +4 -0
- data/lib/mongo_mapper.rb +71 -128
- data/test/{NOTE_ON_TESTING → _NOTE_ON_TESTING} +0 -0
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +5 -5
- data/test/functional/associations/test_belongs_to_proxy.rb +13 -21
- data/test/functional/associations/test_in_array_proxy.rb +7 -9
- data/test/functional/associations/test_many_documents_as_proxy.rb +5 -5
- data/test/functional/associations/test_many_documents_proxy.rb +186 -64
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +22 -22
- data/test/functional/associations/test_many_embedded_proxy.rb +32 -32
- data/test/functional/associations/test_many_polymorphic_proxy.rb +47 -47
- data/test/functional/associations/test_one_embedded_proxy.rb +67 -0
- data/test/functional/associations/test_one_proxy.rb +70 -49
- data/test/functional/test_accessible.rb +168 -0
- data/test/functional/test_associations.rb +11 -11
- data/test/functional/test_binary.rb +5 -5
- data/test/functional/test_caching.rb +76 -0
- data/test/functional/test_callbacks.rb +104 -34
- data/test/functional/test_dirty.rb +16 -16
- data/test/functional/test_document.rb +12 -924
- data/test/functional/test_dynamic_querying.rb +75 -0
- data/test/functional/test_embedded_document.rb +88 -8
- data/test/functional/test_identity_map.rb +41 -43
- data/test/functional/{test_indexing.rb → test_indexes.rb} +3 -5
- data/test/functional/test_logger.rb +1 -1
- data/test/functional/test_modifiers.rb +275 -181
- data/test/functional/test_pagination.rb +13 -15
- data/test/functional/test_protected.rb +25 -11
- data/test/functional/test_querying.rb +873 -0
- data/test/functional/test_safe.rb +76 -0
- data/test/functional/test_sci.rb +230 -0
- data/test/functional/test_scopes.rb +171 -0
- data/test/functional/test_string_id_compatibility.rb +11 -11
- data/test/functional/test_timestamps.rb +0 -2
- data/test/functional/test_userstamps.rb +0 -1
- data/test/functional/test_validations.rb +44 -31
- data/test/models.rb +18 -17
- data/test/{active_model_lint_test.rb → test_active_model_lint.rb} +3 -1
- data/test/test_helper.rb +59 -16
- data/test/unit/associations/test_base.rb +47 -42
- data/test/unit/associations/test_proxy.rb +15 -15
- data/test/unit/serializers/test_json_serializer.rb +29 -29
- data/test/unit/test_clone.rb +69 -0
- data/test/unit/test_descendant_appends.rb +3 -3
- data/test/unit/test_document.rb +49 -67
- data/test/unit/test_dynamic_finder.rb +53 -51
- data/test/unit/test_embedded_document.rb +19 -38
- data/test/unit/{test_support.rb → test_extensions.rb} +136 -122
- data/test/unit/test_key.rb +185 -0
- data/test/unit/test_keys.rb +29 -147
- data/test/unit/test_mongo_mapper.rb +3 -48
- data/test/unit/test_pagination.rb +1 -150
- data/test/unit/test_rails.rb +77 -19
- data/test/unit/test_rails_compatibility.rb +12 -12
- data/test/unit/test_serialization.rb +5 -5
- data/test/unit/test_time_zones.rb +9 -9
- data/test/unit/test_validations.rb +46 -46
- metadata +157 -155
- data/.gitignore +0 -10
- data/Rakefile +0 -55
- data/VERSION +0 -1
- data/lib/mongo_mapper/plugins/pagination/proxy.rb +0 -72
- data/lib/mongo_mapper/query.rb +0 -130
- data/lib/mongo_mapper/support.rb +0 -215
- data/mongo_mapper.gemspec +0 -196
- data/performance/read_write.rb +0 -52
- data/specs.watchr +0 -51
- data/test/support/custom_matchers.rb +0 -55
- data/test/support/timing.rb +0 -16
- data/test/unit/test_query.rb +0 -340
@@ -13,7 +13,7 @@ class ProtectedTest < Test::Unit::TestCase
|
|
13
13
|
@doc = @doc_class.create(:name => 'Steve Sloan')
|
14
14
|
end
|
15
15
|
|
16
|
-
should
|
16
|
+
should "have protected attributes class method" do
|
17
17
|
@doc_class.protected_attributes.should == [:admin].to_set
|
18
18
|
end
|
19
19
|
|
@@ -25,13 +25,25 @@ class ProtectedTest < Test::Unit::TestCase
|
|
25
25
|
@doc.protected_attributes.should equal(@doc_class.protected_attributes)
|
26
26
|
end
|
27
27
|
|
28
|
+
should "raise error if there are accessible attributes" do
|
29
|
+
doc = Doc('Post')
|
30
|
+
doc.attr_accessible :name
|
31
|
+
lambda { doc.attr_protected :admin }.
|
32
|
+
should raise_error(/Declare either attr_protected or attr_accessible for Post/)
|
33
|
+
end
|
34
|
+
|
35
|
+
should "know if using protected attributes" do
|
36
|
+
@doc_class.protected_attributes?.should be(true)
|
37
|
+
Doc().protected_attributes?.should be(false)
|
38
|
+
end
|
39
|
+
|
28
40
|
should "work with :protected shortcut when defining key" do
|
29
41
|
Doc() do
|
30
42
|
key :user_id, ObjectId, :protected => true
|
31
43
|
end.protected_attributes.should == [:user_id].to_set
|
32
44
|
end
|
33
45
|
|
34
|
-
should
|
46
|
+
should "assign protected attribute through accessor" do
|
35
47
|
@doc.admin = true
|
36
48
|
@doc.admin.should be_true
|
37
49
|
end
|
@@ -52,23 +64,27 @@ class ProtectedTest < Test::Unit::TestCase
|
|
52
64
|
doc.name.should == 'John'
|
53
65
|
end
|
54
66
|
|
55
|
-
should
|
67
|
+
should "ignore protected attribute on #update_attributes" do
|
56
68
|
@doc.update_attributes(:name => 'Ren Hoek', :admin => true)
|
57
69
|
@doc.name.should == 'Ren Hoek'
|
58
70
|
@doc.admin.should be_false
|
59
71
|
end
|
60
72
|
|
61
|
-
should
|
73
|
+
should "ignore protected attribute on #update_attributes!" do
|
62
74
|
@doc.update_attributes!(:name => 'Stimpson J. Cat', :admin => true)
|
63
75
|
@doc.name.should == 'Stimpson J. Cat'
|
64
76
|
@doc.admin.should be_false
|
65
77
|
end
|
66
78
|
|
67
|
-
should
|
79
|
+
should "be indifferent to whether the protected keys are strings or symbols" do
|
68
80
|
@doc.update_attributes!("name" => 'Stimpson J. Cat', "admin" => true)
|
69
81
|
@doc.name.should == 'Stimpson J. Cat'
|
70
82
|
@doc.admin.should be_false
|
71
83
|
end
|
84
|
+
|
85
|
+
should "accept nil as constructor's argument without raising exception" do
|
86
|
+
lambda { @doc_class.new(nil) }.should_not raise_error
|
87
|
+
end
|
72
88
|
end
|
73
89
|
|
74
90
|
context "Single collection inherited protected attributes" do
|
@@ -76,9 +92,7 @@ class ProtectedTest < Test::Unit::TestCase
|
|
76
92
|
class ::GrandParent
|
77
93
|
include MongoMapper::Document
|
78
94
|
|
79
|
-
key :_type, String
|
80
95
|
key :site_id, ObjectId
|
81
|
-
|
82
96
|
attr_protected :site_id
|
83
97
|
end
|
84
98
|
GrandParent.collection.remove
|
@@ -129,7 +143,7 @@ class ProtectedTest < Test::Unit::TestCase
|
|
129
143
|
@doc.people << @edoc
|
130
144
|
end
|
131
145
|
|
132
|
-
should
|
146
|
+
should "have protected attributes class method" do
|
133
147
|
@edoc_class.protected_attributes.should == [:admin].to_set
|
134
148
|
end
|
135
149
|
|
@@ -141,18 +155,18 @@ class ProtectedTest < Test::Unit::TestCase
|
|
141
155
|
@edoc.protected_attributes.should equal(@edoc_class.protected_attributes)
|
142
156
|
end
|
143
157
|
|
144
|
-
should
|
158
|
+
should "assign protected attribute through accessor" do
|
145
159
|
@edoc.admin = true
|
146
160
|
@edoc.admin.should be_true
|
147
161
|
end
|
148
162
|
|
149
|
-
should
|
163
|
+
should "ignore protected attribute on #update_attributes" do
|
150
164
|
@edoc.update_attributes(:name => 'Ren Hoek', :admin => true)
|
151
165
|
@edoc.name.should == 'Ren Hoek'
|
152
166
|
@edoc.admin.should be_false
|
153
167
|
end
|
154
168
|
|
155
|
-
should
|
169
|
+
should "ignore protected attribute on #update_attributes!" do
|
156
170
|
@edoc.update_attributes!(:name => 'Stimpson J. Cat', :admin => true)
|
157
171
|
@edoc.name.should == 'Stimpson J. Cat'
|
158
172
|
@edoc.admin.should be_false
|