mongo_mapper 0.12.0 → 0.13.0.beta1

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 (154) hide show
  1. checksums.yaml +7 -0
  2. data/README.rdoc +35 -13
  3. data/bin/mmconsole +1 -1
  4. data/lib/mongo_mapper.rb +4 -0
  5. data/lib/mongo_mapper/connection.rb +17 -6
  6. data/lib/mongo_mapper/document.rb +1 -0
  7. data/lib/mongo_mapper/exceptions.rb +4 -1
  8. data/lib/mongo_mapper/extensions/binary.rb +1 -1
  9. data/lib/mongo_mapper/extensions/boolean.rb +20 -23
  10. data/lib/mongo_mapper/extensions/date.rb +3 -3
  11. data/lib/mongo_mapper/extensions/integer.rb +5 -1
  12. data/lib/mongo_mapper/extensions/kernel.rb +2 -0
  13. data/lib/mongo_mapper/extensions/ordered_hash.rb +23 -0
  14. data/lib/mongo_mapper/extensions/string.rb +2 -2
  15. data/lib/mongo_mapper/extensions/time.rb +7 -5
  16. data/lib/mongo_mapper/middleware/identity_map.rb +3 -4
  17. data/lib/mongo_mapper/plugins.rb +1 -1
  18. data/lib/mongo_mapper/plugins/associations.rb +11 -5
  19. data/lib/mongo_mapper/plugins/associations/base.rb +5 -3
  20. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +0 -0
  21. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +8 -8
  22. data/lib/mongo_mapper/plugins/associations/collection.rb +2 -0
  23. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +32 -7
  24. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +2 -2
  25. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +12 -12
  26. data/lib/mongo_mapper/plugins/associations/proxy.rb +5 -1
  27. data/lib/mongo_mapper/plugins/associations/single_association.rb +6 -6
  28. data/lib/mongo_mapper/plugins/clone.rb +4 -2
  29. data/lib/mongo_mapper/plugins/dirty.rb +22 -21
  30. data/lib/mongo_mapper/plugins/document.rb +4 -4
  31. data/lib/mongo_mapper/plugins/dumpable.rb +22 -0
  32. data/lib/mongo_mapper/plugins/embedded_callbacks.rb +58 -9
  33. data/lib/mongo_mapper/plugins/identity_map.rb +42 -32
  34. data/lib/mongo_mapper/plugins/keys.rb +133 -54
  35. data/lib/mongo_mapper/plugins/keys/key.rb +68 -22
  36. data/lib/mongo_mapper/plugins/modifiers.rb +26 -19
  37. data/lib/mongo_mapper/plugins/persistence.rb +15 -5
  38. data/lib/mongo_mapper/plugins/querying.rb +15 -40
  39. data/lib/mongo_mapper/plugins/querying/{decorator.rb → decorated_plucky_query.rb} +24 -4
  40. data/lib/mongo_mapper/plugins/rails.rb +22 -2
  41. data/lib/mongo_mapper/plugins/safe.rb +8 -5
  42. data/lib/mongo_mapper/plugins/sci.rb +26 -4
  43. data/lib/mongo_mapper/plugins/scopes.rb +5 -4
  44. data/lib/mongo_mapper/plugins/timestamps.rb +11 -4
  45. data/lib/mongo_mapper/plugins/validations.rb +1 -1
  46. data/lib/mongo_mapper/utils.rb +12 -0
  47. data/lib/mongo_mapper/version.rb +1 -1
  48. data/lib/rails/generators/mongo_mapper/config/config_generator.rb +20 -7
  49. data/lib/rails/generators/mongo_mapper/config/templates/mongo.yml +6 -0
  50. data/lib/rails/generators/mongo_mapper/model/model_generator.rb +18 -1
  51. data/lib/rails/generators/mongo_mapper/model/templates/model.rb +9 -5
  52. data/{test/functional/test_accessible.rb → spec/functional/accessible_spec.rb} +29 -29
  53. data/{test/functional/associations/test_belongs_to_polymorphic_proxy.rb → spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb} +10 -10
  54. data/{test/functional/associations/test_belongs_to_proxy.rb → spec/functional/associations/belongs_to_proxy_spec.rb} +82 -64
  55. data/{test/functional/associations/test_in_array_proxy.rb → spec/functional/associations/in_array_proxy_spec.rb} +68 -68
  56. data/{test/functional/associations/test_many_documents_as_proxy.rb → spec/functional/associations/many_documents_as_proxy_spec.rb} +37 -38
  57. data/{test/functional/associations/test_many_documents_proxy.rb → spec/functional/associations/many_documents_proxy_spec.rb} +233 -146
  58. data/{test/functional/associations/test_many_embedded_polymorphic_proxy.rb → spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb} +19 -20
  59. data/{test/functional/associations/test_many_embedded_proxy.rb → spec/functional/associations/many_embedded_proxy_spec.rb} +23 -24
  60. data/{test/functional/associations/test_many_polymorphic_proxy.rb → spec/functional/associations/many_polymorphic_proxy_spec.rb} +45 -46
  61. data/{test/functional/associations/test_one_as_proxy.rb → spec/functional/associations/one_as_proxy_spec.rb} +75 -77
  62. data/{test/functional/associations/test_one_embedded_polymorphic_proxy.rb → spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb} +31 -32
  63. data/{test/functional/associations/test_one_embedded_proxy.rb → spec/functional/associations/one_embedded_proxy_spec.rb} +10 -10
  64. data/{test/functional/associations/test_one_proxy.rb → spec/functional/associations/one_proxy_spec.rb} +125 -102
  65. data/spec/functional/associations_spec.rb +48 -0
  66. data/{test/functional/test_binary.rb → spec/functional/binary_spec.rb} +6 -6
  67. data/spec/functional/caching_spec.rb +75 -0
  68. data/{test/functional/test_callbacks.rb → spec/functional/callbacks_spec.rb} +84 -26
  69. data/{test/functional/test_dirty.rb → spec/functional/dirty_spec.rb} +57 -42
  70. data/{test/functional/test_document.rb → spec/functional/document_spec.rb} +52 -52
  71. data/spec/functional/dumpable_spec.rb +24 -0
  72. data/{test/functional/test_dynamic_querying.rb → spec/functional/dynamic_querying_spec.rb} +14 -14
  73. data/{test/functional/test_embedded_document.rb → spec/functional/embedded_document_spec.rb} +51 -42
  74. data/{test/functional/test_equality.rb → spec/functional/equality_spec.rb} +4 -4
  75. data/spec/functional/extensions_spec.rb +16 -0
  76. data/{test/functional/test_identity_map.rb → spec/functional/identity_map_spec.rb} +73 -61
  77. data/spec/functional/indexes_spec.rb +48 -0
  78. data/spec/functional/keys_spec.rb +224 -0
  79. data/{test/functional/test_logger.rb → spec/functional/logger_spec.rb} +6 -6
  80. data/spec/functional/modifiers_spec.rb +550 -0
  81. data/spec/functional/pagination_spec.rb +89 -0
  82. data/spec/functional/protected_spec.rb +199 -0
  83. data/spec/functional/querying_spec.rb +1003 -0
  84. data/spec/functional/rails_spec.rb +55 -0
  85. data/spec/functional/safe_spec.rb +163 -0
  86. data/{test/functional/test_sci.rb → spec/functional/sci_spec.rb} +123 -34
  87. data/{test/functional/test_scopes.rb → spec/functional/scopes_spec.rb} +59 -26
  88. data/spec/functional/timestamps_spec.rb +97 -0
  89. data/{test/functional/test_touch.rb → spec/functional/touch_spec.rb} +13 -13
  90. data/spec/functional/userstamps_spec.rb +46 -0
  91. data/{test/functional/test_validations.rb → spec/functional/validations_spec.rb} +64 -64
  92. data/spec/spec_helper.rb +81 -0
  93. data/spec/support/matchers.rb +24 -0
  94. data/{test → spec/support}/models.rb +1 -6
  95. data/spec/unit/associations/base_spec.rb +146 -0
  96. data/spec/unit/associations/belongs_to_association_spec.rb +30 -0
  97. data/spec/unit/associations/many_association_spec.rb +64 -0
  98. data/spec/unit/associations/one_association_spec.rb +48 -0
  99. data/{test/unit/associations/test_proxy.rb → spec/unit/associations/proxy_spec.rb} +21 -21
  100. data/{test/unit/test_clone.rb → spec/unit/clone_spec.rb} +21 -11
  101. data/spec/unit/config_generator_spec.rb +24 -0
  102. data/{test/unit/test_document.rb → spec/unit/document_spec.rb} +42 -42
  103. data/{test/unit/test_dynamic_finder.rb → spec/unit/dynamic_finder_spec.rb} +28 -28
  104. data/{test/unit/test_embedded_document.rb → spec/unit/embedded_document_spec.rb} +102 -108
  105. data/{test/unit/test_equality.rb → spec/unit/equality_spec.rb} +7 -7
  106. data/{test/unit/test_exceptions.rb → spec/unit/exceptions_spec.rb} +3 -3
  107. data/{test/unit/test_extensions.rb → spec/unit/extensions_spec.rb} +85 -71
  108. data/spec/unit/identity_map_middleware_spec.rb +134 -0
  109. data/{test/unit/test_inspect.rb → spec/unit/inspect_spec.rb} +8 -8
  110. data/{test/unit/test_key.rb → spec/unit/key_spec.rb} +82 -52
  111. data/spec/unit/keys_spec.rb +155 -0
  112. data/spec/unit/model_generator_spec.rb +47 -0
  113. data/spec/unit/mongo_mapper_spec.rb +184 -0
  114. data/spec/unit/pagination_spec.rb +11 -0
  115. data/{test/unit/test_plugins.rb → spec/unit/plugins_spec.rb} +14 -14
  116. data/spec/unit/rails_compatibility_spec.rb +40 -0
  117. data/{test/unit/test_rails_reflect_on_association.rb → spec/unit/rails_reflect_on_association_spec.rb} +9 -9
  118. data/{test/unit/test_rails.rb → spec/unit/rails_spec.rb} +31 -31
  119. data/spec/unit/serialization_spec.rb +169 -0
  120. data/spec/unit/serializers/json_serializer_spec.rb +218 -0
  121. data/spec/unit/serializers/xml_serializer_spec.rb +198 -0
  122. data/{test/unit/test_time_zones.rb → spec/unit/time_zones_spec.rb} +8 -8
  123. data/{test/unit/test_translation.rb → spec/unit/translation_spec.rb} +6 -6
  124. data/{test/unit/test_validations.rb → spec/unit/validations_spec.rb} +72 -59
  125. metadata +199 -179
  126. data/test/_NOTE_ON_TESTING +0 -1
  127. data/test/functional/test_associations.rb +0 -46
  128. data/test/functional/test_caching.rb +0 -77
  129. data/test/functional/test_indexes.rb +0 -50
  130. data/test/functional/test_modifiers.rb +0 -537
  131. data/test/functional/test_pagination.rb +0 -91
  132. data/test/functional/test_protected.rb +0 -201
  133. data/test/functional/test_querying.rb +0 -935
  134. data/test/functional/test_safe.rb +0 -76
  135. data/test/functional/test_timestamps.rb +0 -62
  136. data/test/functional/test_userstamps.rb +0 -44
  137. data/test/support/railtie.rb +0 -4
  138. data/test/support/railtie/autoloaded.rb +0 -2
  139. data/test/support/railtie/not_autoloaded.rb +0 -3
  140. data/test/support/railtie/parent.rb +0 -3
  141. data/test/test_active_model_lint.rb +0 -18
  142. data/test/test_helper.rb +0 -93
  143. data/test/unit/associations/test_base.rb +0 -146
  144. data/test/unit/associations/test_belongs_to_association.rb +0 -29
  145. data/test/unit/associations/test_many_association.rb +0 -63
  146. data/test/unit/associations/test_one_association.rb +0 -47
  147. data/test/unit/serializers/test_json_serializer.rb +0 -216
  148. data/test/unit/serializers/test_xml_serializer.rb +0 -196
  149. data/test/unit/test_identity_map_middleware.rb +0 -132
  150. data/test/unit/test_keys.rb +0 -65
  151. data/test/unit/test_mongo_mapper.rb +0 -157
  152. data/test/unit/test_pagination.rb +0 -11
  153. data/test/unit/test_rails_compatibility.rb +0 -38
  154. data/test/unit/test_serialization.rb +0 -166
