Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

RDoc for have_db_column matcher

  • Loading branch information...
commit 9fc346be34f6f89a99dff9bbebdfe2a5ed05173c 1 parent d261e12
@croaky croaky authored jferris committed
View
2  lib/shoulda/active_record/macros.rb
@@ -414,6 +414,8 @@ def should_have_instance_methods(*methods)
# Takes the same options available in migrations:
# :type, :precision, :limit, :default, :null, and :scale
#
+ # Examples:
+ #
# should_have_db_columns :id, :email, :name, :created_at
#
# should_have_db_column :email, :type => "string", :limit => 255
View
23 lib/shoulda/active_record/matchers/have_db_column_matcher.rb
@@ -2,7 +2,24 @@ module Shoulda # :nodoc:
module ActiveRecord # :nodoc:
module Matchers # :nodoc:
- class HaveDbColumnMatcher
+ # Ensures the database column exists.
+ #
+ # Options:
+ # * <tt>of_type</tt> - db column type (:integer, :string, etc.)
+ # <tt>with_options</tt> - same options available in migrations
+ # (:default, :null, :limit, :precision, :scale)
+ #
+ # Example:
+ # it { should_not have_db_column(:admin).of_type(:boolean) }
+ # it { should have_db_column(:salary).
+ # of_type(:decimal).
+ # with_options(:precision => 10, :scale => 2) }
+ #
+ def have_db_column(column)
+ HaveDbColumnMatcher.new(:have_db_column, column)
+ end
+
+ class HaveDbColumnMatcher # :nodoc:
def initialize(macro, column)
@macro = macro
@column = column
@@ -147,10 +164,6 @@ def expectation
end
end
- def have_db_column(column)
- HaveDbColumnMatcher.new(:have_db_column, column)
- end
-
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.