Sha256: f5b9d94bae32a9229592d486d8ef8904c126fff89f24b1ee501a17311b7692d7

Contents?: true

Size: 1.48 KB

Versions: 39

Compression:

Stored size: 1.48 KB

Contents

module TestLogging
  def log(msg)
    Rails.logger.info(msg)
  end
  
  def log_array(obj, *columns)
    lengths = columns.map{|m| m.to_s.length }

    obj.each do |r|
      columns.each_with_index do |m, i|
        v = r.send(m)
        if v.to_s.length > lengths[i]
          lengths[i] = v.to_s.length
        end
      end
    end

    str = "  "
    columns.each_with_index do |m, i|
      str << "%#{lengths[i]}s" % m
      str << "  "
    end
    str << "\n  "

    columns.each_with_index do |m, i|
      str << ("-"*lengths[i])
      str << "  "
    end
    str << "\n  "

    obj.each do |r|
      columns.each_with_index do |m, i|
        str << "%#{lengths[i]}s" % r.send(m)
        str << "  "
      end
      str << "\n  "      
    end

    log str    
  end  
  
  def log_table(cls, options={})
    if options[:include_columns]
      columns = options[:include_columns]
    elsif options[:exclude_columns]
      columns = cls.column_names - options[:exclude_columns].map(&:to_s)
    else
      columns = cls.column_names      
    end
    log_array (cls.uses_soft_delete? ? cls.find_with_deleted(:all) : cls.all), *columns
  end
  
  def log_table_with(cls, *columns)
    log_table(cls, :include_columns => columns)
  end
  
  def log_table_without(cls, *columns)
    log_table(cls, :exclude_columns => columns)
  end

  def log_table_without_stamps(cls, *columns)
    log_table(cls, :exclude_columns => %w[created_at updated_at created_by_id updated_by_id] + columns)
  end    
  
  extend self
  
end

Version data entries

39 entries across 39 versions & 10 rubygems

Version Path
SFEley-browsercms-3.0.2 test/test_logging.rb
buzzware-browsercms-3.0.2 test/test_logging.rb
coredumplings-browsercms-3.0.0 test/test_logging.rb
we5-browsercms-3.0.1.1 test/test_logging.rb
webficient-browsercms-3.0.1 test/test_logging.rb
webficient-browsercms-3.0.2 test/test_logging.rb
webficient-browsercms-3.0.3 test/test_logging.rb
webficient-browsercms-3.0.4 test/test_logging.rb
browsercms-3.4.2 test/test_logging.rb
browsercms-3.4.2.rc1 test/test_logging.rb
browsercms-3.4.1 test/test_logging.rb
browsercms-3.4.0 test/test_logging.rb
browsercms-3.4.0.rc2 test/test_logging.rb
browsercms-3.4.0.rc1 test/test_logging.rb
browsercms-3.1.5 test/test_logging.rb
browsercms-3.1.4 test/test_logging.rb
browsercms-3.1.3 test/test_logging.rb
bf4-browsercms-3.1.0 test/test_logging.rb
drujensen-browsercms-3.2.0 test/test_logging.rb
browsercmsi-3.1.2 test/test_logging.rb