1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00
fog--fog-aws/tests/helpers/model_helper.rb
David Bishop 62256219f4 Modernize various tests to Ruby 2.x syntax
Also fix up various things that rubocop called out, though not
everything. Mostly whitespace fixes, changing double-quotes to single if
double wasn't required, changing to use ruby 2.x hash syntax where
possible, etc. While tests don't run, they are no more broken than
before (at least, as far as I can tell).
2018-10-16 16:12:42 -06:00

30 lines
784 B
Ruby

def model_tests(collection, params = {}, mocks_implemented = true)
tests('success') do
@instance = collection.new(params)
tests('#save').succeeds do
pending if Fog.mocking? && !mocks_implemented
@instance.save
end
if block_given?
yield(@instance)
end
tests('#destroy').succeeds do
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
suffix = rand(65_536).to_s(16).rjust(4, '0')
[base_name, suffix].join('-')
end