New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

birdbath

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

birdbath

  • 1.3.5
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= Birdbath

Birdbath provides methods which let you assert the current state of the schema and run your migrations against the test database.

== Install

gem install birdbath

If you're using it outside of a Rails environment (for whatever reason) include the Birdbath module in your tests:

require 'test/unit' require 'birdbath'

class MyTest < Test::Unit::TestCase include Birdbath

def test_something
  ...
end

end

== Use

assert_schema: verifies the schema of the database exactly matches the one specified.

def test_the_schema assert_schema do |s| s.table :books do |t| t.column :id, :integer t.column :title, :string, :limit => 5 t.column :author, :string end

  s.table :reviews do |t|
    t.column :id,      :integer
    t.column :book_id, :integer
    t.column :body,    :text
    t.column :rating,  :integer, :default => 0
    t.index  :book_id, :name => 'index_book_id_on_reviews'
  end
end

end

This would verify there are only two tables defined in the test database: books and reviews (schema_info is ignored). It will also verify that the book table has the three columns, id, title and author, each with their respective types. Indexes are verified too.

assert_table: verify a table is found exactly as specified:

assert_table :books do |t| t.column :id, :integer t.column :title, :string, :limit => 5 t.column :author, :string t.index :author, :name => 'index_author_on_books' end

drop_all_tables: does just what it says to your test database.

migrate: executes the migrations against the test database using the same mechanism as rake db:migrate.

def test_the_migrations migrate migrate :version => 0 migrate :version => 10 migrate end

This would do the same thing as running the following rake commands, but within a test case:

rake db:migrate rake db:migrate VERSION=0 rake db:migrate VERSION=10 rake db:migrate

By combining the two helpers you can write a test that shows you can run all your migrations and get the final schema:

def test_should_be_able_to_migrate_from_an_empty_schema drop_all_tables

# we shouldn't have any tables
assert_schema do |s|
end

migrate  

assert_schema do |s|
  s.table :books do |t|
    t.column :id,     :integer
    t.column :title,  :string
    t.column :author, :string
  end

  s.table :reviews do |t|
    t.column :id,      :integer
    t.column :book_id, :integer
    t.column :body,    :text
    t.column :rating,  :integer
    t.index  :book_id, :name => 'index_book_id_on_reviews'
  end
end

end

The migrate helper can also be useful for testing data tranformation migrations:

def test_should_get_rid_of_bad_data drop_all_tables migrate :version => 7 Book.reset_column_information book = Book.create! :title => "bad title\nwith\todd spacing" migrate :version => 8 # should cleanse spacing in book titles book.reload assert_equal "bad title with odd spacing", book.title end

== Authors

  • Micah Alles (alles@atomicobject.com)
  • David Crosby (crosby@atomicobject.com)
  • Patrick Bacon (bacon@atomicobject.com)
  • © 2007-2011 {Atomic Object}[http://www.atomicobject.com]
  • More Atomic Object {open source}[http://www.atomicobject.com/pages/Software+Commons] projects

FAQs

Package last updated on 09 Aug 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc