ign-mongo_mapper 0.8.6.1

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 (147) 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/keys.rb +40 -0
  12. data/examples/modifiers/set.rb +25 -0
  13. data/examples/plugins.rb +41 -0
  14. data/examples/querying.rb +35 -0
  15. data/examples/safe.rb +43 -0
  16. data/examples/scopes.rb +52 -0
  17. data/examples/validating/embedded_docs.rb +29 -0
  18. data/lib/mongo_mapper.rb +83 -0
  19. data/lib/mongo_mapper/connection.rb +83 -0
  20. data/lib/mongo_mapper/document.rb +41 -0
  21. data/lib/mongo_mapper/embedded_document.rb +31 -0
  22. data/lib/mongo_mapper/exceptions.rb +27 -0
  23. data/lib/mongo_mapper/extensions/array.rb +19 -0
  24. data/lib/mongo_mapper/extensions/binary.rb +22 -0
  25. data/lib/mongo_mapper/extensions/boolean.rb +44 -0
  26. data/lib/mongo_mapper/extensions/date.rb +25 -0
  27. data/lib/mongo_mapper/extensions/float.rb +14 -0
  28. data/lib/mongo_mapper/extensions/hash.rb +14 -0
  29. data/lib/mongo_mapper/extensions/integer.rb +19 -0
  30. data/lib/mongo_mapper/extensions/kernel.rb +9 -0
  31. data/lib/mongo_mapper/extensions/nil_class.rb +18 -0
  32. data/lib/mongo_mapper/extensions/object.rb +27 -0
  33. data/lib/mongo_mapper/extensions/object_id.rb +30 -0
  34. data/lib/mongo_mapper/extensions/set.rb +20 -0
  35. data/lib/mongo_mapper/extensions/string.rb +18 -0
  36. data/lib/mongo_mapper/extensions/time.rb +29 -0
  37. data/lib/mongo_mapper/middleware/identity_map.rb +16 -0
  38. data/lib/mongo_mapper/plugins.rb +15 -0
  39. data/lib/mongo_mapper/plugins/accessible.rb +44 -0
  40. data/lib/mongo_mapper/plugins/associations.rb +134 -0
  41. data/lib/mongo_mapper/plugins/associations/base.rb +124 -0
  42. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +29 -0
  43. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +24 -0
  44. data/lib/mongo_mapper/plugins/associations/collection.rb +27 -0
  45. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +40 -0
  46. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +151 -0
  47. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +28 -0
  48. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +109 -0
  49. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +32 -0
  50. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +24 -0
  51. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +14 -0
  52. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +41 -0
  53. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +68 -0
  54. data/lib/mongo_mapper/plugins/associations/proxy.rb +139 -0
  55. data/lib/mongo_mapper/plugins/caching.rb +21 -0
  56. data/lib/mongo_mapper/plugins/callbacks.rb +243 -0
  57. data/lib/mongo_mapper/plugins/clone.rb +22 -0
  58. data/lib/mongo_mapper/plugins/descendants.rb +17 -0
  59. data/lib/mongo_mapper/plugins/dirty.rb +124 -0
  60. data/lib/mongo_mapper/plugins/document.rb +41 -0
  61. data/lib/mongo_mapper/plugins/dynamic_querying.rb +43 -0
  62. data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +44 -0
  63. data/lib/mongo_mapper/plugins/embedded_document.rb +48 -0
  64. data/lib/mongo_mapper/plugins/equality.rb +17 -0
  65. data/lib/mongo_mapper/plugins/identity_map.rb +128 -0
  66. data/lib/mongo_mapper/plugins/indexes.rb +12 -0
  67. data/lib/mongo_mapper/plugins/inspect.rb +15 -0
  68. data/lib/mongo_mapper/plugins/keys.rb +311 -0
  69. data/lib/mongo_mapper/plugins/keys/key.rb +65 -0
  70. data/lib/mongo_mapper/plugins/logger.rb +18 -0
  71. data/lib/mongo_mapper/plugins/modifiers.rb +112 -0
  72. data/lib/mongo_mapper/plugins/pagination.rb +14 -0
  73. data/lib/mongo_mapper/plugins/persistence.rb +69 -0
  74. data/lib/mongo_mapper/plugins/protected.rb +53 -0
  75. data/lib/mongo_mapper/plugins/querying.rb +176 -0
  76. data/lib/mongo_mapper/plugins/querying/decorator.rb +46 -0
  77. data/lib/mongo_mapper/plugins/querying/plucky_methods.rb +15 -0
  78. data/lib/mongo_mapper/plugins/rails.rb +58 -0
  79. data/lib/mongo_mapper/plugins/safe.rb +28 -0
  80. data/lib/mongo_mapper/plugins/sci.rb +32 -0
  81. data/lib/mongo_mapper/plugins/scopes.rb +21 -0
  82. data/lib/mongo_mapper/plugins/serialization.rb +76 -0
  83. data/lib/mongo_mapper/plugins/timestamps.rb +22 -0
  84. data/lib/mongo_mapper/plugins/userstamps.rb +15 -0
  85. data/lib/mongo_mapper/plugins/validations.rb +50 -0
  86. data/lib/mongo_mapper/support/descendant_appends.rb +45 -0
  87. data/lib/mongo_mapper/version.rb +4 -0
  88. data/rails/init.rb +15 -0
  89. data/test/_NOTE_ON_TESTING +1 -0
  90. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +64 -0
  91. data/test/functional/associations/test_belongs_to_proxy.rb +117 -0
  92. data/test/functional/associations/test_in_array_proxy.rb +349 -0
  93. data/test/functional/associations/test_many_documents_as_proxy.rb +229 -0
  94. data/test/functional/associations/test_many_documents_proxy.rb +615 -0
  95. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +176 -0
  96. data/test/functional/associations/test_many_embedded_proxy.rb +256 -0
  97. data/test/functional/associations/test_many_polymorphic_proxy.rb +303 -0
  98. data/test/functional/associations/test_one_embedded_proxy.rb +100 -0
  99. data/test/functional/associations/test_one_proxy.rb +206 -0
  100. data/test/functional/test_accessible.rb +168 -0
  101. data/test/functional/test_associations.rb +46 -0
  102. data/test/functional/test_binary.rb +27 -0
  103. data/test/functional/test_caching.rb +76 -0
  104. data/test/functional/test_callbacks.rb +151 -0
  105. data/test/functional/test_dirty.rb +163 -0
  106. data/test/functional/test_document.rb +272 -0
  107. data/test/functional/test_dynamic_querying.rb +75 -0
  108. data/test/functional/test_embedded_document.rb +210 -0
  109. data/test/functional/test_identity_map.rb +513 -0
  110. data/test/functional/test_indexes.rb +42 -0
  111. data/test/functional/test_logger.rb +20 -0
  112. data/test/functional/test_modifiers.rb +416 -0
  113. data/test/functional/test_pagination.rb +91 -0
  114. data/test/functional/test_protected.rb +175 -0
  115. data/test/functional/test_querying.rb +873 -0
  116. data/test/functional/test_safe.rb +76 -0
  117. data/test/functional/test_sci.rb +230 -0
  118. data/test/functional/test_scopes.rb +171 -0
  119. data/test/functional/test_string_id_compatibility.rb +67 -0
  120. data/test/functional/test_timestamps.rb +62 -0
  121. data/test/functional/test_userstamps.rb +27 -0
  122. data/test/functional/test_validations.rb +342 -0
  123. data/test/models.rb +233 -0
  124. data/test/test_active_model_lint.rb +13 -0
  125. data/test/test_helper.rb +102 -0
  126. data/test/unit/associations/test_base.rb +212 -0
  127. data/test/unit/associations/test_proxy.rb +105 -0
  128. data/test/unit/serializers/test_json_serializer.rb +217 -0
  129. data/test/unit/test_clone.rb +69 -0
  130. data/test/unit/test_descendant_appends.rb +71 -0
  131. data/test/unit/test_document.rb +208 -0
  132. data/test/unit/test_dynamic_finder.rb +125 -0
  133. data/test/unit/test_embedded_document.rb +639 -0
  134. data/test/unit/test_extensions.rb +376 -0
  135. data/test/unit/test_identity_map_middleware.rb +34 -0
  136. data/test/unit/test_inspect.rb +22 -0
  137. data/test/unit/test_key.rb +205 -0
  138. data/test/unit/test_keys.rb +89 -0
  139. data/test/unit/test_mongo_mapper.rb +110 -0
  140. data/test/unit/test_pagination.rb +11 -0
  141. data/test/unit/test_plugins.rb +50 -0
  142. data/test/unit/test_rails.rb +181 -0
  143. data/test/unit/test_rails_compatibility.rb +52 -0
  144. data/test/unit/test_serialization.rb +51 -0
  145. data/test/unit/test_time_zones.rb +39 -0
  146. data/test/unit/test_validations.rb +564 -0
  147. metadata +385 -0
