mongo_mapper-unstable 2010.3.8 → 2010.06.23

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.
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
@@ -6,11 +6,11 @@ class DocumentTest < Test::Unit::TestCase
6
6
  setup do
7
7
  @document = Doc()
8
8
  end
9
-
9
+
10
10
  should "return false for embeddable" do
11
11
  Doc().embeddable?.should be_false
12
12
  end
13
-
13
+
14
14
  should "have logger method" do
15
15
  @document.logger.should == MongoMapper.logger
16
16
  @document.logger.should be_instance_of(Logger)
@@ -39,34 +39,33 @@ class DocumentTest < Test::Unit::TestCase
39
39
  another_document = Doc()
40
40
  another_document.database.should == MongoMapper.database
41
41
  end
42
-
43
- should "default collection name to class name tableized" do
44
- class ::Item
45
- include MongoMapper::Document
46
- end
47
-
48
- Item.collection.should be_instance_of(Mongo::Collection)
49
- Item.collection.name.should == 'items'
50
- end
51
-
52
- should "default collection name of namespaced class to tableized with dot separation" do
53
- module ::BloggyPoo
54
- class Post
55
- include MongoMapper::Document
56
- end
57
- end
58
-
59
- BloggyPoo::Post.collection.should be_instance_of(Mongo::Collection)
60
- BloggyPoo::Post.collection.name.should == 'bloggy_poo.posts'
61
- end
62
42
 
63
43
  should "allow setting the collection name" do
64
44
  @document.set_collection_name('foobar')
65
- @document.collection.should be_instance_of(Mongo::Collection)
66
45
  @document.collection.name.should == 'foobar'
67
46
  end
47
+
48
+ context ".collection" do
49
+ should "default collection name to class name tableized" do
50
+ class ::Item
51
+ include MongoMapper::Document
52
+ end.collection.name.should == 'items'
53
+ end
54
+
55
+ should "default collection name of namespaced class to tableized with dot separation" do
56
+ module ::BloggyPoo
57
+ class Post
58
+ include MongoMapper::Document
59
+ end.collection.name.should == 'bloggy_poo.posts'
60
+ end
61
+ end
62
+
63
+ should "be an instance of a Mongo::Collection" do
64
+ @document.collection.should be_instance_of(Mongo::Collection)
65
+ end
66
+ end
68
67
  end # Document class
69
-
68
+
70
69
  context "Documents that inherit from other documents" do
71
70
  should "default collection name to inherited class" do
72
71
  Message.collection_name.should == 'messages'
@@ -82,10 +81,10 @@ class DocumentTest < Test::Unit::TestCase
82
81
  Chat.associations.keys.should include("room")
83
82
  end
84
83
  end
85
-
84
+
86
85
  context "descendants" do
87
- should "default to nil" do
88
- Enter.descendants.should be_nil
86
+ should "default to an empty array" do
87
+ Enter.descendants.should == []
89
88
  end
90
89
 
91
90
  should "be recorded" do
@@ -100,17 +99,15 @@ class DocumentTest < Test::Unit::TestCase
100
99
  key :age, Integer
101
100
  end
102
101
  end
103
-
104
- should "create id during initialization" do
105
- @document.new._id.should be_instance_of(Mongo::ObjectID)
102
+
103
+ should "respond to cache_key" do
104
+ @document.new.should respond_to(:cache_key)
106
105
  end
107
-
108
- should "have to_param that is string representation of id" do
109
- doc = @document.new(:id => Mongo::ObjectID.new)
110
- doc.to_param.should == doc.id.to_s
111
- doc.to_param.should be_instance_of(String)
106
+
107
+ should "create id during initialization" do
108
+ @document.new._id.should be_instance_of(BSON::ObjectID)
112
109
  end
113
-
110
+
114
111
  should "have access to logger" do
115
112
  doc = @document.new
116
113
  doc.logger.should == @document.logger
@@ -128,23 +125,23 @@ class DocumentTest < Test::Unit::TestCase
128
125
  @document.new.active.should be_true
129
126
  @document.new(:active => false).active.should be_false
130
127
  end
131
-
128
+
132
129
  should "use default values if defined even when custom data type" do
133
130
  @document.key :window, WindowSize, :default => WindowSize.new(600, 480)
134
-
131
+
135
132
  doc = @document.new
136
133
  doc.window.should == WindowSize.new(600, 480)
