Yan Pritzker photographer, entrepreneur, software engineer, musician, skier

Blog :: Git Workflows Book :: Dotfiles :: Photography :: About Me

TwitterCounter for @skwp

Get the news feed
Get updates by email
Follow me on twitter

hello, i'm yan

I am a photographer, entrepreneur, software engineer, guitarist, climber, and telemark skier

This blog is about startups, blogging, Ruby On Rails, virtualization and cloud computing, photography, customer service, marketing, ux and design, git, and lots more.

Enterprise intelligence with prediction markets

Find out what your team, colleagues and partners really know about the future — and leverage their knowledge to improve business decisions.

I'm the founder of Planypus, the place to share your plans!

Archives

Contact

Reach me at yan at pritzker.ws

Testing your ActiveRecord migrations

Posted 9 June 2008 @ 5pm | Tagged rails, ruby, RubyOnRails, testing, thoughts


Submit to HN

Sometimes you have a data migration that creates or modifies records in some way, and you would like to test it in your unit tests right? Except that Rails typically just clones the structure of your dev database, not its data. So how do you test that a migration succeeded? Simple, just invoke it during your test:

This code is written using the shoulda plugin which gives a slightly more verbose breakdown of the setup and the test, but it can be done with test/unit just as well.


context "orphan user migration" do
  setup do
    require "#{RAILS_ROOT}/db/migrate/163_create_orphan_owner"
    CreateOrphanOwner.up
  end
  should "create the orphan user" do
    assert orphan = User.orphan_owner
    assert orphan.role?(User::ORPHAN_OWNER)
  end
end

1 Comment

Posted by
RoR Tuesday June 13, 2008
10 June 2008 @ 1pm

[...] Testing your ActiveRecord migrations [...]


Leave a Comment