module Shoulda::ActiveRecord::Macros

def should_have_db_columns(*columns)


should_have_db_column :admin, :default => false, :null => false
should_have_db_column :salary, :decimal, :precision => 15, :scale => 2
should_have_db_column :email, :type => "string", :limit => 255

should_have_db_columns :id, :email, :name, :created_at

Examples:

:type, :precision, :limit, :default, :null, and :scale
Takes the same options available in migrations:
Also aliased to should_have_index for readability.
Ensure that the given columns are defined on the models backing SQL table.
def should_have_db_columns(*columns)
  column_type, precision, limit, default, null, scale, sql_type = 
    get_options!(columns, :type, :precision, :limit,
                          :default, :null, :scale, :sql_type)
  klass = model_class
  columns.each do |name|
    matcher = have_db_column(name).
                of_type(column_type).
                with_options(:precision => precision, :limit    => limit,
                             :default   => default,   :null     => null,
                             :scale     => scale,     :sql_type => sql_type)
    should matcher.description do
      assert_accepts(matcher, klass.new)
    end
  end
end