Sha256: acea35761862332a17b33635fe8a224a21b59ea78732b494f3c030cde8caca6b

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 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

  def test_setting_disable_inheritance_instantiation_does_not_load_child_columns
    unless Locomotive.first
      puts "num locomotives:", @connection.select_one("SELECT count(id) FROM locomotives")
    end
    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

3 entries across 3 versions & 1 rubygems

Version Path
updateable_views_inheritance-1.4.6 test/instantiation_test.rb
updateable_views_inheritance-1.4.5 test/instantiation_test.rb
updateable_views_inheritance-1.4.4 test/instantiation_test.rb