DataDumper

Installation

  1. Gemfile gem “data_dumper”, :group => [:development, :test]

Usage

You’re knee deep in a debugger session, and you can’t understand why something’s wrong. You wish you could fire up your application against the test database, but sadly, the process which is running the tests is within a transaction, and thus the actual data is opaque. What can you do?

  1. Somewhere deep in your tests test “the frobble touches the widget” do debugger assert_equal 42, frobble.widget_id end

You’ve been on this assert_equal call for the past hour wondering…:

[814, 823] in test/unit/widget_test.rb 814 frobble.save! 815 end 816 817 test “the frobble touches the widget” do 818 debugger => 819 assert_equal 42, frobble.widget_id 820 end 821 822 test “the widget touched the frobble in turn” do 823 assert widget.touched_by_frobble? test/unit/widget_test.rb:819 => 819 assert_equal 42, frobble.widget_id (rdb:112)

Luckily, you have the DataDumper gem lying around on your machine (pre-declared in your Gemfile!):

(rdb:112) require “data_dumper” (rdb:113) File.mkdir(Rails.root + “dump”) (rdb:114) DataDumper.dump(Rails.root + “dump”)

Then, finish your failing tests, and from the trusty command line:

$ rails console > require “data_dumper” > DataDumper.load(Rails.root + “dump”) > exit $ rails server

Any and all data from your test database will be loaded in your development environment. You can now explore your model with your trusty application, to find out what’s really going on.

Caveats

This tool is known to work with Rails 2.3.5, PostgreSQL 8.4 and REE 1.8.7 2011.03. Anything else is up for you to test.

LICENSE

(The MIT License)

Copyright © 2011 François Beausoleil ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.