OSDN Git Service

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