I have a model with some boolean fields (PostgreSQL column type
"bool"). However, when I run the unit tests, the boolean fields in
the fixtures are being converted to integers, causing an error.
Does anyone have suggestions for how to avoid this problem, other
than changing the column type to int?
Fixture
----------
bob_preference:
id: 1
user_id: 1
visible: false
username_visible: false
fullname_visible: true
Unit test error
----------
ActiveRecord::StatementInvalid: ERROR: column "visible" is of type
boolean but expression is of type integer
HINT: You will need to rewrite or cast the expression.
: INSERT INTO user_preferences ("visible",
"fullname_visible",
"username_visible", "id", "user_id") VALUES (0, 1,
0, 1, 1)
thanks,
Jeff
On 7/14/05, Jeff Cole <jeff-5tvxCauQEQjk1uMJSBkQmQ@public.gmane.org> wrote:> I have a model with some boolean fields (PostgreSQL column type > "bool"). However, when I run the unit tests, the boolean fields in > the fixtures are being converted to integers, causing an error. > Does anyone have suggestions for how to avoid this problem, other > than changing the column type to int?Try ''true'' / ''false'' or ''1'' / ''0''. I use quoted ints to maintain mysql compatibility just in case. -- rick http://techno-weenie.net
Well, this solves the problem of loading the fixture data into the
database. However, if you do this you cannot use the fixture hash in
your unit test, because it expects a value of type
"''false''" instead
of "false". Shouldn''t the original fixture YML just have
worked
correctly without quoting the true/false?
Fixture
-------
bob_preference:
id: 1
visible: ''false''
Unit test
-----------
def test_read_with_hash
bob_pref_fixture = @user_preferences["bob_preference"]
assert_equal bob_pref_fixture["id"], @bob_preference.id
assert_equal bob_pref_fixture["visible"], @bob_preference.visible
end
Error
----------
1) Failure:
test_read_with_hash(UserPreferenceTest) [test/unit/
user_preference_test.rb:11]:
<"false"> expected but was
<false>.
-Jeff
On Jul 14, 2005, at 5:05 PM, Rick Olson wrote:
> On 7/14/05, Jeff Cole <jeff-5tvxCauQEQjk1uMJSBkQmQ@public.gmane.org>
wrote:
>
>> I have a model with some boolean fields (PostgreSQL column type
>> "bool"). However, when I run the unit tests, the boolean
fields in
>> the fixtures are being converted to integers, causing an error.
>> Does anyone have suggestions for how to avoid this problem, other
>> than changing the column type to int?
>>
>
> Try ''true'' / ''false'' or
''1'' / ''0''. I use quoted ints to maintain
> mysql compatibility just in case.
>
> --
> rick
> http://techno-weenie.net
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>