1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

cleanup toward better model tests

This commit is contained in:
geemus 2010-09-29 11:42:50 -07:00
parent 0d78d10451
commit 4c388d0108
2 changed files with 51 additions and 43 deletions

View file

@ -2,7 +2,8 @@ Shindo.tests('AWS::Storage | directory models', ['aws']) do
@collection = AWS[:storage].directories @collection = AWS[:storage].directories
@model = @collection.new(:key => Time.now.to_f.to_s) @model = @collection.new(:key => Time.now.to_f.to_s)
@non_id = 'not_a_directory'
tests_models tests_model
end end

View file

@ -1,65 +1,72 @@
def tests_models def tests_model
tests_model_first
tests_collection
tests_model_last
end
tests('model#save') do def tests_model_first
test('does not exist remotely before save') do tests(@model.class) do
!@collection.get(@model.identity)
end
test('succeeds') do test('#save') do
@model.save @model.save
end end
test('does exist remotely after save') do if @model.respond_to?(:ready?)
@model.save @model.wait_for { ready? }
if @model.respond_to?(:ready?) end
@model.wait_for { ready? }
end test('#reload') do
reloaded = @model.reload reloaded = @model.reload
@model.attributes == reloaded.attributes @model.attributes == reloaded.attributes
end end
end end
test('model#reload') do end
if @model.respond_to?(:ready?)
@model.wait_for { ready? }
end
reloaded = @model.reload
@model.attributes == reloaded.attributes
end
test('collection#all includes persisted models') do def tests_collection
@model.save
@collection.all.map {|model| model.identity}.include? @model.identity
end
tests('collection#get') do tests(@collection.class) do
test 'should return a matching model if one exists' do test('collection#all includes persisted models') do
@model.save @collection.all.map {|model| model.identity}.include?(@model.identity)
get = @collection.get(@model.identity)
@model.attributes == get.attributes
end end
test 'should return nil if no matching model exists' do tests('collection#get') do
!@collection.get('0')
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 end
end test('collection#reload') do
@collection.all
test('collection#reload') do reloaded = @collection.reload
@model.save @collection.attributes == reloaded.attributes
@collection.all
reloaded = @collection.reload
@collection.attributes == reloaded.attributes
end
test('model#destroy') do
if @model.respond_to?(:ready?)
@model.wait_for{ ready? }
end end
@model.destroy
end 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