#1048 ✓resolved
mpd

Tests and (merb) controllers + belongs_to = red

Reported by mpd | September 19th, 2009 @ 03:27 AM | in 1.0.0

In a test, set a nullable belongs_to field to nil in a model via update, then request a controller action that sets that same field.

For the object within the controller, the field will show up as being set and remains set if you reload, as expected.

The object within the test, if you inspect it after that controller request, will still show nil in that field, even if reloaded.

The two objects do have different object ids.

Running on rspec 1.2.8 with sqlite3 database.


  belongs_to :foo, :nullable => true

  it "should set the foo attribute" do
    @instance.update(:foo => nil)
    request(url(:action_that_sets_foo), :method => 'POST', :params => {:instance => @instance})
    @instance.foo.reload.should_not be_nil # fails
  end

Comments and changes to this ticket

  • mpd

    mpd September 19th, 2009 @ 04:01 AM

    • Tag changed from 0.10.0, merb, merb_datamapper, specs, sqlite3, tests to 0.10.0, belo, belongs_to, merb, merb_datamapper, specs, sqlite3, tests
  • mpd

    mpd September 19th, 2009 @ 04:01 AM

    • Tag changed from 0.10.0, belo, belongs_to, merb, merb_datamapper, specs, sqlite3, tests to 0.10.0, belongs_to, merb, merb_datamapper, specs, sqlite3, tests
  • mpd

    mpd September 19th, 2009 @ 03:46 PM

    I just pushed a toy merb project containing a single spec that demonstrates this issue to http://github.com/xxx/dm10-controller-test

    The failure only happens if the association was originally set within the test itself, then nullified, also within the test (which can happen when using sweatshop with a reasonably factored test suite).

  • mpd

    mpd September 22nd, 2009 @ 03:10 PM

    This makes sense, and thanks for checking this. This is the major showstopper for me on 0.10.0 right now (the rest can be worked around).

    I will try putting your before/after repository set in and report the results here when I get home. All of these specs passed on 0.9.11.

  • mpd

    mpd September 22nd, 2009 @ 08:44 PM

    This greened around 25% of my remaining test failures, thank you!

    It didn't solve it in every case, however, which seems strange. I still have about 70 failing specs, though, so maybe something else is involved. Will keep digging and update this if I find anything.

  • mpd

    mpd September 23rd, 2009 @ 11:05 AM

    Some of them are. Often it's coming up that when I think I fix a spec, it still fails, but with a new error. Now, #1057 and #1058 are in my way. One step at a time, I guess ;)

  • mpd

    mpd September 25th, 2009 @ 08:11 PM

    Will do.

    I also originally had the issue where one thing would break many, many specs, but I'm getting to the one-offs now, and it's always a bit brutal when that happens ;)

    thanks!

  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) March 25th, 2010 @ 09:21 AM

    • State changed from “new” to “unconfirmed”

    Any updates on this ticket? Can it be closed?

  • mpd

    mpd March 25th, 2010 @ 12:43 PM

    Probably closable. I dropped that project awhile ago but the suite is green so I'm guessing this has been solved.

  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) March 26th, 2010 @ 06:03 AM

    • Milestone set to 1.0.0
    • State changed from “unconfirmed” to “resolved”

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Pages