(strange) error on assert_equal

Hi all,

I’m having error on all unit test. Even this one:

hash = { :title => “recipe title”,
:description => “recipe description”,
:serving => 1,
:directions => “do it”
}
recipe_expected = Recipe.new(hash)
recipe_should_be_equal = Recipe.new(hash)
assert_equal(recipe_expected, recipe_should_be_equal)

And this is the error i get:

test_should_be_equal
FAIL
./test/unit/recipe_test.rb:16:in `test_should_be_equal’
<#<Recipe id: nil, title: “recipe title”, serving: 1,
description:
“recipe description”, directions: “do it”, created_at: nil, updated_at:
nil>> expected but was
<#<Recipe id: nil, title: “recipe title”, serving: 1,
description:
“recipe description”, directions: “do it”, created_at: nil, updated_at:
nil>>.

As far as i can see, the object is the same. I’m wondering why this is
happening.

Thanks,

Dida

On Sep 17, 6:56 am, “Adinda P.” [email protected] wrote:

Hi all,

As far as i can see, the object is the same. I’m wondering why this is
happening.

That’s just how == is implemented for activerecord: if they have the
same id then they are equal, if not (or if one is unsaved) then they
are not equal (since saving them would result in 2 different rows in
the database.

Fred