mongo_mapper_ign 0.7.4 → 0.7.6

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 (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,51 +0,0 @@
1
- def growl(title, msg, img)
2
- %x{growlnotify -m #{ msg.inspect} -t #{title.inspect} --image ~/.watchr/#{img}.png}
3
- end
4
-
5
- def form_growl_message(str)
6
- results = str.split("\n").last
7
- if results =~ /[1-9]\s(failure|error)s?/
8
- growl "Test Results", "#{results}", "fail"
9
- elsif results != ""
10
- growl "Test Results", "#{results}", "pass"
11
- end
12
- end
13
-
14
- def run(cmd)
15
- puts(cmd)
16
- output = ""
17
- IO.popen(cmd) do |com|
18
- com.each_char do |c|
19
- print c
20
- output << c
21
- $stdout.flush
22
- end
23
- end
24
- form_growl_message output
25
- end
26
-
27
- def run_test_file(file)
28
- run %Q(ruby -I"lib:test" -rubygems #{file})
29
- end
30
-
31
- def run_all_tests
32
- run "rake test"
33
- end
34
-
35
- def related_test_files(path)
36
- Dir['test/**/*.rb'].select { |file| file =~ /test_#{File.basename(path)}/ }
37
- end
38
-
39
- watch('test/test_helper\.rb') { system('clear'); run_all_tests }
40
- watch('test/.*/test_.*\.rb') { |m| system('clear'); run_test_file(m[0]) }
41
- watch('lib/.*') { |m| related_test_files(m[0]).each { |file| run_test_file(file) } }
42
-
43
- # Ctrl-\
44
- Signal.trap('QUIT') do
45
- puts " --- Running all tests ---\n\n"
46
- run_all_tests
47
- end
48
-
49
- # Ctrl-C
50
- Signal.trap('INT') { abort("\n") }
51
-
@@ -1 +0,0 @@
1
- I am doing my best to keep unit and functional tests separate. As I see them, functional tests hit the database and should never care about internals. Unit tests do not hit the database.
@@ -1,13 +0,0 @@
1
- require 'test_helper'
2
- # For testing against edge rails also.
3
- # $:.unshift '/Users/jnunemaker/dev/ruby/rails/activemodel/lib'
4
- require 'active_model'
5
- require 'models'
6
-
7
- class ActiveModelLintTest < ActiveModel::TestCase
8
- include ActiveModel::Lint::Tests
9
-
10
- def setup
11
- @model = Post.new
12
- end
13
- end
@@ -1,63 +0,0 @@
1
- require 'test_helper'
2
- require 'models'
3
-
4
- class BelongsToPolymorphicProxyTest < Test::Unit::TestCase
5
- def setup
6
- Status.collection.remove
7
- Project.collection.remove
8
- end
9
-
10
- should "default to nil" do
11
- status = Status.new
12
- status.target.nil?.should be_true
13
- status.target.inspect.should == "nil"
14
- end
15
-
16
- should "have boolean presence method" do
17
- status = Status.new
18
- status.target?.should be_false
19
-
20
- status.target = Project.new(:name => 'mongomapper')
21
- status.target?.should be_true
22
- end
23
-
24
- should "be able to replace the association" do
25
- status = Status.new(:name => 'Foo!')
26
- project = Project.new(:name => "mongomapper")
27
- status.target = project
28
- status.save.should be_true
29
-
30
- status = status.reload
31
- status.target.nil?.should be_false
32
- status.target_id.should == project._id
33
- status.target_type.should == "Project"
34
- status.target.name.should == "mongomapper"
35
- end
36
-
37
- should "unset the association" do
38
- status = Status.new(:name => 'Foo!')
39
- project = Project.new(:name => "mongomapper")
40
- status.target = project
41
- status.save.should be_true
42
-
43
- status = status.reload
44
- status.target = nil
45
- status.target_type.nil?.should be_true
46
- status.target_id.nil?.should be_true
47
- status.target.nil?.should be_true
48
- end
49
-
50
- context "association id set but document not found" do
51
- setup do
52
- @status = Status.new(:name => 'Foo!')
53
- project = Project.new(:name => "mongomapper")
54
- @status.target = project
55
- @status.save.should be_true
56
- project.destroy
57
- end
58
-
59
- should "return nil instead of raising error" do
60
- @status.target.nil?.should be_true
61
- end
62
- end
63
- end
@@ -1,101 +0,0 @@
1
- require 'test_helper'
2
- require 'models'
3
-
4
- class BelongsToProxyTest < Test::Unit::TestCase
5
- def setup
6
- @post_class = Doc()
7
- @comment_class = Doc do
8
- key :post_id, String
9
- end
10
-
11
- @comment_class.belongs_to :post, :class => @post_class
12
- end
13
-
14
- should "default to nil" do
15
- @comment_class.new.post.nil?.should be_true
16
- end
17
-
18
- should "send object id to target" do
19
- post = @post_class.new(:name => 'mongomapper')
20
- comment = @comment_class.new(:name => 'Foo!', :post => post)
21
- comment.save
22
-
23
- comment.post.object_id.should == comment.post.target.object_id
24
- end
25
-
26
- should "have boolean presence method" do
27
- comment = @comment_class.new(:name => 'Foo!')
28
- comment.post?.should be_false
29
-
30
- comment.post = @post_class.new(:name => 'mongomapper')
31
- comment.post?.should be_true
32
- end
33
-
34
- should "be able to replace the association" do
35
- post = @post_class.new(:name => 'mongomapper')
36
- comment = @comment_class.new(:name => 'Foo!', :post => post)
37
- comment.save.should be_true
38
-
39
- comment = comment.reload
40
- comment.post.should == post
41
- comment.post.nil?.should be_false
42
- end
43
-
44
- should "unset the association" do
45
- post = @post_class.new(:name => 'mongomapper')
46
- comment = @comment_class.new(:name => 'Foo!', :post => post)
47
- comment.save.should be_true
48
-
49
- comment = comment.reload
50
- comment.post = nil
51
- comment.post.nil?.should be_true
52
- end
53
-
54
- should "return nil if id set but document not found" do
55
- id = BSON::ObjectID.new
56
- @comment_class.new(:name => 'Foo', :post_id => id).post.nil?.should be_true
57
- end
58
-
59
- context ":dependent" do
60
- setup do
61
- # FIXME: make use of already defined models
62
- class ::Property
63
- include MongoMapper::Document
64
- end
65
- Property.collection.remove
66
-
67
- class ::Thing
68
- include MongoMapper::Document
69
- key :name, String
70
- end
71
- Thing.collection.remove
72
- end
73
-
74
- teardown do
75
- Object.send :remove_const, 'Property' if defined?(::Property)
76
- Object.send :remove_const, 'Thing' if defined?(::Thing)
77
- end
78
-
79
- context "=> destroy" do
80
- setup do
81
- Property.key :thing_id, ObjectId
82
- Property.belongs_to :thing, :dependent => :destroy
83
- Thing.many :properties
84
-
85
- @thing = Thing.create(:name => "Tree")
86
- @property1 = Property.create
87
- @property2 = Property.create
88
- @property3 = Property.create
89
- @thing.properties << @property1
90
- @thing.properties << @property2
91
- @thing.properties << @property3
92
- end
93
-
94
- should "not execute on a belongs_to association" do
95
- Thing.count.should == 1
96
- @property1.destroy
97
- Thing.count.should == 1
98
- end
99
- end
100
- end
101
- end
@@ -1,325 +0,0 @@
1
- require 'test_helper'
2
-
3
- class InArrayProxyTest < Test::Unit::TestCase
4
- context "description" do
5
- setup do
6
- class ::List
7
- include MongoMapper::Document
8
- key :name, String, :required => true
9
- end
10
-
11
- class ::User
12
- include MongoMapper::Document
13
- key :name, String, :required => true
14
- key :list_ids, Array
15
- many :lists, :in => :list_ids
16
- end
17
- User.collection.remove
18
- List.collection.remove
19
- end
20
-
21
- teardown do
22
- Object.send :remove_const, 'List' if defined?(::List)
23
- Object.send :remove_const, 'User' if defined?(::User)
24
- end
25
-
26
- should "default reader to empty array" do
27
- User.new.lists.should == []
28
- end
29
-
30
- should "allow adding to association like it was an array" do
31
- user = User.new(:name => 'John')
32
- user.lists << List.new(:name => 'Foo1!')
33
- user.lists.push List.new(:name => 'Foo2!')
34
- user.lists.concat List.new(:name => 'Foo3!')
35
- user.lists.size.should == 3
36
- end
37
-
38
- should "ignore adding duplicate ids" do
39
- user = User.create(:name => 'John')
40
- list = List.create(:name => 'Foo')
41
- user.lists << list
42
- user.lists << list
43
- user.lists << list
44
-
45
- user.list_ids.should == [list.id]
46
- user.lists.count.should == 1
47
- end
48
-
49
- should "be able to replace the association" do
50
- user = User.new(:name => 'John')
51
- list = List.new(:name => 'Foo')
52
- user.lists = [list]
53
- user.save.should be_true
54
-
55
- user.reload
56
- user.list_ids.should == [list.id]
57
- user.lists.size.should == 1
58
- user.lists[0].name.should == 'Foo'
59
- end
60
-
61
- context "create" do
62
- setup do
63
- @user = User.create(:name => 'John')
64
- @list = @user.lists.create(:name => 'Foo!')
65
- end
66
-
67
- should "add id to key" do
68
- @user.list_ids.should include(@list.id)
69
- end
70
-
71
- should "persist id addition to key in database" do
72
- @user.reload
73
- @user.list_ids.should include(@list.id)
74
- end
75
-
76
- should "add doc to association" do
77
- @user.lists.should include(@list)
78
- end
79
-
80
- should "save doc" do
81
- @list.should_not be_new
82
- end
83
-
84
- should "reset cache" do
85
- @user.lists.size.should == 1
86
- @user.lists.create(:name => 'Moo!')
87
- @user.lists.size.should == 2
88
- end
89
- end
90
-
91
- context "create!" do
92
- setup do
93
- @user = User.create(:name => 'John')
94
- @list = @user.lists.create!(:name => 'Foo!')
95
- end
96
-
97
- should "add id to key" do
98
- @user.list_ids.should include(@list.id)
99
- end
100
-
101
- should "persist id addition to key in database" do
102
- @user.reload
103
- @user.list_ids.should include(@list.id)
104
- end
105
-
106
- should "add doc to association" do
107
- @user.lists.should include(@list)
108
- end
109
-
110
- should "save doc" do
111
- @list.should_not be_new
112
- end
113
-
114
- should "raise exception if invalid" do
115
- assert_raises(MongoMapper::DocumentNotValid) do
116
- @user.lists.create!
117
- end
118
- end
119
-
120
- should "reset cache" do
121
- @user.lists.size.should == 1
122
- @user.lists.create!(:name => 'Moo!')
123
- @user.lists.size.should == 2
124
- end
125
- end
126
-
127
- context "Finding scoped to association" do
128
- setup do
129
- @user = User.create(:name => 'John')
130
- @user2 = User.create(:name => 'Brandon')
131
- @list1 = @user.lists.create!(:name => 'Foo 1', :position => 1)
132
- @list2 = @user.lists.create!(:name => 'Foo 2', :position => 2)
133
- @list3 = @user2.lists.create!(:name => 'Foo 3', :position => 1)
134
- end
135
-
136
- context "all" do
137
- should "work" do
138
- @user.lists.find(:all, :order => :position.asc).should == [@list1, @list2]
139
- @user.lists.all(:order => :position.asc).should == [@list1, @list2]
140
- end
141
-
142
- should "work with conditions" do
143
- @user.lists.find(:all, :name => 'Foo 1').should == [@list1]
144
- @user.lists.all(:name => 'Foo 1').should == [@list1]
145
- end
146
- end
147
-
148
- context "first" do
149
- should "work" do
150
- @user.lists.find(:first, :order => 'position').should == @list1
151
- @user.lists.first(:order => 'position').should == @list1
152
- end
153
-
154
- should "work with conditions" do
155
- @user.lists.find(:first, :position => 2).should == @list2
156
- @user.lists.first(:position => 2).should == @list2
157
- end
158
- end
159
-
160
- context "last" do
161
- should "work" do
162
- @user.lists.find(:last, :order => 'position').should == @list2
163
- @user.lists.last(:order => 'position').should == @list2
164
- end
165
-
166
- should "work with conditions" do
167
- @user.lists.find(:last, :position => 2, :order => 'position').should == @list2
168
- @user.lists.last(:position => 2, :order => 'position').should == @list2
169
- end
170
- end
171
-
172
- context "with one id" do
173
- should "work for id in association" do
174
- @user.lists.find(@list1.id).should == @list1
175
- end
176
-
177
- should "work with string ids" do
178
- @user.lists.find(@list1.id.to_s).should == @list1
179
- end
180
-
181
- should "not work for id not in association" do
182
- @user.lists.find(@list3.id).should be_nil
183
- end
184
-
185
- should "raise error when using ! and not found" do
186
- assert_raises MongoMapper::DocumentNotFound do
187
- @user.lists.find!(@list3.id)
188
- end
189
- end
190
- end
191
-
192
- context "with multiple ids" do
193
- should "work for ids in association" do
194
- @user.lists.find(@list1.id, @list2.id).should == [@list1, @list2]
195
- end
196
-
197
- should "not work for ids not in association" do
198
- @user.lists.find(@list1.id, @list2.id, @list3.id).should == [@list1, @list2]
199
- end
200
- end
201
-
202
- context "with #paginate" do
203
- setup do
204
- @lists = @user.lists.paginate(:per_page => 1, :page => 1, :order => 'position')
205
- end
206
-
207
- should "return total pages" do
208
- @lists.total_pages.should == 2
209
- end
210
-
211
- should "return total entries" do
212
- @lists.total_entries.should == 2
213
- end
214
-
215
- should "return the subject" do
216
- @lists.collect(&:name).should == ['Foo 1']
217
- end
218
- end
219
-
220
- context "dynamic finders" do
221
- should "work with single key" do
222
- @user.lists.find_by_name('Foo 1').should == @list1
223
- @user.lists.find_by_name!('Foo 1').should == @list1
224
- @user.lists.find_by_name('Foo 3').should be_nil
225
- end
226
-
227
- should "work with multiple keys" do
228
- @user.lists.find_by_name_and_position('Foo 1', 1).should == @list1
229
- @user.lists.find_by_name_and_position!('Foo 1', 1).should == @list1
230
- @user.lists.find_by_name_and_position('Foo 3', 1).should be_nil
231
- end
232
-
233
- should "raise error when using ! and not found" do
234
- assert_raises(MongoMapper::DocumentNotFound) do
235
- @user.lists.find_by_name!('Foo 3')
236
- end
237
- end
238
-
239
- context "find_or_create_by" do
240
- should "not create document if found" do
241
- lambda {
242
- list = @user.lists.find_or_create_by_name('Foo 1')
243
- list.should == @list1
244
- }.should_not change { List.count }
245
- end
246
-
247
- should "create document if not found" do
248
- lambda {
249
- list = @user.lists.find_or_create_by_name('Home')
250
- @user.lists.should include(list)
251
- }.should change { List.count }
252
- end
253
- end
254
- end
255
- end
256
-
257
- context "count" do
258
- setup do
259
- @user = User.create(:name => 'John')
260
- @user2 = User.create(:name => 'Brandon')
261
- @list1 = @user.lists.create!(:name => 'Foo 1')
262
- @list2 = @user.lists.create!(:name => 'Foo 2')
263
- @list3 = @user2.lists.create!(:name => 'Foo 3')
264
- end
265
-
266
- should "return number of ids" do
267
- @user.lists.count.should == 2
268
- @user2.lists.count.should == 1
269
- end
270
-
271
- should "return correct count when given criteria" do
272
- @user.lists.count(:name => 'Foo 1').should == 1
273
- @user2.lists.count(:name => 'Foo 1').should == 0
274
- end
275
- end
276
-
277
- context "Removing documents" do
278
- setup do
279
- @user = User.create(:name => 'John')
280
- @user2 = User.create(:name => 'Brandon')
281
- @list1 = @user.lists.create!(:name => 'Foo 1', :position => 1)
282
- @list2 = @user.lists.create!(:name => 'Foo 2', :position => 2)
283
- @list3 = @user2.lists.create!(:name => 'Foo 3', :position => 1)
284
- end
285
-
286
- context "destroy_all" do
287
- should "work" do
288
- @user.lists.count.should == 2
289
- @user.lists.destroy_all
290
- @user.lists.count.should == 0
291
- end
292
-
293
- should "work with conditions" do
294
- @user.lists.count.should == 2
295
- @user.lists.destroy_all(:name => 'Foo 1')
296
- @user.lists.count.should == 1
297
- end
298
- end
299
-
300
- context "delete_all" do
301
- should "work" do
302
- @user.lists.count.should == 2
303
- @user.lists.delete_all
304
- @user.lists.count.should == 0
305
- end
306
-
307
- should "work with conditions" do
308
- @user.lists.count.should == 2
309
- @user.lists.delete_all(:name => 'Foo 1')
310
- @user.lists.count.should == 1
311
- end
312
- end
313
-
314
- should "work with nullify" do
315
- @user.lists.count.should == 2
316
-
317
- lambda {
318
- @user.lists.nullify
319
- }.should_not change { List.count }
320
-
321
- @user.lists.count.should == 0
322
- end
323
- end
324
- end
325
- end