Hi guys, I''ve been really frusterated with fixtures as of late. As wonderful as migrations are (allowing me to develop, test and deploy on different systems) being able to support multiple databases isn''t nearly as cool when my tests don''t work on all the systems the codebase does due to non db agnostic fixtures. I''m working with some code to make a ruby fixture markup similar to the migrations code. The approach I think might work is to allow each adapter to define to_datatype methods in a fixtures module which tells the code how to translate the data held in fixtures to be placed in the db. So how to place true and false (1 and 0, ''t'' and ''f'' etc) or Date values or what have you. Does anyone have suggestions/comments to that end? Kev
> So how to place true and false (1 and 0, ''t'' and ''f'' etc) or > Date values or what have you. > > Does anyone have suggestions/comments to that end?For boolean values, you can just use true/false. The adapters know how to quote the values correctly. AR''s own unit tests rely on this behaviour. I think you should be able to use dates and times similarly: irb(main):005:0> d = YAML.load("thing: 2001-12-14t21:59:43.10-05:00 ") => {"thing"=>Sat Dec 15 15:59:43 NZDT 2001} irb(main):007:0> d["iso8601"].class => Time -- Cheers Koz
Ok, looks like I was getting which db errs which way incorrectly. Date definitely doesn''t quote for SQLServer.. here''s a snip of my test code. Everything runs fine on sqlite and mysql (it handles the date). ActiveRecord::StatementInvalid: DBI::DatabaseError: Execute OLE error code:80040E07 in Microsoft OLE DB Provider for SQL Server Syntax error converting datetime from character string. ... For the values section for that field I get ''Sat Jan 07 08:51:09 Pacific Standard Time 2006'' which looks to be the the correct date.to_s On 1/3/06, Michael Koziarski <michael@koziarski.com> wrote:> > So how to place true and false (1 and 0, ''t'' and ''f'' etc) or > > Date values or what have you. > > > > Does anyone have suggestions/comments to that end? > > For boolean values, you can just use true/false. The adapters know > how to quote the values correctly. AR''s own unit tests rely on this > behaviour. > > I think you should be able to use dates and times similarly: > > irb(main):005:0> d = YAML.load("thing: 2001-12-14t21:59:43.10-05:00 ") > => {"thing"=>Sat Dec 15 15:59:43 NZDT 2001} > irb(main):007:0> d["iso8601"].class > => Time > > > > -- > Cheers > > Koz >
On 1/5/06, Kevin Clark <kevin.clark@gmail.com> wrote:> Ok, looks like I was getting which db errs which way incorrectly. Date > definitely doesn''t quote for SQLServer.. here''s a snip of my test > code. Everything runs fine on sqlite and mysql (it handles the date). > > ActiveRecord::StatementInvalid: DBI::DatabaseError: Execute > OLE error code:80040E07 in Microsoft OLE DB Provider for SQL Server > Syntax error converting datetime from character string. > ... > > For the values section for that field I get ''Sat Jan 07 08:51:09 > Pacific Standard Time 2006'' which looks to be the the correct > date.to_sfoo: id: 1 created_at: <%= 5.days.ago.to_s(:db) %> -- rick http://techno-weenie.net
> foo: > id: 1 > created_at: <%= 5.days.ago.to_s(:db) %> >This definitely works, and we use it throughout the strongspace fixtures. But ... yuck. Yaml has a format for dates and times, and I think we should support it if possible. Kevin, would you be able to look into a patch which fixes that? -- Cheers Koz
Sure, I''ll look into it ASAP. Kev On 1/5/06, Michael Koziarski <michael@koziarski.com> wrote:> > foo: > > id: 1 > > created_at: <%= 5.days.ago.to_s(:db) %> > > > > This definitely works, and we use it throughout the strongspace > fixtures. But ... yuck. > > Yaml has a format for dates and times, and I think we should support > it if possible. Kevin, would you be able to look into a patch which > fixes that? > > -- > Cheers > > Koz >
YAML for dates and times works already as long as the data is formatted correctly (yaml dates are being used in the AR tests). There were some bugs in the AR for SQLServer though so I''ve submitted a patch (http://dev.rubyonrails.org/ticket/3406) for several of them. Kev On 1/5/06, Kevin Clark <kevin.clark@gmail.com> wrote:> Sure, I''ll look into it ASAP. > Kev > > On 1/5/06, Michael Koziarski <michael@koziarski.com> wrote: > > > foo: > > > id: 1 > > > created_at: <%= 5.days.ago.to_s(:db) %> > > > > > > > This definitely works, and we use it throughout the strongspace > > fixtures. But ... yuck. > > > > Yaml has a format for dates and times, and I think we should support > > it if possible. Kevin, would you be able to look into a patch which > > fixes that? > > > > -- > > Cheers > > > > Koz > > >