Sha256: 7774f1693f30d78faa5d8f5b44cc5914030789a4dffec09493b427cd49fa8ca5

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require File.join(File.dirname(__FILE__), 'test_helper')

class InstantiationTest < ActiveSupport::TestCase
  def setup
    ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 7)
    # order of fixtures is important for the test - last loaded should not be with max(id)
    %w[steam_locomotives electric_locomotives maglev_locomotives bicycles].each do |f|
      ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', f)
    end
    @connection = ActiveRecord::Base.connection
  end

  def teardown
    ActiveRecord::FixtureSet.reset_cache
  end

  class ::Locomotive < ActiveRecord::Base
    self.disable_inheritance_instantiation = true
  end

  class ::ElectricLocomotive < Locomotive
    self.disable_inheritance_instantiation = false
  end

  def test_setting_disable_inheritance_instantiation_does_not_load_child_columns
    assert_equal %w[id max_speed name type],
                 Locomotive.first.attributes.keys.sort
  end

  def test_switching_off_disable_inheritance_instantiation_loads_child_columns
    assert_equal %w[electricity_consumption id magnetic_field max_speed name type],
                 MaglevLocomotive.first.attributes.keys.sort
  end

  def test_disable_inheritance_instantiatioon_not_set_loads_child_attributes
    assert_equal %w[id name number_of_gears number_of_wheels vehicle_type],
                 Bicycle.first.attributes.keys.sort

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
updateable_views_inheritance-1.4.3 test/instantiation_test.rb