Sha256: d9f1a095f48766057a1d6218429b3208bf0c2c3195bb6b31b099e7790a596b4e
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
require "to_fixture/version" require "active_support" require "active_record" module ToFixture module Base 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 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 end module Relation def to_fixture map(&:to_fixture).join("\n\n") end end end ActiveSupport.on_load(:active_record) do include ToFixture::Base ActiveRecord::Relation.include(ToFixture::Relation) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
to_fixture-0.3.0 | lib/to_fixture.rb |