137
134
  end
138
135
 
139
136
  context "root document" do
140
- should "set self to the root document on embedded documents" do
137
+ should "set self to the root document on embedded documents" do
141
138
  klass = Doc()
142
139
  pets = EDoc()
143
-
140
+
144
141
  klass.many :pets, :class => pets
145
-
142
+
146
143
  doc = klass.new(:pets => [{}])
147
- doc.pets.first._root_document.should == doc
144
+ doc.pets.first._root_document.should == doc
148
145
  end
149
146
  end
150
147
 
@@ -152,7 +149,7 @@ class DocumentTest < Test::Unit::TestCase
152
149
  should "be true if no id" do
153
150
  @document.new.new?.should be_true
154
151
  end
155
-
152
+
156
153
  should "be true if id but using custom id and not saved yet" do
157
154
  @document.key :_id, String
158
155
  doc = @document.new
@@ -161,21 +158,6 @@ class DocumentTest < Test::Unit::TestCase
161
158
  end
162
159
  end
163
160
 
164
- context "clone" do
165
- should "be new" do
166
- doc = @document.create(:name => "foo", :age => 27)
167
- clone = doc.clone
168
- clone.should be_new
169
- end
170
-
171
- should "copy the attributes" do
172
- doc = @document.create(:name => "foo", :age => 27)
173
- clone = doc.clone
174
- clone.name.should == "foo"
175
- clone.age.should == 27
176
- end
177
- end
178
-
179
161
  should "call inspect on the document's attributes instead of to_s when inspecting the document" do
180
162
  doc = @document.new(:animals => %w(dog cat))
181
163
  doc.inspect.should include(%(animals: ["dog", "cat"]))
@@ -183,43 +165,43 @@ class DocumentTest < Test::Unit::TestCase
183
165
 
184
166
  context "equality" do
185
167
  setup do
186
- @oid = Mongo::ObjectID.new
168
+ @oid = BSON::ObjectID.new
187
169
  end
188
-
170
+
189
171
  should "delegate hash to _id" do
190
172
  doc = @document.new
191
173
  doc.hash.should == doc._id.hash
192
174
  end
193
-
175
+
194
176
  should "delegate eql to ==" do
195
177
  doc = @document.new
196
178
  other = @document.new
197
179
  doc.eql?(other).should == (doc == other)
198
180
  doc.eql?(doc).should == (doc == doc)
199
181
  end
200
-
182
+
201
183
  should "know if same object as another" do
202
184
  doc = @document.new
203
185
  doc.should equal(doc)
204
186
  doc.should_not equal(@document.new)
205
187
  end
206
-
188
+
207
189
  should "allow set operations on array of documents" do
208
190
  @document.key :parent_id, ObjectId
209
191
  @document.belongs_to :parent, :class => @document
210
-
192
+
211
193
  parent = @document.create
212
194
  child = @document.create(:parent => parent)
213
-
195
+
214
196
  ([child.parent] & [parent]).should == [parent]
215
197
  end
216
-
198
+
217
199
  should "be equal if id and class are the same" do
218
200
  (@document.new('_id' => @oid) == @document.new('_id' => @oid)).should be(true)
219
201
  end
220
202
 
221
203
  should "not be equal if class same but id different" do
222
- (@document.new('_id' => @oid) == @document.new('_id' => Mongo::ObjectID.new)).should be(false)
204
+ (@document.new('_id' => @oid) == @document.new('_id' => BSON::ObjectID.new)).should be(false)
223
205
  end
224
206
 
225
207
  should "not be equal if id same but class different" do
@@ -1,123 +1,125 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class DynamicFinderTest < Test::Unit::TestCase
4
+ include MongoMapper::Plugins::DynamicQuerying
5
+
4
6
  should "initialize with method" do
5
- finder = MongoMapper::Support::Find::DynamicFinder.new(:foobar)
7
+ finder = DynamicFinder.new(:foobar)
6
8
  finder.method.should == :foobar
7
9
  end
8
-
10
+
9
11
  context "found?" do
10
12
  should "be true for find_by" do
11
- MongoMapper::Support::Find::DynamicFinder.new(:find_by_foo).found?.should be_true
13
+ DynamicFinder.new(:find_by_foo).found?.should be_true
12
14
  end
13
-
15
+
14
16
  should "be true for find_by with !" do
