tpitale-mongo_mapper 0.6.9 → 0.6.10

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 (57) hide show
  1. data/README.rdoc +2 -17
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/lib/mongo_mapper/associations/base.rb +19 -10
  5. data/lib/mongo_mapper/associations/in_array_proxy.rb +137 -0
  6. data/lib/mongo_mapper/associations/one_proxy.rb +64 -0
  7. data/lib/mongo_mapper/associations/proxy.rb +7 -4
  8. data/lib/mongo_mapper/associations.rb +11 -3
  9. data/lib/mongo_mapper/callbacks.rb +30 -78
  10. data/lib/mongo_mapper/dirty.rb +5 -24
  11. data/lib/mongo_mapper/document.rb +117 -144
  12. data/lib/mongo_mapper/embedded_document.rb +7 -11
  13. data/lib/mongo_mapper/finder_options.rb +42 -30
  14. data/lib/mongo_mapper/mongo_mapper.rb +125 -0
  15. data/lib/mongo_mapper/pagination.rb +12 -1
  16. data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +1 -0
  17. data/lib/mongo_mapper/serialization.rb +2 -2
  18. data/lib/mongo_mapper/serializers/json_serializer.rb +2 -46
  19. data/lib/mongo_mapper/support.rb +5 -2
  20. data/lib/mongo_mapper/validations.rb +1 -3
  21. data/lib/mongo_mapper.rb +8 -2
  22. data/mongo_mapper.gemspec +14 -8
  23. data/specs.watchr +3 -5
  24. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +8 -0
  25. data/test/functional/associations/test_belongs_to_proxy.rb +54 -9
  26. data/test/functional/associations/test_in_array_proxy.rb +309 -0
  27. data/test/functional/associations/test_many_documents_proxy.rb +103 -53
  28. data/test/functional/associations/test_many_embedded_proxy.rb +4 -14
  29. data/test/functional/associations/test_many_polymorphic_proxy.rb +4 -3
  30. data/test/functional/associations/test_one_proxy.rb +149 -0
  31. data/test/functional/test_binary.rb +13 -4
  32. data/test/functional/test_callbacks.rb +1 -5
  33. data/test/functional/test_dirty.rb +1 -4
  34. data/test/functional/test_document.rb +576 -640
  35. data/test/functional/test_embedded_document.rb +7 -20
  36. data/test/functional/test_modifiers.rb +238 -0
  37. data/test/functional/test_pagination.rb +1 -3
  38. data/test/functional/test_string_id_compatibility.rb +3 -8
  39. data/test/functional/test_validations.rb +13 -75
  40. data/test/models.rb +1 -1
  41. data/test/support/timing.rb +1 -1
  42. data/test/test_helper.rb +28 -0
  43. data/test/unit/associations/test_base.rb +54 -13
  44. data/test/unit/associations/test_proxy.rb +12 -0
  45. data/test/unit/test_document.rb +36 -26
  46. data/test/unit/test_embedded_document.rb +14 -51
  47. data/test/unit/test_finder_options.rb +36 -7
  48. data/test/unit/test_key.rb +1 -4
  49. data/test/unit/test_pagination.rb +6 -0
  50. data/test/unit/test_rails_compatibility.rb +4 -1
  51. data/test/unit/test_serializations.rb +1 -2
  52. data/test/unit/test_support.rb +4 -0
  53. data/test/unit/test_time_zones.rb +1 -2
  54. data/test/unit/test_validations.rb +3 -14
  55. metadata +12 -6
  56. data/lib/mongo_mapper/observing.rb +0 -50
  57. data/test/unit/test_observing.rb +0 -101
@@ -53,6 +53,7 @@ class ProxyTest < Test::Unit::TestCase
53
53
  context "blank?" do
54
54
  should "be true if blank" do
55
55
  @blank_proxy.blank?.should be_true
56
+ @nil_proxy.blank?.should be_true
56
57
  end
57
58
 
58
59
  should "be false if not blank" do
@@ -60,6 +61,17 @@ class ProxyTest < Test::Unit::TestCase
60
61
  end
61
62
  end
62
63
 
