mongo_mapper_ign 0.7.4 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/README.rdoc +1 -1
  2. data/lib/mongo_mapper.rb +5 -8
  3. data/lib/mongo_mapper/document.rb +24 -53
  4. data/lib/mongo_mapper/embedded_document.rb +1 -0
  5. data/lib/mongo_mapper/plugins.rb +1 -0
  6. data/lib/mongo_mapper/plugins/associations.rb +2 -1
  7. data/lib/mongo_mapper/plugins/associations/base.rb +5 -4
  8. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +2 -1
  9. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +2 -1
  10. data/lib/mongo_mapper/plugins/associations/collection.rb +1 -0
  11. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +1 -0
  12. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +1 -0
  13. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +1 -0
  14. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +2 -1
  15. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +1 -0
  16. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +1 -0
  17. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +1 -0
  18. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +1 -0
  19. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +2 -1
  20. data/lib/mongo_mapper/plugins/associations/proxy.rb +1 -0
  21. data/lib/mongo_mapper/plugins/callbacks.rb +1 -0
  22. data/lib/mongo_mapper/plugins/clone.rb +1 -0
  23. data/lib/mongo_mapper/plugins/descendants.rb +1 -0
  24. data/lib/mongo_mapper/plugins/dirty.rb +1 -0
  25. data/lib/mongo_mapper/plugins/equality.rb +4 -3
  26. data/lib/mongo_mapper/plugins/identity_map.rb +9 -7
  27. data/lib/mongo_mapper/plugins/inspect.rb +1 -0
  28. data/lib/mongo_mapper/plugins/keys.rb +50 -73
  29. data/lib/mongo_mapper/plugins/keys/key.rb +54 -0
  30. data/lib/mongo_mapper/plugins/logger.rb +1 -0
  31. data/lib/mongo_mapper/plugins/modifiers.rb +10 -5
  32. data/lib/mongo_mapper/plugins/pagination.rb +1 -0
  33. data/lib/mongo_mapper/plugins/pagination/proxy.rb +4 -3
  34. data/lib/mongo_mapper/plugins/persistence.rb +1 -0
  35. data/lib/mongo_mapper/plugins/protected.rb +1 -0
  36. data/lib/mongo_mapper/plugins/rails.rb +1 -0
  37. data/lib/mongo_mapper/plugins/serialization.rb +4 -3
  38. data/lib/mongo_mapper/plugins/timestamps.rb +2 -1
  39. data/lib/mongo_mapper/plugins/userstamps.rb +1 -0
  40. data/lib/mongo_mapper/plugins/validations.rb +3 -2
  41. data/lib/mongo_mapper/query.rb +10 -129
  42. data/lib/mongo_mapper/support.rb +18 -39
  43. data/lib/mongo_mapper/support/descendant_appends.rb +1 -0
  44. data/lib/mongo_mapper/support/find.rb +1 -0
  45. data/lib/mongo_mapper/version.rb +2 -1
  46. metadata +32 -134
  47. data/.gitignore +0 -10
  48. data/Rakefile +0 -37
  49. data/mongo_mapper.gemspec +0 -214
  50. data/mongo_mapper_ign.gemspec +0 -217
  51. data/performance/read_write.rb +0 -52
  52. data/specs.watchr +0 -51
  53. data/test/NOTE_ON_TESTING +0 -1
  54. data/test/active_model_lint_test.rb +0 -13
  55. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +0 -63
  56. data/test/functional/associations/test_belongs_to_proxy.rb +0 -101
  57. data/test/functional/associations/test_in_array_proxy.rb +0 -325
  58. data/test/functional/associations/test_many_documents_as_proxy.rb +0 -229
  59. data/test/functional/associations/test_many_documents_proxy.rb +0 -536
  60. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +0 -176
  61. data/test/functional/associations/test_many_embedded_proxy.rb +0 -256
  62. data/test/functional/associations/test_many_polymorphic_proxy.rb +0 -302
  63. data/test/functional/associations/test_one_embedded_proxy.rb +0 -68
  64. data/test/functional/associations/test_one_proxy.rb +0 -196
  65. data/test/functional/test_associations.rb +0 -44
  66. data/test/functional/test_binary.rb +0 -27
  67. data/test/functional/test_callbacks.rb +0 -151
  68. data/test/functional/test_dirty.rb +0 -163
  69. data/test/functional/test_document.rb +0 -1219
  70. data/test/functional/test_embedded_document.rb +0 -210
  71. data/test/functional/test_identity_map.rb +0 -507
  72. data/test/functional/test_indexing.rb +0 -44
  73. data/test/functional/test_logger.rb +0 -20
  74. data/test/functional/test_modifiers.rb +0 -394
  75. data/test/functional/test_pagination.rb +0 -93
  76. data/test/functional/test_protected.rb +0 -163
  77. data/test/functional/test_string_id_compatibility.rb +0 -67
  78. data/test/functional/test_timestamps.rb +0 -64
  79. data/test/functional/test_userstamps.rb +0 -28
  80. data/test/functional/test_validations.rb +0 -342
  81. data/test/models.rb +0 -227
  82. data/test/support/custom_matchers.rb +0 -37
  83. data/test/support/timing.rb +0 -16
  84. data/test/test_helper.rb +0 -64
  85. data/test/unit/associations/test_base.rb +0 -212
  86. data/test/unit/associations/test_proxy.rb +0 -105
  87. data/test/unit/serializers/test_json_serializer.rb +0 -202
  88. data/test/unit/test_descendant_appends.rb +0 -71
  89. data/test/unit/test_document.rb +0 -225
  90. data/test/unit/test_dynamic_finder.rb +0 -123
  91. data/test/unit/test_embedded_document.rb +0 -657
  92. data/test/unit/test_keys.rb +0 -185
  93. data/test/unit/test_mongo_mapper.rb +0 -118
  94. data/test/unit/test_pagination.rb +0 -160
  95. data/test/unit/test_plugins.rb +0 -50
  96. data/test/unit/test_query.rb +0 -374
  97. data/test/unit/test_rails.rb +0 -181
  98. data/test/unit/test_rails_compatibility.rb +0 -52
  99. data/test/unit/test_serialization.rb +0 -51
  100. data/test/unit/test_support.rb +0 -382
  101. data/test/unit/test_time_zones.rb +0 -39
  102. data/test/unit/test_validations.rb +0 -544
