2014-12-30 17:25:09 -05:00
|
|
|
def model_tests(collection, params = {}, mocks_implemented = true)
|
|
|
|
tests('success') do
|
|
|
|
@instance = collection.new(params)
|
|
|
|
|
2018-10-16 18:12:42 -04:00
|
|
|
tests('#save').succeeds do
|
2014-12-30 17:25:09 -05:00
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
@instance.save
|
|
|
|
end
|
|
|
|
|
|
|
|
if block_given?
|
|
|
|
yield(@instance)
|
|
|
|
end
|
|
|
|
|
2018-10-16 18:12:42 -04:00
|
|
|
tests('#destroy').succeeds do
|
2014-12-30 17:25:09 -05:00
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
@instance.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Generates a unique identifier with a random differentiator.
|
|
|
|
# Useful when rapidly re-running tests, so we don't have to wait
|
|
|
|
# serveral minutes for deleted objects to disappear from the API
|
|
|
|
# E.g. 'fog-test-1234'
|
|
|
|
def uniq_id(base_name = 'fog-test')
|
|
|
|
# random_differentiator
|
2018-10-16 18:12:42 -04:00
|
|
|
suffix = rand(65_536).to_s(16).rjust(4, '0')
|
|
|
|
[base_name, suffix].join('-')
|
2014-12-30 17:25:09 -05:00
|
|
|
end
|