ssherman-mongo_mapper 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +33 -0
  3. data/UPGRADES +7 -0
  4. data/bin/mmconsole +60 -0
  5. data/examples/attr_accessible.rb +22 -0
  6. data/examples/attr_protected.rb +22 -0
  7. data/examples/cache_key.rb +24 -0
  8. data/examples/custom_types.rb +24 -0
  9. data/examples/identity_map.rb +33 -0
  10. data/examples/identity_map/automatic.rb +8 -0
  11. data/examples/identity_map/middleware.rb +14 -0
  12. data/examples/keys.rb +40 -0
  13. data/examples/modifiers/set.rb +25 -0
  14. data/examples/plugins.rb +41 -0
  15. data/examples/querying.rb +35 -0
  16. data/examples/safe.rb +43 -0
  17. data/examples/scopes.rb +52 -0
  18. data/examples/validating/embedded_docs.rb +29 -0
  19. data/lib/mongo_mapper.rb +79 -0
  20. data/lib/mongo_mapper/connection.rb +83 -0
  21. data/lib/mongo_mapper/document.rb +41 -0
  22. data/lib/mongo_mapper/embedded_document.rb +31 -0
  23. data/lib/mongo_mapper/exceptions.rb +27 -0
  24. data/lib/mongo_mapper/extensions/array.rb +19 -0
  25. data/lib/mongo_mapper/extensions/binary.rb +22 -0
  26. data/lib/mongo_mapper/extensions/boolean.rb +44 -0
  27. data/lib/mongo_mapper/extensions/date.rb +25 -0
  28. data/lib/mongo_mapper/extensions/float.rb +14 -0
  29. data/lib/mongo_mapper/extensions/hash.rb +14 -0
  30. data/lib/mongo_mapper/extensions/integer.rb +19 -0
  31. data/lib/mongo_mapper/extensions/kernel.rb +9 -0
  32. data/lib/mongo_mapper/extensions/nil_class.rb +18 -0
  33. data/lib/mongo_mapper/extensions/object.rb +27 -0
  34. data/lib/mongo_mapper/extensions/object_id.rb +30 -0
  35. data/lib/mongo_mapper/extensions/set.rb +20 -0
  36. data/lib/mongo_mapper/extensions/string.rb +18 -0
  37. data/lib/mongo_mapper/extensions/time.rb +29 -0
  38. data/lib/mongo_mapper/plugins.rb +15 -0
  39. data/lib/mongo_mapper/plugins.rb~ +15 -0
  40. data/lib/mongo_mapper/plugins/accessible.rb +44 -0
  41. data/lib/mongo_mapper/plugins/associations.rb +97 -0
  42. data/lib/mongo_mapper/plugins/associations/base.rb +124 -0
  43. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +29 -0
  44. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +24 -0
  45. data/lib/mongo_mapper/plugins/associations/collection.rb +27 -0
  46. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +40 -0
  47. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +127 -0
  48. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +28 -0
  49. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +109 -0
  50. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +32 -0
  51. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +24 -0
  52. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +14 -0
  53. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +40 -0
  54. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +68 -0
  55. data/lib/mongo_mapper/plugins/associations/proxy.rb +139 -0
  56. data/lib/mongo_mapper/plugins/caching.rb +21 -0
  57. data/lib/mongo_mapper/plugins/callbacks.rb +241 -0
  58. data/lib/mongo_mapper/plugins/clone.rb +22 -0
  59. data/lib/mongo_mapper/plugins/descendants.rb +17 -0
  60. data/lib/mongo_mapper/plugins/dirty.rb +124 -0
  61. data/lib/mongo_mapper/plugins/document.rb +41 -0
  62. data/lib/mongo_mapper/plugins/dynamic_querying.rb +43 -0
  63. data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +44 -0
  64. data/lib/mongo_mapper/plugins/embedded_document.rb +48 -0
  65. data/lib/mongo_mapper/plugins/equality.rb +17 -0
  66. data/lib/mongo_mapper/plugins/identity_map.rb +128 -0
  67. data/lib/mongo_mapper/plugins/indexes.rb +12 -0
  68. data/lib/mongo_mapper/plugins/inspect.rb +15 -0
  69. data/lib/mongo_mapper/plugins/keys.rb +313 -0
  70. data/lib/mongo_mapper/plugins/keys/key.rb +59 -0
  71. data/lib/mongo_mapper/plugins/logger.rb +18 -0
  72. data/lib/mongo_mapper/plugins/modifiers.rb +112 -0
  73. data/lib/mongo_mapper/plugins/pagination.rb +14 -0
  74. data/lib/mongo_mapper/plugins/persistence.rb +69 -0
  75. data/lib/mongo_mapper/plugins/protected.rb +53 -0
  76. data/lib/mongo_mapper/plugins/querying.rb +176 -0
  77. data/lib/mongo_mapper/plugins/querying/decorator.rb +46 -0
  78. data/lib/mongo_mapper/plugins/querying/plucky_methods.rb +15 -0
  79. data/lib/mongo_mapper/plugins/rails.rb +58 -0
  80. data/lib/mongo_mapper/plugins/safe.rb +28 -0
  81. data/lib/mongo_mapper/plugins/sci.rb +32 -0
  82. data/lib/mongo_mapper/plugins/scopes.rb +21 -0
  83. data/lib/mongo_mapper/plugins/serialization.rb +76 -0
  84. data/lib/mongo_mapper/plugins/timestamps.rb +22 -0
  85. data/lib/mongo_mapper/plugins/userstamps.rb +15 -0
  86. data/lib/mongo_mapper/plugins/validations.rb +50 -0
  87. data/lib/mongo_mapper/support/descendant_appends.rb +45 -0
  88. data/lib/mongo_mapper/version.rb +4 -0
  89. data/rails/init.rb +19 -0
  90. data/test/_NOTE_ON_TESTING +1 -0
  91. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +63 -0
  92. data/test/functional/associations/test_belongs_to_proxy.rb +93 -0
  93. data/test/functional/associations/test_in_array_proxy.rb +319 -0
  94. data/test/functional/associations/test_many_documents_as_proxy.rb +229 -0
  95. data/test/functional/associations/test_many_documents_proxy.rb +615 -0
  96. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +176 -0
  97. data/test/functional/associations/test_many_embedded_proxy.rb +256 -0
  98. data/test/functional/associations/test_many_polymorphic_proxy.rb +302 -0
  99. data/test/functional/associations/test_one_embedded_proxy.rb +81 -0
  100. data/test/functional/associations/test_one_proxy.rb +181 -0
  101. data/test/functional/test_accessible.rb +168 -0
  102. data/test/functional/test_associations.rb +44 -0
  103. data/test/functional/test_binary.rb +27 -0
  104. data/test/functional/test_caching.rb +76 -0
  105. data/test/functional/test_callbacks.rb +151 -0
  106. data/test/functional/test_dirty.rb +163 -0
  107. data/test/functional/test_document.rb +253 -0
  108. data/test/functional/test_dynamic_querying.rb +75 -0
  109. data/test/functional/test_embedded_document.rb +210 -0
  110. data/test/functional/test_identity_map.rb +514 -0
  111. data/test/functional/test_indexes.rb +42 -0
  112. data/test/functional/test_logger.rb +20 -0
  113. data/test/functional/test_modifiers.rb +416 -0
  114. data/test/functional/test_pagination.rb +91 -0
  115. data/test/functional/test_protected.rb +175 -0
  116. data/test/functional/test_querying.rb +873 -0
  117. data/test/functional/test_safe.rb +76 -0
  118. data/test/functional/test_sci.rb +230 -0
  119. data/test/functional/test_scopes.rb +171 -0
  120. data/test/functional/test_string_id_compatibility.rb +67 -0
  121. data/test/functional/test_timestamps.rb +62 -0
  122. data/test/functional/test_userstamps.rb +27 -0
  123. data/test/functional/test_validations.rb +342 -0
  124. data/test/models.rb +233 -0
  125. data/test/test_active_model_lint.rb +13 -0
  126. data/test/test_helper.rb +100 -0
  127. data/test/unit/associations/test_base.rb +212 -0
  128. data/test/unit/associations/test_proxy.rb +105 -0
  129. data/test/unit/serializers/test_json_serializer.rb +217 -0
  130. data/test/unit/test_clone.rb +69 -0
  131. data/test/unit/test_descendant_appends.rb +71 -0
  132. data/test/unit/test_document.rb +213 -0
  133. data/test/unit/test_dynamic_finder.rb +125 -0
  134. data/test/unit/test_embedded_document.rb +644 -0
  135. data/test/unit/test_extensions.rb +376 -0
  136. data/test/unit/test_key.rb +185 -0
  137. data/test/unit/test_keys.rb +89 -0
  138. data/test/unit/test_mongo_mapper.rb +110 -0
  139. data/test/unit/test_pagination.rb +11 -0
  140. data/test/unit/test_plugins.rb +50 -0
  141. data/test/unit/test_rails.rb +181 -0
  142. data/test/unit/test_rails_compatibility.rb +52 -0
  143. data/test/unit/test_serialization.rb +51 -0
  144. data/test/unit/test_time_zones.rb +39 -0
  145. data/test/unit/test_validations.rb +564 -0
  146. metadata +340 -0
