module ThoughtBot::Shoulda::ActiveRecord::Macros
def should_have_db_column(name, opts = {})
:null => true, :primary => false, :scale => nil, :sql_type => 'varchar(255)'
should_have_db_column :email, :type => "string", :default => nil, :precision => nil, :limit => 255,
:primary, :type, :scale, and :sql_type.
the instance variables defined on the column definition: :precision, :limit, :default, :null,
Ensure that the given column is defined on the models backing SQL table. The options are the same as
def should_have_db_column(name, opts = {}) klass = model_class test_name = "have column named :#{name}" test_name += " with options " + opts.inspect unless opts.empty? should test_name do column = klass.columns.detect {|c| c.name == name.to_s } assert column, "#{klass.name} does not have column #{name}" opts.each do |k, v| assert_equal column.instance_variable_get("@#{k}").to_s, v.to_s, ":#{name} column on table for #{klass} does not match option :#{k}" end end end