Hi, In fixtures, whenever I define a string as "yes", it is stored as "t" in the database. Here is an example in YAML. active_user: username: active_user is_active: yes Now when I run the test, and check the test database (SQLite), I find string "t" stored in place of "yes" for the column "is_active". Now consider following example (changed "yes" to "yup") - active_user: username: active_user is_active: yup Now everything goes as expected and string "yup" is stored in database for column "is_active". In my code, I use `User.is_active == "yes"`, to check that an user is active. And any other value for is_active means user is inactive. It took me almost four hours to identify why my tests are failing! Later found that string "true" is also stored as "t" in database. and "no" is stored as "f". I''m using - Rails 2.0.2 SQLite 3.5.7 Ruby 1.8.6 (patch 111) Microsoft Winodws XP Home Edtn. SP2 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Oops just discovered that this is the problem in YAML and not in rails. Anyway this should be considered as a bug and not a feature. reference - http://wiki.rubyonrails.org/rails/pages/ActiveRecordYamlFixtures On May 26, 12:06 pm, Vikrant <nas...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > In fixtures, whenever I define a string as "yes", it is stored as "t" > in the database. > > Here is an example in YAML. > > active_user: > username: active_user > is_active: yes > > Now when I run the test, and check the test database (SQLite), I find > string "t" stored in place of "yes" for the column "is_active". > > Now consider following example (changed "yes" to "yup") - > > active_user: > username: active_user > is_active: yup > > Now everything goes as expected and string "yup" is stored in database > for column "is_active". > > In my code, I use `User.is_active == "yes"`, to check that an user is > active. And any other value for is_active means user is inactive. > > It took me almost four hours to identify why my tests are failing! > > Later found that string "true" is also stored as "t" in database. and > "no" is stored as "f". > > I''m using - > Rails 2.0.2 > SQLite 3.5.7 > Ruby 1.8.6 (patch 111) > Microsoft Winodws XP Home Edtn. SP2--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 26 May 2008, at 08:13, Vikrant wrote:> > Oops just discovered that this is the problem in YAML and not in > rails. > Anyway this should be considered as a bug and not a feature. > reference - http://wiki.rubyonrails.org/rails/pages/ActiveRecordYamlFixtures >This is intentional. Instead of checking foo.is_active == ''blah'', use foo.is_active? If you do want to stop yaml guessing that you''re trying to store a boolean, quote it (ie "yes") Fred> > On May 26, 12:06 pm, Vikrant <nas...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Hi, >> >> In fixtures, whenever I define a string as "yes", it is stored as "t" >> in the database. >> >> Here is an example in YAML. >> >> active_user: >> username: active_user >> is_active: yes >> >> Now when I run the test, and check the test database (SQLite), I find >> string "t" stored in place of "yes" for the column "is_active". >> >> Now consider following example (changed "yes" to "yup") - >> >> active_user: >> username: active_user >> is_active: yup >> >> Now everything goes as expected and string "yup" is stored in >> database >> for column "is_active". >> >> In my code, I use `User.is_active == "yes"`, to check that an user is >> active. And any other value for is_active means user is inactive. >> >> It took me almost four hours to identify why my tests are failing! >> >> Later found that string "true" is also stored as "t" in database. and >> "no" is stored as "f". >> >> I''m using - >> Rails 2.0.2 >> SQLite 3.5.7 >> Ruby 1.8.6 (patch 111) >> Microsoft Winodws XP Home Edtn. SP2 > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---