@@ -1,8 +1,8 @@
1
- require 'test_helper'
1
+ require 'spec_helper'
2
2
 
3
- class CloneTest < Test::Unit::TestCase
3
+ describe "Clone" do
4
4
  context "Document" do
5
- setup do
5
+ before do
6
6
  @document = Doc()
7
7
  @embedded = EDoc()
8
8
  @document.many :widgets, :class => @embedded
@@ -16,33 +16,43 @@ class CloneTest < Test::Unit::TestCase
16
16
  end
17
17
 
18
18
  context "#clone" do
19
- should "be new" do
19
+ it "should be new" do
20
20
  @doc.clone.should be_new
21
21
  end
22
22
 
23
- should "copy the attributes" do
23
+ it "should copy the attributes" do
24
24
  clone = @doc.clone
25
25
  clone.name.should == "foo"
26
26
  clone.age.should == 27
27
27
  end
28
28
 
29
- should "clone duplicable attributes" do
29
+ it "should clone duplicable attributes" do
30
30
  @doc.clone.tags.should_not equal(@tags)
31
31
  end
32
32
 
33
- should "clone many embedded documents" do
33
+ it "should clone many embedded documents" do
34
34
  @doc.clone.widgets.object_id.should_not equal(@doc.widgets.object_id)
35
35
  end
