I''ve written some fun code to ease the pain of associating between fixtures. ''Tis tested and documented! Essentially it allows you to replace this syntax user_id: 5 with this: user: :joe as long as you have users.yml with joe: id: 5 http://blog.caboo.se/articles/2006/10/17/named-references-for-test-fixtures http://dev.rubyonrails.org/ticket/6424 There''s not much actual code in there, and I sacrificed brevity for readability. Comments? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core -~----------~----~----~----~------~----~------~--~---
Obie Fernandez
2006-Oct-17 14:38 UTC
Re: fixture magic with associations: never use a FK id again!
How do the dependencies work? Does it just scan the already-loaded fixtures? Use the first-found in case of duplicate keys? On 10/17/06, Courtenay <court3nay@gmail.com> wrote:> > I''ve written some fun code to ease the pain of associating between > fixtures. ''Tis tested and documented! Essentially it allows you to > replace this syntax > > user_id: 5 > > with this: > > user: :joe > > as long as you have users.yml with > > joe: > id: 5 > > > http://blog.caboo.se/articles/2006/10/17/named-references-for-test-fixtures > http://dev.rubyonrails.org/ticket/6424 > > There''s not much actual code in there, and I sacrificed brevity for readability. > Comments? > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core -~----------~----~----~----~------~----~------~--~---
Courtenay
2006-Oct-17 18:17 UTC
Re: fixture magic with associations: never use a FK id again!
No. Once all fixtures are loaded from this statement fixtures :foo, :bar It looks in :foo and :bar as the table names to match. It will only attempt to match if the value in this statement is a symbol: user: :fred In the case of duplicate keys, you''re on your own and probably have bigger fish to fry. If you''re relying on symbols loading into fixtures you''re probably screwed, but then, who does that? This is intended to be a really lightweight addition for people on the golden path of rails. More advanced matching algorithms of course welcome. On 10/17/06, Obie Fernandez <obiefernandez@gmail.com> wrote:> > How do the dependencies work? Does it just scan the already-loaded > fixtures? Use the first-found in case of duplicate keys? > > On 10/17/06, Courtenay <court3nay@gmail.com> wrote: > > > > I''ve written some fun code to ease the pain of associating between > > fixtures. ''Tis tested and documented! Essentially it allows you to > > replace this syntax > > > > user_id: 5 > > > > with this: > > > > user: :joe > > > > as long as you have users.yml with > > > > joe: > > id: 5 > > > > > > http://blog.caboo.se/articles/2006/10/17/named-references-for-test-fixtures > > http://dev.rubyonrails.org/ticket/6424 > > > > There''s not much actual code in there, and I sacrificed brevity for readability. > > Comments? > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core -~----------~----~----~----~------~----~------~--~---
richcollins@gmail.com
2006-Oct-27 23:11 UTC
Re: fixture magic with associations: never use a FK id again!
Been waiting for this for a while. Thanks for the patch! Remind me why yaml is preferred to a ruby DSL again? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core -~----------~----~----~----~------~----~------~--~---