skwpspace yan pritzker’s home on the web

skwpspace is Yan Pritzker's home on the web

Blog :: Photography :: About Me

TwitterCounter for @skwp

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

hello, i'm yan

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

Top Posts

planypus

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

cohesiveft

Accessible, manageable, virtualized application stacks ready to download or deploy to the cloud!

flickr

smokingThe old man and the accordionBicycle 6x6Eva 6x6Shaffies 6x6Phone Booth Velvia 6x6WynnStar 6x6

Archives

Contact

Reach me at yan at pritzker.ws

Posted
9 June 2008 @ 5pm

Tagged
RubyOnRails, rails, ruby, testing, thoughts

Testing your ActiveRecord migrations

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

Heads up! Wordpress hack is in the wild. Git rm pending files