2010-11-16 18:31:34 -05:00
|
|
|
def model_tests(collection, params = {}, mocks_implemented = true)
|
2010-11-11 14:54:55 -05:00
|
|
|
tests('success') do
|
|
|
|
|
2011-05-24 17:59:48 -04:00
|
|
|
@instance = collection.new(params)
|
2010-11-11 14:54:55 -05:00
|
|
|
|
|
|
|
tests("#save").succeeds do
|
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
@instance.save
|
|
|
|
end
|
|
|
|
|
|
|
|
if block_given?
|
2014-06-13 10:10:00 -04:00
|
|
|
yield(@instance)
|
2010-11-11 14:54:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests("#destroy").succeeds do
|
|
|
|
pending if Fog.mocking? && !mocks_implemented
|
|
|
|
@instance.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2011-06-04 07:55:56 -04:00
|
|
|
|
|
|
|
# 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
|
|
|
|
suffix = rand(65536).to_s(16).rjust(4, '0')
|
|
|
|
[base_name, suffix] * '-'
|
|
|
|
end
|