diff options
5 files changed, 49 insertions, 33 deletions
diff --git a/activerecord/lib/rails/generators/active_record/model/model_generator.rb b/activerecord/lib/rails/generators/active_record/model/model_generator.rb index e4c9539362..15aecf28ca 100644 --- a/activerecord/lib/rails/generators/active_record/model/model_generator.rb +++ b/activerecord/lib/rails/generators/active_record/model/model_generator.rb @@ -29,25 +29,25 @@ module ActiveRecord template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke end - def attributes_with_index - attributes.select { |a| !a.reference? && a.has_index? } - end - - def accessible_attributes - attributes.reject(&:reference?) - end - hook_for :test_framework protected + def attributes_with_index + attributes.select { |a| !a.reference? && a.has_index? } + end + # Used by the migration template to determine the parent name of the model def parent_class_name options[:parent] || determine_default_parent_class end def determine_default_parent_class - if File.exist?('app/models/application_record.rb') + application_record = nil + + in_root { application_record = File.exist?('app/models/application_record.rb') } + + if application_record "ApplicationRecord" else "ActiveRecord::Base" diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 19be357b6e..b6813891c6 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -549,7 +549,6 @@ class MigrationTest < ActiveRecord::TestCase expected_id = Zlib.crc32(current_database) * salt assert lock_id == expected_id, "expected lock id generated by the migrator to be #{expected_id}, but it was #{lock_id} instead" - assert lock_id.is_a?(Fixnum), "expected lock id to be a Fixnum, but it wasn't" assert lock_id.bit_length <= 63, "lock id must be a signed integer of max 63 bits magnitude" end diff --git a/activesupport/lib/active_support/logger.rb b/activesupport/lib/active_support/logger.rb index 33fccdcf95..82117a64d2 100644 --- a/activesupport/lib/active_support/logger.rb +++ b/activesupport/lib/active_support/logger.rb @@ -1,4 +1,3 @@ -require 'active_support/core_ext/module/attribute_accessors' require 'active_support/logger_silence' require 'logger' @@ -6,16 +5,18 @@ module ActiveSupport class Logger < ::Logger include LoggerSilence + attr_accessor :broadcast_messages + # Broadcasts logs to multiple loggers. def self.broadcast(logger) # :nodoc: Module.new do define_method(:add) do |*args, &block| - logger.add(*args, &block) + logger.add(*args, &block) if broadcast_messages super(*args, &block) end define_method(:<<) do |x| - logger << x + logger << x if broadcast_messages super(x) end @@ -44,6 +45,7 @@ module ActiveSupport def initialize(*args) super @formatter = SimpleFormatter.new + @broadcast_messages = true end # Simple formatter which only displays the message. diff --git a/activesupport/lib/active_support/logger_silence.rb b/activesupport/lib/active_support/logger_silence.rb index a8efdef944..7d92256f24 100644 --- a/activesupport/lib/active_support/logger_silence.rb +++ b/activesupport/lib/active_support/logger_silence.rb @@ -1,8 +1,9 @@ require 'active_support/concern' +require 'active_support/core_ext/module/attribute_accessors' module LoggerSilence extend ActiveSupport::Concern - + included do cattr_accessor :silencer self.silencer = true @@ -21,4 +22,4 @@ module LoggerSilence yield self end end -end
\ No newline at end of file +end diff --git a/activesupport/test/broadcast_logger_test.rb b/activesupport/test/broadcast_logger_test.rb index 6d4e3b74f7..e7d56c80c3 100644 --- a/activesupport/test/broadcast_logger_test.rb +++ b/activesupport/test/broadcast_logger_test.rb @@ -2,56 +2,69 @@ require 'abstract_unit' module ActiveSupport class BroadcastLoggerTest < TestCase - attr_reader :logger, :log1, :log2 + attr_reader :logger, :receiving_logger def setup - @log1 = FakeLogger.new - @log2 = FakeLogger.new - @log1.extend Logger.broadcast @log2 - @logger = @log1 + @logger = FakeLogger.new + @receiving_logger = FakeLogger.new + @logger.extend Logger.broadcast @receiving_logger end def test_debug logger.debug "foo" - assert_equal 'foo', log1.adds.first[2] - assert_equal 'foo', log2.adds.first[2] + assert_equal 'foo', logger.adds.first[2] + assert_equal 'foo', receiving_logger.adds.first[2] + end + + def test_debug_without_message_broadcasts + logger.broadcast_messages = false + logger.debug "foo" + assert_equal 'foo', logger.adds.first[2] + assert_equal [], receiving_logger.adds end def test_close logger.close - assert log1.closed, 'should be closed' - assert log2.closed, 'should be closed' + assert logger.closed, 'should be closed' + assert receiving_logger.closed, 'should be closed' end def test_chevrons logger << "foo" - assert_equal %w{ foo }, log1.chevrons - assert_equal %w{ foo }, log2.chevrons + assert_equal %w{ foo }, logger.chevrons + assert_equal %w{ foo }, receiving_logger.chevrons + end + + def test_chevrons_without_message_broadcasts + logger.broadcast_messages = false + logger << "foo" + assert_equal %w{ foo }, logger.chevrons + assert_equal [], receiving_logger.chevrons end def test_level assert_nil logger.level logger.level = 10 - assert_equal 10, log1.level - assert_equal 10, log2.level + assert_equal 10, logger.level + assert_equal 10, receiving_logger.level end def test_progname assert_nil logger.progname logger.progname = 10 - assert_equal 10, log1.progname - assert_equal 10, log2.progname + assert_equal 10, logger.progname + assert_equal 10, receiving_logger.progname end def test_formatter assert_nil logger.formatter logger.formatter = 10 - assert_equal 10, log1.formatter - assert_equal 10, log2.formatter + assert_equal 10, logger.formatter + assert_equal 10, receiving_logger.formatter end class FakeLogger attr_reader :adds, :closed, :chevrons - attr_accessor :level, :progname, :formatter + attr_accessor :level, :progname, :formatter, :broadcast_messages def initialize @adds = [] @@ -60,6 +73,7 @@ module ActiveSupport @level = nil @progname = nil @formatter = nil + @broadcast_messages = true end def debug msg, &block |