Lite Fixtures – The Last Nail in the standard Fixtures’ Coffin


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.

One thought on “Lite Fixtures – The Last Nail in the standard Fixtures’ Coffin

  1. 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

Your email address will not be published. Required fields are marked *