15
- MongoMapper::Support::Find::DynamicFinder.new(:find_by_foo!).found?.should be_true
17
+ DynamicFinder.new(:find_by_foo!).found?.should be_true
16
18
  end
17
-
19
+
18
20
  should "be true for find_all_by" do
19
- MongoMapper::Support::Find::DynamicFinder.new(:find_all_by_foo).found?.should be_true
21
+ DynamicFinder.new(:find_all_by_foo).found?.should be_true
20
22
  end
21
-
23
+
22
24
  should "be true for find_or_initialize_by" do
23
- MongoMapper::Support::Find::DynamicFinder.new(:find_or_initialize_by_foo).found?.should be_true
25
+ DynamicFinder.new(:find_or_initialize_by_foo).found?.should be_true
24
26
  end
25
-
27
+
26
28
  should "be true for find_or_create_by" do
27
- MongoMapper::Support::Find::DynamicFinder.new(:find_or_create_by_foo).found?.should be_true
29
+ DynamicFinder.new(:find_or_create_by_foo).found?.should be_true
28
30
  end
29
-
31
+
30
32
  should "be false for anything else" do
31
33
  [:foobar, :bazwick].each do |method|
32
- MongoMapper::Support::Find::DynamicFinder.new(method).found?.should be_false
34
+ DynamicFinder.new(method).found?.should be_false
33
35
  end
34
36
  end
35
37
  end
36
-
38
+
37
39
  context "find_all_by" do
38
40
  should "parse one attribute" do
39
- MongoMapper::Support::Find::DynamicFinder.new(:find_all_by_foo).attributes.should == %w(foo)
41
+ DynamicFinder.new(:find_all_by_foo).attributes.should == %w(foo)
40
42
  end
41
-
43
+
42
44
  should "parse multiple attributes" do
43
- MongoMapper::Support::Find::DynamicFinder.new(:find_all_by_foo_and_bar).attributes.should == %w(foo bar)
44
- MongoMapper::Support::Find::DynamicFinder.new(:find_all_by_foo_and_bar_and_baz).attributes.should == %w(foo bar baz)
45
+ DynamicFinder.new(:find_all_by_foo_and_bar).attributes.should == %w(foo bar)
46
+ DynamicFinder.new(:find_all_by_foo_and_bar_and_baz).attributes.should == %w(foo bar baz)
45
47
  end
46
-
48
+
47
49
  should "set finder to :all" do
48
- MongoMapper::Support::Find::DynamicFinder.new(:find_all_by_foo_and_bar).finder.should == :all
50
+ DynamicFinder.new(:find_all_by_foo_and_bar).finder.should == :all
49
51
  end
50
52
  end
51
-
53
+
52
54
  context "find_by" do
53
55
  should "parse one attribute" do
54
- MongoMapper::Support::Find::DynamicFinder.new(:find_by_foo).attributes.should == %w(foo)
56
+ DynamicFinder.new(:find_by_foo).attributes.should == %w(foo)
55
57
  end
56
-
58
+
57
59
  should "parse multiple attributes" do
58
- MongoMapper::Support::Find::DynamicFinder.new(:find_by_foo_and_bar).attributes.should == %w(foo bar)
60
+ DynamicFinder.new(:find_by_foo_and_bar).attributes.should == %w(foo bar)
59
61
  end
60
-
62
+
61
63
  should "set finder to :first" do
62
- MongoMapper::Support::Find::DynamicFinder.new(:find_by_foo).finder.should == :first
64
+ DynamicFinder.new(:find_by_foo).finder.should == :first
63
65
  end
64
-
66
+
65
67
  should "set bang to false" do
66
- MongoMapper::Support::Find::DynamicFinder.new(:find_by_foo).bang.should be_false
68
+ DynamicFinder.new(:find_by_foo).bang.should be_false
67
69
  end
68
70
  end
69
-
71
+
70
72
  context "find_by with !" do
71
73
  should "parse one attribute" do
72
- MongoMapper::Support::Find::DynamicFinder.new(:find_by_foo!).attributes.should == %w(foo)
74
+ DynamicFinder.new(:find_by_foo!).attributes.should == %w(foo)
73
75
  end
74
-
76
+
75
77
  should "parse multiple attributes" do
76
- MongoMapper::Support::Find::DynamicFinder.new(:find_by_foo_and_bar!).attributes.should == %w(foo bar)
78
+ DynamicFinder.new(:find_by_foo_and_bar!).attributes.should == %w(foo bar)
77
79
  end