@@ -1,68 +0,0 @@
1
- require 'test_helper'
2
-
3
- class OneEmbeddedProxyTest < Test::Unit::TestCase
4
- def setup
5
- @post_class = Doc('Post') do
6
- key :title, String
7
- end
8
- @author_class = EDoc('Author') do
9
- key :name, String
10
- embedded_in :post
11
- end
12
- end
13
-
14
- should "default to nil" do
15
- @post_class.one :author, :class => @author_class
16
- @post_class.new.author.should be_nil
17
- end
18
-
19
- should "be able to build" do
20
- @post_class.one :author, :class => @author_class
21
-
22
- post = @post_class.create
23
- author = post.author.build(:name => "John")
24
- post.author.should be_instance_of(@author_class)
25
- post.author.should be_new
26
- post.author.name.should == 'John'
27
- post.author.should == author
28
- post.author.post.should == post
29
- end
30
-
31
- should "send object id to target" do
32
- @post_class.one :author, :class => @author_class
33
-
34
- post = @post_class.new
35
- author = @author_class.new(:name => 'Frank')
36
- post.author = author
37
-
38
- post.author.object_id.should == post.author.target.object_id
39
- end
40
-
41
- should "be able to replace the association" do
42
- @post_class.one :author, :class => @author_class
43
-
44
- post = @post_class.new
45
- author = @author_class.new(:name => 'Frank')
46
- post.author = author
47
- post.save
48
- post.reload
49
-
50
- post.author.should == author
51
- post.author.nil?.should be_false
52
-
53
- new_author = @author_class.new(:name => 'Emily')
54
- post.author = new_author
55
- post.author.should == new_author
56
- end
57
-
58
- should "have boolean method for testing presence" do
59
- @post_class.one :author, :class => @author_class
60
-
61
- post = @post_class.new
62
- post.author?.should be_false
63
-
64
- post.author = @author_class.new(:name => 'Frank')
65
- post.author?.should be_true
66
- end
67
-
68
- end
@@ -1,196 +0,0 @@
1
- require 'test_helper'
2
-
3
- class OneProxyTest < Test::Unit::TestCase
4
- def setup
5
- @post_class = Doc('Post')
6
- @author_class = Doc do
7
- key :post_id, ObjectId
8
- end
9
- end
10
-
11
- should "default to nil" do
12
- @post_class.one :author, :class => @author_class
13
- @post_class.new.author.nil?.should be_true
14
- end
15
-
16
- should "send object id to target" do
17
- @post_class.one :author, :class => @author_class
18
-
19
- post = @post_class.new
20
- author = @author_class.new(:name => 'Frank')
21
- post.author = author
22
- author.save.should be_true
23
- post.save.should be_true
24
-
25
- post.author.object_id.should == post.author.target.object_id
26
- end
27
-
28
- should "allow assignment of associated document using a hash" do
29
- @post_class.one :author, :class => @author_class
30
-
31
- post = @post_class.new('author' => { 'name' => 'Frank' })
32
- post.author.name.should == 'Frank'
33
-
34
- post.save.should be_true
35
- post.reload
36
-
37
- post.author.name.should == 'Frank'
38
- end
39
-
40
- context "replacing the association" do
41
- context "with an object of the class" do
42
- should "work" do
43
- @post_class.one :author, :class => @author_class
44
-
45
- post = @post_class.new
46
- author = @author_class.new(:name => 'Frank')
47
- post.author = author
48
- post.reload
49
-
50
- post.author.should == author
51
- post.author.nil?.should be_false
52
-
53
- new_author = @author_class.new(:name => 'Emily')
54
- post.author = new_author
55
- post.author.should == new_author
56
- end
57
- end
58
-
59
- context "with a Hash" do
60
- should "convert to an object of the class and work" do
61
- @post_class.one :author, :class => @author_class
62
-
63
- post = @post_class.new
64
- author = { 'name' => 'Frank' }
65
- post.author = author
66
- post.reload
67
-
68
- post.author.name.should == 'Frank'
69
- post.author.nil?.should be_false
70
-
71
- new_author = { 'name' => 'Emily' }
72
- post.author = new_author
73
- post.author.name.should == 'Emily'
74
- end
75
- end
76
- end
77
-
78
- should "have boolean method for testing presence" do
79
- @post_class.one :author, :class => @author_class
80
-
81
- post = @post_class.new
82
- post.author?.should be_false
83
-
84
- post.author = @author_class.new(:name => 'Frank')
85
- post.author?.should be_true
86
- end
87
-
88
- should "work with criteria" do
89
- @post_class.one :primary_author, :class => @author_class, :primary => true
90
- @post_class.one :author, :class => @author_class
91
-
92
- post = @post_class.create
93
- author = @author_class.create(:name => 'Frank', :primary => false, :post_id => post.id)
94
- primary = @author_class.create(:name => 'Bill', :primary => true, :post_id => post.id)
95
- post.reload
96
- post.author.should == author
97
- post.primary_author.should == primary
98
- end
99
-
100
- should "unset the association" do
101
- @post_class.one :author, :class => @author_class
102
- post = @post_class.new
103
- author = @author_class.new
104
- post.author = author
105
- post.reload
106
-
107
- post.author = nil
108
- post.author.nil?.should be_false
109
- end
110
-
111
- should "work with :dependent delete" do
112
- @post_class.one :author, :class => @author_class, :dependent => :delete
113
-
114
- post = @post_class.create
115
- author = @author_class.new
116
- post.author = author
117
- post.reload
118
-
119
- @author_class.any_instance.expects(:delete).once
120
- post.author = @author_class.new
121
- end
122
-
123
- should "work with :dependent destroy" do
124
- @post_class.one :author, :class => @author_class, :dependent => :destroy
125
-
126
- post = @post_class.create
127
- author = @author_class.new
128
- post.author = author
129
- post.reload
130
-
131
- @author_class.any_instance.expects(:destroy).once
132
- post.author = @author_class.new
133
- end
134
-
135
- should "work with :dependent nullify" do
136
- @post_class.one :author, :class => @author_class, :dependent => :nullify
137
-
138
- post = @post_class.create
139
- author = @author_class.new
140
- post.author = author
141
- post.reload
142
-
143
- post.author = @author_class.new
144
-
145
- author.reload
146
- author.post_id.should be_nil
147
- end
148
-
149
- should "be able to build" do
150
- @post_class.one :author, :class => @author_class
151
-
152
- post = @post_class.create
153
- author = post.author.build(:name => 'John')
154
- post.author.should be_instance_of(@author_class)
155
- post.author.should be_new
156
- post.author.name.should == 'John'
157
- post.author.should == author
158
- post.author.post_id.should == post.id
159
- end
160
-
161
- should "be able to create" do
162
- @post_class.one :author, :class => @author_class
163
-
164
- post = @post_class.create
165
- author = post.author.create(:name => 'John')
166
- post.author.should be_instance_of(@author_class)
167
- post.author.should_not be_new
168
- post.author.name.should == 'John'
169
- post.author.should == author
170
- post.author.post_id.should == post.id
171
- end
172
-
173
- context "#create!" do
174
- setup do
175
- @author_class.key :name, String, :required => true
176
- @post_class.one :author, :class => @author_class
177
- end
178
-
179
- should "raise exception if invalid" do
180
- post = @post_class.create
181
- assert_raises(MongoMapper::DocumentNotValid) do
182
- post.author.create!
183
- end
184
- end
185
-
186
- should "work if valid" do
187
- post = @post_class.create
188
- author = post.author.create!(:name => 'John')
189
- post.author.should be_instance_of(@author_class)
190
- post.author.should_not be_new
191
- post.author.name.should == 'John'
192
- post.author.should == author
193
- post.author.post_id.should == post.id
194
- end
195
- end
196
- end
@@ -1,44 +0,0 @@
1
- require 'test_helper'
2
- require 'models'
3
-
4
- class AssociationsTest < Test::Unit::TestCase
5
- should "allow changing class names" do
6
- class AwesomeUser
7
- include MongoMapper::Document
8
-
9
- many :posts, :class_name => 'AssociationsTest::AwesomePost', :foreign_key => :creator_id
10
- end
11
- AwesomeUser.collection.remove
12
-
13
- class AwesomeTag
14
- include MongoMapper::EmbeddedDocument
15
-
16
- key :name, String
17
- key :post_id, ObjectId
18
-
19
- belongs_to :post, :class_name => 'AssociationsTest::AwesomeUser'
20
- end
21
-
22
- class AwesomePost
23
- include MongoMapper::Document
24
-
25
- key :creator_id, ObjectId
26
-
27
- belongs_to :creator, :class_name => 'AssociationsTest::AwesomeUser'
28
- many :tags, :class_name => 'AssociationsTest::AwesomeTag', :foreign_key => :post_id
29
- end
30
-
31
- AwesomeUser.collection.remove
32
- AwesomePost.collection.remove
33
-
34
- user = AwesomeUser.create
35
- tag1 = AwesomeTag.new(:name => 'awesome')
36
- tag2 = AwesomeTag.new(:name => 'grand')
37
- post1 = AwesomePost.create(:creator => user, :tags => [tag1])
38
- post2 = AwesomePost.create(:creator => user, :tags => [tag2])
39
- user.posts.should == [post1, post2]
40
-
41
- post1 = post1.reload
42
- post1.tags.should == [tag1]
43
- end
44
- end
@@ -1,27 +0,0 @@
1
- require 'test_helper'
2
-
3
- class BinaryTest < Test::Unit::TestCase
4
- should "serialize and deserialize correctly" do
5
- klass = Doc do
6
- key :contents, Binary
7
- end
8
-
9
- doc = klass.new(:contents => '010101')
10
- doc.save
11
-
12
- doc = doc.reload
13
- doc.contents.to_s.should == BSON::ByteBuffer.new('010101').to_s
14
- end
15
-
16
- context "Saving a document with a blank binary value" do
17
- setup do
18
- @document = Doc do
19
- key :file, Binary
20
- end
21
- end
22
-
23
- should "not fail" do
24
- assert_nothing_raised { @document.new(:file => nil).save }
25
- end
26
- end
27
- end
@@ -1,151 +0,0 @@
1
- require 'test_helper'
2
-
3
- module CallbacksSupport
4
- def self.included base
5
- base.key :name, String
6
-
7
- [ :before_validation_on_create, :before_validation_on_update,
8
- :before_validation, :after_validation,
9
- :before_create, :after_create,
10
- :before_update, :after_update,
11
- :before_save, :after_save,
12
- :before_destroy, :after_destroy].each do |callback|
13
- callback_method = "#{callback}_callback"
14
- base.send(callback, callback_method)
15
- define_method(callback_method) do
16
- history << callback.to_sym
17
- end
18
- end
19
- end
20
-
21
- def history
22
- @history ||= []
23
- end
24
-
25
- def clear_history
26
- embedded_associations.each { |a| self.send(a.name).each(&:clear_history) }
27
- @history = nil
28
- end
29
- end
30
-
31
- class CallbacksTest < Test::Unit::TestCase
32
- CreateCallbackOrder = [:before_validation, :before_validation_on_create, :after_validation, :before_save, :before_create, :after_create, :after_save]
33
- UpdateCallbackOrder = [:before_validation, :before_validation_on_update, :after_validation, :before_save, :before_update, :after_update, :after_save]
34
-
35
- context "Defining and running callbacks on documents" do
36
- setup do
37
- @document = Doc { include CallbacksSupport }
38
- end
39
-
40
- should "get the order right for creating documents" do
41
- doc = @document.create(:name => 'John Nunemaker')
42
- doc.history.should == CreateCallbackOrder
43
- end
44
-
45
- should "get the order right for updating documents" do
46
- doc = @document.create(:name => 'John Nunemaker')
47
- doc.clear_history
48
- doc.name = 'John'
49
- doc.save
50
- doc.history.should == UpdateCallbackOrder
51
- end
52
-
53
- should "work for before and after validation" do
54
- doc = @document.new(:name => 'John Nunemaker')
55
- doc.valid?
56
- doc.history.should include(:before_validation)
57
- doc.history.should include(:after_validation)
58
- end
59
-
60
- should "work for before and after create" do
61
- doc = @document.create(:name => 'John Nunemaker')
62
- doc.history.should include(:before_create)
63
- doc.history.should include(:after_create)
64
- end
65
-
66
- should "work for before and after update" do
67
- doc = @document.create(:name => 'John Nunemaker')
68
- doc.name = 'John Doe'
69
- doc.save
70
- doc.history.should include(:before_update)
71
- doc.history.should include(:after_update)
72
- end
73
-
74
- should "work for before and after save" do
75
- doc = @document.new
76
- doc.name = 'John Doe'
77
- doc.save
78
- doc.history.should include(:before_save)
79
- doc.history.should include(:after_save)
80
- end
81
-
82
- should "work for before and after destroy" do
83
- doc = @document.create(:name => 'John Nunemaker')
84
- doc.destroy
85
- doc.history.should include(:before_destroy)
86
- doc.history.should include(:after_destroy)
87
- end
88
- end
89
-
90
- context "Defining and running callbacks on many embedded documents" do
91
- setup do
92
- @root_class = Doc { include CallbacksSupport }
93
- @child_class = EDoc { include CallbacksSupport }
94
- @grand_child_class = EDoc { include CallbacksSupport }
95
-
96
- @root_class.many :children, :class => @child_class
97
- @child_class.many :children, :class => @grand_child_class
98
- end
99
-
100
- should "get the order right based on root document creation" do
101
- grand = @grand_child_class.new(:name => 'Grand Child')
102
- child = @child_class.new(:name => 'Child', :children => [grand])
103
- root = @root_class.create(:name => 'Parent', :children => [child])
104
-
105
- child = root.children.first
106
- child.history.should == CreateCallbackOrder
107
-
108
- grand = root.children.first.children.first
109
- grand.history.should == CreateCallbackOrder
110
- end
111
-
112
- should "get the order right based on root document updating" do
113
- grand = @grand_child_class.new(:name => 'Grand Child')
114
- child = @child_class.new(:name => 'Child', :children => [grand])
115
- root = @root_class.create(:name => 'Parent', :children => [child])
116
- root.clear_history
117
- root.update_attributes(:name => 'Updated Parent')
118
-
119
- child = root.children.first
120
- child.history.should == UpdateCallbackOrder
121
-
122
- grand = root.children.first.children.first
123
- grand.history.should == UpdateCallbackOrder
124
- end
125
-
126
- should "work for before and after destroy" do
127
- grand = @grand_child_class.new(:name => 'Grand Child')
128
- child = @child_class.new(:name => 'Child', :children => [grand])
129
- root = @root_class.create(:name => 'Parent', :children => [child])
130
- root.destroy
131
- child = root.children.first
132
- child.history.should include(:before_destroy)
133
- child.history.should include(:after_destroy)
134
-
135
- grand = root.children.first.children.first
136
- grand.history.should include(:before_destroy)
137
- grand.history.should include(:after_destroy)
138
- end
139
-
140
- should "not attempt to run callback defined on root that is not defined on embedded association" do
141
- @root_class.define_callbacks :after_publish
142
- @root_class.after_save { |d| d.run_callbacks(:after_publish) }
143
-
144
- assert_nothing_raised do
145
- child = @child_class.new(:name => 'Child')
146
- root = @root_class.create(:name => 'Parent', :children => [child])
147
- child.history.should_not include(:after_publish)
148
- end
149
- end
150
- end
151
- end