36
36
 
37
- should "not be destroyed" do
37
+ it "should not be destroyed" do
38
38
  @doc.destroy
39
39
  @doc.clone.should_not be_destroyed
40
40
  end
41
+
42
+ it "should generate a new id" do
43
+ @doc.clone.id.should_not be_nil
44
+ @doc.clone.id.should_not equal(@doc.id)
45
+ end
46
+
47
+ it "should clone a cloned document" do
48
+ expect { @doc.clone.clone }.to_not raise_error
49
+ @doc.clone.clone.id.should be_a BSON::ObjectId
50
+ end
41
51
  end
42
52
  end
43
53
 
44
54
  context "EmbeddedDocument" do
45
- setup do
55
+ before do
46
56
  @document = EDoc do
47
57
  key :name, String
48
58
  key :age, Integer
@@ -50,7 +60,7 @@ class CloneTest < Test::Unit::TestCase
50
60
  end
51
61
 
52
62
  context "#clone" do
53
- should "regenerate the id" do
63
+ it "should regenerate the id" do
54
64
  doc = @document.new(:name => "foo", :age => 27)
55
65
  doc_id = doc.id
56
66
  clone = doc.clone
@@ -58,7 +68,7 @@ class CloneTest < Test::Unit::TestCase
58
68
  clone_id.should_not == doc_id