78
-
80
+
79
81
  should "set finder to :first" do
80
- MongoMapper::Support::Find::DynamicFinder.new(:find_by_foo!).finder.should == :first
82
+ DynamicFinder.new(:find_by_foo!).finder.should == :first
81
83
  end
82
-
84
+
83
85
  should "set bang to true" do
84
- MongoMapper::Support::Find::DynamicFinder.new(:find_by_foo!).bang.should be_true
86
+ DynamicFinder.new(:find_by_foo!).bang.should be_true
85
87
  end
86
88
  end
87
-
89
+
88
90
  context "find_or_initialize_by" do
89
91
  should "parse one attribute" do
90
- MongoMapper::Support::Find::DynamicFinder.new(:find_or_initialize_by_foo).attributes.should == %w(foo)
92
+ DynamicFinder.new(:find_or_initialize_by_foo).attributes.should == %w(foo)
91
93
  end
92
-
94
+
93
95
  should "parse multiple attributes" do
94
- MongoMapper::Support::Find::DynamicFinder.new(:find_or_initialize_by_foo_and_bar).attributes.should == %w(foo bar)
96
+ DynamicFinder.new(:find_or_initialize_by_foo_and_bar).attributes.should == %w(foo bar)
95
97
  end
96
-
98
+
97
99
  should "set finder to :first" do
98
- MongoMapper::Support::Find::DynamicFinder.new(:find_or_initialize_by_foo).finder.should == :first
100
+ DynamicFinder.new(:find_or_initialize_by_foo).finder.should == :first
99
101
  end
100
-
102
+
101
103
  should "set instantiator to new" do
102
- MongoMapper::Support::Find::DynamicFinder.new(:find_or_initialize_by_foo).instantiator.should == :new
104
+ DynamicFinder.new(:find_or_initialize_by_foo).instantiator.should == :new
103
105
  end
104
106
  end
105
107
 
106
108
  context "find_or_create_by" do
107
109
  should "parse one attribute" do
108
- MongoMapper::Support::Find::DynamicFinder.new(:find_or_create_by_foo).attributes.should == %w(foo)
110
+ DynamicFinder.new(:find_or_create_by_foo).attributes.should == %w(foo)
109
111
  end
110
-
112
+
111
113
  should "parse multiple attributes" do
112
- MongoMapper::Support::Find::DynamicFinder.new(:find_or_create_by_foo_and_bar).attributes.should == %w(foo bar)
114
+ DynamicFinder.new(:find_or_create_by_foo_and_bar).attributes.should == %w(foo bar)
113
115
  end
114
-
116
+
115
117
  should "set finder to :first" do
116
- MongoMapper::Support::Find::DynamicFinder.new(:find_or_create_by_foo).finder.should == :first
118
+ DynamicFinder.new(:find_or_create_by_foo).finder.should == :first
117
119
  end
118
-
120
+
119
121
  should "set instantiator to new" do
120
- MongoMapper::Support::Find::DynamicFinder.new(:find_or_create_by_foo).instantiator.should == :create
122
+ DynamicFinder.new(:find_or_create_by_foo).instantiator.should == :create
121
123
  end
122
124
  end
123
125
  end
@@ -11,7 +11,7 @@ module KeyOverride
11
11
  end
12
12
 
13
13
  class EmbeddedDocumentTest < Test::Unit::TestCase
14
- context "" do
14
+ context "EmbeddedDocuments" do
15
15
  setup do
16
16
  class ::Grandparent
17
17
  include MongoMapper::EmbeddedDocument
@@ -179,17 +179,17 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
179
179
 
180
180
  context "keys" do
181
181
  should "be inherited" do
182
- Grandparent.keys.keys.sort.should == ['_id', 'grandparent']
183
- Parent.keys.keys.sort.should == ['_id', 'grandparent', 'parent']
184
- Child.keys.keys.sort.should == ['_id', 'child', 'grandparent', 'parent']
182
+ Grandparent.keys.keys.sort.should == ['_id', '_type', 'grandparent']
183
+ Parent.keys.keys.sort.should == ['_id', '_type', 'grandparent', 'parent']
184
+ Child.keys.keys.sort.should == ['_id', '_type', 'child', 'grandparent', 'parent']
185
185
  end
186
186
 