@@ -0,0 +1,100 @@
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.build_author(: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 "be able to replace the association" 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
+ post.save
38
+ post.reload
39
+
40
+ post.author.should == author
41
+ post.author.nil?.should be_false
42
+
43
+ new_author = @author_class.new(:name => 'Emily')
44
+ post.author = new_author
45
+ post.author.should == new_author
46
+ end
47
+
48
+ should "not have problem loading root document if embedded one is nil" do
49
+ @post_class.one :author, :class => @author_class
50
+ post = @post_class.create
51
+
52
+ lambda {
53
+ @post_class.find(post.id)
54
+ }.should_not raise_error
55
+ end
56
+
57
+ should "load the parent and root documents for nested embedded documents" do
58
+ @address_class = EDoc('Address') do
59
+ key :city, String
60
+ key :state, String
61
+ end
62
+ @author_class.one :address, :class => @address_class
63
+ @post_class.one :author, :class => @author_class
64
+
65
+ post = @post_class.create(:title => 'Post Title', :author => { :name => 'Frank', :address => { :city => 'Boston', :state => 'MA' } })
66
+
67
+ post.author.address._parent_document.should == post.author
68
+ post.author.address._root_document.should == post
69
+ end
70
+
71
+ should "have boolean method for testing presence" do
72
+ @post_class.one :author, :class => @author_class
73
+
74
+ post = @post_class.new
75
+ post.author?.should be_false
76
+
77
+ post.author = @author_class.new(:name => 'Frank')
78
+ post.author?.should be_true
79
+ end
80
+
81
+ should "initialize id for nested embedded document created from hash" do
82
+ @address_class = EDoc('Address') do
83
+ key :city, String
84
+ key :state, String
85
+ end
86
+ @author_class.one(:address, :class => @address_class)
87
+ @post_class.one(:author, :class => @author_class)
88
+
89
+ post = @post_class.create(:title => 'Post Title', :author => {
90
+ :name => 'Frank',
91
+ :address => {
92
+ :city => 'Boston',
93
+ :state => 'MA'
94
+ }
95
+ })
96
+
97
+ post.author.address.id.should_not be_nil
98
+ end
99
+
100
+ end
@@ -0,0 +1,206 @@
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 "return nil instead of a proxy" do
17
+ @post_class.one :author, :class => @author_class
18
+ nil.should === @post_class.new.author
19
+ end
20
+
21
+ should "allow assignment of associated document using a hash" do
22
+ @post_class.one :author, :class => @author_class
23
+
24
+ post = @post_class.new('author' => { 'name' => 'Frank' })
25
+ post.author.name.should == 'Frank'
26
+
27
+ post.save.should be_true
28
+ post.reload
29
+
30
+ post.author.name.should == 'Frank'
31
+ end
32
+
33
+ context "replacing the association" do
34
+ context "with an object of the class" do
35
+ should "work" do
36
+ @post_class.one :author, :class => @author_class
37
+
38
+ post = @post_class.new
39
+ author = @author_class.new(:name => 'Frank')
40
+ post.author = author
41
+ post.reload
42
+
43
+ post.author.should == author
44
+ post.author.nil?.should be_false
45
+
46
+ new_author = @author_class.new(:name => 'Emily')
47
+ post.author = new_author
48
+ post.author.should == new_author
49
+ end
50
+
51
+ should "generate a new proxy instead of modifying the existing one" do
52
+ @post_class.one :author, :class => @author_class
53
+
54
+ post = @post_class.new
55
+ author = @author_class.new(:name => 'Frank')
56
+ post.author = author
57
+ post.reload
58
+
59
+ post.author.should == author
60
+ post.author.nil?.should be_false
61
+
62
+ original_author = post.author
63
+ original_author.name.should == 'Frank'
64
+ new_author = @author_class.new(:name => 'Emily')
65
+ post.author = new_author
66
+ post.author.should == new_author
67
+
68
+ original_author.name.should == 'Frank'
69
+ end
70
+ end
71
+
72
+ context "with a Hash" do
73
+ should "convert to an object of the class and work" do
74
+ @post_class.one :author, :class => @author_class
75
+
76
+ post = @post_class.new
77
+ post.author = {'name' => 'Frank'}
78
+ post.reload
79
+
80
+ post.author.name.should == 'Frank'
81
+ post.author.nil?.should be_false
82
+
83
+ post.author = {'name' => 'Emily'}
84
+ post.author.name.should == 'Emily'
85
+ end
86
+ end
87
+ end
88
+
89
+ should "have boolean method for testing presence" do
90
+ @post_class.one :author, :class => @author_class
91
+
92
+ post = @post_class.new
93
+ post.author?.should be_false
94
+
95
+ post.author = @author_class.new(:name => 'Frank')
96
+ post.author?.should be_true
97
+ end
98
+
99
+ should "work with criteria" do
100
+ @post_class.one :primary_author, :class => @author_class, :primary => true
101
+ @post_class.one :author, :class => @author_class, :primary => false
102
+
103
+ post = @post_class.create
104
+ author = @author_class.create(:name => 'Frank', :primary => false, :post_id => post.id)
105
+ primary = @author_class.create(:name => 'Bill', :primary => true, :post_id => post.id)
106
+ post.reload
107
+ post.author.should == author
108
+ post.primary_author.should == primary
109
+ end
110
+
111
+ should "unset the association" do
112
+ @post_class.one :author, :class => @author_class
113
+ post = @post_class.create
114
+ author = @author_class.create
115
+ post.update_attributes!(:author => author)
116
+ post.reload
117
+ post.author = nil
118
+ post.author.nil?.should be_true
119
+ end
120
+
121
+ should "work with :dependent delete" do
122
+ @post_class.one :author, :class => @author_class, :dependent => :delete
123
+
124
+ post = @post_class.create
125
+ author = @author_class.new
126
+ post.author = author
127
+ post.reload
128
+
129
+ @author_class.any_instance.expects(:delete).once
130
+ post.author = @author_class.new
131
+ end
132
+
133
+ should "work with :dependent destroy" do
134
+ @post_class.one :author, :class => @author_class, :dependent => :destroy
135
+
136
+ post = @post_class.create
137
+ author = @author_class.new
138
+ post.author = author
139
+ post.reload
140
+
141
+ @author_class.any_instance.expects(:destroy).once
142
+ post.author = @author_class.new
143
+ end
144
+
145
+ should "work with :dependent nullify" do
146
+ @post_class.one :author, :class => @author_class, :dependent => :nullify
147
+
148
+ post = @post_class.create
149
+ author = @author_class.new
150
+ post.author = author
151
+ post.reload
152
+
153
+ post.author = @author_class.new
154
+
155
+ author.reload
156
+ author.post_id.should be_nil
157
+ end
158
+
159
+ should "be able to build" do
160
+ @post_class.one :author, :class => @author_class
161
+
162
+ post = @post_class.create
163
+ author = post.build_author(:name => 'John')
164
+ post.author.should be_instance_of(@author_class)
165
+ post.author.should be_new
166
+ post.author.name.should == 'John'
167
+ post.author.should == author
168
+ post.author.post_id.should == post.id
169
+ end
170
+
171
+ should "be able to create" do
172
+ @post_class.one :author, :class => @author_class
173
+
174
+ post = @post_class.create
175
+ author = post.create_author(:name => 'John')
176
+ post.author.should be_instance_of(@author_class)
177
+ post.author.should_not be_new
178
+ post.author.name.should == 'John'
179
+ post.author.should == author
180
+ post.author.post_id.should == post.id
181
+ end
182
+
183
+ context "#create!" do
184
+ setup do
185
+ @author_class.key :name, String, :required => true
186
+ @post_class.one :author, :class => @author_class
187
+ end
188
+
189
+ should "raise exception if invalid" do
190
+ post = @post_class.create
191
+ assert_raises(MongoMapper::DocumentNotValid) do
192
+ post.create_author!
193
+ end
194
+ end
195
+
196
+ should "work if valid" do
197
+ post = @post_class.create
198
+ author = post.create_author!(:name => 'John')
199
+ post.author.should be_instance_of(@author_class)
200
+ post.author.should_not be_new
201
+ post.author.name.should == 'John'
202
+ post.author.should == author
203
+ post.author.post_id.should == post.id
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,168 @@
1
+ require 'test_helper'
2
+
3
+ class AccessibleTest < Test::Unit::TestCase
4
+ context 'A document with accessible attributes' do
5
+ setup do
6
+ @doc_class = Doc do
7
+ key :name, String
8
+ key :admin, Boolean, :default => false
9
+
10
+ attr_accessible :name
11
+ end
12
+
13
+ @doc = @doc_class.create(:name => 'Steve Sloan')
14
+ end
15
+
16
+ should 'have accessible attributes class method' do
17
+ @doc_class.accessible_attributes.should == [:name].to_set
18
+ end
19
+
20
+ should "default accessible attributes to nil" do
21
+ Doc().accessible_attributes.should be_nil
22
+ end
23
+
24
+ should "have accessible_attributes instance method" do
25
+ @doc.accessible_attributes.should equal(@doc_class.accessible_attributes)
26
+ end
27
+
28
+ should "raise error if there are protected attributes" do
29
+ doc = Doc('Post')
30
+ doc.attr_protected :admin
31
+ lambda { doc.attr_accessible :name }.
32
+ should raise_error(/Declare either attr_protected or attr_accessible for Post/)
33
+ end
34
+
35
+ should "know if using accessible attributes" do
36
+ @doc_class.accessible_attributes?.should be(true)
37
+ Doc().accessible_attributes?.should be(false)
38
+ end
39
+
40
+ should "assign inaccessible attribute through accessor" do
41
+ @doc.admin = true
42
+ @doc.admin.should be_true
43
+ end
44
+
45
+ should "ignore inaccessible attribute on #initialize" do
46
+ doc = @doc_class.new(:name => 'John', :admin => true)
47
+ doc.admin.should be_false
48
+ doc.name.should == 'John'
49
+ end
50
+
51
+ should "not ignore inaccessible attributes on #initialize from the database" do
52
+ doc = @doc_class.new(:name => 'John')
53
+ doc.admin = true
54
+ doc.save!
55
+
56
+ doc = @doc_class.first(:name => 'John')
57
+ doc.admin.should be_true
58
+ doc.name.should == 'John'
59
+ end
60
+
61
+ should "ignore inaccessible attribute on #update_attributes" do
62
+ @doc.update_attributes(:name => 'Ren Hoek', :admin => true)
63
+ @doc.name.should == 'Ren Hoek'
64
+ @doc.admin.should be_false
65
+ end
66
+
67
+ should "ignore inaccessible attribute on #update_attributes!" do
68
+ @doc.update_attributes!(:name => 'Stimpson J. Cat', :admin => true)
69
+ @doc.name.should == 'Stimpson J. Cat'
70
+ @doc.admin.should be_false
71
+ end
72
+
73
+ should "be indifferent to whether the accessible keys are strings or symbols" do
74
+ @doc.update_attributes!("name" => 'Stimpson J. Cat', "admin" => true)
75
+ @doc.name.should == 'Stimpson J. Cat'
76
+ @doc.admin.should be_false
77
+ end
78
+
79
+ should "accept nil as constructor's argument without raising exception" do
80
+ lambda { @doc_class.new(nil) }.should_not raise_error
81
+ end
82
+ end
83
+
84
+ context "Single collection inherited accessible attributes" do
85
+ setup do
86
+ class ::GrandParent
87
+ include MongoMapper::Document
88
+ attr_accessible :name
89
+ key :name, String
90
+ key :site_id, ObjectId
91
+ end
92
+ GrandParent.collection.remove
93
+
94
+ class ::Child < ::GrandParent
95
+ attr_accessible :position
96
+ key :position, Integer
97
+ end
98
+
99
+ class ::GrandChild < ::Child; end
100
+
101
+ class ::OtherChild < ::GrandParent
102
+ attr_accessible :favorite_color
103
+ key :favorite_color, String
104
+ key :blog_id, ObjectId
105
+ end
106
+ end
107
+
108
+ teardown do
109
+ Object.send :remove_const, 'GrandParent' if defined?(::GrandParent)
110
+ Object.send :remove_const, 'Child' if defined?(::Child)
111
+ Object.send :remove_const, 'GrandChild' if defined?(::GrandChild)
112
+ Object.send :remove_const, 'OtherChild' if defined?(::OtherChild)
113
+ end
114
+
115
+ should "share keys down the inheritance trail" do
116
+ GrandParent.accessible_attributes.should == [:name].to_set
117
+ Child.accessible_attributes.should == [:name, :position].to_set
118
+ GrandChild.accessible_attributes.should == [:name, :position].to_set
119
+ OtherChild.accessible_attributes.should == [:name, :favorite_color].to_set
120
+ end
121
+ end
122
+
123
+ context "An embedded document with accessible attributes" do
124
+ setup do
125
+ @doc_class = Doc('Project')
126
+ @edoc_class = EDoc('Person') do
127
+ key :name, String
128
+ key :admin, Boolean, :default => false
129
+
130
+ attr_accessible :name
131
+ end
132
+ @doc_class.many :people, :class => @edoc_class
133
+
134
+ @doc = @doc_class.create(:title => 'MongoMapper')
135
+ @edoc = @edoc_class.new(:name => 'Steve Sloan')
136
+ @doc.people << @edoc
137
+ end
138
+
139
+ should "have accessible attributes class method" do
140
+ @edoc_class.accessible_attributes.should == [:name].to_set
141
+ end
142
+
143
+ should "default accessible attributes to nil" do
144
+ EDoc().accessible_attributes.should be_nil
145
+ end
146
+
147
+ should "have accessible attributes instance method" do
148
+ @edoc.accessible_attributes.should equal(@edoc_class.accessible_attributes)
149
+ end
150
+
151
+ should "assign inaccessible attribute through accessor" do
152
+ @edoc.admin = true
153
+ @edoc.admin.should be_true
154
+ end
155
+
156
+ should "ignore inaccessible attribute on #update_attributes" do
157
+ @edoc.update_attributes(:name => 'Ren Hoek', :admin => true)
158
+ @edoc.name.should == 'Ren Hoek'
159
+ @edoc.admin.should be_false
160
+ end
161
+
162
+ should "ignore inaccessible attribute on #update_attributes!" do
163
+ @edoc.update_attributes!(:name => 'Stimpson J. Cat', :admin => true)
164
+ @edoc.name.should == 'Stimpson J. Cat'
165
+ @edoc.admin.should be_false
166
+ end
167
+ end
168
+ end