Module: ToFixture::Base

Defined in:
lib/to_fixture.rb

Instance Method Summary collapse

Instance Method Details

#columns_for_fixtureObject



21
22
23
24
25
26
27
28
# File 'lib/to_fixture.rb', line 21

def columns_for_fixture
  timestamp_attributes = if respond_to?(:all_timestamp_attributes_in_model, true)
                           all_timestamp_attributes_in_model
                         else
                           all_timestamp_attributes
                         end
  self.class.column_names - timestamp_attributes.map(&:to_s) - %w(id)
end

#to_fixture(label = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/to_fixture.rb', line 7

def to_fixture(label = nil)
  label = "#{self.class.table_name}_#{self.id}" unless label

  inspection = if defined?(@attributes) && @attributes
    columns_for_fixture.collect do |name|
      "  #{name}: #{read_attribute(name)}" if has_attribute?(name)
    end.compact.join("\n")
  else
    "not initialized"
  end

  "#{label}:\n#{inspection}"
end