Module: ActiveRecord::LiteTable::Etest

Defined in:
lib/vex/active_record/lite_table.rb

Defined Under Namespace

Classes: TestLiteModel

Instance Method Summary collapse

Instance Method Details

#test_lite_tableObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/vex/active_record/lite_table.rb', line 101

def test_lite_table
  TestLiteModel.lite_table do
  end
  
  assert_equal(%w(id), TestLiteModel.column_names.sort)

  # we can use this class.
  m = TestLiteModel.create!
  assert_not_nil(m)
  assert_not_nil(m.id)
  
  # we cannot change a column type
  assert_raise(ActiveRecord::LiteTable::ColumnTypeMismatch) {  
    TestLiteModel.lite_table do
      string :id
    end
  }

  # we can add additional columns
  TestLiteModel.lite_table do
    string :name
  end
  
  # we can use this class.
  m = TestLiteModel.create! :name => "name"
  assert_not_nil(m)
  assert_not_nil(m.id)
  assert_equal("name", m.name)

  # we can add indices: we test index creation by creating a unique index
  # on a column that contains two identical entries.
  m = TestLiteModel.create! :name => "name"

  assert_raises(ActiveRecord::StatementInvalid) {  
    TestLiteModel.lite_table do
      index :name, :unique => true
    end
  }

  TestLiteModel.lite_table do
    index :name
  end
end