header image

We all know that standard Rails fixtures suck - they were good at the time of their invention, mainly because nothing better existed - but numerous weaknesses and problems have been mentioned since then.

After some time people addressed the pain points with various approaches - factory_girl, object_daddy, machinist, you name it.

While the above solutions are really great, they are quite different from standard fixtures in their philosophy, and I believe because of that some people just rolled on with the standard solution. Well, there is a new player in the town, so no more excuses.

Lite Fixtures are backward compatible with normal fixtures, while drastically reducing their complexity. Check out these examples from the GitHub README:

Patterns in fixture names - Using the pattern “(owners)s_(color)_(make)” in conjunction with the fixture name “Freds_red_Ford” unpacks owner to Fred, color to red and make to Ford.

 
      (owners)s_(color)_(make)

        Freds_red_Ford:
          year: 1977

        Eds_blue_Chevy:
          year: 1987


    Becomes

        Freds_red_Ford:
          owner: Fred
          color: red
          make:  Ford
          year:  1977

        Eds_blue_Chevy:
          owner: Ed
          color: blue
          make:  Chevy
          year: 1987

Grouping of Data - Often fixtures group cleanly- family of users, manufacturers of cars, etc. Lite fixtures lets you nest data, so scoped values are propigated inward.

    red_fords:
      make: ford
      color: red

      mustang:
        owner: freddy

      taurus:
        owner: freddy

    Becomes:

      mustang:
        make: ford
        color: red
        owner: freddy

      taurus:
        make: ford
        color: red
        owner: freddy

I really think this improvement should make it to the Rails core - unless they are replacing the fixtures with something radically different.



If you liked the article, subscribe to the feed   and follow me on twitter!.


      

One Response to “Lite Fixtures - The Last Nail in the standard Fixtures’ Coffin”

  1. Abhishek Parolkar (MarketHero) Says:

    I am wondering if some body could write some thing similar to AR.to_fixture , for the lite fixture… I really need a quick and mature tool that can generate fixtures of data that already exist in the database maintaining the relationships..

Leave a Reply




Bad Behavior has blocked 1031 access attempts in the last 7 days.