64
+ context "present?" do
65
+ should "be true if present" do
66
+ @proxy.present?.should be_true
67
+ end
68
+
69
+ should "be false if not present" do
70
+ @blank_proxy.present?.should be_false
71
+ @nil_proxy.present?.should be_false
72
+ end
73
+ end
74
+
63
75
  should "delegate respond_to? to target" do
64
76
  @proxy.respond_to?(:each).should be_true
65
77
  @proxy.respond_to?(:size).should be_true
@@ -4,11 +4,7 @@ require 'models'
4
4
  class DocumentTest < Test::Unit::TestCase
5
5
  context "The Document Class" do
6
6
  setup do
7
- @document = Class.new do
8
- include MongoMapper::Document
9
- set_collection_name 'test'
10
- end
11
- @document.collection.remove
7
+ @document = Doc()
12
8
  end
13
9
 
14
10
  should "have logger method" do
@@ -40,10 +36,7 @@ class DocumentTest < Test::Unit::TestCase
40
36
  @document.database_name.should == 'test2'
41
37
  @document.database.name.should == 'test2'
42
38
 
43
- another_document = Class.new do
44
- include MongoMapper::Document
45
- set_collection_name 'test'
46
- end
39
+ another_document = Doc()
47
40
  another_document.database.should == MongoMapper.database
48
41
  end
49
42
 
@@ -72,6 +65,34 @@ class DocumentTest < Test::Unit::TestCase
72
65
  @document.collection.should be_instance_of(Mongo::Collection)
73
66
  @document.collection.name.should == 'foobar'
74
67
  end
68
+
69
+ should 'allow extensions to Document to be appended' do
70
+ module Extension; def test_this_extension; end end
71
+ MongoMapper::Document.append_extensions(Extension)
72
+ article = Doc()
73
+ article.should respond_to(:test_this_extension)
74
+ end
75
+
76
+ should 'add appended extensions to classes that include Document before they are added' do
77
+ module Extension; def test_this_extension; end end
78
+ article = Doc()
79
+ MongoMapper::Document.append_extensions(Extension)
80
+ article.should respond_to(:test_this_extension)
81
+ end
82
+
83
+ should 'allow inclusions to Document to be appended' do
84
+ module Inclusion; def test_this_inclusion; end end
85
+ MongoMapper::Document.append_inclusions(Inclusion)
86
+ article = Doc()
87
+ article.new.should respond_to(:test_this_inclusion)
88
+ end
89
+
90
+ should 'add appended inclusions to classes that include Document before they are added' do
91
+ module Inclusion; def test_this_inclusion; end end
92
+ article = Doc()
93
+ MongoMapper::Document.append_inclusions(Inclusion)
94
+ article.new.should respond_to(:test_this_inclusion)
95
+ end
75
96
  end # Document class
76
97
 
77
98
  context "Documents that inherit from other documents" do
@@ -96,14 +117,10 @@ class DocumentTest < Test::Unit::TestCase
96
117
 
97
118
  context "An instance of a document" do
98
119
  setup do
99
- @document = Class.new do
100
- include MongoMapper::Document
101
- set_collection_name 'test'
102
-
120
+ @document = Doc do
103
121
  key :name, String
104
122
  key :age, Integer
105
123
  end
106
- @document.collection.remove
107
124
  end
108
125
 
109
126
  should "have access to logger" do
@@ -137,13 +154,9 @@ class DocumentTest < Test::Unit::TestCase
137
154
  end
138
155
 
139
156
  should "set self to the root document on embedded documents" do
140
- klass = Class.new do
141
- include MongoMapper::Document
142
- end
157
+ klass = Doc()
158
+ pets = EDoc()
143
159
 
144
- pets = Class.new do
145
- include MongoMapper::EmbeddedDocument
146
- end
147
160
  klass.many :pets, :class => pets
148
161
 
149
162
  doc = klass.new(:pets => [{}])
@@ -183,6 +196,7 @@ class DocumentTest < Test::Unit::TestCase
183
196
  setup do
184
197
  @oid = Mongo::ObjectID.new
185
198
  end
199
+
186
200
  should "be equal if id and class are the same" do