59
69
  end
60
70
 
61
- should "copy the attributes" do
71
+ it "should copy the attributes" do
62
72
  doc = @document.new(:name => "foo", :age => 27)
63
73
  clone = doc.clone
64
74
  clone.name.should == "foo"
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'rails/generators'
3
+ require 'rails/generators/test_case'
4
+ require 'rails/generators/mongo_mapper/config/config_generator'
5
+
6
+ describe MongoMapper::Generators::ConfigGenerator do
7
+ include GeneratorSpec::TestCase
8
+
9
+ destination File.expand_path('../../tmp', File.dirname(__FILE__))
10
+ before do
11
+ prepare_destination
12
+ end
13
+
14
+ it 'mongo.yml are properly created' do
15
+ run_generator
16
+ assert_file 'config/mongo.yml', /#{File.basename(destination_root)}/
17
+ end
18
+
19
+ it 'mongo.yml are properly created with defined database_name' do
20
+ run_generator %w{dummy}
21
+ assert_file 'config/mongo.yml', /dummy/
22
+ end
23
+
24
+ end
@@ -1,37 +1,37 @@
1
- require 'test_helper'
2
- require 'models'
1
+ require 'spec_helper'
3
2
 
4
- class DocumentTest < Test::Unit::TestCase
3
+
4
+ describe "Document" do
5
5
  context "The Document Class" do
