mongoid 4.0.1 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b25a1415535c09fc18f98e85225d38fd4e39877
4
- data.tar.gz: 7dcb8aa291c865b59a10f2a7fa1508d2ae999850
3
+ metadata.gz: a5340f453822e7cbecd2710795296c23db607d92
4
+ data.tar.gz: 0adcfd1449d91980fb45bb60aa336e661b1482f9
5
5
  SHA512:
6
- metadata.gz: 6087a7ef04b49630a195f2019c575ca50abb1fd46b96739f77a8dba22a9cc3b5c5bcf49771a91785bb88a68e68c4227589b1560da18e7555e872f0c3c5776329
7
- data.tar.gz: a0a0c271e5fe084d0e2360cab8f4296629907f85422a0ce4d46212b348428bc49c8eaab9a713faf4a63aebd41acca86bc0cefdfd1932c143c0d9336509c86e5e
6
+ metadata.gz: 9b1733f089831c0b58049cb486a8c13687f16a0845d2d9eb2acfb8c5aa0c99de3bbe3a81d6ab0bae0be9c8e4493c77864d64626b341565b5be8f7d695fb93acc
7
+ data.tar.gz: 1c7a4d343e583880595366b2f4afcb58a8d0f763c8a3bc5f04cea4134d1fb947f420d3ce7cb9b070902a0fd50cd03e71c1c4188c7f349a0e591774435b6a9908
@@ -3,6 +3,36 @@
3
3
  For instructions on upgrading to newer versions, visit