187
187
  should "propogate to descendants if key added after class definition" do
188
- Grandparent.key :_type, String
188
+ Grandparent.key :foo, String
189
189
 
190
- Grandparent.keys.keys.sort.should == ['_id', '_type', 'grandparent']
191
- Parent.keys.keys.sort.should == ['_id', '_type', 'grandparent', 'parent']
192
- Child.keys.keys.sort.should == ['_id', '_type', 'child', 'grandparent', 'parent']
190
+ Grandparent.keys.keys.sort.should == ['_id', '_type', 'foo', 'grandparent']
191
+ Parent.keys.keys.sort.should == ['_id', '_type', 'foo', 'grandparent', 'parent']
192
+ Child.keys.keys.sort.should == ['_id', '_type', 'child', 'foo', 'grandparent', 'parent']
193
193
  end
194
194
 
195
195
  should "not add anonymous objects to the ancestor tree" do
@@ -202,8 +202,8 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
202
202
  end
203
203
 
204
204
  context "descendants" do
205
- should "default to nil" do
206
- Child.descendants.should be_nil
205
+ should "default to an empty array" do
206
+ Child.descendants.should == []
207
207
  end
208
208
 
209
209
  should "be recorded" do
@@ -221,10 +221,8 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
221
221
  end
222
222
  end
223
223
 
224
- should "have to_param that is string representation of id" do
225
- doc = @document.new
226
- doc.to_param.should == doc.id.to_s
227
- doc.to_param.should be_instance_of(String)
224
+ should "respond to cache_key" do
225
+ @document.new.should respond_to(:cache_key)
228
226
  end
229
227
 
230
228
  should "have access to class logger" do
@@ -238,17 +236,17 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
238
236
  end
239
237
 
240
238
  should "create id during initialization" do
241
- @document.new._id.should be_instance_of(Mongo::ObjectID)
239
+ @document.new._id.should be_instance_of(BSON::ObjectID)
242
240
  end
243
241
 
244
242
  should "have id method returns _id" do
245
- id = Mongo::ObjectID.new
243
+ id = BSON::ObjectID.new
246
244
  doc = @document.new(:_id => id)
247
245
  doc.id.should == id
248
246
  end
249
247
 
250
248
  should "convert string object id to mongo object id when assigning id with _id object id type" do
251
- id = Mongo::ObjectID.new
249
+ id = BSON::ObjectID.new
252
250
  doc = @document.new(:id => id.to_s)
253
251
  doc._id.should == id
254
252
  doc.id.should == id
@@ -308,8 +306,8 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
308
306
  @klass.new._type.should == 'FooBar'
309
307
  end
310
308
 
311
- should "not change _type if already set" do
312
- @klass.new(:_type => 'Foo')._type.should == 'Foo'
309
+ should "ignore _type attribute and always use class" do
310
+ @klass.new(:_type => 'Foo')._type.should == 'FooBar'
313
311
  end
314
312
  end
315
313
 
@@ -382,23 +380,6 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
382
380
  end
383
381
  end
384
382
 
385
- context "clone" do
386
- should "regenerate the id" do
387
- doc = @document.new(:name => "foo", :age => 27)
388
- doc_id = doc.id
389
- clone = doc.clone
390
- clone_id = clone.id
391
- clone_id.should_not == doc_id
392
- end
393
-
394
- should "copy the attributes" do
395
- doc = @document.new(:name => "foo", :age => 27)
396
- clone = doc.clone
397
- clone.name.should == "foo"
398
- clone.age.should == 27
399
- end
400
- end
401
-
402
383
  context "key shorcut access" do
403
384
  context "[]" do
404
385
  should "work when key found" do
@@ -574,7 +555,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
574
555
 
575
556
  context "equality" do
576
557
  setup do
577
- @oid = Mongo::ObjectID.new
558
+ @oid = BSON::ObjectID.new
578
559
  end
579
560
 
580
561
  should "delegate hash to _id" do
@@ -605,7 +586,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
605
586
  end
606
587
 
607
588
  should "not be equal if class same but id different" do
608
- (@document.new('_id' => @oid) == @document.new('_id' => Mongo::ObjectID.new)).should be_false
589
+ (@document.new('_id' => @oid) == @document.new('_id' => BSON::ObjectID.new)).should be_false
609
590
  end
610
591
 
611
592
  should "not be equal if id same but class different" do