6
- setup do
6
+ before do
7
7
  @document = Doc()
8
8
  end
9
9
 
10
- should "return false for embeddable" do
10
+ it "should return false for embeddable" do
11
11
  Doc().embeddable?.should be_false
12
12
  end
13
13
 
14
- should "have logger method" do
14
+ it "should have logger method" do
15
15
  @document.logger.should == MongoMapper.logger
16
16
  @document.logger.should be_instance_of(Logger)
17
17
  end
18
18
 
19
- should "use default database by default" do
19
+ it "should use default database by default" do
20
20
  @document.database.should == MongoMapper.database
21
21
  end
22
22
 
23
- should "have a connection" do
24
- @document.connection.should be_instance_of(Mongo::Connection)
23
+ it "should have a connection" do
24
+ @document.connection.should be_instance_of(Mongo::MongoClient)
25
25
  end
26
26
 
27
- should "allow setting different connection without affecting the default" do
28
- conn = Mongo::Connection.new
27
+ it "should allow setting different connection without affecting the default" do
28
+ conn = Mongo::MongoClient.new
29
29
  @document.connection conn
30
30
  @document.connection.should == conn
31
31
  @document.connection.should_not == MongoMapper.connection
32
32
  end
33
33
 
34
- should "allow setting a different database without affecting the default" do
34
+ it "should allow setting a different database without affecting the default" do
35
35
  @document.set_database_name 'test2'
36
36
  @document.database_name.should == 'test2'
37
37
  @document.database.name.should == 'test2'
@@ -40,19 +40,19 @@ class DocumentTest < Test::Unit::TestCase
40
40
  another_document.database.should == MongoMapper.database
41
41
  end
42
42
 
43
- should "allow setting the collection name" do
43
+ it "should allow setting the collection name" do
44
44
  @document.set_collection_name('foobar')
45
45
  @document.collection.name.should == 'foobar'
46
46
  end
47
47
 
48
48
  context ".collection" do
49
- should "default collection name to class name tableized" do
49
+ it "should default collection name to class name tableized" do
50
50
  class ::Item
51
51
  include MongoMapper::Document
52
52
  end.collection.name.should == 'items'
53
53
  end
54
54
 
55
- should "default collection name of namespaced class to tableized with dot separation" do
55
+ it "should default collection name of namespaced class to tableized with dot separation" do
56
56
  module ::BloggyPoo
57
57
  class Post
58
58
  include MongoMapper::Document
@@ -60,21 +60,21 @@ class DocumentTest < Test::Unit::TestCase
60
60
  end
61
61
  end
62
62
 
63
- should "be an instance of a Mongo::Collection" do
63
+ it "should be an instance of a Mongo::Collection" do
64
64
  @document.collection.should be_instance_of(Mongo::Collection)
65
65
  end
66
66
  end
67
67
  end # Document class
68
68
 
69
69
  context "Documents that inherit from other documents" do
70
- should "default collection name to inherited class" do
70
+ it "should default collection name to inherited class" do
71
71
  Message.collection_name.should == 'messages'
72
72
  Enter.collection_name.should == 'messages'
73
73
  Exit.collection_name.should == 'messages'
74
74
  Chat.collection_name.should == 'messages'
75
75
  end
76
76
 
77
- should "default associations to inherited class" do
77
+ it "should default associations to inherited class" do
78
78
  Message.associations.keys.should include(:room)
79
79
  Enter.associations.keys.should include(:room)
80
80
  Exit.associations.keys.should include(:room)
@@ -83,50 +83,50 @@ class DocumentTest < Test::Unit::TestCase
83
83
  end
84
84
 
85
85
  context "descendants" do
86
- should "default to an empty array" do
86
+ it "should default to an empty array" do
87
87
  Enter.descendants.should == []
88
88
  end
89
89
 
90
- should "be recorded" do
90
+ it "should be recorded" do
91
91
  Message.descendants.should == [Enter, Exit, Chat]
92
92
  end
93
93
  end
94
94
 
95
95
  context "An instance of a document" do
