OSDN Git Service

pass test
[pettanr/pettanr.git] / spec / models / resource_picture_spec.rb
1 # -*- encoding: utf-8 -*-\r
2 require 'spec_helper'
3
4 describe ResourcePicture do
5   before do
6     Factory :admin
7     @user = Factory( :user_yas)
8     @author = @user.author
9     @artist = Factory :artist_yas, :author_id => @author.id\r
10     @other_user = Factory( :user_yas)
11     @other_author = @other_user.author
12     @other_artist = Factory :artist_yas, :author_id => @other_author.id
13     @license = Factory :license
14     @original_picture = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id\r
15     
16     class Mgk ; class Image ; end ; end
17     Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])
18     Mgk.any_instance.stub(:format).with(any_args).and_return('png')
19     Mgk.any_instance.stub(:format=).with(any_args)
20     Mgk.any_instance.stub(:rows).with(any_args).and_return(200)
21     Mgk.any_instance.stub(:columns).with(any_args).and_return(100)
22     Mgk.any_instance.stub(:filesize).with(any_args).and_return(20000)
23     Mgk.any_instance.stub(:to_blob).with(any_args).and_return('data')
24     #原画ファイル削除だけは必ず成功するものとしておく
25     PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
26   end\r
27   
28   describe '検証に於いて' do
29     before do\r
30     end
31     
32     it 'オーソドックスなデータなら通る' do
33       @rp = Factory.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id
34       @rp.should be_valid
35     end
36     
37     context 'extを検証するとき' do
38       before do
39         @rp = Factory.build :resource_picture, \r
40           :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id
41       end
42       it 'テストデータの確認' do
43         @rp.ext = 'jpeg'
44         @rp.should be_valid
45       end
46       it 'nullなら失敗する' do
47         @rp.ext = ''
48         @rp.should_not be_valid
49       end
50       it '5文字以上なら失敗する' do
51         @rp.ext = 'a'*5
52         @rp.should_not be_valid
53       end
54       it 'png,gif,jpeg以外なら失敗する' do
55         @rp.ext = 'bmp'
56         @rp.should_not be_valid
57       end
58     end
59     context 'widthを検証するとき' do
60       before do
61         @rp = Factory.build :resource_picture, \r
62           :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id
63       end
64       it 'テストデータの確認' do
65         @rp.width = 1
66         @rp.should be_valid
67       end
68       it 'nullなら失敗する' do
69         @rp.width = nil
70         @rp.should_not be_valid
71       end
72       it '数値でなければ失敗する' do
73         @rp.width = 'a'
74         @rp.should_not be_valid
75       end
76       it '0なら失敗する' do
77         @rp.width = '0'
78         @rp.should_not be_valid
79       end
80       it '負でも失敗する' do
81         @rp.width = -1
82         @rp.should_not be_valid
83       end
84     end
85     context 'heightを検証するとき' do
86       before do
87         @rp = Factory.build :resource_picture, \r
88           :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id
89       end
90       it 'テストデータの確認' do
91         @rp.height = '1'
92         @rp.should be_valid
93       end
94       it 'nullなら失敗する' do
95         @rp.height = nil
96         @rp.should_not be_valid
97       end
98       it '数値でなければ失敗する' do
99         @rp.height = 'a'
100         @rp.should_not be_valid
101       end
102       it '0なら失敗する' do
103         @rp.height = '0'
104         @rp.should_not be_valid
105       end
106       it '負でも失敗する' do
107         @rp.height = -1
108         @rp.should_not be_valid
109       end
110     end
111     context 'filesizeを検証するとき' do
112       before do
113         @rp = Factory.build :resource_picture, \r
114           :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id
115       end
116       it 'テストデータの確認' do
117         @rp.filesize = '1'
118         @rp.should be_valid
119       end
120       it 'nullなら失敗する' do
121         @rp.filesize = nil
122         @rp.should_not be_valid
123       end
124       it '数値でなければ失敗する' do
125         @rp.filesize = 'a'
126         @rp.should_not be_valid
127       end
128       it '負なら失敗する' do
129         @rp.filesize = '-1'
130         @rp.should_not be_valid
131       end
132       it '2MB以上なら失敗する' do
133         @rp.filesize = 2000000+1
134         @rp.should_not be_valid
135       end
136     end
137     context 'artist_idを検証するとき' do
138       before do
139         @rp = Factory.build :resource_picture, \r
140           :original_picture_id => @original_picture.id, :license_id => @license.id
141       end
142       it 'テストデータの確認' do
143         @rp.artist_id = @artist.id
144         @rp.should be_valid
145       end
146       it 'nullなら失敗する' do
147         @rp.artist_id = nil
148         @rp.should_not be_valid
149       end
150       it '数値でなければ失敗する' do
151         @rp.artist_id = 'a'
152         @rp.should_not be_valid
153       end
154       it '存在する絵師でなければ失敗する' do
155         @rp.artist_id = 0
156         @rp.should_not be_valid
157       end
158     end
159     context 'license_idを検証するとき' do
160       before do
161         @rp = Factory.build :resource_picture, \r
162           :artist_id => @artist.id, :original_picture_id => @original_picture.id
163       end
164       it 'テストデータの確認' do
165         @rp.license_id = @license.id
166         @rp.should be_valid
167       end
168       it 'nullなら失敗する' do
169         @rp.license_id = nil
170         @rp.should_not be_valid
171       end
172       it '数値でなければ失敗する' do
173         @rp.license_id = 'a'
174         @rp.should_not be_valid
175       end
176       it '存在する絵師でなければ失敗する' do
177         @rp.license_id = 0
178         @rp.should_not be_valid
179       end
180     end
181     context 'original_picture_idを検証するとき' do
182       before do
183         @rp = Factory.build :resource_picture, \r
184           :artist_id => @artist.id, :license_id => @license.id
185       end
186       it 'テストデータの確認' do
187         @rp.original_picture_id = @original_picture.id
188         @rp.should be_valid
189       end
190       it 'nullなら失敗する' do
191         @rp.original_picture_id = nil
192         @rp.should_not be_valid
193       end
194       it '数値でなければ失敗する' do
195         @rp.original_picture_id = 'a'
196         @rp.should_not be_valid
197       end
198       it '存在する原画でなければ失敗する' do
199         @rp.original_picture_id = 0
200         @rp.should_not be_valid
201       end
202     end
203   end
204   
205   describe 'データ補充に於いて' do
206     before do
207     end
208     
209   end
210   \r
211   describe '単体取得に於いて' do
212     before do
213       @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
214       @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id
215     end
216     it '指定の素材を返す' do
217       pic = ResourcePicture.show @rp.id
218       pic.should eq @rp
219     end
220     context '関連テーブルオプションがないとき' do
221       it 'ライセンスと絵師を含んでいる' do
222         r = ResourcePicture.show_include_opt
223         r.should eq [:license, :artist]
224       end
225     end
226     context '関連テーブルオプションで原画を含ませたとき' do
227       it 'ライセンスと絵師と原画データを含んでいる' do
228         r = ResourcePicture.show_include_opt(:include => :original_picture)
229         r.should eq [:license, :artist, :original_picture]
230       end
231     end
232     context '存在しない素材を開こうとしたとき' do
233       it '404RecordNotFound例外を返す' do
234         lambda{
235           pic = ResourcePicture.show 0
236         }.should raise_error(ActiveRecord::RecordNotFound)
237       end
238     end
239   end
240   describe 'json単体出力オプションに於いて' do
241     it 'includeキーがライセンスと絵師を含んでいる' do
242       r = ResourcePicture.show_json_include_opt
243       r[:include].should eq [:license, :artist]
244     end
245   end
246   describe '一覧取得に於いて' do
247     before do
248       @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
249       @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id
250     end
251     context 'page補正について' do
252       it '文字列から数値に変換される' do
253         ResourcePicture.page('8').should eq 8
254       end
255       it 'nilの場合は1になる' do
256         ResourcePicture.page().should eq 1
257       end
258       it '0以下の場合は1になる' do
259         ResourcePicture.page('0').should eq 1
260       end
261     end
262     context 'page_size補正について' do
263       it '文字列から数値に変換される' do
264         ResourcePicture.page_size('7').should eq 7
265       end
266       it 'nilの場合はResourcePicture.default_page_sizeになる' do
267         ResourcePicture.page_size().should eq ResourcePicture.default_page_size
268       end
269       it '0以下の場合はResourcePicture.default_page_sizeになる' do
270         ResourcePicture.page_size('0').should eq ResourcePicture.default_page_size
271       end
272       it 'ResourcePicture.max_page_sizeを超えた場合はResourcePicture.max_page_sizeになる' do
273         ResourcePicture.page_size('1000').should eq ResourcePicture.max_page_size
274       end
275     end
276     it 'リストを返す' do
277       pic = ResourcePicture.list
278       pic.should eq [@rp]
279     end
280     it '時系列で並んでいる' do
281       nop = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
282       nrp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop.id
283       pic = ResourcePicture.list
284       pic.should eq [nrp, @rp]
285     end
286     context 'DBに5件あって1ページの件数を2件に変えたとして' do
287       before do
288         nop2 = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
289         @nrp2 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop2.id
290         nop3 = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
291         @nrp3 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop3.id
292         nop4 = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
293         @nrp4 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop4.id
294         nop5 = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
295         @nrp5 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop5.id
296         ResourcePicture.stub(:default_page_size).and_return(2)
297       end
298       it '通常は2件を返す' do
299         pic = ResourcePicture.list
300         pic.should have(2).items 
301       end
302       it 'page=1なら末尾2件を返す' do
303         #時系列で並んでいる
304         pic = ResourcePicture.list({}, 1)
305         pic.should eq [@nrp5, @nrp4]
306       end
307       it 'page=2なら中間2件を返す' do
308         pic = ResourcePicture.list({}, 2)
309         pic.should eq [@nrp3, @nrp2]
310       end
311       it 'page=3なら先頭1件を返す' do
312         pic = ResourcePicture.list({}, 3)
313         pic.should eq [@rp]
314       end
315     end
316   end
317   describe 'json一覧出力オプションに於いて' do
318     it 'includeキーがライセンスと絵師を含んでいる' do
319       r = ResourcePicture.list_json_opt
320       r[:include].should eq [:license, :artist]
321     end
322   end\r
323   
324   describe 'サイズの調整に於いて' do
325     before do
326     end
327     
328     it 'サイズに収まるときはそのまま使う' do
329       ResourcePicture.fix_size_both(64, 64, 64, 64).should eq [64, 64]
330     end
331     it '小さくても拡大しない' do
332       ResourcePicture.fix_size_both(64, 64, 32, 32).should eq [32, 32]
333     end
334     it '縦長のときは縦に合わせて縮小' do
335       ResourcePicture.fix_size_both(64, 64, 64, 128).should eq [32, 64]
336     end
337     it '横長のときは横に合わせて縮小' do
338       ResourcePicture.fix_size_both(64, 64, 128, 64).should eq [64, 32]
339     end
340   end
341   \r
342   describe 'フォーマット変換対象判定に於いて' do
343     before do
344       @rp = Factory.build :resource_picture, \r
345         :artist_id => @artist.id, :license_id => @license.id
346     end
347     context '変換するケース' do\r
348       it '画像フォーマットがpngかつライセンスの変換禁止フラグが無効のときTrue' do\r
349         License.any_instance.stub(:no_convert).with(any_args).and_return(0)
350         @rp.ext = 'png'\r
351         @rp.to_gif?.should be_true
352       end
353     end
354     context '変換しないケース' do
355       it '画像フォーマットがでない' do\r
356         License.any_instance.stub(:no_convert).with(any_args).and_return(0)
357         @rp.ext = 'gif'\r
358         @rp.to_gif?.should be_false
359       end
360       it 'ライセンスの変換禁止フラグが無効' do\r
361         License.any_instance.stub(:no_convert).with(any_args).and_return(1)
362         @rp.ext = 'png'\r
363         @rp.to_gif?.should be_false
364       end
365     end
366   end
367   
368   describe 'Gifフォーマット変換に於いて' do
369     before do
370       Magick::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])
371     end
372     context 'つつがなく終わるとき' do
373       it 'Mgkオブジェクトが返る' do
374         mgk = ResourcePicture.png_to_gif('mgkbin')\r
375         mgk.is_a?(Mgk).should be_true
376       end
377       it 'Mgkオブジェクトはgif変換されている' do\r
378         #スタブばかりで変換できないので代入されているかでチェックする
379         Mgk.any_instance.should_receive(:format=).with('gif').exactly(1)
380         ResourcePicture.png_to_gif('mgkbin')\r
381       end
382     end
383     context 'RMagick変換が失敗したとき' do
384       before do
385         Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')
386       end
387       it 'falseを返す' do
388         res = ResourcePicture.png_to_gif('mgkbin')\r
389         res.should be_false\r
390       end
391     end
392   end
393   
394   describe '対象素材の取得に於いて' do
395     before do\r
396       @op = Factory.build :original_picture, :ext => 'jpeg', :width => 264, :height => 265, :filesize => 266, \r
397         :artist_id => @artist.id, :license_id => @license.id
398       @rp = Factory.build :resource_picture, \r
399         :artist_id => @artist.id, :license_id => @license.id
400     end
401     context '原画オブジェクトが素材を持っている(更新ケース)' do
402       before do\r
403         OriginalPicture.any_instance.stub(:resource_picture).with(any_args).and_return(@rp)\r
404       end
405       it 'それを対象素材として返す' do
406         res = ResourcePicture.update_picture(@op)\r
407         res.should eq @rp\r
408       end
409     end
410     context '持っていない(新規作成ケース)' do
411       before do\r
412         OriginalPicture.any_instance.stub(:resource_picture).with(any_args).and_return(nil)\r
413       end
414       it '新規素材モデルを用意し、それを対象素材として返す' do
415         res = ResourcePicture.update_picture(@op)\r
416         res.should be_a_new ResourcePicture\r
417       end\r
418       it '原画オブジェクトから属性を取り出して対象素材にセットしている' do
419         res = ResourcePicture.update_picture(@op)\r
420         res.ext.should eq 'jpeg'\r
421         res.width.should eq 264\r
422         res.height.should eq 265\r
423         res.filesize.should eq 266\r
424         res.artist_id.should eq @artist.id\r
425         res.license_id.should eq @license.id\r
426       end\r
427       
428     end
429   end
430   
431   describe '作成・更新に於いて' do
432     before do
433       @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
434       @rp = Factory.build :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id
435     end
436     context '事前チェック' do
437       before do
438         #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
439         #それで外部のメソッド呼び出しだけに着目してテストする。
440         ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
441         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
442         ResourcePicture.stub(:to_gif?).with(any_args).and_return(true)\r
443         class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために\r
444         @gifmgk = GifMgk.new      #パラメータを二種類用意する。\r
445         ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
446       end
447       it '自身を保存している' do
448         ResourcePicture.any_instance.should_receive(:save).with(any_args).exactly(1)
449         res = @rp.store(Mgk.new)\r
450       end\r
451       it '画像ファイルの作成・更新機能で画像を保存している' do\r
452         mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
453         ResourcePicture.any_instance.should_receive(:store_picture).with(mgk).exactly(1)
454         res = @rp.store(mgk)\r
455       end\r
456       it '自身にフォーマット変換対象かを問い合わせている' do
457         ResourcePicture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)
458         res = @rp.store(Mgk.new)\r
459       end\r
460       it '自身にGifフォーマット変換を依頼している' do
461         ResourcePicture.should_receive(:png_to_gif).with(any_args).exactly(1)
462         res = @rp.store(Mgk.new)\r
463       end\r
464       it '画像ファイルの作成・更新機能でgif画像を保存している' do\r
465         #二回目の保存はgif変換の結果を渡す。
466         ResourcePicture.any_instance.should_receive(:store_picture).with(@gifmgk).exactly(1)
467         res = @rp.store(Mgk.new)\r
468       end\r
469     end
470     context 'つつがなく終わるとき' do
471       before do
472         #すべての処理を正常パターンで通過させ、保存機能をチェックする。
473 #        ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
474         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
475         ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
476         class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために\r
477         @gifmgk = GifMgk.new      #パラメータを二種類用意する。\r
478         ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
479       end
480       it 'Trueを返す' do
481         res = @rp.store(Mgk.new)\r
482         res.should be_true\r
483       end\r
484       it '自身が保存されている' do\r
485         lambda {
486           res = @rp.store(Mgk.new)\r
487         }.should change ResourcePicture, :count\r
488       end\r
489     end
490     context 'gif変換なしで、つつがなく終わるとき' do
491       before do
492         #すべての処理を正常パターンで通過させ、保存機能をチェックする。
493         ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
494         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
495         ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(false)\r
496       end
497       it 'Trueを返す' do
498         res = @rp.store(Mgk.new)\r
499         res.should be_true\r
500       end\r
501       it 'gif保存は呼ばれていない' do\r
502         ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
503         res = @rp.store(Mgk.new)\r
504       end\r
505     end
506     #以下から例外ケース。処理先頭から失敗させていく
507     context '自身の保存に失敗したとき' do
508       before do
509         ResourcePicture.any_instance.stub(:save).with(any_args).and_return(false)\r
510       end
511       it 'Falseを返す' do
512         res = @rp.store(Mgk.new)\r
513         res.should be_false\r
514       end\r
515       it '更新されていない' do
516         @rp.store(Mgk.new)
517         @rp.should be_a_new ResourcePicture\r
518       end
519     end
520     context '画像の保存に失敗したとき' do
521       before do
522         ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
523         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(false)\r
524       end
525       it 'Falseを返す' do
526         res = @rp.store(Mgk.new)\r
527         res.should be_false\r
528       end\r
529       it 'gif変換判定は呼ばれていない' do\r
530         ResourcePicture.any_instance.should_not_receive(:to_gif?).with(any_args)
531         res = @rp.store(Mgk.new)\r
532       end\r
533     end
534     context 'gif変換に失敗したとき' do
535       before do
536         ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
537         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
538         ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
539         ResourcePicture.stub(:png_to_gif).with(any_args).and_return(false)
540       end
541       it 'Falseを返す' do
542         res = @rp.store(Mgk.new)\r
543         res.should be_false\r
544       end\r
545       it 'gif画像の保存は呼ばれていない' do\r
546         #本画像の保存があるので、一度は呼ばれる\r
547         ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
548         res = @rp.store(Mgk.new)\r
549       end\r
550     end
551     context 'gif画像の保存に失敗したとき' do
552       before do\r
553         @mgk = Mgk.new
554         ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
555         ResourcePicture.any_instance.stub(:store_picture).with(@mgk).and_return(true)\r
556         ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
557         class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために\r
558         @gifmgk = GifMgk.new      #パラメータを二種類用意する。\r
559         ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
560         ResourcePicture.any_instance.stub(:store_picture).with(@gifmgk).and_return(false)\r
561       end
562       it 'Falseを返す' do
563         res = @rp.store(@mgk)\r
564         res.should be_false\r
565       end\r
566     end
567   end\r
568   
569   describe '画像ファイルの作成・更新に於いて' do\r
570     #PictureIo経由で画像を保存するための機能。ファイル名に自身のidを使うので事前に自身の保存が必要。\r
571     before do
572       PictureIO.resource_picture_io.class.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh', 'thumbnail'])\r
573       ResourcePicture.any_instance.stub(:h).with(any_args).and_return('data')
574       ResourcePicture.any_instance.stub(:v).with(any_args).and_return('data')
575       ResourcePicture.any_instance.stub(:vh).with(any_args).and_return('data')
576       ResourcePicture.any_instance.stub(:thumbnail).with(any_args).and_return('data')
577       @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
578       @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id
579     end
580     context '事前チェック' do
581       before do
582         #すべての処理を正常パターンで通過させ、保存機能をチェックする。
583         PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)
584       end
585       it '画像ファイルの保存が5回呼ばれる' do\r
586         PictureIO.resource_picture_io.should_receive(:put).with(any_args).exactly(5)
587         res = @rp.store_picture(Mgk.new)\r
588       end\r
589       it '画像ファイルのベースへの保存が1回呼ばれる' do\r
590         PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, '').exactly(1)
591         res = @rp.store_picture(Mgk.new)\r
592       end\r
593       it '画像ファイルの垂直反転への保存が1回呼ばれる' do\r
594         PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, 'v').exactly(1)
595         res = @rp.store_picture(Mgk.new)\r
596       end\r
597       it '画像ファイルの水平反転への保存が1回呼ばれる' do\r
598         PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, 'h').exactly(1)
599         res = @rp.store_picture(Mgk.new)\r
600       end\r
601       it '画像ファイルの垂直水平反転への保存が1回呼ばれる' do\r
602         PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, 'vh').exactly(1)
603         res = @rp.store_picture(Mgk.new)\r
604       end\r
605       it '画像ファイルのサムネイルへの保存が1回呼ばれる' do\r
606         PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, 'thumbnail').exactly(1)
607         res = @rp.store_picture(Mgk.new)\r
608       end\r
609       it '垂直反転が1回呼ばれる' do\r
610         ResourcePicture.any_instance.should_receive(:v).with(any_args).exactly(1)
611         res = @rp.store_picture(Mgk.new)\r
612       end\r
613       it '水平反転が1回呼ばれる' do\r
614         ResourcePicture.any_instance.should_receive(:h).with(any_args).exactly(1)
615         res = @rp.store_picture(Mgk.new)\r
616       end\r
617       it '垂直水平反転が1回呼ばれる' do\r
618         ResourcePicture.any_instance.should_receive(:vh).with(any_args).exactly(1)
619         res = @rp.store_picture(Mgk.new)\r
620       end\r
621       it 'サムネイル化が1回呼ばれる' do\r
622         ResourcePicture.any_instance.should_receive(:thumbnail).with(any_args).exactly(1)
623         res = @rp.store_picture(Mgk.new)\r
624       end\r
625     end
626     context 'つつがなく終わるとき' do
627       before do
628         #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
629         PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)
630       end
631       it 'Trueを返す' do
632         res = @rp.store_picture(Mgk.new)\r
633         res.should be_true\r
634       end\r
635     end
636     context '例外ケース' do
637       before do
638         PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(false)
639       end
640       it 'Falseを返す' do
641         res = @rp.store_picture(Mgk.new)\r
642         res.should be_false\r
643       end\r
644     end
645     
646   end
647   
648 describe 'サムネイル変換に於いて' do
649     #サムネイル化した画像データを返すが、スタブをおくので、リサイズと画像データ化を試みるかをチェックする
650     before do
651       ResourcePicture.stub(:resize).with(any_args).and_return(Mgk.new)
652       @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id
653     end
654     it 'サムネイルサイズに縮小した画像データを返す' do\r
655       ResourcePicture.should_receive(:resize).with(any_args).exactly(1)
656       @rp.thumbnail(Mgk.new)\r
657     end\r
658     it 'データが返る' do\r
659       #全体スタブより\r
660       @rp.thumbnail(Mgk.new).should eq 'data'\r
661     end\r
662   end
663   
664   describe '垂直反転変換に於いて' do
665     #垂直反転した画像データを返すが、スタブをおくので、反転と画像データ化を試みるかをチェックする
666     before do
667       Mgk.any_instance.stub(:flip).with(any_args).and_return(Mgk.new)
668       @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id
669     end\r
670     it '垂直反転する' do\r
671       Mgk.any_instance.should_receive(:flip).exactly(1)
672       @rp.v(Mgk.new)\r
673     end\r
674     it '画像データ化する' do\r
675       Mgk.any_instance.should_receive(:to_blob).exactly(1)
676       @rp.v(Mgk.new)\r
677     end\r
678     it 'データが返る' do\r
679       #全体スタブより\r
680       @rp.v(Mgk.new).should eq 'data'\r
681     end\r
682   end
683   
684   describe '水平反転変換に於いて' do
685     #水平反転した画像データを返すが、スタブをおくので、反転と画像データ化を試みるかをチェックする
686     before do
687       Mgk.any_instance.stub(:flop).with(any_args).and_return(Mgk.new)
688       @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id
689     end
690     it '水平反転する' do\r
691       Mgk.any_instance.should_receive(:flop).exactly(1)
692       @rp.h(Mgk.new)\r
693     end\r
694     it '画像データ化する' do\r
695       Mgk.any_instance.should_receive(:to_blob).exactly(1)
696       @rp.h(Mgk.new)\r
697     end\r
698     it 'データが返る' do\r
699       #全体スタブより\r
700       @rp.h(Mgk.new).should eq 'data'\r
701     end\r
702   end
703   
704   describe '垂直水平反転変換に於いて' do
705     #垂直水平反転した画像データを返すが、スタブをおくので、反転と画像データ化を試みるかをチェックする
706     before do
707       Mgk.any_instance.stub(:flip).with(any_args).and_return(Mgk.new)
708       Mgk.any_instance.stub(:flop).with(any_args).and_return(Mgk.new)
709       @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id
710     end
711     it '垂直反転する' do\r
712       Mgk.any_instance.should_receive(:flip).exactly(1)
713       @rp.vh(Mgk.new)\r
714     end\r
715     it '水平反転する' do\r
716       Mgk.any_instance.should_receive(:flop).exactly(1)
717       @rp.vh(Mgk.new)\r
718     end\r
719     it '画像データ化する' do\r
720       Mgk.any_instance.should_receive(:to_blob).exactly(1)
721       @rp.vh(Mgk.new)\r
722     end\r
723     it 'データが返る' do\r
724       #全体スタブより\r
725       @rp.vh(Mgk.new).should eq 'data'\r
726     end\r
727   end
728   
729 end
730 \r