@@ -0,0 +1,105 @@
1
+ require 'test_helper'
2
+
3
+ class FakeNilProxy < MongoMapper::Plugins::Associations::Proxy
4
+ def find_target; nil end
5
+ end
6
+
7
+ class FakeBlankProxy < MongoMapper::Plugins::Associations::Proxy
8
+ def find_target; '' end
9
+ end
10
+
11
+ class FakeNumberProxy < MongoMapper::Plugins::Associations::Proxy
12
+ def find_target; 17 end
13
+ end
14
+
15
+ class FakeProxy < MongoMapper::Plugins::Associations::Proxy
16
+ def find_target; [1, 2] end
17
+ end
18
+
19
+ class ProxyTest < Test::Unit::TestCase
20
+ def setup
21
+ @owner = mock('owner')
22
+ @owner.stubs(:new?).returns(false)
23
+ @association = mock('association')
24
+ @association.stubs(:options).returns({:extend => []})
25
+
26
+ @proxy = FakeProxy.new(@owner, @association)
27
+ @nil_proxy = FakeNilProxy.new(@owner, @association)
28
+ @blank_proxy = FakeBlankProxy.new(@owner, @association)
29
+ end
30
+
31
+ should 'return true for === target' do
32
+ @proxy = FakeProxy.new(@owner, @association)
33
+ @proxy.should === Array
34
+ end
35
+
36
+ should "set target to nil when reset is called" do
37
+ @proxy.reset
38
+ @proxy.target.should be_nil
39
+ end
40
+
41
+ should "be able to inspect the proxy" do
42
+ @proxy.inspect.should == '[1, 2]'
43
+ end
44
+
45
+ context "nil?" do
46
+ should "be true if nil" do
47
+ @nil_proxy.nil?.should be_true
48
+ end
49
+
50
+ should "be false if not nil" do
51
+ @proxy.nil?.should be_false
52
+ end
53
+ end
54
+
55
+ context "blank?" do
56
+ should "be true if blank" do
57
+ @blank_proxy.blank?.should be_true
58
+ @nil_proxy.blank?.should be_true
59
+ end
60
+
61
+ should "be false if not blank" do
62
+ @proxy.blank?.should be_false
63
+ end
64
+ end
65
+
66
+ context "present?" do
67
+ should "be true if present" do
68
+ @proxy.present?.should be_true
69
+ end
70
+
71
+ should "be false if not present" do
72
+ @blank_proxy.present?.should be_false
73
+ @nil_proxy.present?.should be_false
74
+ end
75
+ end
76
+
77
+ should "delegate respond_to? to target" do
78
+ @proxy.respond_to?(:each).should be_true
79
+ @proxy.respond_to?(:size).should be_true
80
+ @proxy.respond_to?(:gsub).should be_false
81
+ end
82
+
83
+ should "alias proxy owner to owner" do
84
+ @proxy.proxy_owner.should == @owner
85
+ end
86
+
87
+ should "alias proxy target to target" do
88
+ @proxy.proxy_target.should == @target
89
+ end
90
+
91
+ context "send" do
92
+ should "work if proxy responds to method" do
93
+ @proxy.send(:reset)
94
+ @proxy.target.should be_nil
95
+ end
96
+
97
+ should "work if the target responds to the method" do
98
+ @proxy.send(:size).should == 2
99
+ end
100
+
101
+ should "not work if neither the proxy or target respond to method" do
102
+ lambda { @proxy.send(:gsub) }.should raise_error
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,217 @@
1
+ require 'test_helper'
2
+ require 'active_support/version'
3
+
4
+ class JsonSerializationTest < Test::Unit::TestCase
5
+
6
+ # Helper function in case things change in the future
7
+ # - replacing all those to_json calls was a nightmare
8
+ def convert_to_json(object, options={})
9
+ ActiveSupport::JSON.encode(object, options)
10
+ end
11
+
12
+ class Tag
13
+ include MongoMapper::EmbeddedDocument
14
+ key :name, String
15
+ end
16
+
17
+ class Contact
18
+ include MongoMapper::Document
19
+ key :name, String
20
+ key :age, Integer
21
+ key :created_at, Time
22
+ key :awesome, Boolean
23
+ key :preferences, Hash
24
+
25
+ many :tags, :class_name => 'JsonSerializationTest::Tag'
26
+ end
27
+
28
+ def setup
29
+ Kernel.const_set('TopLevelContact', Doc('TopLevelContact'))
30
+ TopLevelContact.key :name, String
31
+
32
+ Contact.include_root_in_json = false
33
+ @contact = Contact.new(
34
+ :name => 'Konata Izumi',
35
+ :age => 16,
36
+ :created_at => Time.utc(2006, 8, 1),
37
+ :awesome => true,
38
+ :preferences => { :shows => 'anime' }
39
+ )
40
+ @top_level_contact = TopLevelContact.new(
41
+ :name => 'Konata Izumi'
42
+ )
43
+ end
44
+
45
+ def teardown
46
+ Kernel.send(:remove_const, 'TopLevelContact') if Object.const_defined?('TopLevelContact')
47
+ end
48
+
49
+ should "include root for class with no module" do
50
+ TopLevelContact.include_root_in_json = true
51
+ assert_match %r{^\{"top_level_contact":\s?\{}, convert_to_json(@top_level_contact)
52
+ end
53
+
54
+ should "include demodulized root" do
55
+ Contact.include_root_in_json = true
56
+ assert_match %r{^\{"contact":\s?\{}, convert_to_json(@contact)
57
+ end
58
+
59
+ should "encode all encodable attributes" do
60
+ json = convert_to_json(@contact)
61
+
62
+ assert_no_match %r{"_id"}, json
63
+ assert_match %r{"name":"Konata Izumi"}, json
64
+ assert_match %r{"age":16}, json
65
+ assert json.include?(%("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))}))
66
+ assert_match %r{"awesome":true}, json
67
+ assert_match %r{"preferences":\{"shows":"anime"\}}, json
68
+ end
69
+
70
+ should "allow attribute filtering with only" do
71
+ json = convert_to_json(@contact, :only => [:name, :age])
72
+
73
+ assert_no_match %r{"_id"}, json
74
+ assert_match %r{"name":"Konata Izumi"}, json
75
+ assert_match %r{"age":16}, json
76
+ assert_no_match %r{"awesome"}, json
77
+ assert_no_match %r{"created_at"}, json
78
+ assert_no_match %r{"preferences"}, json
79
+ end
80
+
81
+ should "allow attribute filtering with except" do
82
+ json = convert_to_json(@contact, :except => [:name, :age])
83
+
84
+ assert_no_match %r{"_id"}, json
85
+ assert_no_match %r{"name"}, json
86
+ assert_no_match %r{"age"}, json
87
+ assert_match %r{"awesome"}, json
88
+ assert_match %r{"created_at"}, json
89
+ assert_match %r{"preferences"}, json
90
+ end
91
+
92
+ context "_id key" do
93
+ should "not be included by default" do
94
+ json = convert_to_json(@contact)
95
+ assert_no_match %r{"_id":}, json
96
+ end
97
+
98
+ should "not be included even if :except is used" do
99
+ json = convert_to_json(@contact, :except => :name)
100
+ assert_no_match %r{"_id":}, json
101
+ end
102
+ end
103
+
104
+ context "id method" do
105
+ setup do
106
+ def @contact.label; "Has cheezburger"; end
107
+ def @contact.favorite_quote; "Constraints are liberating"; end
108
+ end
109
+
110
+ should "be included by default" do
111
+ json = convert_to_json(@contact)
112
+ assert_match %r{"id"}, json
113
+ end
114
+
115
+ should "be included when single method included" do
116
+ json = convert_to_json(@contact, :methods => :label)
117
+ assert_match %r{"id"}, json
118
+ assert_match %r{"label":"Has cheezburger"}, json
119
+ assert_match %r{"name":"Konata Izumi"}, json
120
+ assert_no_match %r{"favorite_quote":"Constraints are liberating"}, json
121
+ end
122
+
123
+ should "be included when multiple methods included" do
124
+ json = convert_to_json(@contact, :methods => [:label, :favorite_quote])
125
+ assert_match %r{"id"}, json
126
+ assert_match %r{"label":"Has cheezburger"}, json
127
+ assert_match %r{"favorite_quote":"Constraints are liberating"}, json
128
+ assert_match %r{"name":"Konata Izumi"}, json
129
+ end
130
+
131
+ should "not be included if :only is present" do
132
+ json = convert_to_json(@contact, :only => :name)
133
+ assert_no_match %r{"id":}, json
134
+ end
135
+
136
+ should "be represented by a string" do
137
+ json = convert_to_json(@contact)
138
+ assert_match %r{"id":"}, json
139
+ end
140
+ end
141
+
142
+ context "including methods" do
143
+ setup do
144
+ def @contact.label; "Has cheezburger"; end
145
+ def @contact.favorite_quote; "Constraints are liberating"; end
146
+ end
147
+
148
+ should "include single method" do
149
+ json = convert_to_json(@contact, :methods => :label)
150
+ assert_match %r{"label":"Has cheezburger"}, json
151
+ end
152
+
153
+ should "include multiple methods" do
154
+ json = convert_to_json(@contact, :only => :name, :methods => [:label, :favorite_quote])
155
+ assert_match %r{"label":"Has cheezburger"}, json
156
+ assert_match %r{"favorite_quote":"Constraints are liberating"}, json
157
+ assert_match %r{"name":"Konata Izumi"}, json
158
+ assert_no_match %r{"age":16}, json
159
+ assert_no_match %r{"awesome"}, json
160
+ assert_no_match %r{"created_at"}, json
161
+ assert_no_match %r{"preferences"}, json
162
+ end
163
+ end
164
+
165
+ context "array of records" do
166
+ setup do
167
+ @contacts = [
168
+ Contact.new(:name => 'David', :age => 39),
169
+ Contact.new(:name => 'Mary', :age => 14)
170
+ ]
171
+ end
172
+
173
+ should "allow attribute filtering with only" do
174
+ json =convert_to_json(@contacts, :only => :name)
175
+ assert_match %r{\{"name":"David"\}}, json
176
+ assert_match %r{\{"name":"Mary"\}}, json
177
+ end
178
+
179
+ should "allow attribute filtering with except" do
180
+ json = convert_to_json(@contacts, :except => [:name, :preferences, :awesome, :created_at, :updated_at])
181
+ assert_match %r{"age":39}, json
182
+ assert_match %r{"age":14}, json
183
+ assert_no_match %r{"name":}, json
184
+ assert_no_match %r{"preferences":}, json
185
+ assert_no_match %r{"awesome":}, json
186
+ assert_no_match %r{"created_at":}, json
187
+ assert_no_match %r{"updated_at":}, json
188
+ end
189
+ end
190
+
191
+ should "allow options for hash of records" do
192
+ contacts = {
193
+ 1 => Contact.new(:name => 'David', :age => 39),
194
+ 2 => Contact.new(:name => 'Mary', :age => 14)
195
+ }
196
+ json = convert_to_json(contacts, :only => [1, :name])
197
+ assert_match %r{"1":}, json
198
+ assert_match %r{\{"name":"David"\}}, json
199
+ assert_no_match %r{"2":}, json
200
+ end
201
+
202
+ should "include embedded attributes" do
203
+ contact = Contact.new(:name => 'John', :age => 27)
204
+ contact.tags = [Tag.new(:name => 'awesome'), Tag.new(:name => 'ruby')]
205
+ json = convert_to_json(contact)
206
+ assert_match %r{"tags":}, json
207
+ assert_match %r{"name":"awesome"}, json
208
+ assert_match %r{"name":"ruby"}, json
209
+ end
210
+
211
+ should "include dynamic attributes" do
212
+ contact = Contact.new(:name => 'John', :age => 27, :foo => 'bar')
213
+ contact['smell'] = 'stinky'
214
+ json = convert_to_json(contact)
215
+ assert_match %r{"smell":"stinky"}, json
216
+ end
217
+ end
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ class CloneTest < Test::Unit::TestCase
4
+ context "Document" do
5
+ setup do
6
+ @document = Doc()
7
+ @embedded = EDoc()
8
+ @document.many :widgets, :class => @embedded
9
+ @tags = ['red', 'green', 'blue']
10
+ @doc = @document.create({
11
+ :name => "foo",
12
+ :age => 27,
13
+ :tags => @tags,
14
+ :widgets => [@embedded.new, @embedded.new],
15
+ })
16
+ end
17
+
18
+ context "#clone" do
19
+ should "be new" do
20
+ @doc.clone.should be_new
21
+ end
22
+
23
+ should "copy the attributes" do
24
+ clone = @doc.clone
25
+ clone.name.should == "foo"
26
+ clone.age.should == 27
27
+ end
28
+
29
+ should "clone duplicable attributes" do
30
+ @doc.clone.tags.should_not equal(@tags)
31
+ end
32
+
33
+ should "clone many embedded documents" do
34
+ @doc.clone.widgets.object_id.should_not equal(@doc.widgets.object_id)
35
+ end
36
+
37
+ should "not be destroyed" do
38
+ @doc.destroy
39
+ @doc.clone.should_not be_destroyed
40
+ end
41
+ end
42
+ end
43
+
44
+ context "EmbeddedDocument" do
45
+ setup do
46
+ @document = EDoc do
47
+ key :name, String
48
+ key :age, Integer
49
+ end
50
+ end
51
+
52
+ context "#clone" do
53
+ should "regenerate the id" do
54
+ doc = @document.new(:name => "foo", :age => 27)
55
+ doc_id = doc.id
56
+ clone = doc.clone
57
+ clone_id = clone.id
58
+ clone_id.should_not == doc_id
59
+ end
60
+
61
+ should "copy the attributes" do
62
+ doc = @document.new(:name => "foo", :age => 27)
63
+ clone = doc.clone
64
+ clone.name.should == "foo"
65
+ clone.age.should == 27
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+
3
+ class DescendantAppendsTest < Test::Unit::TestCase
4
+ context "Document" do
5
+ should "default descendants to a new set" do
6
+ MongoMapper::Document.descendants.should be_instance_of(Set)
7
+ end
8
+
9
+ should 'allow extensions to Document to be appended' do
10
+ module Extension; def test_this_extension; end end
11
+ MongoMapper::Document.append_extensions(Extension)
12
+ article = Doc()
13
+ article.should respond_to(:test_this_extension)
14
+ end
15
+
16
+ should 'add appended extensions to classes that include Document before they are added' do
17
+ module Extension; def test_this_extension; end end
18
+ article = Doc()
19
+ MongoMapper::Document.append_extensions(Extension)
20
+ article.should respond_to(:test_this_extension)
21
+ end
22
+
23
+ should 'allow inclusions to Document to be appended' do
24
+ module Inclusion; def test_this_inclusion; end end
25
+ MongoMapper::Document.append_inclusions(Inclusion)
26
+ article = Doc()
27
+ article.new.should respond_to(:test_this_inclusion)
28
+ end
29
+
30
+ should 'add appended inclusions to classes that include Document before they are added' do
31
+ module Inclusion; def test_this_inclusion; end end
32
+ article = Doc()
33
+ MongoMapper::Document.append_inclusions(Inclusion)
34
+ article.new.should respond_to(:test_this_inclusion)
35
+ end
36
+ end
37
+
38
+ context "EmbeddedDocument" do
39
+ should "default descendants to a new set" do
40
+ MongoMapper::EmbeddedDocument.descendants.should be_instance_of(Set)
41
+ end
42
+
43
+ should 'allow extensions to Document to be appended' do
44
+ module Extension; def test_this_extension; end end
45
+ MongoMapper::EmbeddedDocument.append_extensions(Extension)
46
+ article = EDoc()
47
+ article.should respond_to(:test_this_extension)
48
+ end
49
+
50
+ should 'add appended extensions to classes that include Document before they are added' do
51
+ module Extension; def test_this_extension; end end
52
+ article = EDoc()
53
+ MongoMapper::EmbeddedDocument.append_extensions(Extension)
54
+ article.should respond_to(:test_this_extension)
55
+ end
56
+
57
+ should 'allow inclusions to Document to be appended' do
58
+ module Inclusion; def test_this_inclusion; end end
59
+ MongoMapper::EmbeddedDocument.append_inclusions(Inclusion)
60
+ article = EDoc()
61
+ article.new.should respond_to(:test_this_inclusion)
62
+ end
63
+
64
+ should 'add appended inclusions to classes that include Document before they are added' do
65
+ module Inclusion; def test_this_inclusion; end end
66
+ article = EDoc()
67
+ MongoMapper::EmbeddedDocument.append_inclusions(Inclusion)
68
+ article.new.should respond_to(:test_this_inclusion)
69
+ end
70
+ end
71
+ end