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.
Files changed (143) hide show
  1. data/README.rdoc +4 -8
  2. data/bin/mmconsole +1 -1
  3. data/examples/keys.rb +37 -0
  4. data/examples/plugins.rb +41 -0
  5. data/examples/querying.rb +35 -0
  6. data/examples/scopes.rb +52 -0
  7. data/lib/mongo_mapper/connection.rb +83 -0
  8. data/lib/mongo_mapper/document.rb +11 -329
  9. data/lib/mongo_mapper/embedded_document.rb +9 -38
  10. data/lib/mongo_mapper/exceptions.rb +30 -0
  11. data/lib/mongo_mapper/extensions/array.rb +19 -0
  12. data/lib/mongo_mapper/extensions/binary.rb +22 -0
  13. data/lib/mongo_mapper/extensions/boolean.rb +44 -0
  14. data/lib/mongo_mapper/extensions/date.rb +25 -0
  15. data/lib/mongo_mapper/extensions/float.rb +14 -0
  16. data/lib/mongo_mapper/extensions/hash.rb +14 -0
  17. data/lib/mongo_mapper/extensions/integer.rb +19 -0
  18. data/lib/mongo_mapper/extensions/kernel.rb +9 -0
  19. data/lib/mongo_mapper/extensions/nil_class.rb +18 -0
  20. data/lib/mongo_mapper/extensions/object.rb +27 -0
  21. data/lib/mongo_mapper/extensions/object_id.rb +30 -0
  22. data/lib/mongo_mapper/extensions/set.rb +20 -0
  23. data/lib/mongo_mapper/extensions/string.rb +18 -0
  24. data/lib/mongo_mapper/extensions/time.rb +29 -0
  25. data/lib/mongo_mapper/plugins/accessible.rb +44 -0
  26. data/lib/mongo_mapper/plugins/associations/base.rb +7 -6
  27. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +5 -6
  28. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +5 -6
  29. data/lib/mongo_mapper/plugins/associations/collection.rb +1 -0
  30. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +2 -1
  31. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +25 -39
  32. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +4 -4
  33. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +36 -46
  34. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +1 -0
  35. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +5 -4
  36. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +1 -0
  37. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +40 -0
  38. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +7 -7
  39. data/lib/mongo_mapper/plugins/associations/proxy.rb +16 -8
  40. data/lib/mongo_mapper/plugins/associations.rb +14 -22
  41. data/lib/mongo_mapper/plugins/caching.rb +21 -0
  42. data/lib/mongo_mapper/plugins/callbacks.rb +17 -5
  43. data/lib/mongo_mapper/plugins/clone.rb +10 -4
  44. data/lib/mongo_mapper/plugins/descendants.rb +3 -2
  45. data/lib/mongo_mapper/plugins/dirty.rb +1 -0
  46. data/lib/mongo_mapper/plugins/document.rb +41 -0
  47. data/lib/mongo_mapper/{support/find.rb → plugins/dynamic_querying/dynamic_finder.rb} +3 -36
  48. data/lib/mongo_mapper/plugins/dynamic_querying.rb +43 -0
  49. data/lib/mongo_mapper/plugins/embedded_document.rb +49 -0
  50. data/lib/mongo_mapper/plugins/equality.rb +4 -10
  51. data/lib/mongo_mapper/plugins/identity_map.rb +29 -23
  52. data/lib/mongo_mapper/plugins/indexes.rb +12 -0
  53. data/lib/mongo_mapper/plugins/inspect.rb +1 -0
  54. data/lib/mongo_mapper/plugins/keys/key.rb +55 -0
  55. data/lib/mongo_mapper/plugins/keys.rb +85 -110
  56. data/lib/mongo_mapper/plugins/logger.rb +1 -0
  57. data/lib/mongo_mapper/plugins/modifiers.rb +41 -16
  58. data/lib/mongo_mapper/plugins/pagination.rb +5 -15
  59. data/lib/mongo_mapper/plugins/persistence.rb +69 -0
  60. data/lib/mongo_mapper/plugins/protected.rb +9 -1
  61. data/lib/mongo_mapper/plugins/querying/decorator.rb +46 -0
  62. data/lib/mongo_mapper/plugins/querying/plucky_methods.rb +15 -0
  63. data/lib/mongo_mapper/plugins/querying.rb +176 -0
  64. data/lib/mongo_mapper/plugins/rails.rb +6 -1
  65. data/lib/mongo_mapper/plugins/safe.rb +28 -0
  66. data/lib/mongo_mapper/plugins/sci.rb +32 -0
  67. data/lib/mongo_mapper/plugins/scopes.rb +21 -0
  68. data/lib/mongo_mapper/plugins/serialization.rb +5 -4
  69. data/lib/mongo_mapper/plugins/timestamps.rb +2 -1
  70. data/lib/mongo_mapper/plugins/userstamps.rb +1 -0
  71. data/lib/mongo_mapper/plugins/validations.rb +9 -5
  72. data/lib/mongo_mapper/plugins.rb +1 -20
  73. data/lib/mongo_mapper/support/descendant_appends.rb +5 -6
  74. data/lib/mongo_mapper/version.rb +4 -0
  75. data/lib/mongo_mapper.rb +71 -128
  76. data/test/{NOTE_ON_TESTING → _NOTE_ON_TESTING} +0 -0
  77. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +5 -5
  78. data/test/functional/associations/test_belongs_to_proxy.rb +13 -21
  79. data/test/functional/associations/test_in_array_proxy.rb +7 -9
  80. data/test/functional/associations/test_many_documents_as_proxy.rb +5 -5
  81. data/test/functional/associations/test_many_documents_proxy.rb +186 -64
  82. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +22 -22
  83. data/test/functional/associations/test_many_embedded_proxy.rb +32 -32
  84. data/test/functional/associations/test_many_polymorphic_proxy.rb +47 -47
  85. data/test/functional/associations/test_one_embedded_proxy.rb +67 -0
  86. data/test/functional/associations/test_one_proxy.rb +70 -49
  87. data/test/functional/test_accessible.rb +168 -0
  88. data/test/functional/test_associations.rb +11 -11
  89. data/test/functional/test_binary.rb +5 -5
  90. data/test/functional/test_caching.rb +76 -0
  91. data/test/functional/test_callbacks.rb +104 -34
  92. data/test/functional/test_dirty.rb +16 -16
  93. data/test/functional/test_document.rb +12 -924
  94. data/test/functional/test_dynamic_querying.rb +75 -0
  95. data/test/functional/test_embedded_document.rb +88 -8
  96. data/test/functional/test_identity_map.rb +41 -43
  97. data/test/functional/{test_indexing.rb → test_indexes.rb} +3 -5
  98. data/test/functional/test_logger.rb +1 -1
  99. data/test/functional/test_modifiers.rb +275 -181
  100. data/test/functional/test_pagination.rb +13 -15
  101. data/test/functional/test_protected.rb +25 -11
  102. data/test/functional/test_querying.rb +873 -0
  103. data/test/functional/test_safe.rb +76 -0
  104. data/test/functional/test_sci.rb +230 -0
  105. data/test/functional/test_scopes.rb +171 -0
  106. data/test/functional/test_string_id_compatibility.rb +11 -11
  107. data/test/functional/test_timestamps.rb +0 -2
  108. data/test/functional/test_userstamps.rb +0 -1
  109. data/test/functional/test_validations.rb +44 -31
  110. data/test/models.rb +18 -17
  111. data/test/{active_model_lint_test.rb → test_active_model_lint.rb} +3 -1
  112. data/test/test_helper.rb +59 -16
  113. data/test/unit/associations/test_base.rb +47 -42
  114. data/test/unit/associations/test_proxy.rb +15 -15
  115. data/test/unit/serializers/test_json_serializer.rb +29 -29
  116. data/test/unit/test_clone.rb +69 -0
  117. data/test/unit/test_descendant_appends.rb +3 -3
  118. data/test/unit/test_document.rb +49 -67
  119. data/test/unit/test_dynamic_finder.rb +53 -51
  120. data/test/unit/test_embedded_document.rb +19 -38
  121. data/test/unit/{test_support.rb → test_extensions.rb} +136 -122
  122. data/test/unit/test_key.rb +185 -0
  123. data/test/unit/test_keys.rb +29 -147
  124. data/test/unit/test_mongo_mapper.rb +3 -48
  125. data/test/unit/test_pagination.rb +1 -150
  126. data/test/unit/test_rails.rb +77 -19
  127. data/test/unit/test_rails_compatibility.rb +12 -12
  128. data/test/unit/test_serialization.rb +5 -5
  129. data/test/unit/test_time_zones.rb +9 -9
  130. data/test/unit/test_validations.rb +46 -46
  131. metadata +157 -155
  132. data/.gitignore +0 -10
  133. data/Rakefile +0 -55
  134. data/VERSION +0 -1
  135. data/lib/mongo_mapper/plugins/pagination/proxy.rb +0 -72
  136. data/lib/mongo_mapper/query.rb +0 -130
  137. data/lib/mongo_mapper/support.rb +0 -215
  138. data/mongo_mapper.gemspec +0 -196
  139. data/performance/read_write.rb +0 -52
  140. data/specs.watchr +0 -51
  141. data/test/support/custom_matchers.rb +0 -55
  142. data/test/support/timing.rb +0 -16
  143. 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 'have protected attributes class method' do
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 'assign protected attribute through accessor' do
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 'ignore protected attribute on #update_attributes' do
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 'ignore protected attribute on #update_attributes!' do
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 'be indifferent to whether the protected keys are strings or symbols' do
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 'have protected attributes class method' do
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 'assign protected attribute through accessor' do
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 'ignore protected attribute on #update_attributes' do
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 'ignore protected attribute on #update_attributes!' do
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