1 # -*- encoding: utf-8 -*-
7 @path = Rails.root + 'lib/test/temp/'
8 Dir.glob @path + '*' do |filename|
9 if File.directory?(filename)
10 Dir.glob filename do |filename2|
11 File.delete(filename2) unless File.directory?(filename2)
17 describe PictureIO::S3Picture do
20 @io = PictureIO::S3Picture.new @path
23 describe 'サブディレクトリに於いて' do
25 PictureIO::S3Picture.subdirs.is_a?(Array).should be_true
28 it 'カレント、サムネ、水平反転、垂直反転、水平垂直反転が返る' do
29 PictureIO::S3Picture.subdirs.size.should eq 5
30 PictureIO::S3Picture.subdirs.include?('').should eq true
31 PictureIO::S3Picture.subdirs.include?('v').should eq true
32 PictureIO::S3Picture.subdirs.include?('h').should eq true
33 PictureIO::S3Picture.subdirs.include?('vh').should eq true
34 PictureIO::S3Picture.subdirs.include?('thumbnail').should eq true
38 describe 'ファイル存在確認に於いて' do
40 AWS::S3::S3Object.stub(:exist?).with(any_args).and_return(true)
42 context 'ベースディレクトリから取るとき' do
45 AWS::S3::S3Object.should_receive(:exist?).with(testname, @path).exactly(1)
49 context 'サブディレクトリvから取るとき' do
53 AWS::S3::S3Object.should_receive(:exist?).with(subd + '/' + testname, @path).exactly(1)
54 @io.exist?(testname, subd)
57 context '例外が発生するとき' do
59 AWS::S3::S3Object.stub(:exist?).with(any_args()).and_raise(StandardError)
60 @io.exist?('test.get').should be_false
65 describe 'ファイル取得に於いて' do
68 context 'ベースディレクトリから取るとき' do
71 AWS::S3::S3Object.should_receive(:stream).with(testname, @path).exactly(1)
75 AWS::S3::S3Object.stub(:stream).with(any_args()).and_yield('data')
76 @io.get('test.get').should eq 'data'
79 context 'サブディレクトリvから取るとき' do
83 AWS::S3::S3Object.should_receive(:stream).with(subd + '/' + testname, @path).exactly(1)
84 @io.get(testname, subd)
88 AWS::S3::S3Object.stub(:stream).with(any_args()).and_yield('data')
89 @io.get('test.get', subd).should eq 'data'
92 context '例外が発生するとき' do
94 AWS::S3::S3Object.stub(:get).with(any_args()).and_raise(StandardError)
95 @io.get('test.get').should be_false
100 describe 'ファイル作成に於いて' do
103 context 'ベースディレクトリに作成するとき' do
106 AWS::S3::S3Object.should_receive(:store).with(testname, 'bindata', @path).exactly(1)
107 @io.put('bindata', testname)
110 context 'サブディレクトリvに作成するとき' do
114 AWS::S3::S3Object.should_receive(:store).with(subd + '/' + testname, 'bindata', @path).exactly(1)
115 @io.put('bindata', testname, subd)
118 context '例外が発生するとき' do
120 AWS::S3::S3Object.stub(:store).with(any_args()).and_raise(StandardError)
121 @io.put('bindata', 'test.put').should be_false
126 describe 'ファイル削除に於いて' do
129 context 'ベースディレクトリから削除するとき' do
132 AWS::S3::S3Object.should_receive(:delete).with(testname, @path).exactly(1)
136 context 'サブディレクトリvhから削除するとき' do
140 AWS::S3::S3Object.should_receive(:delete).with(subd + '/' + testname, @path).exactly(1)
141 @io.delete(testname, subd)
144 context '例外が発生するとき' do
146 AWS::S3::S3Object.stub(:delete).with(any_args()).and_raise(StandardError)
147 @io.delete('test.del.not.exist').should be_false