Hi I'm running the following test in rails and I can't seem to figure out its behaviour. The @institution object has an array of LicenseType objects, license_types() starts of as an array of 2. Basically, I'm removing one of the LicenseType objects from the license_types array, saving @institution and then confirming that its size is now 1 instead of 2. here's what I don't get. If I remove the license type with the 'delete_if' block, then call save(), there are still two license_types in the Array. However, if I remove the LicenseType with the 'delete( ltype )' method, then call save() there is 1 LicenseType in the array. I would think that both of these methods should have the same result, but only the latter is passing the test.

Any ideas?

Code:
def test_update()
  assert_equal('The Mathworks, Inc.', @institution.name())
  @institution.name = 'Mathworks'
  assert('Mathworks', @institution.name())

  assert_kind_of(Array, @institution.license_types())
  assert_equal(2, @institution.license_types().size())

  ltype = @institution.license_types().detect() { |lt| lt.name == 'group' }
  assert_equal('group', ltype.name())

  @institution.license_types().delete_if { |lt| lt.name() == 'group' }
  assert_equal(1, @institution.license_types().size())

  assert(@institution.save())
  @institution.reload()

  assert_equal('Mathworks', @institution.name())
  // test fails here as license_types().size() == 2
  assert_equal(1, @institution.license_types().size())

end

Code:
def test_update()
  assert_equal('The Mathworks, Inc.', @institution.name())
  @institution.name = 'Mathworks'
  assert('Mathworks', @institution.name())

  assert_kind_of(Array, @institution.license_types())
  assert_equal(2, @institution.license_types().size())

  ltype = @institution.license_types().detect() { |lt| lt.name == 'group' }
  assert_equal('group', ltype.name())

  @institution.license_types().delete(ltype)
  assert_equal(1, @institution.license_types().size())

  assert(@institution.save())
  @institution.reload()

  assert_equal('Mathworks', @institution.name())
  assert_equal(1, @institution.license_types().size())

end