1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/tests/helpers/model_helper.rb
2010-09-29 11:42:50 -07:00

72 lines
No EOL
1.2 KiB
Ruby

def tests_model
tests_model_first
tests_collection
tests_model_last
end
def tests_model_first
tests(@model.class) do
test('#save') do
@model.save
end
if @model.respond_to?(:ready?)
@model.wait_for { ready? }
end
test('#reload') do
reloaded = @model.reload
@model.attributes == reloaded.attributes
end
end
end
def tests_collection
tests(@collection.class) do
test('collection#all includes persisted models') do
@collection.all.map {|model| model.identity}.include?(@model.identity)
end
tests('collection#get') do
test 'should return a matching model if one exists' do
get = @collection.get(@model.identity)
@model.attributes == get.attributes
end
test 'should return nil if no matching model exists' do
!@collection.get(@non_id)
end
end
test('collection#reload') do
@collection.all
reloaded = @collection.reload
@collection.attributes == reloaded.attributes
end
end
end
def tests_model_last
tests(@model.class) do
test('#destroy') do
if @model.respond_to?(:ready?)
@model.wait_for{ ready? }
end
@model.destroy
end
end
end