4
4
  [mongoid.org](http://mongoid.org/en/mongoid/docs/upgrading.html).
5
5
 
6
+ ## 4.0.3 - Not released
7
+
8
+ ## 4.0.2
9
+
10
+ ### New Features
11
+
12
+ * \#3931 Add #find_or_create_by! method to many associations. (Tom Beynon)
13
+
14
+ * \#3731 Add find_by! method. (Guillermo Iguaran)
15
+
16
+ ### Resolved Issues
17
+
18
+ * \#3722 Use the right database name when combining #store_in and #with. (Arthur Neves)
19
+
20
+ * \#3934 Dont apply sort when doing a find_by. (Arthur Neves)
21
+
22
+ * \#3935 fix multiple fields sorting on contextual memory. (chamnap)
23
+
24
+ * \#3904 BSON::Document#symbolize_keys should return keys as symbols. (Arthur Neves)
25
+
26
+ * \#3948 Fix remove_undefined_indexes on rails 4.2, to symbolize right the Document keys. (Adam Wróbel)
27
+
28
+ * \#3626 Document#to_key, needs to return a ObjectId as String so we can query back using that id. (Arthur Neves)
29
+
30
+ * \#3888 raise UnknownAttributeError when 'set' is called on non existing field and Mongoid::Attributes::Dynamic is not included in model. (Shweta Kale)
31
+
32
+ * \#3889 'set' will allow to set value of non existing field when Mongoid::Attributes::Dynamic is included in model. (Shweta Kale)
33
+
34
+ * \#3812 Fixed validation context when saving (Yaroslav Zemlyanuhin)
35
+
6
36
  ## 4.0.1
7
37
 
8
38
  ### Resolved Issues
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Mongoid
2
- [![Build Status](https://travis-ci.org/mongoid/mongoid.svg)](https://travis-ci.org/mongoid/mongoid)
2
+ [![Build Status](https://travis-ci.org/mongoid/mongoid.svg?branch=master)](https://travis-ci.org/mongoid/mongoid)
3
3
  [![Code Climate](https://codeclimate.com/github/mongoid/mongoid.svg)](https://codeclimate.com/github/mongoid/mongoid)
4
4
  [![Coverage Status](https://img.shields.io/coveralls/mongoid/mongoid/master.svg)](https://coveralls.io/r/mongoid/mongoid?branch=master)
5
5
  [![Dependency Status](https://www.versioneye.com/ruby/mongoid/4.0.0/badge.svg)](https://www.versioneye.com/ruby/mongoid/4.0.0)
@@ -135,6 +135,7 @@ module Mongoid
135
135
  doc
136
136
  end
137
137
  alias :one :first
138
+ alias :find_first :first
138
139
 
139
140
  # Create the new in memory context.
140
141
  #
@@ -421,12 +422,11 @@ module Mongoid
421
422
  #
422
423
  # @since 3.0.0
423
424
  def in_place_sort(values)
424
- values.keys.reverse.each do |field|
425
- documents.sort! do |a, b|
425
+ documents.sort! do |a, b|
426
+ values.map do |field, direction|
426
427
  a_value, b_value = a[field], b[field]
427
- value = compare(a_value.__sortable__, b_value.__sortable__)
428
- values[field] < 0 ? value * -1 : value
429
- end
428
+ direction * compare(a_value.__sortable__, b_value.__sortable__)
429
+ end.find { |value| !value.zero? } || 0
430
430
  end
431
431
  end
432
432
 
@@ -202,6 +202,16 @@ module Mongoid
202
202
  end
203
203
  alias :one :first
204
204
 
205
+ # Return the first result without applying sort
206
+ #
207
+ # @api private
208
+ #
209
+ # @since 4.0.2
210
+ def find_first
211
+ return documents.first if cached? && cache_loaded?
212
+ with_eager_loading(query.first)
213
+ end
214
+
205
215
  # Execute a $geoNear command against the database.
206
216
  #
207
217
  # @example Find documents close to 10, 10.
@@ -134,11 +134,11 @@ module Mongoid
134
134
  # @example Return the key.
135
135
  # document.to_key
136
136
  #
137
- # @return [ Object ] The id of the document or nil if new.
137
+ # @return [ String ] The id of the document or nil if new.
138
138
  #
139
139
  # @since 2.4.0
140
140
  def to_key
141
- (persisted? || destroyed?) ? [ id ] : nil
141
+ (persisted? || destroyed?) ? [ id.to_s ] : nil
142
142
  end
143
143
 
144
144
  # Return an array with this +Document+ only in it.
@@ -12,6 +12,19 @@ class Symbol
12
12
  remove_method :size if instance_methods.include? :size # temporal fix for ruby 1.9
13
13
  end
14
14
 
15
+ class BSON::Document
16
+ # We need to override this as ActiveSupport creates a new Object, instead of a new Hash
17
+ # see https://github.com/rails/rails/commit/f1bad130d0c9bd77c94e43b696adca56c46a66aa
18
+ def transform_keys
19
+ return enum_for(:transform_keys) unless block_given?
20
+ result = {}
21
+ each_key do |key|
22
+ result[yield(key)] = self[key]
23
+ end
24
+ result
25
+ end
26
+ end
27
+
15
28
  require "mongoid/extensions/array"
16
29
  require "mongoid/extensions/big_decimal"
17
30
  require "mongoid/extensions/boolean"
@@ -90,21 +90,24 @@ module Mongoid
90
90
  with_default_scope.find(*args)
91
91
  end
92
92
 
93
- # Find the first +Document+ given the conditions, or raises
94
- # Mongoid::Errors::DocumentNotFound
93
+ # Find the first +Document+ given the conditions.
94
+ # If a matching Document is not found and
95
+ # Mongoid.raise_not_found_error is true it raises
96
+ # Mongoid::Errors::DocumentNotFound, return null nil elsewise.
95
97
  #
96
98
  # @example Find the document by attribute other than id
97
99
  # Person.find_by(:username => "superuser")
98
100
  #
99
101
  # @param [ Hash ] attrs The attributes to check.
100
102
  #
101
- # @raise [ Errors::DocumentNotFound ] If no document found.
103
+ # @raise [ Errors::DocumentNotFound ] If no document found
104
+ # and Mongoid.raise_not_found_error is true.
102
105
  #
103
- # @return [ Document ] A matching document.
106
+ # @return [ Document, nil ] A matching document.
104
107
  #
105
108
  # @since 3.0.0
106
109
  def find_by(attrs = {})
107
- result = where(attrs).first
110
+ result = where(attrs).find_first
108
111
  if result.nil? && Mongoid.raise_not_found_error
109
112
  raise(Errors::DocumentNotFound.new(self, attrs))
110
113
  end
@@ -112,6 +115,25 @@ module Mongoid
112
115
  result
113
116
  end
114
117
 
118
+ # Find the first +Document+ given the conditions, or raises
119
+ # Mongoid::Errors::DocumentNotFound
120
+ #
121
+ # @example Find the document by attribute other than id
122
+ # Person.find_by(:username => "superuser")
123
+ #
124
+ # @param [ Hash ] attrs The attributes to check.
125
+ #
126
+ # @raise [ Errors::DocumentNotFound ] If no document found.
127
+ #
128
+ # @return [ Document ] A matching document.
129
+ #
130
+ def find_by!(attrs = {})
131
+ result = where(attrs).find_first
132
+ raise(Errors::DocumentNotFound.new(self, attrs)) unless result
133
+ yield(result) if result && block_given?
134
+ result
135
+ end
136
+
115
137
  # Find the first +Document+ given the conditions.
116
138
  #
117
139
  # @example Find the first document.
@@ -111,7 +111,8 @@ module Mongoid
111
111
  #
112
112
  # @since 4.0.0
113
113
  def prepare_insert(options = {})
114
- return self if performing_validations?(options) && invalid?(:create)
114
+ return self if performing_validations?(options) &&
115
+ invalid?(options[:context] || :create)
115
116
  result = run_callbacks(:save) do
116
117
  run_callbacks(:create) do
117
118
  yield(self)
@@ -22,7 +22,7 @@ module Mongoid
22
22
  def set(setters)
23
23
  prepare_atomic_operation do |ops|
24
24
  process_atomic_operations(setters) do |field, value|
25
- send("#{field}=", value)
25
+ process_attribute(field.to_s, value)
26
26
  ops[atomic_attribute_name(field)] = attributes[field]
27
27
  end
28
28
  { "$set" => ops }
@@ -110,7 +110,8 @@ module Mongoid
110
110
  #
111
111
  # @since 4.0.0
112
112
  def prepare_update(options = {})
113
- return false if performing_validations?(options) && invalid?(:update)
113
+ return false if performing_validations?(options) &&
114
+ invalid?(options[:context] || :update)
114
115
  process_flagged_destroys
115
116
  result = run_callbacks(:save) do
116
117
  run_callbacks(:update) do
@@ -98,6 +98,27 @@ module Mongoid
98
98
  find_or(:create, attrs, type, &block)
99
99
  end
100
100
 
101
+ # Find the first document given the conditions, or creates a new document
102
+ # with the conditions that were supplied. This will raise an error if validation fails.
103
+ #
104
+ # @example Find or create.
105
+ # person.posts.find_or_create_by!(:title => "Testing")
106
+ #
107
+ # @overload find_or_create_by!(attributes = nil, type = nil)
108
+ # @param [ Hash ] attributes The attributes to search or create with.
109
+ # @param [ Class ] type The optional type of document to create.
110
+ #
111
+ # @overload find_or_create_by!(attributes = nil, type = nil)
112
+ # @param [ Hash ] attributes The attributes to search or create with.
113
+ # @param [ Class ] type The optional type of document to create.
114
+ #
115
+ # @raise [ Errors::Validations ] If validation failed.
116
+ #
117
+ # @return [ Document ] An existing document or newly created one.
118
+ def find_or_create_by!(attrs = {}, type = nil, &block)
119
+ find_or(:create!, attrs, type, &block)
120
+ end
121
+
101
122
  # Find the first +Document+ given the conditions, or instantiates a new document
102
123
  # with the conditions that were supplied
103
124
  #
@@ -39,8 +39,13 @@ module Mongoid
39
39
 
40
40
  def mongo_session
41
41
  if persistence_options
42
- session_name = persistence_options[:session] || self.class.session_name
43
- Sessions.with_name(session_name).with(persistence_options)
42
+ if persistence_options[:session]
43
+ session = Sessions.with_name(persistence_options[:session])
44
+ else
45
+ session = Sessions.with_name(self.class.session_name)
46
+ session.use(self.class.database_name)
47
+ end
48
+ session.with(persistence_options)
44
49
  end
45
50
  end
46
51
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
- VERSION = "4.0.1"
3
+ VERSION = "4.0.2"
4
4
  end
@@ -27,6 +27,38 @@ development:
27
27
  # The time in seconds that Moped should wait before retrying an
28
28
  # operation on failure. (default: 0.25)
29
29
  # retry_interval: 0.25
30
+
31
+ # The connection pool size per-node. This should match or exceed the
32
+ # number of threads for a multi-threaded application. (default: 5)
33
+ # pool_size: 5
34
+
35
+ # The time in seconds that Moped should wait for the pool to provide
36
+ # an available connection. This number should probably remain at the
37
+ # default, unless for some reason you absolutely need to limit the
38
+ # pool_size, as this wait is only used when the pool is saturated.
39
+ # (default: 0.5)
40
+ # pool_timeout: 0.5
41
+
42
+ # The time in seconds before Moped will timeout connection and node
43
+ # operations. (default: 5)
44
+ # timeout: 5
45
+
46
+ # The amount of time in seconds between forced refreshes of node
47
+ # information including the discovery of new peers. (default: 300)
48
+ # refresh_interval: 300
49
+
50
+ # The amount of time in seconds that a node will be flagged as down.
51
+ # (default: 30)
52
+ # down_interval: 30
53
+
54
+ # Whether connections should use SSL. (default: nil/false)
55
+ # ssl: false
56
+
57
+ # Whether Moped will use the existing seeds/nodes to find other peers.
58
+ # (default: true)
59
+ # auto_discover: true
60
+
61
+
30
62
  # Configure Mongoid specific options. (optional)
31
63
  options:
32
64
  # Includes the root model name in json serialization. (default: false)
@@ -0,0 +1,5 @@
1
+ class ContextableItem
2
+ include Mongoid::Document
3
+ field :title
4
+ validates :title, presence: true, on: :in_context
5
+ end
@@ -55,7 +55,7 @@ describe Mongoid::Attributes::Nested do
55
55
 
56
56
  context "when the relation is an embeds one" do
57
57
 
58
- before(:all) do
58
+ before do
59
59
  Person.send(:undef_method, :name_attributes=)
60
60
  Person.accepts_nested_attributes_for :name
61
61
  end
@@ -71,7 +71,7 @@ describe Mongoid::Attributes::Nested do
71
71
 
72
72
  context "when the relation is an embeds many" do
73
73
 
74
- before(:all) do
74
+ before do
75
75
  Person.send(:undef_method, :addresses_attributes=)
76
76
  Person.accepts_nested_attributes_for :addresses
77
77
  end
@@ -104,7 +104,7 @@ describe Mongoid::Attributes::Nested do
104
104
 
105
105
  context "when the relation is an embedded in" do
106
106
 
107
- before(:all) do
107
+ before do
108
108
  Video.accepts_nested_attributes_for :person
109
109
  end
110
110
 
@@ -119,7 +119,7 @@ describe Mongoid::Attributes::Nested do
119
119
 
120
120
  context "when the relation is a references one" do
121
121
 
122
- before(:all) do
122
+ before do
123
123
  Person.send(:undef_method, :game_attributes=)
124
124
  Person.accepts_nested_attributes_for :game
125
125
  end
@@ -135,7 +135,7 @@ describe Mongoid::Attributes::Nested do
135
135
 
136
136
  context "when the relation is a references many" do
137
137
 
138
- before(:all) do
138
+ before do
139
139
  Person.send(:undef_method, :posts_attributes=)
140
140
  Person.accepts_nested_attributes_for :posts
141
141
  end
@@ -151,7 +151,7 @@ describe Mongoid::Attributes::Nested do
151
151
 
152
152
  context "when the relation is a references and referenced in many" do
153
153
 
154
- before(:all) do
154
+ before do
155
155
  Person.send(:undef_method, :preferences_attributes=)
156
156
  Person.accepts_nested_attributes_for :preferences
157
157
  end
@@ -167,7 +167,7 @@ describe Mongoid::Attributes::Nested do
167
167
 
168
168
  context "when the relation is a referenced in" do
169
169
 
170
- before(:all) do
170
+ before do
171
171
  Post.accepts_nested_attributes_for :person
172
172
  end
173
173
 
@@ -237,13 +237,13 @@ describe Mongoid::Attributes::Nested do
237
237
 
238
238
  context "when a reject proc is specified" do
239
239
 
240
- before(:all) do
240
+ before do
241
241
  Person.send(:undef_method, :name_attributes=)
242
242
  Person.accepts_nested_attributes_for \
243
243
  :name, reject_if: ->(attrs){ attrs[:first_name].blank? }
244
244
  end
245
245
 
246
- after(:all) do
246
+ after do
247
247
  Person.send(:undef_method, :name_attributes=)
248
248
  Person.accepts_nested_attributes_for :name
249
249
  end
@@ -275,13 +275,13 @@ describe Mongoid::Attributes::Nested do
275
275
 
276
276
  context "when the relation is not autobuilding" do
277
277
 
278
- before(:all) do
278
+ before do
279
279
  Person.send(:undef_method, :name_attributes=)
280
280
  Person.accepts_nested_attributes_for \
281
281
  :name, reject_if: :all_blank
282
282
  end
283
283
 
284
- after(:all) do
284
+ after do
285
285
  Person.send(:undef_method, :name_attributes=)
286
286
  Person.accepts_nested_attributes_for :name
287
287
  end
@@ -311,11 +311,11 @@ describe Mongoid::Attributes::Nested do
311
311
 
312
312
  context "when the relation is autobuilding" do
313
313
 
314
- before(:all) do
314
+ before do
315
315
  Product.accepts_nested_attributes_for :seo, reject_if: :all_blank
316
316
  end
317
317
 
318
- after(:all) do
318
+ after do
319
319
  Product.send(:undef_method, :seo_attributes=)
320
320
  end
321
321
 
@@ -349,12 +349,12 @@ describe Mongoid::Attributes::Nested do
349
349
 
350
350
  context "when allow_destroy is true" do
351
351
 
352
- before(:all) do
352
+ before do
353
353
  Person.send(:undef_method, :name_attributes=)
354
354
  Person.accepts_nested_attributes_for :name, allow_destroy: true
355
355
  end
356
356
 
357
- after(:all) do
357
+ after do
358
358
  Person.send(:undef_method, :name_attributes=)
359
359
  Person.accepts_nested_attributes_for :name
360
360
  end
@@ -384,12 +384,12 @@ describe Mongoid::Attributes::Nested do
384
384
 
385
385
  context "when allow_destroy is false" do
386
386
 
387
- before(:all) do
387
+ before do
388
388
  Person.send(:undef_method, :name_attributes=)
389
389
  Person.accepts_nested_attributes_for :name, allow_destroy: false
390
390
  end
391
391
 
392
- after(:all) do
392
+ after do
393
393
  Person.send(:undef_method, :name_attributes=)
394
394
  Person.accepts_nested_attributes_for :name
395
395
  end
@@ -433,12 +433,12 @@ describe Mongoid::Attributes::Nested do
433
433
 
434
434
  context "when allow_destroy is true" do
435
435
 
436
- before(:all) do
436
+ before do
437
437
  Person.send(:undef_method, :name_attributes=)
438
438
  Person.accepts_nested_attributes_for :name, allow_destroy: true
439
439
  end
440
440
 
441
- after(:all) do
441
+ after do
442
442
  Person.send(:undef_method, :name_attributes=)
443
443
  Person.accepts_nested_attributes_for :name
444
444
  end
@@ -455,12 +455,12 @@ describe Mongoid::Attributes::Nested do
455
455
 
456
456
  context "when allow_destroy is false" do
457
457
 
458
- before(:all) do
458
+ before do
459
459
  Person.send(:undef_method, :name_attributes=)
460
460
  Person.accepts_nested_attributes_for :name, allow_destroy: false
461
461
  end
462
462
 
463
- after(:all) do
463
+ after do
464
464
  Person.send(:undef_method, :name_attributes=)
465
465
  Person.accepts_nested_attributes_for :name
466
466
  end
@@ -518,12 +518,12 @@ describe Mongoid::Attributes::Nested do
518
518
 
519
519
  context "when allow_destroy is true" do
520
520
 
521
- before(:all) do
521
+ before do
522
522
  Person.send(:undef_method, :name_attributes=)
523
523
  Person.accepts_nested_attributes_for :name, allow_destroy: true
524
524
  end
525
525
 
526
- after(:all) do
526
+ after do
527
527
  Person.send(:undef_method, :name_attributes=)
528
528
  Person.accepts_nested_attributes_for :name
529
529
  end
@@ -546,11 +546,11 @@ describe Mongoid::Attributes::Nested do
546
546
 
547
547
  context "when the document has destroy callbacks" do
548
548
 
549
- before(:all) do
549
+ before do
550
550
  PetOwner.accepts_nested_attributes_for :pet, allow_destroy: true
551
551
  end
552
552
 
553
- after(:all) do
553
+ after do
554
554
  PetOwner.send(:undef_method, :pet_attributes=)
555
555
  end
556
556
 
@@ -596,12 +596,12 @@ describe Mongoid::Attributes::Nested do
596
596
 
597
597
  context "when allow destroy is false" do
598
598
 
599
- before(:all) do
599
+ before do
600
600
  Person.send(:undef_method, :name_attributes=)
601
601
  Person.accepts_nested_attributes_for :name, allow_destroy: false
602
602
  end
603
603
 
604
- after(:all) do
604
+ after do
605
605
  Person.send(:undef_method, :name_attributes=)
606
606
  Person.accepts_nested_attributes_for :name
607
607
  end
@@ -621,7 +621,7 @@ describe Mongoid::Attributes::Nested do
621
621
 
622
622
  context "when update only is true" do
623
623
 
624
- before(:all) do
624
+ before do
625
625
  Person.send(:undef_method, :name_attributes=)
626
626
  Person.accepts_nested_attributes_for \
627
627
  :name,
@@ -629,7 +629,7 @@ describe Mongoid::Attributes::Nested do
629
629
  allow_destroy: true
630
630
  end
631
631
 
632
- after(:all) do
632
+ after do
633
633
  Person.send(:undef_method, :name_attributes=)
634
634
  Person.accepts_nested_attributes_for :name
635
635
  end
@@ -693,11 +693,11 @@ describe Mongoid::Attributes::Nested do
693
693
 
694
694
  context "when the nested document is invalid" do
695
695
 
696
- before(:all) do
696
+ before do
697
697
  Person.validates_associated(:pet)
698
698
  end
699
699
 
700
- after(:all) do
700
+ after do
701
701
  Person.reset_callbacks(:validate)
702
702
  end
703
703
 
@@ -755,12 +755,12 @@ describe Mongoid::Attributes::Nested do
755
755
 
756
756
  context "when allow_destroy is true" do
757
757
 
758
- before(:all) do
758
+ before do
759
759
  Animal.send(:undef_method, :person_attributes=)
760
760
  Animal.accepts_nested_attributes_for :person, allow_destroy: true
761
761
  end
762
762
 
763
- after(:all) do
763
+ after do
764
764
  Animal.send(:undef_method, :person_attributes=)
765
765
  Animal.accepts_nested_attributes_for :person
766
766
  end
@@ -776,12 +776,12 @@ describe Mongoid::Attributes::Nested do
776
776
 
777
777
  context "when allow_destroy is false" do
778
778
 
779
- before(:all) do
779
+ before do
780
780
  Animal.send(:undef_method, :person_attributes=)
781
781
  Animal.accepts_nested_attributes_for :person, allow_destroy: false
782
782
  end
783
783
 
784
- after(:all) do
784
+ after do
785
785
  Animal.send(:undef_method, :person_attributes=)
786
786
  Animal.accepts_nested_attributes_for :person
787
787
  end
@@ -825,12 +825,12 @@ describe Mongoid::Attributes::Nested do
825
825
 
826
826
  context "when allow destroy is true" do
827
827
 
828
- before(:all) do
828
+ before do
829
829
  Animal.send(:undef_method, :person_attributes=)
830
830
  Animal.accepts_nested_attributes_for :person, allow_destroy: true
831
831
  end
832
832
 
833
- after(:all) do
833
+ after do
834
834
  Animal.send(:undef_method, :person_attributes=)
835
835
  Animal.accepts_nested_attributes_for :person
836
836
  end
@@ -868,12 +868,12 @@ describe Mongoid::Attributes::Nested do
868
868
 
869
869
  context "when allow destroy is false" do
870
870
 
871
- before(:all) do
871
+ before do
872
872
  Animal.send(:undef_method, :person_attributes=)
873
873
  Animal.accepts_nested_attributes_for :person, allow_destroy: false
874
874
  end
875
875
 
876
- after(:all) do
876
+ after do
877
877
  Animal.send(:undef_method, :person_attributes=)
878
878
  Animal.accepts_nested_attributes_for :person
879
879
  end
@@ -942,11 +942,11 @@ describe Mongoid::Attributes::Nested do
942
942
 
943
943
  context "when the nested document is invalid" do
944
944
 
945
- before(:all) do
945
+ before do
946
946
  Person.validates_format_of :ssn, without: /\$\$\$/
947
947
  end
948
948
 
949
- after(:all) do
949
+ after do
950
950
  Person.reset_callbacks(:validate)
951
951
  end
952
952
 
@@ -1041,12 +1041,12 @@ describe Mongoid::Attributes::Nested do
1041
1041
 
1042
1042
  context "when a limit is specified" do
1043
1043
 
1044
- before(:all) do
1044
+ before do
1045
1045
  Person.send(:undef_method, :addresses_attributes=)
1046
1046
  Person.accepts_nested_attributes_for :addresses, limit: 2
1047
1047
  end
1048
1048
 
1049
- after(:all) do
1049
+ after do
1050
1050
  Person.send(:undef_method, :addresses_attributes=)
1051
1051
  Person.accepts_nested_attributes_for :addresses
1052
1052
  end
@@ -1106,11 +1106,11 @@ describe Mongoid::Attributes::Nested do
1106
1106
 
1107
1107
  context "when cascading callbacks" do
1108
1108
 
1109
- before(:all) do
1109
+ before do
1110
1110
  Band.accepts_nested_attributes_for :records
1111
1111
  end
1112
1112
 
1113
- after(:all) do
1113
+ after do
1114
1114
  Band.send(:undef_method, :records_attributes=)
1115
1115
  end
1116
1116
 
@@ -1314,18 +1314,13 @@ describe Mongoid::Attributes::Nested do
1314
1314
 
1315
1315
  context "when the parent validation failed" do
1316
1316
 
1317
- before(:all) do
1318
- Band.validates_presence_of :name
1319
- Band.accepts_nested_attributes_for :records, :allow_destroy => true
1320
- end
1321
-
1322
- after(:all) do
1323
- Band.send(:undef_method, :records_attributes=)
1324
- Band.reset_callbacks(:validate)
1317
+ class BandWithAllowDestroyedRecords < Band
1318
+ validates_presence_of :name
1319
+ accepts_nested_attributes_for :records, :allow_destroy => true
1325
1320
  end
1326
1321
 
1327
1322
  let!(:band) do
1328
- Band.create(name: "Depeche Mode")
1323
+ BandWithAllowDestroyedRecords.create(name: "Depeche Mode")
1329
1324
  end
1330
1325
 
1331
1326
  let!(:record) do
@@ -1358,11 +1353,11 @@ describe Mongoid::Attributes::Nested do
1358
1353
 
1359
1354
  context "when the child accesses the parent after destroy" do
1360
1355
 
1361
- before(:all) do
1356
+ before do
1362
1357
  Band.accepts_nested_attributes_for :records, :allow_destroy => true
1363
1358
  end
1364
1359
 
1365
- after(:all) do
1360
+ after do
1366
1361
  Band.send(:undef_method, :records_attributes=)
1367
1362
  end
1368
1363
 
@@ -1391,11 +1386,11 @@ describe Mongoid::Attributes::Nested do
1391
1386
 
1392
1387
  context "when the child has defaults" do
1393
1388
 
1394
- before(:all) do
1389
+ before do
1395
1390
  Person.accepts_nested_attributes_for :appointments, allow_destroy: true
1396
1391
  end
1397
1392
 
1398
- after(:all) do
1393
+ after do
1399
1394
  Person.send(:undef_method, :appointments_attributes=)
1400
1395
  end
1401
1396
 
@@ -1470,12 +1465,12 @@ describe Mongoid::Attributes::Nested do
1470
1465
 
1471
1466
  context "when the child is not paranoid" do
1472
1467
 
1473
- before(:all) do
1468
+ before do
1474
1469
  Person.send(:undef_method, :addresses_attributes=)
1475
1470
  Person.accepts_nested_attributes_for :addresses, allow_destroy: true
1476
1471
  end
1477
1472
 
1478
- after(:all) do
1473
+ after do
1479
1474
  Person.send(:undef_method, :addresses_attributes=)
1480
1475
  Person.accepts_nested_attributes_for :addresses
1481
1476
  end
@@ -1675,12 +1670,12 @@ describe Mongoid::Attributes::Nested do
1675
1670
 
1676
1671
  context "when allow_destroy is false" do
1677
1672
 
1678
- before(:all) do
1673
+ before do
1679
1674
  Person.send(:undef_method, :addresses_attributes=)
1680
1675
  Person.accepts_nested_attributes_for :addresses, allow_destroy: false
1681
1676
  end
1682
1677
 
1683
- after(:all) do
1678
+ after do
1684
1679
  Person.send(:undef_method, :addresses_attributes=)
1685
1680
  Person.accepts_nested_attributes_for :addresses
1686
1681
  end
@@ -1737,7 +1732,7 @@ describe Mongoid::Attributes::Nested do
1737
1732
 
1738
1733
  context "when allow_destroy is undefined" do
1739
1734
 
1740
- before(:all) do
1735
+ before do
1741
1736
  Person.send(:undef_method, :addresses_attributes=)
1742
1737
  Person.accepts_nested_attributes_for :addresses
1743
1738
  end
@@ -1833,13 +1828,13 @@ describe Mongoid::Attributes::Nested do
1833
1828
 
1834
1829
  context "when a reject block is supplied" do
1835
1830
 
1836
- before(:all) do
1831
+ before do
1837
1832
  Person.send(:undef_method, :addresses_attributes=)
1838
1833
  Person.accepts_nested_attributes_for \
1839
1834
  :addresses, reject_if: ->(attrs){ attrs["street"].blank? }
1840
1835
  end
1841
1836
 
1842
- after(:all) do
1837
+ after do
1843
1838
  Person.send(:undef_method, :addresses_attributes=)
1844
1839
  Person.accepts_nested_attributes_for :addresses
1845
1840
  end
@@ -1875,13 +1870,13 @@ describe Mongoid::Attributes::Nested do
1875
1870
 
1876
1871
  context "when :reject_if => :all_blank is supplied" do
1877
1872
 
1878
- before(:all) do
1873
+ before do
1879
1874
  Person.send(:undef_method, :addresses_attributes=)
1880
1875
  Person.accepts_nested_attributes_for \
1881
1876
  :addresses, reject_if: :all_blank
1882
1877
  end
1883
1878
 
1884
- after(:all) do
1879
+ after do
1885
1880
  Person.send(:undef_method, :addresses_attributes=)
1886
1881
  Person.accepts_nested_attributes_for :addresses
1887
1882
  end
@@ -1919,12 +1914,12 @@ describe Mongoid::Attributes::Nested do
1919
1914
 
1920
1915
  context "when allow_destroy is true" do
1921
1916
 
1922
- before(:all) do
1917
+ before do
1923
1918
  Person.send(:undef_method, :addresses_attributes=)
1924
1919
  Person.accepts_nested_attributes_for :addresses, allow_destroy: true
1925
1920
  end
1926
1921
 
1927
- after(:all) do
1922
+ after do
1928
1923
  Person.send(:undef_method, :addresses_attributes=)
1929
1924
  Person.accepts_nested_attributes_for :addresses
1930
1925
  end
@@ -1980,12 +1975,12 @@ describe Mongoid::Attributes::Nested do
1980
1975
 
1981
1976
  context "when allow destroy is false" do
1982
1977
 
1983
- before(:all) do
1978
+ before do
1984
1979
  Person.send(:undef_method, :addresses_attributes=)
1985
1980
  Person.accepts_nested_attributes_for :addresses, allow_destroy: false
1986
1981
  end
1987
1982
 
1988
- after(:all) do
1983
+ after do
1989
1984
  Person.send(:undef_method, :addresses_attributes=)
1990
1985
  Person.accepts_nested_attributes_for :addresses
1991
1986
  end
@@ -2045,7 +2040,7 @@ describe Mongoid::Attributes::Nested do
2045
2040
 
2046
2041
  context "when allow destroy is not defined" do
2047
2042
 
2048
- before(:all) do
2043
+ before do
2049
2044
  Person.send(:undef_method, :addresses_attributes=)
2050
2045
  Person.accepts_nested_attributes_for :addresses
2051
2046
  end
@@ -2106,13 +2101,13 @@ describe Mongoid::Attributes::Nested do
2106
2101
 
2107
2102
  context "when 'reject_if: :all_blank' and 'allow_destroy: true' are specified" do
2108
2103
 
2109
- before(:all) do
2104
+ before do
2110
2105
  Person.send(:undef_method, :addresses_attributes=)
2111
2106
  Person.accepts_nested_attributes_for \
2112
2107
  :addresses, reject_if: :all_blank, allow_destroy: true
2113
2108
  end
2114
2109
 
2115
- after(:all) do
2110
+ after do
2116
2111
  Person.send(:undef_method, :addresses_attributes=)
2117
2112
  Person.accepts_nested_attributes_for :addresses
2118
2113
  end
@@ -2133,11 +2128,11 @@ describe Mongoid::Attributes::Nested do
2133
2128
 
2134
2129
  context "when the nested document is invalid" do
2135
2130
 
2136
- before(:all) do
2131
+ before do
2137
2132
  Person.validates_associated(:addresses)
2138
2133
  end
2139
2134
 
2140
- after(:all) do
2135
+ after do
2141
2136
  Person.reset_callbacks(:validate)
2142
2137
  end
2143
2138
 
@@ -2183,13 +2178,13 @@ describe Mongoid::Attributes::Nested do
2183
2178
 
2184
2179
  context "when a reject proc is specified" do
2185
2180
 
2186
- before(:all) do
2181
+ before do
2187
2182
  Person.send(:undef_method, :game_attributes=)
2188
2183
  Person.accepts_nested_attributes_for \
2189
2184
  :game, reject_if: ->(attrs){ attrs[:name].blank? }
2190
2185
  end
2191
2186
 
2192
- after(:all) do
2187
+ after do
2193
2188
  Person.send(:undef_method, :game_attributes=)
2194
2189
  Person.accepts_nested_attributes_for :game
2195
2190
  end
@@ -2219,13 +2214,13 @@ describe Mongoid::Attributes::Nested do
2219
2214
 
2220
2215
  context "when reject_if => :all_blank is specified" do
2221
2216
 
2222
- before(:all) do
2217
+ before do
2223
2218
  Person.send(:undef_method, :game_attributes=)
2224
2219
  Person.accepts_nested_attributes_for \
2225
2220
  :game, reject_if: :all_blank
2226
2221
  end
2227
2222
 
2228
- after(:all) do
2223
+ after do
2229
2224
  Person.send(:undef_method, :game_attributes=)
2230
2225
  Person.accepts_nested_attributes_for :game
2231
2226
  end
@@ -2270,12 +2265,12 @@ describe Mongoid::Attributes::Nested do
2270
2265
 
2271
2266
  context "when allow_destroy is true" do
2272
2267
 
2273
- before(:all) do
2268
+ before do
2274
2269
  Person.send(:undef_method, :game_attributes=)
2275
2270
  Person.accepts_nested_attributes_for :game, allow_destroy: true
2276
2271
  end
2277
2272
 
2278
- after(:all) do
2273
+ after do
2279
2274
  Person.send(:undef_method, :game_attributes=)
2280
2275
  Person.accepts_nested_attributes_for :game
2281
2276
  end
@@ -2291,12 +2286,12 @@ describe Mongoid::Attributes::Nested do
2291
2286
 
2292
2287
  context "when allow_destroy is false" do
2293
2288
 
2294
- before(:all) do
2289
+ before do
2295
2290
  Person.send(:undef_method, :game_attributes=)
2296
2291
  Person.accepts_nested_attributes_for :game, allow_destroy: false
2297
2292
  end
2298
2293
 
2299
- after(:all) do
2294
+ after do
2300
2295
  Person.send(:undef_method, :game_attributes=)
2301
2296
  Person.accepts_nested_attributes_for :game
2302
2297
  end
@@ -2356,12 +2351,12 @@ describe Mongoid::Attributes::Nested do
2356
2351
 
2357
2352
  context "when allow_destroy is true" do
2358
2353
 
2359
- before(:all) do
2354
+ before do
2360
2355
  Person.send(:undef_method, :game_attributes=)
2361
2356
  Person.accepts_nested_attributes_for :game, allow_destroy: true
2362
2357
  end
2363
2358
 
2364
- after(:all) do
2359
+ after do
2365
2360
  Person.send(:undef_method, :game_attributes=)
2366
2361
  Person.accepts_nested_attributes_for :game
2367
2362
  end
@@ -2378,12 +2373,12 @@ describe Mongoid::Attributes::Nested do
2378
2373
 
2379
2374
  context "when allow_destroy is false" do
2380
2375
 
2381
- before(:all) do
2376
+ before do
2382
2377
  Person.send(:undef_method, :game_attributes=)
2383
2378
  Person.accepts_nested_attributes_for :game, allow_destroy: false
2384
2379
  end
2385
2380
 
2386
- after(:all) do
2381
+ after do
2387
2382
  Person.send(:undef_method, :game_attributes=)
2388
2383
  Person.accepts_nested_attributes_for :game
2389
2384
  end
@@ -2441,12 +2436,12 @@ describe Mongoid::Attributes::Nested do
2441
2436
 
2442
2437
  context "when allow_destroy is true" do
2443
2438
 
2444
- before(:all) do
2439
+ before do
2445
2440
  Person.send(:undef_method, :game_attributes=)
2446
2441
  Person.accepts_nested_attributes_for :game, allow_destroy: true
2447
2442
  end
2448
2443
 
2449
- after(:all) do
2444
+ after do
2450
2445
  Person.send(:undef_method, :game_attributes=)
2451
2446
  Person.accepts_nested_attributes_for :game
2452
2447
  end
@@ -2484,12 +2479,12 @@ describe Mongoid::Attributes::Nested do
2484
2479
 
2485
2480
  context "when allow destroy is false" do
2486
2481
 
2487
- before(:all) do
2482
+ before do
2488
2483
  Person.send(:undef_method, :game_attributes=)
2489
2484
  Person.accepts_nested_attributes_for :game, allow_destroy: false
2490
2485
  end
2491
2486
 
2492
- after(:all) do
2487
+ after do
2493
2488
  Person.send(:undef_method, :game_attributes=)
2494
2489
  Person.accepts_nested_attributes_for :game
2495
2490
  end
@@ -2509,7 +2504,7 @@ describe Mongoid::Attributes::Nested do
2509
2504
 
2510
2505
  context "when update only is true" do
2511
2506
 
2512
- before(:all) do
2507
+ before do
2513
2508
  Person.send(:undef_method, :game_attributes=)
2514
2509
  Person.accepts_nested_attributes_for \
2515
2510
  :game,
@@ -2517,7 +2512,7 @@ describe Mongoid::Attributes::Nested do
2517
2512
  allow_destroy: true
2518
2513
  end
2519
2514
 
2520
- after(:all) do
2515
+ after do
2521
2516
  Person.send(:undef_method, :game_attributes=)
2522
2517
  Person.accepts_nested_attributes_for :game
2523
2518
  end
@@ -2564,11 +2559,11 @@ describe Mongoid::Attributes::Nested do
2564
2559
 
2565
2560
  context "when the nested document is invalid" do
2566
2561
 
2567
- before(:all) do
2562
+ before do
2568
2563
  Person.validates_associated(:game)
2569
2564
  end
2570
2565
 
2571
- after(:all) do
2566
+ after do
2572
2567
  Person.reset_callbacks(:validate)
2573
2568
  end
2574
2569
 
@@ -2626,12 +2621,12 @@ describe Mongoid::Attributes::Nested do
2626
2621
 
2627
2622
  context "when allow_destroy is true" do
2628
2623
 
2629
- before(:all) do
2624
+ before do
2630
2625
  Game.send(:undef_method, :person_attributes=)
2631
2626
  Game.accepts_nested_attributes_for :person, allow_destroy: true
2632
2627
  end
2633
2628
 
2634
- after(:all) do
2629
+ after do
2635
2630
  Game.send(:undef_method, :person_attributes=)
2636
2631
  Game.accepts_nested_attributes_for :person
2637
2632
  end
@@ -2647,12 +2642,12 @@ describe Mongoid::Attributes::Nested do
2647
2642
 
2648
2643
  context "when allow_destroy is false" do
2649
2644
 
2650
- before(:all) do
2645
+ before do
2651
2646
  Game.send(:undef_method, :person_attributes=)
2652
2647
  Game.accepts_nested_attributes_for :person, allow_destroy: false
2653
2648
  end
2654
2649
 
2655
- after(:all) do
2650
+ after do
2656
2651
  Game.send(:undef_method, :person_attributes=)
2657
2652
  Game.accepts_nested_attributes_for :person
2658
2653
  end
@@ -2696,12 +2691,12 @@ describe Mongoid::Attributes::Nested do
2696
2691
 
2697
2692
  context "when allow destroy is true" do
2698
2693
 
2699
- before(:all) do
2694
+ before do
2700
2695
  Game.send(:undef_method, :person_attributes=)
2701
2696
  Game.accepts_nested_attributes_for :person, allow_destroy: true
2702
2697
  end
2703
2698
 
2704
- after(:all) do
2699
+ after do
2705
2700
  Game.send(:undef_method, :person_attributes=)
2706
2701
  Game.accepts_nested_attributes_for :person
2707
2702
  end
@@ -2739,12 +2734,12 @@ describe Mongoid::Attributes::Nested do
2739
2734
 
2740
2735
  context "when allow destroy is false" do
2741
2736
 
2742
- before(:all) do
2737
+ before do
2743
2738
  Game.send(:undef_method, :person_attributes=)
2744
2739
  Game.accepts_nested_attributes_for :person, allow_destroy: false
2745
2740
  end
2746
2741
 
2747
- after(:all) do
2742
+ after do
2748
2743
  Game.send(:undef_method, :person_attributes=)
2749
2744
  Game.accepts_nested_attributes_for :person
2750
2745
  end
@@ -2813,11 +2808,11 @@ describe Mongoid::Attributes::Nested do
2813
2808
 
2814
2809
  context "when the nested document is invalid" do
2815
2810
 
2816
- before(:all) do
2811
+ before do
2817
2812
  Person.validates_format_of :ssn, without: /\$\$\$/
2818
2813
  end
2819
2814
 
2820
- after(:all) do
2815
+ after do
2821
2816
  Person.reset_callbacks(:validate)
2822
2817
  end
2823
2818
 
@@ -2866,12 +2861,12 @@ describe Mongoid::Attributes::Nested do
2866
2861
 
2867
2862
  context "when a limit is specified" do
2868
2863
 
2869
- before(:all) do
2864
+ before do
2870
2865
  Person.send(:undef_method, :posts_attributes=)
2871
2866
  Person.accepts_nested_attributes_for :posts, limit: 2
2872
2867
  end
2873
2868
 
2874
- after(:all) do
2869
+ after do
2875
2870
  Person.send(:undef_method, :posts_attributes=)
2876
2871
  Person.accepts_nested_attributes_for :posts
2877
2872
  end
@@ -3141,12 +3136,12 @@ describe Mongoid::Attributes::Nested do
3141
3136
 
3142
3137
  context "when allow_destroy is undefined" do
3143
3138
 
3144
- before(:all) do
3139
+ before do
3145
3140
  Person.send(:undef_method, :posts_attributes=)
3146
3141
  Person.accepts_nested_attributes_for :posts
3147
3142
  end
3148
3143
 
3149
- after(:all) do
3144
+ after do
3150
3145
  Person.send(:undef_method, :posts_attributes=)
3151
3146
  Person.accepts_nested_attributes_for :posts
3152
3147
  end
@@ -3294,13 +3289,13 @@ describe Mongoid::Attributes::Nested do
3294
3289
 
3295
3290
  context "when a reject block is supplied" do
3296
3291
 
3297
- before(:all) do
3292
+ before do
3298
3293
  Person.send(:undef_method, :posts_attributes=)
3299
3294
  Person.accepts_nested_attributes_for \
3300
3295
  :posts, reject_if: ->(attrs){ attrs["title"].blank? }
3301
3296
  end
3302
3297
 
3303
- after(:all) do
3298
+ after do
3304
3299
  Person.send(:undef_method, :posts_attributes=)
3305
3300
  Person.accepts_nested_attributes_for :posts
3306
3301
  end
@@ -3336,13 +3331,13 @@ describe Mongoid::Attributes::Nested do
3336
3331
 
3337
3332
  context "when :reject_if => :all_blank is supplied" do
3338
3333
 
3339
- before(:all) do
3334
+ before do
3340
3335
  Person.send(:undef_method, :posts_attributes=)
3341
3336
  Person.accepts_nested_attributes_for \
3342
3337
  :posts, reject_if: :all_blank
3343
3338
  end
3344
3339
 
3345
- after(:all) do
3340
+ after do
3346
3341
  Person.send(:undef_method, :posts_attributes=)
3347
3342
  Person.accepts_nested_attributes_for :posts
3348
3343
  end
@@ -3380,12 +3375,12 @@ describe Mongoid::Attributes::Nested do
3380
3375
 
3381
3376
  context "when allow_destroy is true" do
3382
3377
 
3383
- before(:all) do
3378
+ before do
3384
3379
  Person.send(:undef_method, :posts_attributes=)
3385
3380
  Person.accepts_nested_attributes_for :posts, allow_destroy: true
3386
3381
  end
3387
3382
 
3388
- after(:all) do
3383
+ after do
3389
3384
  Person.send(:undef_method, :posts_attributes=)
3390
3385
  Person.accepts_nested_attributes_for :posts
3391
3386
  end
@@ -3441,12 +3436,12 @@ describe Mongoid::Attributes::Nested do
3441
3436
 
3442
3437
  context "when allow destroy is false" do
3443
3438
 
3444
- before(:all) do
3439
+ before do
3445
3440
  Person.send(:undef_method, :posts_attributes=)
3446
3441
  Person.accepts_nested_attributes_for :posts, allow_destroy: false
3447
3442
  end
3448
3443
 
3449
- after(:all) do
3444
+ after do
3450
3445
  Person.send(:undef_method, :posts_attributes=)
3451
3446
  Person.accepts_nested_attributes_for :posts
3452
3447
  end
@@ -3506,7 +3501,7 @@ describe Mongoid::Attributes::Nested do
3506
3501
 
3507
3502
  context "when allow destroy is not defined" do
3508
3503
 
3509
- before(:all) do
3504
+ before do
3510
3505
  Person.send(:undef_method, :posts_attributes=)
3511
3506
  Person.accepts_nested_attributes_for :posts
3512
3507
  end
@@ -3568,11 +3563,11 @@ describe Mongoid::Attributes::Nested do
3568
3563
 
3569
3564
  context "when the nested document is invalid" do
3570
3565
 
3571
- before(:all) do
3566
+ before do
3572
3567
  Person.validates_associated(:posts)
3573
3568
  end
3574
3569
 
3575
- after(:all) do
3570
+ after do
3576
3571
  Person.reset_callbacks(:validate)
3577
3572
  end
3578
3573
 
@@ -3626,12 +3621,12 @@ describe Mongoid::Attributes::Nested do
3626
3621
 
3627
3622
  context "when a limit is specified" do
3628
3623
 
3629
- before(:all) do
3624
+ before do
3630
3625
  Person.send(:undef_method, :preferences_attributes=)
3631
3626
  Person.accepts_nested_attributes_for :preferences, limit: 2
3632
3627
  end
3633
3628
 
3634
- after(:all) do
3629
+ after do
3635
3630
  Person.send(:undef_method, :preferences_attributes=)
3636
3631
  Person.accepts_nested_attributes_for :preferences
3637
3632
  end
@@ -3727,12 +3722,12 @@ describe Mongoid::Attributes::Nested do
3727
3722
 
3728
3723
  context "when allow_destroy is true" do
3729
3724
 
3730
- before(:all) do
3725
+ before do
3731
3726
  Person.send(:undef_method, :preferences_attributes=)
3732
3727
  Person.accepts_nested_attributes_for :preferences, allow_destroy: true
3733
3728
  end
3734
3729
 
3735
- after(:all) do
3730
+ after do
3736
3731
  Person.send(:undef_method, :preferences_attributes=)
3737
3732
  Person.accepts_nested_attributes_for :preferences
3738
3733
  end
@@ -3790,12 +3785,12 @@ describe Mongoid::Attributes::Nested do
3790
3785
 
3791
3786
  context "when allow_destroy is false" do
3792
3787
 
3793
- before(:all) do
3788
+ before do
3794
3789
  Person.send(:undef_method, :preferences_attributes=)
3795
3790
  Person.accepts_nested_attributes_for :preferences, allow_destroy: false
3796
3791
  end
3797
3792
 
3798
- after(:all) do
3793
+ after do
3799
3794
  Person.send(:undef_method, :preferences_attributes=)
3800
3795
  Person.accepts_nested_attributes_for :preferences
3801
3796
  end
@@ -3858,7 +3853,7 @@ describe Mongoid::Attributes::Nested do
3858
3853
 
3859
3854
  context "when allow_destroy is undefined" do
3860
3855
 
3861
- before(:all) do
3856
+ before do
3862
3857
  Person.send(:undef_method, :preferences_attributes=)
3863
3858
  Person.accepts_nested_attributes_for :preferences
3864
3859
  end
@@ -3960,13 +3955,13 @@ describe Mongoid::Attributes::Nested do
3960
3955
 
3961
3956
  context "when a reject block is supplied" do
3962
3957
 
3963
- before(:all) do
3958
+ before do
3964
3959
  Person.send(:undef_method, :preferences_attributes=)
3965
3960
  Person.accepts_nested_attributes_for \
3966
3961
  :preferences, reject_if: ->(attrs){ attrs["name"].blank? }
3967
3962
  end
3968
3963
 
3969
- after(:all) do
3964
+ after do
3970
3965
  Person.send(:undef_method, :preferences_attributes=)
3971
3966
  Person.accepts_nested_attributes_for :preferences
3972
3967
  end
@@ -4002,13 +3997,13 @@ describe Mongoid::Attributes::Nested do
4002
3997
 
4003
3998
  context "when :reject_if => :all_blank is supplied" do
4004
3999
 
4005
- before(:all) do
4000
+ before do
4006
4001
  Person.send(:undef_method, :preferences_attributes=)
4007
4002
  Person.accepts_nested_attributes_for \
4008
4003
  :preferences, reject_if: :all_blank
4009
4004
  end
4010
4005
 
4011
- after(:all) do
4006
+ after do
4012
4007
  Person.send(:undef_method, :preferences_attributes=)
4013
4008
  Person.accepts_nested_attributes_for :preferences
4014
4009
  end
@@ -4046,12 +4041,12 @@ describe Mongoid::Attributes::Nested do
4046
4041
 
4047
4042
  context "when allow_destroy is true" do
4048
4043
 
4049
- before(:all) do
4044
+ before do
4050
4045
  Person.send(:undef_method, :preferences_attributes=)
4051
4046
  Person.accepts_nested_attributes_for :preferences, allow_destroy: true
4052
4047
  end
4053
4048
 
4054
- after(:all) do
4049
+ after do
4055
4050
  Person.send(:undef_method, :preferences_attributes=)
4056
4051
  Person.accepts_nested_attributes_for :preferences
4057
4052
  end
@@ -4107,12 +4102,12 @@ describe Mongoid::Attributes::Nested do
4107
4102
 
4108
4103
  context "when allow destroy is false" do
4109
4104
 
4110
- before(:all) do
4105
+ before do
4111
4106
  Person.send(:undef_method, :preferences_attributes=)
4112
4107
  Person.accepts_nested_attributes_for :preferences, allow_destroy: false
4113
4108
  end
4114
4109
 
4115
- after(:all) do
4110
+ after do
4116
4111
  Person.send(:undef_method, :preferences_attributes=)
4117
4112
  Person.accepts_nested_attributes_for :preferences
4118
4113
  end
@@ -4172,7 +4167,7 @@ describe Mongoid::Attributes::Nested do
4172
4167
 
4173
4168
  context "when allow destroy is not defined" do
4174
4169
 
4175
- before(:all) do
4170
+ before do
4176
4171
  Person.send(:undef_method, :preferences_attributes=)
4177
4172
  Person.accepts_nested_attributes_for :preferences
4178
4173
  end
@@ -4234,11 +4229,11 @@ describe Mongoid::Attributes::Nested do
4234
4229
 
4235
4230
  context "when the nested document is invalid" do
4236
4231
 
4237
- before(:all) do
4232
+ before do
4238
4233
  Person.validates_associated(:preferences)
4239
4234
  end
4240
4235
 
4241
- after(:all) do
4236
+ after do
4242
4237
  Person.reset_callbacks(:validate)
4243
4238
  end
4244
4239
 
@@ -4259,7 +4254,7 @@ describe Mongoid::Attributes::Nested do
4259
4254
 
4260
4255
  describe "#update_attributes" do
4261
4256
 
4262
- before(:all) do
4257
+ before do
4263
4258
  Person.send(:undef_method, :addresses_attributes=)
4264
4259
  Person.accepts_nested_attributes_for :addresses
4265
4260
  end
@@ -4348,7 +4343,7 @@ describe Mongoid::Attributes::Nested do
4348
4343
 
4349
4344
  context "when nesting multiple levels and parent is timestamped" do
4350
4345
 
4351
- before(:all) do
4346
+ before do
4352
4347
  class Address
4353
4348
  after_save do
4354
4349
  addressable.touch
@@ -4356,7 +4351,7 @@ describe Mongoid::Attributes::Nested do
4356
4351
  end
4357
4352
  end
4358
4353
 
4359
- after(:all) do
4354
+ after do
4360
4355
  Address.reset_callbacks(:save)
4361
4356
  end
4362
4357
 
@@ -4452,12 +4447,12 @@ describe Mongoid::Attributes::Nested do
4452
4447
 
4453
4448
  context "when cascading callbacks" do
4454
4449
 
4455
- before(:all) do
4450
+ before do
4456
4451
  Band.accepts_nested_attributes_for :records
4457
4452
  Record.accepts_nested_attributes_for :tracks, allow_destroy: true
4458
4453
  end
4459
4454
 
4460
- after(:all) do
4455
+ after do
4461
4456
  Band.send(:undef_method, :records_attributes=)
4462
4457
  Record.send(:undef_method, :tracks_attributes=)
4463
4458
  end