class Kibutsu::Fixture

Corresponds to one named fixture from a fixture file.

Constants

TIMESTAMP_COLUMN_NAMES

Attributes

attributes[R]
name[R]
table[R]

Public Class Methods

new(table, name, attributes) click to toggle source
# File lib/kibutsu/fixture.rb, line 8
def initialize(table, name, attributes)
  @table = table
  @name = name
  @attributes = attributes
end

Public Instance Methods

enriched_attributes() click to toggle source
# File lib/kibutsu/fixture.rb, line 14
def enriched_attributes
  enriched_attributes = enrich_with_id(attributes)
  enriched_attributes = enrich_with_foreign_keys(enriched_attributes)
  enrich_with_timestamps(enriched_attributes)
end

Private Instance Methods

column_name_to_model_name(column_name) click to toggle source
# File lib/kibutsu/fixture.rb, line 56
def column_name_to_model_name(column_name)
  column_name.to_s[0..-4]
end
enrich_with_foreign_keys(attr) click to toggle source
# File lib/kibutsu/fixture.rb, line 28
def enrich_with_foreign_keys(attr)
  foreign_key_columns.each do |foreign_key_column|
    foreign_fixture_name = foreign_table_reference(attr, foreign_key_column)
    if foreign_fixture_name
      attr[foreign_key_column.name] =
        Kibutsu.fixture_name_to_id(foreign_fixture_name)
    end
  end
  attr
end
enrich_with_id(attr) click to toggle source
# File lib/kibutsu/fixture.rb, line 24
def enrich_with_id(attr)
  attr.merge('id' => Kibutsu.fixture_name_to_id(@name))
end
enrich_with_timestamps(attr) click to toggle source
# File lib/kibutsu/fixture.rb, line 43
def enrich_with_timestamps(attr)
  time = Time.now
  TIMESTAMP_COLUMN_NAMES.each do |timestamp_column_name|
    next unless table.column_names.include? timestamp_column_name.to_sym
    attr[timestamp_column_name] = time
  end
  attr
end
foreign_key_columns() click to toggle source
# File lib/kibutsu/fixture.rb, line 39
def foreign_key_columns
  table.foreign_key_columns
end
foreign_table_reference(attr, foreign_key_column) click to toggle source
# File lib/kibutsu/fixture.rb, line 52
def foreign_table_reference(attr, foreign_key_column)
  attr.delete(column_name_to_model_name(foreign_key_column.name))
end