Class: MigrationTestHelper::Table
- Inherits:
-
Object
- Object
- MigrationTestHelper::Table
- Includes:
- Connection, Test::Unit::Assertions
- Defined in:
- lib/migration_test_helper.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #column(colname, type, options = {}) ⇒ Object
- #index(column_name, options = {}) ⇒ Object
-
#initialize(name) ⇒ Table
constructor
:nodoc:.
-
#verify ⇒ Object
:nodoc:.
Methods included from Connection
Constructor Details
#initialize(name) ⇒ Table
:nodoc:
128 129 130 131 132 133 |
# File 'lib/migration_test_helper.rb', line 128 def initialize(name) #:nodoc: @name = name.to_s @columns = [] @indexes = [] assert conn.tables.include?(@name), "table <#{@name}> not found in schema" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
126 127 128 |
# File 'lib/migration_test_helper.rb', line 126 def name @name end |
Instance Method Details
#column(colname, type, options = {}) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/migration_test_helper.rb', line 135 def column(colname,type,={}) colname = colname.to_s @columns << colname col = conn.columns(name).find {|c| c.name == colname } assert_not_nil col, "column <#{colname}> not found in table <#{self.name}>" assert_equal type, col.type, "wrong type for column <#{colname}> in table <#{name}>" .each do |k,v| k = k.to_sym; actual = col.send(k); actual = actual.is_a?(String) ? actual.sub(/'$/,'').sub(/^'/,'') : actual assert_equal v, actual, "column <#{colname}> in table <#{name}> has wrong :#{k}" end end |
#index(column_name, options = {}) ⇒ Object
147 148 149 |
# File 'lib/migration_test_helper.rb', line 147 def index(column_name, = {}) @indexes << "name <#{[:name]}> columns <#{Array(column_name).join(",")}> unique <#{[:unique] == true}>" end |
#verify ⇒ Object
:nodoc:
151 152 153 154 155 156 157 |
# File 'lib/migration_test_helper.rb', line 151 def verify #:nodoc: actual_columns = conn.columns(name).map {|c| c.name } assert_equal @columns.sort, actual_columns.sort, "wrong columns for table: <#{name}>" actual_indexes = conn.indexes(@name).collect { |i| "name <#{i.name}> columns <#{i.columns.join(",")}> unique <#{i.unique}>" } assert_equal @indexes.sort, actual_indexes.sort, "wrong indexes for table: <#{name}>" end |