187
201
  (@document.new('_id' => @oid) == @document.new('_id' => @oid)).should be(true)
188
202
  end
@@ -192,12 +206,8 @@ class DocumentTest < Test::Unit::TestCase
192
206
  end
193
207
 
194
208
  should "not be equal if id same but class different" do
195
- @another_document = Class.new do
196
- include MongoMapper::Document
197
- set_collection_name 'test'
198
- end
199
-
200
- (@document.new('_id' => @oid) == @another_document.new('_id' => @oid)).should be(false)
209
+ another_document = Doc()
210
+ (@document.new('_id' => @oid) == another_document.new('_id' => @oid)).should be(false)
201
211
  end
202
212
  end
203
213
  end # instance of a document
@@ -35,9 +35,7 @@ end
35
35
  class EmbeddedDocumentTest < Test::Unit::TestCase
36
36
  context "Including MongoMapper::EmbeddedDocument in a class" do
37
37
  setup do
38
- @klass = Class.new do
39
- include MongoMapper::EmbeddedDocument
40
- end
38
+ @klass = EDoc()
41
39
  end
42
40
 
43
41
  should "give class access to logger" do
@@ -89,29 +87,16 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
89
87
  end
90
88
  end
91
89
 
92
- context "looking up type constants" do
93
- should "not raise an error" do
94
- klass = Class.new do
95
- include MongoMapper::EmbeddedDocument
96
- key :file, Binary
97
- end
98
- end
99
- end
100
-
101
90
  context "parent_model" do
102
91
  should "be nil if none of parents ancestors include EmbeddedDocument" do
103
92
  parent = Class.new
104
- document = Class.new(parent) do
105
- include MongoMapper::EmbeddedDocument
106
- end
93
+ document = Class.new(parent) { include MongoMapper::EmbeddedDocument }
107
94
  document.parent_model.should be_nil
108
95
  end
109
96
 
110
97
  should "work when other modules have been included" do
111
98
  grandparent = Class.new
112
- parent = Class.new grandparent do
113
- include MongoMapper::EmbeddedDocument
114
- end
99
+ parent = Class.new(grandparent) { include MongoMapper::EmbeddedDocument }
115
100
 
116
101
  example_module = Module.new
117
102
  document = Class.new(parent) do
@@ -130,9 +115,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
130
115
 
131
116
  context "defining a key" do
132
117
  setup do
133
- @document = Class.new do
134
- include MongoMapper::EmbeddedDocument
135
- end
118
+ @document = EDoc()
136
119
  end
137
120
 
138
121
  should "work with name" do
@@ -226,8 +209,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
226
209
 
227
210
  context "#inspect" do
228
211
  setup do
229
- @document = Class.new do
230
- include MongoMapper::Document
212
+ @document = Doc do
231
213
  key :animals
232
214
  end
233
215
  end
@@ -252,9 +234,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
252
234
 
253
235
  context "Applying default values for keys" do
254
236
  setup do
255
- @document = Class.new do
256
- include MongoMapper::EmbeddedDocument
257
-
237
+ @document = EDoc do
258
238
  key :name, String, :default => 'foo'
259
239
  key :age, Integer, :default => 20
260
240
  key :net_worth, Float, :default => 100.00
@@ -299,9 +279,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
299
279
 
300
280
  context "An instance of an embedded document" do
301
281
  setup do
302
- @document = Class.new do
303
- include MongoMapper::EmbeddedDocument
304
-
282
+ @document = EDoc do
305
283
  key :name, String
306
284
  key :age, Integer
307
285
  end
@@ -398,8 +376,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
398
376
 
399
377
  context "initialized when _type key present" do
400
378
  setup do
401
- ::FooBar = Class.new do
402
- include MongoMapper::EmbeddedDocument
379
+ ::FooBar = EDoc do
403
380
  key :_type, String
404
381
  end
405
382
  end
@@ -580,18 +557,8 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
580
557
  doc.instance_variable_get("@foo").should == []
581
558
  end
582
559
 
