Sha256: 203f4e51f8b9a2d09e01e32a30ee99a0e21bac769d580af4089d58a03a1753c9

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

require_relative '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

    Locomotive.disable_inheritance_instantiation = true
    ElectricLocomotive.disable_inheritance_instantiation = false
  end

  def teardown
    Locomotive.disable_inheritance_instantiation = false
    ActiveRecord::FixtureSet.reset_cache
  end

  # FIXME: flaky test_setting_disable_inheritance_instantiation_does_not_load_child_columns
  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

2 entries across 2 versions & 1 rubygems

Version Path
updateable_views_inheritance-1.4.8 test/instantiation_test.rb
updateable_views_inheritance-1.4.7 test/instantiation_test.rb