Flexible Fixtures in Rails 2

As Matt Magain pointed out yesterday, Rails 2.0 is now gold! Not a lot has changed feature wise from the PR (makes sense – features were frozen at that point), although it seems that the new improvements to fixtures managed to slip in to the final version.

Rather than having to map foreign keys in your fixtures using id numbers, you can use fixture names, which makes life a whole lot easier. So you can now write:

 users.yml  joe_blogs:   id: 1   first_name: Joe   last_name: Blogs mary_smith:   id: 2   first_name: Mary   last_name: Smith   websites.yml  website_1   id: 1   user: joe_blogs   url: "http://www.joeblogs.com"  website_2   id: 2   user: mary_smith   url: "http://mary.smith.id.au" 

which obviously makes a lot more sense to a human reading it, especially when you have a large number of fixtures across many models.

Let me join Matt in congratulating the Rails core dev team for achieving this milestone – roll on Rails 3!

Replay

Category: programming Time: 2007-12-12 Views: 1
Tags:

Related post

  • Load and use fixture in rails console 2011-08-12

    I wonder if there's a way to load and/or use fixture in rails console. Actually, I'd like to create a user from my fixture users.yml to do some testing without having to go through all the "pain" of doing User.new(:name = "John", :emai

  • Rolling With Sinatra 2013-01-21

    When it comes to web development, Sinatra is amazingly flexible. Unlike Rails, it isn't opinionated in the slightest and basically lets you make all the design decisions. It does have some conventions, such as automatically looking for view templates

  • How do I unit test queries which are based on dates from now? 2014-10-28

    I've had a hard time making unit test for most of my queries because they are tied very closely to current dates and data which is added to the database could modify the result of the unit test. For the most part I've been able to avoid problems by r

  • Ruby on Rails 4 fixtures require table 2016-01-23

    Fixtures when using Rails (My environment Rails 4.2) Why when running a test, why does it error when a fixture exists but there isn't a table with the same name? And why does the fixture require to have a matching column in the table? Example 1: (tab

  • Rails Test Case Use one fixture value in another Fixture 2016-01-28

    I have two fixtures files. country.yml KENYA: country_code: kenya short_code: ke post.yml my_post: content: "Lorem Ipsum" location: kenya I am trying to use the KENYA.country_code in my_post.yml. If I use location: KENYA.country_code It will sav

  • Integrate Jasmine into Rails for Solid JavaScript Testing 2016-01-25

    Jasmine is a framework to create tests for JavaScript code in the behavior-driven development style. In this article, you will learn how to integrate Jasmine into a Ruby on Rails application. Jasmine has a clean syntax with the aim to provide descrip

  • The effect of using Rails fragment caching 2006-08-21

    Rails provides a few caching techniques, one of which is a fragment cache. The fragment cache is a dead-easy way to cache bits of your view. After checking that your queries are doing sensible things, the next often slowest part of the Rails stack is

  • A definitive list of IDEs for Ruby on Rails 2009-05-05

    In no particular order: Aptana RadRails Textmate VIM (Rails Plugin) RubyMine EMACS + Rinari E-Texteditor Komodo RDT (Ruby Eclipse) Ruby in Steel (Visual Studio plugin) Please add more and I will update periodically. --------------Solutions-----------

  • Rails - link_to, routes and nested resources 2009-10-10

    As my understanding on nested resources, on edge Rails, should not link_to 'User posts', @user.posts point to /users/:id/posts ? The routes.rb file contains map.resources :users, :has_many => :posts If this is not the default behavior, can it be acco

  • Multiple Rails sites using Passenger and VirtualHosts? 2009-11-10

    What I am trying to do is run multiple Rails apps from a server machine at work. We dont have multiple hostnames for the box. We want to host some rails apps on it as well as our php apps. Currently users can connect http://computername/app/. How can

  • How many Rails apps can I run with VPS? 2010-02-04

    I've been playing around with Rails and have developed a few simple apps. I'm considering purchasing a VPS to host these apps and was wondering how much I could expect to put on it. The product I've been looking at provides 25GB storage, 500GB traffi

  • Checking out the Rails 3 beta, Part III: The Query API 2010-04-13

    In my last two posts I've introduced you to some of my favourite new features in the beta version of Ruby on Rails 3.0: the Bundler gem manager and the new routing module. I think it's fair to say I've saved the best for last: this week I'm delving i

  • Good text editor for Ruby on Rails programming? 2010-11-02

    I'm looking for a text editor for programming in Python, preferably one which is easy to learn for beginners. --------------Solutions------------- Geany Geany is a lightweight IDE that supports python. Some features that I have found particularly use

  • Ruby on Rails Server options 2010-11-06

    The whole issue of setting up a development server for my Ruby on Rails application confuses me. There are WEBrick, Mongrel, Passenger, Apache, Nginx and many more I am sure, and I don't really understand the different roles they play. I started off

  • Are Ruby on Rails / Grails the fastest frameworks for getting sites up quickly? 2010-11-19

    I'm considering using Grails for a new website, but am open to other/new programming languages and frameworks. I have done development using J2EE/JSF2, ASP.NET, and PHP. Is Grails or Ruby on Rails pretty much the best way to get functionality up and

  • Reverse Proxy (mod_rewrite) and Rails (absolute paths) 2010-12-30

    I have front end rails app, that reverse proxies to any of a number of backend rails apps depending on URL, for example http://www.my_host.com/app_one reverse proxies to http://www.remote_host_running_app_one.com such that a URL like http://www.my_ho

  • Are there replacement cords for USB mice? (of mouse flexibility) 2011-01-16

    I have a high end mouse and it'd be silly throwing it away or even sending it away for a chance to be fixed in weeks when one could just replace the cord with at most some soldering. --------------Solutions------------- I'm unaware that there are rep

  • Need to link WP Blog with Rails App on Heroku 2011-02-27

    I have a client who wants to migrate his Rails app to Heroku. However the client also has a blog associated with his domain that runs on WordPress. Currently, the WordPress blog is running happily alongside the Rails app, but once we migrate to Herok

  • Complex Rails Forms with Nested Attributes 2011-03-23

    Rails provides a powerful mechanism for easily creating rich forms called "nested attributes." It allows you to combine more than one model in your forms while keeping the same basic code pattern that you use with simple single model forms. In t

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.438 (s). 13 q(s)