96
- setup do
96
+ before do
97
97
  @document = Doc do
98
98
  key :name, String
99
99
  key :age, Integer
100
100
  end
101
101
  end
102
102
 
103
- should "respond to cache_key" do
103
+ it "should respond to cache_key" do
104
104
  @document.new.should respond_to(:cache_key)
105
105
  end
106
106
 
107
- should "create id during initialization" do
107
+ it "should create id during initialization" do
108
108
  @document.new._id.should be_instance_of(BSON::ObjectId)
109
109
  end
110
110
 
111
- should "have access to logger" do
111
+ it "should have access to logger" do
112
112
  doc = @document.new
113
113
  doc.logger.should == @document.logger
114
114
  doc.logger.should be_instance_of(Logger)
115
115
  end
116
116
 
117
- should "have access to the class's collection" do
117
+ it "should have access to the class's collection" do
118
118
  doc = @document.new
119
119
  doc.collection.name.should == @document.collection.name
120
120
  end
121
121
 
122
- should "use default values if defined for keys" do
122
+ it "should use default values if defined for keys" do
123
123
  @document.key :active, Boolean, :default => true
124
124
 
125
125
  @document.new.active.should be_true
126
126
  @document.new(:active => false).active.should be_false
127
127
  end
128
128
 
129
- should "use default values if defined even when custom data type" do
129
+ it "should use default values if defined even when custom data type" do
130
130
  @document.key :window, WindowSize, :default => WindowSize.new(600, 480)
131
131
 
132
132
  doc = @document.new
@@ -134,7 +134,7 @@ class DocumentTest < Test::Unit::TestCase
134
134
  end
135
135
 
136
136
  context "root document" do
137
- should "set self to the root document on embedded documents" do
137
+ it "should set self to the root document on embedded documents" do
138
138
  klass = Doc()
139
139
  pets = EDoc()
140
140
 
@@ -146,11 +146,11 @@ class DocumentTest < Test::Unit::TestCase
146
146
  end
147
147
 
148
148
  context "new?" do
149
- should "be true if no id" do
149
+ it "should be true if no id" do
150
150
  @document.new.new?.should be_true
151
151
  end
152
152
 
153
- should "be true if id but using custom id and not saved yet" do
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'
@@ -159,29 +159,29 @@ class DocumentTest < Test::Unit::TestCase
159
159
  end
160
160
 
161
161
  context "equality" do
162
- setup do
162
+ before do
163
163
  @oid = BSON::ObjectId.new
164
164
  end
165
165
 
166
- should "delegate hash to _id" do
166
+ it "should delegate hash to _id" do
167
167
  doc = @document.new
168
168
  doc.hash.should == doc._id.hash
169
169
  end
170
170
 
171
- should "delegate eql to ==" do
171
+ it "should delegate eql to ==" do
172
172
  doc = @document.new
173
173
  other = @document.new
174
174
  doc.eql?(other).should == (doc == other)
175
175
  doc.eql?(doc).should == (doc == doc)
176
176
  end
177
177
 
178
- should "know if same object as another" do
178
+ it "should know if same object as another" do
179
179
  doc = @document.new
180
180
  doc.should equal(doc)
181
181
  doc.should_not equal(@document.new)
182
182
  end
183
183
 
184
- should "allow set operations on array of documents" do
184
+ it "should allow set operations on array of documents" do
185
185
  @document.key :parent_id, ObjectId
186
186
  @document.belongs_to :parent, :class => @document
187
187
 
@@ -191,15 +191,15 @@ class DocumentTest < Test::Unit::TestCase
191
191
  ([child.parent] & [parent]).should == [parent]
192
192
  end
193
193
 
194
- should "be equal if id and class are the same" do
194
+ it "should be equal if id and class are the same" do
195
195
  (@document.new('_id' => @oid) == @document.new('_id' => @oid)).should be(true)
196
196
  end
197
197
 
198
- should "not be equal if class same but id different" do
198
+ it "should not be equal if class same but id different" do
199
199
  (@document.new('_id' => @oid) == @document.new('_id' => BSON::ObjectId.new)).should be(false)
200
200
  end
