File tree Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -173,13 +173,14 @@ def as_document
173
173
#
174
174
# @param [ Hash ] options The options.
175
175
#
176
- # @option options [ true, false ] :compact Whether to include fields with
177
- # nil values in the json document.
176
+ # @option options [ true, false ] :compact (Deprecated) Whether to include fields
177
+ # with nil values in the json document.
178
178
#
179
179
# @return [ Hash ] The document as json.
180
180
def as_json ( options = nil )
181
181
rv = super
182
182
if options && options [ :compact ]
183
+ Mongoid . logger . warn ( '#as_json :compact option is deprecated. Please call #compact on the returned Hash object instead.' )
183
184
rv = rv . compact
184
185
end
185
186
rv
Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ def shard_collections(models = ::Mongoid.models)
118
118
next if model . shard_config . nil?
119
119
120
120
if model . embedded? && !model . cyclic?
121
- logger . warn ( "MONGOID: #{ model } has shard config but is emdedded " )
121
+ logger . warn ( "MONGOID: #{ model } has shard config but is embedded " )
122
122
next
123
123
end
124
124
Original file line number Diff line number Diff line change @@ -500,7 +500,7 @@ class << self; attr_accessor :name; end
500
500
end
501
501
end
502
502
503
- context ':compact option' do
503
+ context 'deprecated :compact option' do
504
504
# Since rails 6 differs in how it treats id fields,
505
505
# run this test on one version of rails. Currently rails 6 is in beta,
506
506
# when it is released this version should be changed to 6.
@@ -512,6 +512,26 @@ class << self; attr_accessor :name; end
512
512
expect ( church . as_json . keys . sort ) . to eq ( %w( _id location name ) )
513
513
end
514
514
515
+ context 'deprecation' do
516
+ let ( :church ) do
517
+ Church . create! ( name : 'St. Basil' )
518
+ end
519
+
520
+ let ( :message ) do
521
+ '#as_json :compact option is deprecated. Please call #compact on the returned Hash object instead.'
522
+ end
523
+
524
+ it 'logs a deprecation warning when :compact is given' do
525
+ expect_any_instance_of ( Logger ) . to receive ( :warn ) . with ( message )
526
+ church . as_json ( compact : true )
527
+ end
528
+
529
+ it 'does not log a deprecation warning when :compact is not given' do
530
+ expect_any_instance_of ( Logger ) . to_not receive ( :warn ) . with ( message )
531
+ church . as_json
532
+ end
533
+ end
534
+
515
535
context 'there is a nil valued attribute' do
516
536
let ( :church ) do
517
537
Church . create! ( name : 'St. Basil' )
You can’t perform that action at this time.
0 commit comments