|
| 1 | +require 'cases/helper' |
| 2 | + |
| 3 | +class HotCompatibilityTest < ActiveRecord::TestCase |
| 4 | + self.use_transactional_fixtures = false |
| 5 | + |
| 6 | + setup do |
| 7 | + @klass = Class.new(ActiveRecord::Base) do |
| 8 | + connection.create_table :hot_compatibilities do |t| |
| 9 | + t.string :foo |
| 10 | + t.string :bar |
| 11 | + end |
| 12 | + |
| 13 | + def self.name; 'HotCompatibility'; end |
| 14 | + end |
| 15 | + end |
| 16 | + |
| 17 | + teardown do |
| 18 | + @klass.connection.drop_table :hot_compatibilities |
| 19 | + end |
| 20 | + |
| 21 | + test "insert after remove_column" do |
| 22 | + # warm cache |
| 23 | + @klass.create! |
| 24 | + |
| 25 | + # we have 3 columns |
| 26 | + assert_equal 3, @klass.columns.length |
| 27 | + |
| 28 | + # remove one of them |
| 29 | + @klass.connection.remove_column :hot_compatibilities, :bar |
| 30 | + |
| 31 | + # we still have 3 columns in the cache |
| 32 | + assert_equal 3, @klass.columns.length |
| 33 | + |
| 34 | + # but we can successfully create a record so long as we don't |
| 35 | + # reference the removed column |
| 36 | + record = @klass.create! foo: 'foo' |
| 37 | + record.reload |
| 38 | + assert_equal 'foo', record.foo |
| 39 | + end |
| 40 | + |
| 41 | + test "update after remove_column" do |
| 42 | + record = @klass.create! foo: 'foo' |
| 43 | + assert_equal 3, @klass.columns.length |
| 44 | + @klass.connection.remove_column :hot_compatibilities, :bar |
| 45 | + assert_equal 3, @klass.columns.length |
| 46 | + |
| 47 | + record.reload |
| 48 | + assert_equal 'foo', record.foo |
| 49 | + record.foo = 'bar' |
| 50 | + record.save! |
| 51 | + record.reload |
| 52 | + assert_equal 'bar', record.foo |
| 53 | + end |
| 54 | +end |
0 commit comments