Looking for love for my patch correcting behavior of composed_of with allow_nil => true. This patch, in various forms from various authors, has been around for over a year. It has never been accepted into core due to a lack of tests. Well, I''ve now added the failing tests and the patch against edge that fixes it. I''d like someone else to test my patch and get this damn thing into trunk -I''m tired of rewriting the patch every couple of months. NB: Without this patch, the documentation is wrong as well.>From my ticket:Since composed_of added support for the allow_nil option ([4353]), it has always had a documented defect when assigning nil to the aggregate object. You can see documentation of the defect and a suggested (but now outdated) fix on #5091. This defect was later corrected in a more ambitious patch by a different author in #6322. That patch too has now become outdated - even though I updated it once. This ticket provides a simple patch and failing test that only seeks to correct the defect, which is as follows: class Place composed_of :location, :allow_nil => true end myplace.location @ => #<Location:0x3bf8 @lat=30, @alt=nil, @lon=40> myplace.lat # => 30 myplace.lon # => 40 myplace.alt # => nil myplace.location = nil myplace.lat # => nil (good...) myplace.lon # => nil (good...) myplace.alt # => nil (looking good...) myplace.location @ => #<Location:0x3bf8 @lat=30, @alt=nil, @lon=40> (whoops!! what happened?) Clearly, assigning nil to the aggregate object should result in its value being nil. In the current code, this only happens after a save/ find cycle. My patch makes it immediate, which is consistent with non- nil value object assignment behavior (and common sense). --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Chris Cruft
2007-Oct-13 13:27 UTC
Re: Nil assignment doesn''t result in nil aggregate object
It probably would have helped if I had mentioned the new ticket: It is ticket #9843 http://dev.rubyonrails.org/ticket/9843 -Chris On Oct 12, 10:05 am, Chris Cruft <c...@hapgoods.com> wrote:> Looking for love for my patch correcting behavior of composed_of with > allow_nil => true. This patch, in various forms from various authors, > has been around for over a year. It has never been accepted into core > due to a lack of tests. Well, I''ve now added the failing tests and > the patch against edge that fixes it. > > I''d like someone else to test my patch and get this damn thing into > trunk -I''m tired of rewriting the patch every couple of months. > > NB: Without this patch, the documentation is wrong as well. > > >From my ticket: > > Since composed_of added support for the allow_nil option ([4353]), it > has always had a documented defect when assigning nil to the aggregate > object. You can see documentation of the defect and a suggested (but > now outdated) fix on #5091. > > This defect was later corrected in a more ambitious patch by a > different author in #6322. That patch too has now become outdated - > even though I updated it once. > > This ticket provides a simple patch and failing test that only seeks > to correct the defect, which is as follows: > > class Place > composed_of :location, :allow_nil => true > end > > myplace.location @ => #<Location:0x3bf8 @lat=30, @alt=nil, @lon=40> > myplace.lat # => 30 > myplace.lon # => 40 > myplace.alt # => nil > myplace.location = nil > myplace.lat # => nil (good...) > myplace.lon # => nil (good...) > myplace.alt # => nil (looking good...) > myplace.location @ => #<Location:0x3bf8 @lat=30, @alt=nil, @lon=40> > (whoops!! what happened?) > > Clearly, assigning nil to the aggregate object should result in its > value being nil. In the current code, this only happens after a save/ > find cycle. My patch makes it immediate, which is consistent with non- > nil value object assignment behavior (and common sense).--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---