spec/support/test_app/lib/ar_fixtures.rb
def load_from_file(path = nil)
      path ||= "db/#{table_name}.yml"

      self.destroy_all

      if connection.respond_to?(:reset_pk_sequence!)
       connection.reset_pk_sequence!(table_name)
      end

      records = YAML.load(File.open(File.expand_path(path, Rails.root)))
      records.each do |record|
        record_copy = self.new(record.attributes)
        record_copy.id = record.id

        # For Single Table Inheritance
        klass_col = record.class.inheritance_column.to_sym
        if record[klass_col]
           record_copy.type = record[klass_col]
        end

        record_copy.save
      end

      if connection.respond_to?(:reset_pk_sequence!)
       connection.reset_pk_sequence!(table_name)
      end
    end
# Delete existing data in database and load fresh from file in db/table_name.yml
Delete existing data in database and load fresh from file in db/table_name.yml
Delete existing data in database and load fresh from file in db / table_name . yml
def load_from_file(path = nil)
      path ||= "db/#{table_name}.yml"
      self.destroy_all
      if connection.respond_to?(:reset_pk_sequence!)
       connection.reset_pk_sequence!(table_name)
      end
      records = YAML.load(File.open(File.expand_path(path, Rails.root)))
      records.each do |record|
        record_copy = self.new(record.attributes)
        record_copy.id = record.id
        klass_col = record.class.inheritance_column.to_sym
        if record[klass_col]
           record_copy.type = record[klass_col]
        end
        record_copy.save
      end
      if connection.respond_to?(:reset_pk_sequence!)
       connection.reset_pk_sequence!(table_name)
      end
    end
def load_from_file ( path = nil ) path ||= "db/#{table_name}.yml" self . destroy_all if connection . respond_to? ( :reset_pk_sequence! ) connection . reset_pk_sequence! ( table_name ) end records = YAML . load ( File . open ( File . expand_path ( path , Rails . root ) ) ) records . each do | record | record_copy = self . new ( record . attributes ) record_copy . id = record . id klass_col = record . class . inheritance_column . to_sym if record [ klass_col ] record_copy . type = record [ klass_col ] end record_copy . save end if connection . respond_to? ( :reset_pk_sequence! ) connection . reset_pk_sequence! ( table_name ) end end
Delete existing data in database and load fresh from file in db/table_name.yml
Delete existing data in database and load fresh from file in db / table_name . yml
# For Single Table Inheritance
path