Sha256: 087b8d2a1cc992be7d42658d048406010e7966f399954642a3141ad1c4734130

Contents?: true

Size: 904 Bytes

Versions: 14

Compression:

Stored size: 904 Bytes

Contents

class CollectionFactory
  PREFIX = "fog-test"

  def initialize(subject, example)
    @subject = subject
    @example = example
    @resource_counter = 0
  end

  def cleanup
    resources = @subject.all.select { |resource| resource.name.start_with? PREFIX }
    resources.each(&:destroy)
    resources.each { |r| Fog.wait_for { !@subject.all.map(&:identity).include? r.identity } }
  end

  def create
    @subject.create(params)
  end

  def resource_name(base = @example, prefix = PREFIX)
    index = @resource_counter += 1
    # In prefix, convert - to _ to make sure that it doesn't get stripped by the \W strip below.
    # Then, concatenate prefix, index, and base; strip all non-alphanumerics except _;
    # convert _ to -; downcase; truncate to 62 characters; delete trailing -
    ([prefix.tr("-", "_"), index, base].join("_")).gsub(/\W/, "").tr("_", "-").downcase[0..61].chomp("-")
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
fog-google-0.6.0 test/integration/factories/collection_factory.rb
fog-google-0.5.5 test/integration/factories/collection_factory.rb
fog-google-0.5.4 test/integration/factories/collection_factory.rb
fog-google-0.5.3 test/integration/factories/collection_factory.rb
fog-google-0.5.2 test/integration/factories/collection_factory.rb
fog-google-0.5.1 test/integration/factories/collection_factory.rb
fog-google-0.5.0 test/integration/factories/collection_factory.rb
fog-google-0.4.2 test/integration/factories/collection_factory.rb
fog-google-0.4.1 test/integration/factories/collection_factory.rb
fog-google-0.4.0 test/integration/factories/collection_factory.rb
fog-google-0.3.2 test/integration/factories/collection_factory.rb
fog-google-0.3.1 test/integration/factories/collection_factory.rb
fog-google-0.3.0 test/integration/factories/collection_factory.rb
fog-google-0.2.0 test/integration/factories/collection_factory.rb