I''m playing with dynamic test fixtures and seeing what seems to be odd behavior. I''m fairly new to ruby and rails so it could be something simple. I have the following fixture: <%COUNTRY_MAX=10%> <%0.upto(COUNTRY_MAX) do |number| %> country<%=number%>: id: <%=number%> code: <%=format("%03d", number)%> name: country<%=format("%03d", number)%> <% end %> which produces: DELETE FROM countries INSERT INTO countries ("name", "code", "id") VALUES (''country003'', 3, 3) INSERT INTO countries ("name", "code", "id") VALUES (''country004'', 4, 4) INSERT INTO countries ("name", "code", "id") VALUES (''country005'', 5, 5) INSERT INTO countries ("name", "code", "id") VALUES (''country006'', 6, 6) INSERT INTO countries ("name", "code", "id") VALUES (''country007'', 7, 7) INSERT INTO countries ("name", "code", "id") VALUES (''country008'', ''008'', 8) INSERT INTO countries ("name", "code", "id") VALUES (''country009'', ''009'', 9) INSERT INTO countries ("name", "code", "id") VALUES (''country000'', 0, 0) INSERT INTO countries ("name", "code", "id") VALUES (''country001'', 1, 1) INSERT INTO countries ("name", "code", "id") VALUES (''country010'', 8, 10) INSERT INTO countries ("name", "code", "id") VALUES (''country002'', 2, 2) I have several questions about this. 1) why does the code get out of sync with the name and id? 2) why aren''t they in order as expected? 3) why is the code not always formatted to be length 3? --~--~---------~--~----~------------~-------~--~----~ 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 7/22/07, dailer <d.sailer-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote:> I have several questions about this. > 1) why does the code get out of sync with the name and id? > 2) why aren''t they in order as expected? > 3) why is the code not always formatted to be length 3?Fixtures are just YAML files. What you''re defining is 10 entries in a Ruby hash. Hashes are unordered. The records should not be expected to be INSERT''d in order. -- Chris Wanstrath http://errfree.com // http://errtheblog.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ok, and that led me to YAML:Omap so I can take care of issue #2. Anyone on #1 and #3? On Jul 23, 5:28 am, "Chris Wanstrath" <ch...-G5sj8e7vJc8@public.gmane.org> wrote:> On 7/22/07, dailer <d.sai...-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote: > > > I have several questions about this. > > 1) why does the code get out of sync with the name and id? > > 2) why aren''t they in order as expected? > > 3) why is the code not always formatted to be length 3? > > Fixtures are just YAML files. What you''re defining is 10 entries in a > Ruby hash. Hashes are unordered. The records should not be expected > to be INSERT''d in order. > > -- > Chris Wanstrathhttp://errfree.com//http://errtheblog.com--~--~---------~--~----~------------~-------~--~----~ 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 7/22/07, dailer <d.sailer-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote:> 1) why does the code get out of sync with the name and id?Because 001 is not a decimal number in Ruby, it''s an octal. You need to surround your <%= %> with quotes so Ruby knows you want a string when loading from YAML. In irb:>> 010=> 8>> ''010''=> "010"> 3) why is the code not always formatted to be length 3?See #1. -- Chris Wanstrath http://errfree.com // http://errtheblog.com --~--~---------~--~----~------------~-------~--~----~ 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 7/23/07, dailer <d.sailer-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote:> > Ok, and that led me to YAML:Omap so I can take care of issue #2.Jumping in to the thread late... YAML::Omap is not indicated for database fixtures. Is that what we were discussing? if so, shouldn''t each fixture record have an explicit ''id: 2'', so their hash order doesn''t matter? Sorry but I''m pretty good with Omap, but Google won''t show me the rest of this thread. Jeeze good free help is hard to find! -- Phlip http://www.oreilly.com/catalog/9780596510657/ "Test Driven Ajax (on Rails)" assert_xpath, assert_javascript, & assert_ajax --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
thanks. On Jul 23, 8:16 am, "Chris Wanstrath" <ch...-G5sj8e7vJc8@public.gmane.org> wrote:> On 7/22/07, dailer <d.sai...-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote: > > > 1) why does the code get out of sync with the name and id? > > Because 001 is not a decimal number in Ruby, it''s an octal. You need > to surround your <%= %> with quotes so Ruby knows you want a string > when loading from YAML. > > In irb:>> 010 > => 8 > >> ''010'' > > => "010" > > > 3) why is the code not always formatted to be length 3? > > See #1. > > -- > Chris Wanstrathhttp://errfree.com//http://errtheblog.com--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---