@@ -188,4 +188,64 @@ class WithValidationParent < CouchbaseOrm::Base
188188 expect ( obj . child . child . errors [ :name ] ) . to eq [ "can't be blank" ]
189189 end
190190 end
191+
192+ describe "Ignored Properties" do
193+ class SubTypeWithIgnoredProperties < CouchbaseOrm ::NestedDocument
194+ self . ignored_properties = [ :deprecated_property ]
195+ attribute :name , :string
196+ attribute :value , :string
197+ end
198+
199+ class ParentWithNestedIgnoredProperties < CouchbaseOrm ::Base
200+ self . ignored_properties = [ :deprecated_at_root ]
201+ attribute :title , :string
202+ attribute :nested , :nested , type : SubTypeWithIgnoredProperties
203+ end
204+
205+ it "should ignore deprecated properties in nested documents on reload" do
206+ # Create and save a parent with nested document
207+ parent = ParentWithNestedIgnoredProperties . new
208+ parent . title = "Test Parent"
209+ parent . nested = SubTypeWithIgnoredProperties . new ( name : "Nested" , value : "Valid" )
210+ parent . save!
211+
212+ # Manually add a deprecated property to the nested document in the database
213+ doc_id = parent . id
214+ raw_doc = ParentWithNestedIgnoredProperties . bucket . default_collection . get ( doc_id ) . content
215+ raw_doc [ "nested" ] [ "deprecated_property" ] = "This should be ignored"
216+ ParentWithNestedIgnoredProperties . bucket . default_collection . replace ( doc_id , raw_doc )
217+
218+ # Reload the parent
219+ parent . reload
220+
221+ # The deprecated property should NOT be present in the nested document
222+ expect ( parent . nested . attributes . keys ) . not_to include ( "deprecated_property" )
223+ expect ( parent . nested . name ) . to eq ( "Nested" )
224+ expect ( parent . nested . value ) . to eq ( "Valid" )
225+ end
226+
227+ it "should ignore deprecated properties in deeply nested documents" do
228+ # Create a parent with nested documents that have a child
229+ parent = ParentWithNestedIgnoredProperties . new
230+ parent . title = "Test Parent"
231+ parent . nested = SubTypeWithIgnoredProperties . new ( name : "Parent Nested" , value : "Parent Value" )
232+ parent . save!
233+
234+ # Manually add deprecated properties at multiple levels
235+ doc_id = parent . id
236+ raw_doc = ParentWithNestedIgnoredProperties . bucket . default_collection . get ( doc_id ) . content
237+ raw_doc [ "deprecated_at_root" ] = "Should be ignored at root level"
238+ raw_doc [ "nested" ] [ "deprecated_property" ] = "Should be ignored in nested"
239+ ParentWithNestedIgnoredProperties . bucket . default_collection . replace ( doc_id , raw_doc )
240+
241+ # Reload the parent
242+ parent . reload
243+
244+ # Deprecated properties should not be present at any level
245+ expect ( parent . attributes . keys ) . not_to include ( "deprecated_at_root" )
246+ expect ( parent . nested . attributes . keys ) . not_to include ( "deprecated_property" )
247+ expect ( parent . nested . name ) . to eq ( "Parent Nested" )
248+ expect ( parent . nested . value ) . to eq ( "Parent Value" )
249+ end
250+ end
191251end
0 commit comments