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

72 lines
1.2 KiB
Ruby
Raw Normal View History

2010-09-29 11:42:50 -07:00
def tests_model
tests_model_first
tests_collection
tests_model_last
end
2010-09-29 11:42:50 -07:00
def tests_model_first
2010-09-29 11:42:50 -07:00
tests(@model.class) do
2010-09-29 11:42:50 -07:00
test('#save') do
@model.save
end
2010-09-29 11:42:50 -07:00
if @model.respond_to?(:ready?)
@model.wait_for { ready? }
end
test('#reload') do
reloaded = @model.reload
@model.attributes == reloaded.attributes
end
end
2010-09-29 11:42:50 -07:00
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
2010-09-29 11:42:50 -07:00
tests('collection#get') do
2010-09-29 11:42:50 -07:00
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
2010-09-29 11:42:50 -07:00
test('collection#reload') do
@collection.all
reloaded = @collection.reload
@collection.attributes == reloaded.attributes
end
end
2010-09-29 11:42:50 -07:00
end
2010-09-29 11:42:50 -07:00
def tests_model_last
tests(@model.class) do
test('#destroy') do
if @model.respond_to?(:ready?)
@model.wait_for{ ready? }
end
@model.destroy
end
2010-09-29 11:42:50 -07:00
end
2010-09-29 11:42:50 -07:00
end