1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases/schema_loading_test.rb
Ryuta Kamizono c81af6ae72 Enable Layout/EmptyLinesAroundAccessModifier cop
We sometimes say "✂️ newline after `private`" in a code review (e.g.
https://github.com/rails/rails/pull/18546#discussion_r23188776,
https://github.com/rails/rails/pull/34832#discussion_r244847195).

Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style
`EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059).

That cop and enforced style will reduce the our code review cost.
2019-06-13 12:00:45 +09:00

53 lines
1.2 KiB
Ruby

# frozen_string_literal: true
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