201
201
 
202
- should "not be equal if id same but class different" do
202
+ it "should not be equal if id same but class different" do
203
203
  another_document = Doc()
204
204
  (@document.new('_id' => @oid) == another_document.new('_id' => @oid)).should be(false)
205
205
  end
@@ -207,19 +207,19 @@ class DocumentTest < Test::Unit::TestCase
207
207
 
208
208
  context "nil attributes" do
209
209
 
210
- should "list all the keys and default non nil attributes" do
210
+ it "should list all the keys and default non nil attributes" do
211
211
  doc = @document.new
212
212
  doc.keys.keys.sort.should == ['_id', 'age', 'name']
213
213
  doc.attributes.keys.sort.should == ['_id']
214
214
  end
215
215
 
216
- should "list all the keys and non nil attributes" do
216
+ it "should list all the keys and non nil attributes" do
217
217
  doc = @document.new(:name => "John")
218
218
  doc.keys.keys.sort.should == ['_id', 'age', 'name']
219
219
  doc.attributes.keys.sort.should == ['_id','name']
220
220
  end
221
221
 
222
- should "list all the keys and pickup changed nil attributes" do
222
+ it "should list all the keys and pickup changed nil attributes" do
223
223
  doc = @document.new(:name => "John")
224
224
  doc.keys.keys.sort.should == ['_id', 'age', 'name']
225
225
  doc.attributes.keys.sort.should == ['_id','name']
@@ -230,7 +230,7 @@ class DocumentTest < Test::Unit::TestCase
230
230
  doc.attributes.keys.sort.should == ['_id']
231
231
  end
232
232
 
233
- should "list all the keys and pickup changed nil and non-nil attributes" do
233
+ it "should list all the keys and pickup changed nil and non-nil attributes" do
234
234
  doc = @document.new(:name => "John")
235
235
  doc.keys.keys.sort.should == ['_id', 'age', 'name']
236
236
  doc.attributes.keys.sort.should == ['_id','name']
@@ -1,35 +1,35 @@
1
- require 'test_helper'
1
+ require 'spec_helper'
2
2
 
3
- class DynamicFinderTest < Test::Unit::TestCase
3
+ describe "DynamicFinder" do
4
4
  DynamicFinder = MongoMapper::Plugins::DynamicQuerying::DynamicFinder
5
5
 
6
- should "initialize with method" do
6
+ it "should initialize with method" do
7
7
  finder = DynamicFinder.new(:foobar)
8
8
  finder.method.should == :foobar
9
9
  end
10
10
 
11
11
  context "found?" do
12
- should "be true for find_by" do
12
+ it "should be true for find_by" do
13
13
  DynamicFinder.new(:find_by_foo).found?.should be_true
14
14
  end
15
15
 
16
- should "be true for find_by with !" do
16
+ it "should be true for find_by with !" do
17
17
  DynamicFinder.new(:find_by_foo!).found?.should be_true
18
18
  end
19
19
 
20
- should "be true for find_all_by" do
20
+ it "should be true for find_all_by" do
21
21
  DynamicFinder.new(:find_all_by_foo).found?.should be_true
22
22
  end
23
23
 
24
- should "be true for find_or_initialize_by" do
24
+ it "should be true for find_or_initialize_by" do
25
25
  DynamicFinder.new(:find_or_initialize_by_foo).found?.should be_true
26
26
  end
27
27
 
28
- should "be true for find_or_create_by" do
28
+ it "should be true for find_or_create_by" do
29
29
  DynamicFinder.new(:find_or_create_by_foo).found?.should be_true
30
30
  end
31
31
 
32
- should "be false for anything else" do
32
+ it "should be false for anything else" do
33
33
  [:foobar, :bazwick].each do |method|
34
34
  DynamicFinder.new(method).found?.should be_false
35
35
  end
@@ -37,88 +37,88 @@ class DynamicFinderTest < Test::Unit::TestCase
37
37
  end
38
38
 
39
39
  context "find_all_by" do
40
- should "parse one attribute" do
40
+ it "should parse one attribute" do
41
41
  DynamicFinder.new(:find_all_by_foo).attributes.should == %w(foo)
