0
@@ -29,6 +29,7 @@ module ThoughtBot # :nodoc:
0
# should_require_attributes :name, :phone_number
0
def should_require_attributes(*attributes)
0
message = get_options!(attributes, :message)
0
@@ -53,6 +54,7 @@ module ThoughtBot # :nodoc:
0
# should_require_unique_attributes :keyword, :username
0
def should_require_unique_attributes(*attributes)
0
message, scope = get_options!(attributes, :message, :scoped_to)
0
@@ -92,6 +94,7 @@ module ThoughtBot # :nodoc:
0
# Requires an existing record
0
# should_protect_attributes :password, :admin_flag
0
def should_protect_attributes(*attributes)
0
get_options!(attributes)
0
@@ -118,6 +121,7 @@ module ThoughtBot # :nodoc:
0
# should_not_allow_values_for :isbn, "bad 1", "bad 2"
0
def should_not_allow_values_for(attribute, *bad_values)
0
message = get_options!(bad_values, :message)
0
@@ -142,6 +146,7 @@ module ThoughtBot # :nodoc:
0
# should_allow_values_for :isbn, "isbn 1 2345 6789 0", "ISBN 1-2345-6789-0"
0
def should_allow_values_for(attribute, *good_values)
0
message = get_options!(good_values, :message)
0
@@ -167,6 +172,7 @@ module ThoughtBot # :nodoc:
0
# should_ensure_length_in_range :password, (6..20)
0
def should_ensure_length_in_range(attribute, range, opts = {})
0
short_message, long_message = get_options!([opts], :short_message, :long_message)
0
short_message ||= /short/
0
@@ -208,6 +214,7 @@ module ThoughtBot # :nodoc:
0
# should_ensure_value_in_range :age, (0..100)
0
def should_ensure_value_in_range(attribute, range, opts = {})
0
low_message, high_message = get_options!([opts], :low_message, :high_message)
0
low_message ||= /included/
0
@@ -245,6 +252,7 @@ module ThoughtBot # :nodoc:
0
# should_only_allow_numeric_values_for :age
0
def should_only_allow_numeric_values_for(*attributes)
0
message = get_options!(attributes, :message)
0
@@ -268,6 +276,7 @@ module ThoughtBot # :nodoc:
0
# should_have_many :friends
0
# should_have_many :enemies, :through => :friends
0
def should_have_many(*associations)
0
through = get_options!(associations, :through)
0
@@ -288,6 +297,7 @@ module ThoughtBot # :nodoc:
0
# Ensures that the has_and_belongs_to_many relationship exists.
0
# should_have_and_belong_to_many :posts, :cars
0
def should_have_and_belong_to_many(*associations)
0
get_options!(associations)
0
@@ -302,6 +312,7 @@ module ThoughtBot # :nodoc:
0
# Ensure that the has_one relationship exists.
0
# should_have_one :god # unless hindu
0
def should_have_one(*associations)
0
get_options!(associations)
0
@@ -316,6 +327,7 @@ module ThoughtBot # :nodoc:
0
# Ensure that the belongs_to relationship exists.
0
# should_belong_to :parent
0
def should_belong_to(*associations)
0
get_options!(associations)
0
@@ -333,6 +345,7 @@ module ThoughtBot # :nodoc:
0
# Ensure that the given class methods are defined on the model.
0
# should_have_class_methods :find, :destroy
0
def should_have_class_methods(*methods)
0
@@ -346,6 +359,7 @@ module ThoughtBot # :nodoc:
0
# Ensure that the given instance methods are defined on the model.
0
# should_have_instance_methods :email, :name, :name=
0
def should_have_instance_methods(*methods)
0
@@ -355,6 +369,43 @@ module ThoughtBot # :nodoc:
0
+ # Ensure that the given columns are defined on the models backing SQL table.
0
+ # should_have_db_columns :id, :email, :name, :created_at
0
+ def should_have_db_columns(*columns)
0
+ column_type = get_options!(columns, :exclusive, :type)
0
+ columns.each do |name|
0
+ test_name = "have column #{name}"
0
+ test_name += " of type #{column_type}" if column_type
0
+ column = klass.columns.detect {|c| c.name == name.to_s }
0
+ assert column, "#{klass.name} does not have column #{name}"
0
+ # Ensure that the given column is defined on the models backing SQL table. The options are the same as
0
+ # the instance variables defined on the column definition: :precision, :limit, :default, :null,
0
+ # :primary, :type, :scale, and :sql_type.
0
+ # should_have_db_column :email, :type => "string", :default => nil, :precision => nil, :limit => 255,
0
+ # :null => true, :primary => false, :scale => nil, :sql_type => 'varchar(255)'
0
+ def should_have_db_column(name, opts = {})
0
+ test_name = "have column named :#{name}"
0
+ test_name += " with options " + opts.inspect unless opts.empty?
0
+ column = klass.columns.detect {|c| c.name == name.to_s }
0
+ assert column, "#{klass.name} does not have column #{name}"
0
+ assert_equal column.instance_variable_get("@#{k}").to_s, v.to_s, ":#{name} column on table for #{klass} does not match option :#{k}"
Comments
No one has commented yet.