I have a Rails project, and I created a Country model. I added the basic details of Norway to the countries.yml fixture.
norway:
code: NO
name: Norway
I added a unit test to make sure I could get Norway by it's country code, which is NO
def test_find_by_code
assert_equal countries(:norway), Country.find_by_code('NO')
end
Agreed, I probably don't need a unit test for this, but this should have worked, but it was failing with the following message.
Country id: 318845244, code: "1", name: "Norway" expected but was
nil
Apparently NO in the yaml file is interpreted as a 0 (zero). To prove the theory I changed the code of norway to YES. The unit test failed, and indicated that the model it expected should have had code: "1". Changing countries.yml to be...
norway:
code: "NO"
name: Norway
I personally really like fixtures and the nice features they bring in, but sometimes they can catch you out. I'm sure it's not a bug, I've just never encountered this before. Ever found anything strange in your fixtures?