Sha256: 77ad6e4806b0d009077700111327b7aba28fec0350b021b182fb2015bb59d221

Contents?: true

Size: 867 Bytes

Versions: 1

Compression:

Stored size: 867 Bytes

Contents

class Fixtures
  include Singleton

  # Load all fixtures from json file
  def load!
    cleanup!

    data = JSON.parse(File.open(File.expand_path("spec/support/fixtures/databases.json"), "r").read)
    data.each do |database_data|
      database = connection.db(database_data["name"])

      (database_data["collections"] || []).each do |collection_data|
        collection = database.create_collection(collection_data["name"])

        (collection_data["documents"] || []).each do |document_data|
          collection.insert(document_data)
        end
      end
    end
  end

  # Delete all databases
  def cleanup!
    connection.database_names.each do |db_name|
      connection.drop_database(db_name)
    end
  end

  def connection
    @connection ||= begin
      Mongo::Connection.new(MongoBrowser::DEFAULT_HOST, MongoBrowser.mongodb_port)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongo_browser-0.1.3 spec/support/fixtures.rb