42
42
  end
43
43
 
44
- should "parse multiple attributes" do
44
+ it "should parse multiple attributes" do
45
45
  DynamicFinder.new(:find_all_by_foo_and_bar).attributes.should == %w(foo bar)
46
46
  DynamicFinder.new(:find_all_by_foo_and_bar_and_baz).attributes.should == %w(foo bar baz)
47
47
  end
48
48
 
49
- should "set finder to :all" do
49
+ it "should set finder to :all" do
50
50
  DynamicFinder.new(:find_all_by_foo_and_bar).finder.should == :all
51
51
  end
52
52
  end
53
53
 
54
54
  context "find_by" do
55
- should "parse one attribute" do
55
+ it "should parse one attribute" do
56
56
  DynamicFinder.new(:find_by_foo).attributes.should == %w(foo)
57
57
  end
58
58
 
59
- should "parse multiple attributes" do
59
+ it "should parse multiple attributes" do
60
60
  DynamicFinder.new(:find_by_foo_and_bar).attributes.should == %w(foo bar)
61
61
  end
62
62
 
63
- should "set finder to :first" do
63
+ it "should set finder to :first" do
64
64
  DynamicFinder.new(:find_by_foo).finder.should == :first
65
65
  end
66
66
 
67
- should "set bang to false" do
67
+ it "should set bang to false" do
68
68
  DynamicFinder.new(:find_by_foo).bang.should be_false
69
69
  end
70
70
  end
71
71
 
72
72
  context "find_by with !" do
73
- should "parse one attribute" do
73
+ it "should parse one attribute" do
74
74
  DynamicFinder.new(:find_by_foo!).attributes.should == %w(foo)
75
75
  end
76
76
 
77
- should "parse multiple attributes" do
77
+ it "should parse multiple attributes" do
78
78
  DynamicFinder.new(:find_by_foo_and_bar!).attributes.should == %w(foo bar)
79
79
  end
80
80
 
81
- should "set finder to :first" do
81
+ it "should set finder to :first" do
82
82
  DynamicFinder.new(:find_by_foo!).finder.should == :first
83
83
  end
84
84
 
85
- should "set bang to true" do
85
+ it "should set bang to true" do
86
86
  DynamicFinder.new(:find_by_foo!).bang.should be_true
87
87
  end
88
88
  end
89
89
 
90
90
  context "find_or_initialize_by" do
91
- should "parse one attribute" do
91
+ it "should parse one attribute" do
92
92
  DynamicFinder.new(:find_or_initialize_by_foo).attributes.should == %w(foo)
93
93
  end
94
94
 
95
- should "parse multiple attributes" do
95
+ it "should parse multiple attributes" do
96
96
  DynamicFinder.new(:find_or_initialize_by_foo_and_bar).attributes.should == %w(foo bar)
97
97
  end
98
98
 
99
- should "set finder to :first" do
99
+ it "should set finder to :first" do
100
100
  DynamicFinder.new(:find_or_initialize_by_foo).finder.should == :first
101
101
  end
102
102
 
103
- should "set instantiator to new" do
103
+ it "should set instantiator to new" do
104
104
  DynamicFinder.new(:find_or_initialize_by_foo).instantiator.should == :new
105
105
  end
106
106
  end
107
107
 
108
108
  context "find_or_create_by" do
109
- should "parse one attribute" do
109
+ it "should parse one attribute" do
110
110
  DynamicFinder.new(:find_or_create_by_foo).attributes.should == %w(foo)
111
111
  end
112
112
 
113
- should "parse multiple attributes" do
113
+ it "should parse multiple attributes" do
114
114
  DynamicFinder.new(:find_or_create_by_foo_and_bar).attributes.should == %w(foo bar)
115
115
  end
116
116
 
117
- should "set finder to :first" do
117
+ it "should set finder to :first" do
118
118
  DynamicFinder.new(:find_or_create_by_foo).finder.should == :first
119
119
  end
120
120
 
121
- should "set instantiator to new" do
121
+ it "should set instantiator to new" do
122
122
  DynamicFinder.new(:find_or_create_by_foo).instantiator.should == :create
123
123
  end
124
124
  end