Hey Brandon,
I just figured out why this isn't breaking any test, you fixed it. :-)
Probably not intentionally but here's the commit:
https://github.com/jnunemaker/mongomapper/commit/afecd0c58b746d64241fb0f44235391132ad28c8
Undo that commit and write a test like below and you can easily see
the failure. The reason it was failing was, the previous commit now
doesn't even write to the document if the attribute is null, where in
the past, it would write "name : null" into the doc.
So the previous commit I cited was the problem per-se, but it was a
bummer that a test didn't fail because of it. I can write some tests
to characterize this failure if you want and submit a pull request.
Any chance we can get a 0.9.3 with this fix?
Thanks!
context "#reload" do
should "work" do
doc = ScottDoc.new
doc.name = "scott"
doc.save!
another_doc = ScottDoc.find(
doc.id)
another_doc.name.should ==
doc.name
doc.name = nil
doc.save!
another_doc.reload
another_doc.name.should be_nil
end
end
On Sep 21, 8:56 am, Brandon Keepers <
bran...@opensoul.org> wrote:
> Thanks for uncovering this. None of the tests are failing. Want to see if you can produce a failing test and we'll get this fixed up?
>
> =b
>
>
>
> On Friday, September 16, 2011 at 4:48 PM, Jamie Orchard-Hays wrote:
> > Looking at that code...
>
> > The new code calls select() on the Hash, which returns an Array of Arrays (pairs). Then each_pair() is called on that.
>
> > However, each_pair is NOT a method on Array.
>
> > Looks like a bug. Is there a test covering this?
>
> > Jamie
>
> > On Sep 16, 2011, at 4:13 PM, Scott Tamosunas wrote:
>
> > > I haven't determined why yet, but it seems to be related to this
> > > commit:
>
> > >
https://github.com/jnunemaker/mongomapper/commit/5957d7ec285ff657f05c...
>
> > > When I revert this, the problem goes away. Seems kinda odd this only
> > > happens when in a Rails app.
>
> > > Scott
>
> > > On Sep 16, 2:16 pm, Scott Tamosunas <
tamosu...@gmail.com (
http://gmail.com)> wrote:
> > > > It looks like this behavior was introduced in 0.9.2, I don't see this
> > > > problem with 0.9.1.
>
> > > > Scott
>
> > > > On Sep 16, 11:03 am, Scott Tamosunas <
tamosu...@gmail.com (
http://gmail.com)> wrote:
>
> > > > > I created a simple rails app (3.0.4) and ran the following code from
> > > > > the console:
>
> > > > > MongoMapper.database = 'scott_testing'
>
> > > > > class ScottDoc
> > > > > include MongoMapper::Document
>
> > > > > key :name, String
> > > > > end
>
> > > > > #Create a doc with the name set to 'scott'
> > > > > sdoc = ScottDoc.new
> > > > >
sdoc.name (
http://sdoc.name) = "scott"
> > > > > sdoc.save!
>
> > > > > #Get another copy of the doc
> > > > > another_sdoc = ScottDoc.find(
sdoc.id)
>
> > > > > #Set the original doc name to nil and save
> > > > >
sdoc.name (
http://sdoc.name) = nil
> > > > > sdoc.save!
>
> > > > > #Reload the another doc to get the latest data from the DB
> > > > > p another_sdoc.reload #expect
another_sdoc.name (
http://another_sdoc.name) to be nil, but it's
> > > > > 'scott' - INCORRECT
>
> > > > > However, if I run the same code as just a straight ruby app like so,
> > > > > it works.
>
> > > > > require 'rubygems'
> > > > > require 'mongo_mapper'
> > > > > require 'pp'
>
> > > > > MongoMapper.database = 'scott_testing'
>
> > > > > class ScottDoc
> > > > > include MongoMapper::Document
>
> > > > > key :name, String
>
> > > > > end
>
> > > > > #Create a doc with the name set to 'scott'
> > > > > sdoc = ScottDoc.new
> > > > >
sdoc.name (
http://sdoc.name) = "scott"
> > > > > sdoc.save!
>
> > > > > #Get another copy of the doc
> > > > > another_sdoc = ScottDoc.find(
sdoc.id)
>
> > > > > #Set the original doc name to nil and save
> > > > >
sdoc.name (
http://sdoc.name) = nil