mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[s3] working on easier to reuse testing strategy for models
This commit is contained in:
parent
5ae1a79040
commit
4315a65e51
3 changed files with 86 additions and 0 deletions
8
tests/aws/models/s3/directory_tests.rb
Normal file
8
tests/aws/models/s3/directory_tests.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
Shindo.tests('AWS::S3 | directory models', ['aws']) do
|
||||||
|
|
||||||
|
@collection = AWS[:s3].directories
|
||||||
|
@model = @collection.new(:key => Time.now.to_f.to_s)
|
||||||
|
|
||||||
|
tests_models
|
||||||
|
|
||||||
|
end
|
|
@ -1,6 +1,8 @@
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'fog'))
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'fog'))
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'fog', 'bin'))
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'fog', 'bin'))
|
||||||
|
|
||||||
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'model_helper'))
|
||||||
|
|
||||||
if ENV["FOG_MOCK"] == "true"
|
if ENV["FOG_MOCK"] == "true"
|
||||||
Fog.mock!
|
Fog.mock!
|
||||||
end
|
end
|
||||||
|
|
76
tests/helpers/model_helper.rb
Normal file
76
tests/helpers/model_helper.rb
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
def tests_models
|
||||||
|
|
||||||
|
after do
|
||||||
|
if @model && !@model.new_record?
|
||||||
|
if @model.respond_to?(:ready?)
|
||||||
|
@model.wait_for { ready? }
|
||||||
|
end
|
||||||
|
@model.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('collection') do
|
||||||
|
|
||||||
|
test('#all includes persisted models') do
|
||||||
|
@model.save
|
||||||
|
@collection.all.map {|model| model.identity}.include? @model.identity
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('#get') do
|
||||||
|
|
||||||
|
test 'should return a matching model if one exists' do
|
||||||
|
@model.save
|
||||||
|
get = @collection.get(@model.identity)
|
||||||
|
@model.attributes == get.attributes
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'should return nil if no matching model exists' do
|
||||||
|
!@collection.get('0')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
test('#reload') do
|
||||||
|
@model.save
|
||||||
|
@collection.all
|
||||||
|
reloaded = @collection.reload
|
||||||
|
@collection.attributes == reloaded.attributes
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('model') do
|
||||||
|
|
||||||
|
test('#reload') do
|
||||||
|
@model.save
|
||||||
|
if @model.respond_to?(:ready?)
|
||||||
|
@model.wait_for { ready? }
|
||||||
|
end
|
||||||
|
reloaded = @model.reload
|
||||||
|
@model.attributes == reloaded.attributes
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('#save') do
|
||||||
|
|
||||||
|
test('does not exist remotely before save') do
|
||||||
|
!@collection.get(@model.identity)
|
||||||
|
end
|
||||||
|
|
||||||
|
test('succeeds') do
|
||||||
|
@model.save
|
||||||
|
end
|
||||||
|
|
||||||
|
test('does exist remotely after save') do
|
||||||
|
@model.save
|
||||||
|
if @model.respond_to?(:ready?)
|
||||||
|
@model.wait_for { ready? }
|
||||||
|
end
|
||||||
|
reloaded = @model.reload
|
||||||
|
@model.attributes == reloaded.attributes
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in a new issue