583
- should "not set instance variable if frozen" do
584
- @document.key :foo, Array
585
- doc = @document.new
586
- doc.instance_variable_get("@foo").should be_nil
587
- doc.freeze
588
- doc.foo
589
- doc.instance_variable_get("@foo").should be_nil
590
- end
591
-
592
560
  should "be overrideable by modules" do
593
- @document = Class.new do
594
- include MongoMapper::Document
561
+ @document = Doc do
595
562
  key :other_child, String
596
563
  end
597
564
 
@@ -665,8 +632,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
665
632
  end
666
633
 
667
634
  should "be overrideable by modules" do
668
- @document = Class.new do
669
- include MongoMapper::Document
635
+ @document = Doc do
670
636
  key :other_child, String
671
637
  end
672
638
 
@@ -699,19 +665,16 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
699
665
  @oid = Mongo::ObjectID.new
700
666
  end
701
667
  should "be equal if id and class are the same" do
702
- (@document.new('_id' => @oid) == @document.new('_id' => @oid)).should be(true)
668
+ (@document.new('_id' => @oid) == @document.new('_id' => @oid)).should be_true
703
669
  end
704
670
 
705
671
  should "not be equal if class same but id different" do
706
- (@document.new('_id' => @oid) == @document.new('_id' => Mongo::ObjectID.new)).should be(false)
672
+ (@document.new('_id' => @oid) == @document.new('_id' => Mongo::ObjectID.new)).should be_false
707
673
  end
708
674
 
709
675
  should "not be equal if id same but class different" do
710
- @another_document = Class.new do
711
- include MongoMapper::Document
712
- end
713
-
714
- (@document.new('_id' => @oid) == @another_document.new('_id' => @oid)).should be(false)
676
+ another_document = Doc()
677
+ (@document.new('_id' => @oid) == another_document.new('_id' => @oid)).should be_false
715
678
  end
716
679
  end
717
680
  end # instance of a embedded document
@@ -30,6 +30,13 @@ class FinderOptionsTest < Test::Unit::TestCase
30
30
  }
31
31
  end
32
32
 
33
+ should "automatically add _type to query if model is single collection inherited" do
34
+ FinderOptions.new(Enter, :foo => 'bar').criteria.should == {
35
+ :foo => 'bar',
36
+ :_type => 'Enter'
37
+ }
38
+ end
39
+
33
40
  %w{gt lt gte lte ne in nin mod size where exists}.each do |operator|
34
41
  should "convert #{operator} conditions" do
