Sha256: 9a94c1d04663ba5eed56a998d8768f4160c7788a1cda047e862dba8bd255dc30

Contents?: true

Size: 1.15 KB

Versions: 8

Compression:

Stored size: 1.15 KB

Contents

require "cases/helper"

module SchemaLoadCounter
  extend ActiveSupport::Concern

  module ClassMethods
    attr_accessor :load_schema_calls

    def load_schema!
      self.load_schema_calls ||= 0
      self.load_schema_calls +=1
      super
    end
  end
end

class SchemaLoadingTest < ActiveRecord::TestCase
  def test_basic_model_is_loaded_once
    klass = define_model
    klass.new
    assert_equal 1, klass.load_schema_calls
  end

  def test_model_with_custom_lock_is_loaded_once
    klass = define_model do |c|
      c.table_name = :lock_without_defaults_cust
      c.locking_column = :custom_lock_version
    end
    klass.new
    assert_equal 1, klass.load_schema_calls
  end

  def test_model_with_changed_custom_lock_is_loaded_twice
    klass = define_model do |c|
      c.table_name = :lock_without_defaults_cust
    end
    klass.new
    klass.locking_column = :custom_lock_version
    klass.new
    assert_equal 2, klass.load_schema_calls
  end

  private

    def define_model
      Class.new(ActiveRecord::Base) do
        include SchemaLoadCounter
        self.table_name = :lock_without_defaults
        yield self if block_given?
      end
    end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ibm_db-5.2.0 test/cases/schema_loading_test.rb
ibm_db-5.1.0 test/cases/schema_loading_test.rb
ibm_db-5.0.5 test/cases/schema_loading_test.rb
ibm_db-5.0.4 test/cases/schema_loading_test.rb
ibm_db-5.0.3 test/cases/schema_loading_test.rb
ibm_db-5.0.2 test/cases/schema_loading_test.rb
ibm_db-4.0.0-x86-mingw32 test/cases/schema_loading_test.rb
ibm_db-4.0.0 test/cases/schema_loading_test.rb