module PgAuditLogSpecHelper::InstanceMethods

Public Instance Methods

create_object_for_klass(klass, exclude_columns = []) click to toggle source
# File lib/generators/pg_audit_log/templates/spec/models/pg_audit_log_spec_helper.rb, line 91
def create_object_for_klass(klass, exclude_columns = [])
  exclude_columns = exclude_columns | EXCLUDED_COLUMNS

  object = klass.new
  columns = klass.columns.reject {|column| exclude_columns.include? column.name }
  columns.each do |column|
    object.send("#{column.name}=", get_data(column))
  end

  object.send(:create_without_callbacks)
  [object, columns]
end
get_data(column, format_without_timezone = false) click to toggle source
# File lib/generators/pg_audit_log/templates/spec/models/pg_audit_log_spec_helper.rb, line 28
def get_data(column, format_without_timezone = false)
  case column.type
  when :boolean
    true
  when :date
    Date.parse("1/1/2000")
  when :datetime
    if format_without_timezone
      DateTime.parse("1/1/2000 1pm").utc.strftime("%Y-%m-%d %H:%M:%S")
    else
      DateTime.parse("1/1/2000 1pm").utc.to_s
    end
  when :integer
    7
  when :decimal
    "7.1234567891"
  when :float
    7.1234
  when :string
    if column.name == "type"
      "Object"
    else
      "Happy"
    end

  when :text
    "Happy text"
  else
    raise "I don't know how to make data for '#{column.type}'!"
  end
end
get_diff_data(column, format_without_timezone = false) click to toggle source
# File lib/generators/pg_audit_log/templates/spec/models/pg_audit_log_spec_helper.rb, line 60
def get_diff_data(column, format_without_timezone = false)
  case column.type
  when :boolean
    false
  when :date
    Date.parse("12/1/2000")
  when :datetime
    if format_without_timezone
      DateTime.parse("12/1/2000 1pm").utc.strftime("%Y-%m-%d %H:%M:%S")
    else
      DateTime.parse("12/1/2000 1pm").utc.to_s
    end
  when :integer
    9
  when :decimal
    "9.1234567891"
  when :float
    9.1234
  when :string
    if column.name == "type"
      "Object"
    else
      "Sad"
    end
  when :text
    "Sad text"
  else
    raise "I don't know how to make data for '#{column.type}'!"
  end
end