35
42
  FinderOptions.new(Room, :age.send(operator) => 21).criteria.should == {
@@ -38,13 +45,6 @@ class FinderOptionsTest < Test::Unit::TestCase
38
45
  end
39
46
  end
40
47
 
41
- should "automatically add _type to query if model is single collection inherited" do
42
- FinderOptions.new(Enter, :foo => 'bar').criteria.should == {
43
- :foo => 'bar',
44
- :_type => 'Enter'
45
- }
46
- end
47
-
48
48
  should "work with simple criteria" do
49
49
  FinderOptions.new(Room, :foo => 'bar').criteria.should == {
50
50
  :foo => 'bar'
@@ -61,6 +61,13 @@ class FinderOptionsTest < Test::Unit::TestCase
61
61
  FinderOptions.new(Room, :id => id).criteria.should == {:_id => id}
62
62
  end
63
63
 
64
+ should "convert id with symbol operator to _id with modifier" do
65
+ id = Mongo::ObjectID.new
66
+ FinderOptions.new(Room, :id.ne => id).criteria.should == {
67
+ :_id => {'$ne' => id}
68
+ }
69
+ end
70
+
64
71
  should "make sure that _id's are object ids" do
65
72
  id = Mongo::ObjectID.new
66
73
  FinderOptions.new(Room, :_id => id.to_s).criteria.should == {:_id => id}
@@ -81,6 +88,19 @@ class FinderOptionsTest < Test::Unit::TestCase
81
88
  FinderOptions.new(Message, :room_id => id).criteria.should == {:room_id => id}
82
89
  end
83
90
 
91
+ should "convert times to utc if they aren't already" do
92
+ time = Time.now.in_time_zone('Indiana (East)')
93
+ criteria = FinderOptions.new(Room, :created_at => time).criteria
94
+ criteria[:created_at].utc?.should be_true
95
+ end
96
+
97
+ should "not funk with times already in utc" do
98
+ time = Time.now.utc
99
+ criteria = FinderOptions.new(Room, :created_at => time).criteria
100
+ criteria[:created_at].utc?.should be_true
101
+ criteria[:created_at].should == time
102
+ end
103
+
84
104
  should "use $in for arrays" do
85
105
  FinderOptions.new(Room, :foo => [1,2,3]).criteria.should == {
86
106
  :foo => {'$in' => [1,2,3]}
@@ -121,6 +141,15 @@ class FinderOptionsTest < Test::Unit::TestCase
121
141
  FinderOptions.new(Room, :order => 'foo DESC').options[:sort].should == sort
122
142
  end
123
143
 
144
+ should "convert order operators to mongo sort" do
145
+ FinderOptions.new(Room, :order => :foo.asc).options[:sort].should == [['foo', 1]]
146
+ FinderOptions.new(Room, :order => :foo.desc).options[:sort].should == [['foo', -1]]
147
+ end
148
+
149
+ should "convert array of order operators to mongo sort" do
150
+ FinderOptions.new(Room, :order => [:foo.asc, :bar.desc]).options[:sort].should == [['foo', 1], ['bar', -1]]
151
+ end
152
+
124
153
  should "convert field without direction to ascending" do
125
154
  sort = [['foo', 1]]
126
155
  FinderOptions.new(Room, :order => 'foo').options[:sort].should == sort
@@ -82,10 +82,7 @@ class KeyTest < Test::Unit::TestCase
82
82
  end
83
83
 
84
84
  should "know if it is a embedded_document" do
85
- klass = Class.new do
86
- include MongoMapper::EmbeddedDocument
87
- end
88
- Key.new(:name, klass).embeddable?.should be_true
85
+ Key.new(:name, EDoc()).embeddable?.should be_true
89
86
  end
90
87
 
91
88
  should "know if it is not a embedded_document" do
@@ -62,6 +62,12 @@ class PaginationTest < Test::Unit::TestCase
62
62
  should "alias offset to skip" do
63
63
  PaginationProxy.new(25, 2, 10).offset.should == 10
64
64
  end
65
+
66
+ should "return true for === Array" do
67
+ collection = PaginationProxy.new(25, 2, 10)
68
+ collection.subject = [1, 2]
69
+ collection.should === Array
70
+ end
65
71
 
66
72
  context "previous_page" do
67
73
  should "be nil if current page 1" do
@@ -22,7 +22,10 @@ class TestRailsCompatibility < Test::Unit::TestCase
22
22
  context "EmbeddedDocument" do
23
23
  should "alias many to has_many" do
24
24
  FirstItem.should respond_to(:has_many)
25
- FirstItem.method(:has_many).should == FirstItem.method(:many)
25
+ end
26
+
27
+ should "alias one to has_one" do
28
+ FirstItem.should respond_to(:has_one)
26
29
  end
27
30
 
28
31
  should "have column names" do
@@ -2,8 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class SerializationTest < Test::Unit::TestCase
4
4
  def setup
5
- @document = Class.new do
6
- include MongoMapper::EmbeddedDocument
5
+ @document = EDoc do
7
6
  key :name, String
8
7
  key :age, Integer
9
8
  key :awesome, Boolean
@@ -167,6 +167,10 @@ class SupportTest < Test::Unit::TestCase
167
167
  ObjectId.to_mongo(nil).should be_nil
168
168
  end
169
169
 
170
+ should "return nil if blank string" do
171
+ ObjectId.to_mongo('').should be_nil
172
+ end
173
+
170
174
  should "return value if object id" do
171
175
  id = Mongo::ObjectID.new
172
176
  ObjectId.to_mongo(id).should be(id)
@@ -3,8 +3,7 @@ require 'test_helper'
3
3
  class TimeZonesTest < Test::Unit::TestCase
4
4
  context "An instance of an embedded document" do
5
5
  setup do
6
- @document = Class.new do
7
- include MongoMapper::EmbeddedDocument
6
+ @document = EDoc do
8
7
  key :name, String
9
8
  key :created_at, Time
10
9
  end
@@ -2,14 +2,9 @@ require 'test_helper'
2
2
 
3
3
  class ValidationsTest < Test::Unit::TestCase
4
4
  context "Validations" do
5
-
6
5
  context "on a Document" do
7
-
8
6
  setup do
9
- @document = Class.new do
10
- include MongoMapper::Document
11
- set_collection_name 'test'
12
- end
7
+ @document = Doc()
13
8
  end
14
9
 
15
10
  context "Validating acceptance of" do
@@ -240,11 +235,8 @@ class ValidationsTest < Test::Unit::TestCase
240
235
  end # End on a Document
241
236
 
242
237
  context "On an EmbeddedDocument" do
243
-
244
238
  setup do
245
- @embedded_doc = Class.new do
246
- include MongoMapper::EmbeddedDocument
247
- end
239
+ @embedded_doc = EDoc()
248
240
  end
249
241
 
250
242
  context "Validating acceptance of" do
@@ -478,10 +470,7 @@ class ValidationsTest < Test::Unit::TestCase
478
470
 
479
471
  context "Adding validation errors" do
480
472
  setup do
481
- @document = Class.new do
482
- include MongoMapper::Document
483
- set_collection_name 'test'
484
-
473
+ @document = Doc do
485
474
  key :action, String
486
475
  def action_present
487
476
  errors.add(:action, 'is invalid') if action.blank?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tpitale-mongo_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.9
4
+ version: 0.6.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-01 00:00:00 -05:00
12
+ date: 2010-01-04 00:00:00 -05:00
13
13
  default_executable: mmconsole
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - "="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.18.1
33
+ version: 0.18.2
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: jnunemaker-validatable
@@ -104,11 +104,13 @@ files:
104
104
  - lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb
105
105
  - lib/mongo_mapper/associations/belongs_to_proxy.rb
106
106
  - lib/mongo_mapper/associations/collection.rb
107
+ - lib/mongo_mapper/associations/in_array_proxy.rb
107
108
  - lib/mongo_mapper/associations/many_documents_as_proxy.rb
108
109
  - lib/mongo_mapper/associations/many_documents_proxy.rb
109
110
  - lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
110
111
  - lib/mongo_mapper/associations/many_embedded_proxy.rb
111
112
  - lib/mongo_mapper/associations/many_polymorphic_proxy.rb
113
+ - lib/mongo_mapper/associations/one_proxy.rb
112
114
  - lib/mongo_mapper/associations/proxy.rb
113
115
  - lib/mongo_mapper/callbacks.rb
114
116
  - lib/mongo_mapper/dirty.rb
@@ -117,7 +119,7 @@ files:
117
119
  - lib/mongo_mapper/embedded_document.rb
118
120
  - lib/mongo_mapper/finder_options.rb
119
121
  - lib/mongo_mapper/key.rb
120
- - lib/mongo_mapper/observing.rb
122
+ - lib/mongo_mapper/mongo_mapper.rb
121
123
  - lib/mongo_mapper/pagination.rb
122
124
  - lib/mongo_mapper/rails_compatibility/document.rb
123
125
  - lib/mongo_mapper/rails_compatibility/embedded_document.rb
@@ -130,11 +132,13 @@ files:
130
132
  - test/NOTE_ON_TESTING
131
133
  - test/functional/associations/test_belongs_to_polymorphic_proxy.rb
132
134
  - test/functional/associations/test_belongs_to_proxy.rb
135
+ - test/functional/associations/test_in_array_proxy.rb
133
136
  - test/functional/associations/test_many_documents_as_proxy.rb
134
137
  - test/functional/associations/test_many_documents_proxy.rb
135
138
  - test/functional/associations/test_many_embedded_polymorphic_proxy.rb
136
139
  - test/functional/associations/test_many_embedded_proxy.rb
137
140
  - test/functional/associations/test_many_polymorphic_proxy.rb
141
+ - test/functional/associations/test_one_proxy.rb
138
142
  - test/functional/test_associations.rb
139
143
  - test/functional/test_binary.rb
140
144
  - test/functional/test_callbacks.rb
@@ -142,6 +146,7 @@ files:
142
146
  - test/functional/test_document.rb
143
147
  - test/functional/test_embedded_document.rb
144
148
  - test/functional/test_logger.rb
149
+ - test/functional/test_modifiers.rb
145
150
  - test/functional/test_pagination.rb
146
151
  - test/functional/test_rails_compatibility.rb
147
152
  - test/functional/test_string_id_compatibility.rb
@@ -159,7 +164,6 @@ files:
159
164
  - test/unit/test_finder_options.rb
160
165
  - test/unit/test_key.rb
161
166
  - test/unit/test_mongo_mapper.rb
162
- - test/unit/test_observing.rb
163
167
  - test/unit/test_pagination.rb
164
168
  - test/unit/test_rails_compatibility.rb
165
169
  - test/unit/test_serializations.rb
@@ -197,11 +201,13 @@ summary: Awesome gem for modeling your domain and storing it in mongo
197
201
  test_files:
198
202
  - test/functional/associations/test_belongs_to_polymorphic_proxy.rb
199
203
  - test/functional/associations/test_belongs_to_proxy.rb
204
+ - test/functional/associations/test_in_array_proxy.rb
200
205
  - test/functional/associations/test_many_documents_as_proxy.rb
201
206
  - test/functional/associations/test_many_documents_proxy.rb
202
207
  - test/functional/associations/test_many_embedded_polymorphic_proxy.rb
203
208
  - test/functional/associations/test_many_embedded_proxy.rb
204
209
  - test/functional/associations/test_many_polymorphic_proxy.rb
210
+ - test/functional/associations/test_one_proxy.rb
205
211
  - test/functional/test_associations.rb
206
212
  - test/functional/test_binary.rb
207
213
  - test/functional/test_callbacks.rb
@@ -209,6 +215,7 @@ test_files:
209
215
  - test/functional/test_document.rb
210
216
  - test/functional/test_embedded_document.rb
211
217
  - test/functional/test_logger.rb
218
+ - test/functional/test_modifiers.rb
212
219
  - test/functional/test_pagination.rb
213
220
  - test/functional/test_rails_compatibility.rb
214
221
  - test/functional/test_string_id_compatibility.rb
@@ -226,7 +233,6 @@ test_files:
226
233
  - test/unit/test_finder_options.rb
227
234
  - test/unit/test_key.rb
228
235
  - test/unit/test_mongo_mapper.rb
229
- - test/unit/test_observing.rb
230
236
  - test/unit/test_pagination.rb
231
237
  - test/unit/test_rails_compatibility.rb
232
238
  - test/unit/test_serializations.rb
@@ -1,50 +0,0 @@
1
- require 'observer'
2
- require 'singleton'
3
- require 'set'
4
-
5
- module MongoMapper
6
- module Observing #:nodoc:
7
- def self.included(model)
8
- model.class_eval do
9
- extend Observable
10
- end
11
- end
12
- end
13
-
14
- class Observer
15
- include Singleton
16
-
17
- class << self
18
- def observe(*models)
19
- models.flatten!
20
- models.collect! { |model| model.is_a?(Symbol) ? model.to_s.camelize.constantize : model }
21
- define_method(:observed_classes) { Set.new(models) }
22
- end
23
-
24
- def observed_class
25
- if observed_class_name = name[/(.*)Observer/, 1]
26
- observed_class_name.constantize
27
- else
28
- nil
29
- end
30
- end
31
- end
32
-
33
- def initialize
34
- Set.new(observed_classes).each { |klass| add_observer! klass }
35
- end
36
-
37
- def update(observed_method, object) #:nodoc:
38
- send(observed_method, object) if respond_to?(observed_method)
39
- end
40
-
41
- protected
42
- def observed_classes
43
- Set.new([self.class.observed_class].compact.flatten)
44
- end
45
-
46
- def add_observer!(klass)
47
- klass.add_observer(self)
48
- end
49
- end
50
- end