OSDN Git Service

t#29400:itr3?
[pettanr/pettanr.git] / spec / models / original_picture_spec.rb
1 # -*- encoding: utf-8 -*-
2 #原画
3 require 'spec_helper'
4
5 describe OriginalPicture 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   end
18   
19   describe '検証に於いて' do
20     before do
21       @op = FactoryGirl.build :original_picture, :artist_id => @artist.id
22     end
23     
24     context 'オーソドックスなデータのとき' do
25       it '下限データが通る' do
26         @op.ext = 'png' #リストにない拡張子は通らないし
27         @op.width = 1
28         @op.height = 1
29         @op.filesize = 1
30         @op.md5 = 'a'*32
31         @op.should be_valid
32       end
33       it '上限データが通る' do
34         @op.ext = 'jpeg'
35         @op.width = 99999
36         @op.height = 99999
37         @op.filesize = 2000000
38         @op.md5 = 'a'*32
39         @op.should be_valid
40       end
41     end
42     
43     context 'extを検証するとき' do
44       it 'nullなら失敗する' do
45         @op.ext = ''
46         @op.should_not be_valid
47       end
48       it '5文字以上なら失敗する' do
49         @op.ext = 'a'*5
50         @op.should_not be_valid
51       end
52       it 'png,gif,jpeg以外なら失敗する' do
53         @op.ext = 'bmp'
54         @op.should_not be_valid
55       end
56     end
57     context 'widthを検証するとき' do
58       it 'nullなら失敗する' do
59         @op.width = nil
60         @op.should_not be_valid
61       end
62       it '数値でなければ失敗する' do
63         @op.width = 'a'
64         @op.should_not be_valid
65       end
66       it '0なら失敗する' do
67         @op.width = '0'
68         @op.should_not be_valid
69       end
70       it '負でも失敗する' do
71         @op.width = -1
72         @op.should_not be_valid
73       end
74     end
75     context 'heightを検証するとき' do
76       it 'nullなら失敗する' do
77         @op.height = nil
78         @op.should_not be_valid
79       end
80       it '数値でなければ失敗する' do
81         @op.height = 'a'
82         @op.should_not be_valid
83       end
84       it '0なら失敗する' do
85         @op.height = '0'
86         @op.should_not be_valid
87       end
88       it '負でも失敗する' do
89         @op.height = -1
90         @op.should_not be_valid
91       end
92     end
93     context 'filesizeを検証するとき' do
94       it 'nullなら失敗する' do
95         @op.filesize = nil
96         @op.should_not be_valid
97       end
98       it '数値でなければ失敗する' do
99         @op.filesize = 'a'
100         @op.should_not be_valid
101       end
102       it '負なら失敗する' do
103         @op.filesize = '-1'
104         @op.should_not be_valid
105       end
106       it '2MB以上なら失敗する' do
107         @op.filesize = 2000000+1
108         @op.should_not be_valid
109       end
110     end
111     context 'artist_idを検証するとき' do
112       it 'nullなら失敗する' do
113         @op.artist_id = nil
114         @op.should_not be_valid
115       end
116       it '数値でなければ失敗する' do
117         @op.artist_id = 'a'
118         @op.should_not be_valid
119       end
120       it '存在する絵師でなければ失敗する' do
121         @op.artist_id = 0
122         @op.should_not be_valid
123       end
124     end
125     context 'md5を検証するとき' do
126       it 'nullなら失敗する' do
127         @op.md5 = ''
128         @op.should_not be_valid
129       end
130       it '31文字なら失敗する' do
131         @op.md5 = 'a'*31
132         @op.should_not be_valid
133       end
134       it '33文字なら失敗する' do
135         @op.md5 = 'a'*33
136         @op.should_not be_valid
137       end
138     end
139   end
140   
141   describe 'デフォルト値補充に於いて' do
142     it 'defined' do
143       @op = FactoryGirl.build :original_picture, :artist_id => @artist.id
144       @op.supply_default
145     end
146   end
147   
148   describe '上書き補充に於いて' do
149     it '絵師idが設定されている' do
150       @op = FactoryGirl.build :original_picture, :artist_id => nil
151       @op.overwrite @artist
152       @op.artist_id.should eq @artist.id
153     end
154   end
155   
156   describe '作者判定に於いて' do
157     before do
158     end
159     it '自作の原画ならyes' do
160       op = FactoryGirl.create :original_picture, :artist_id => @artist.id
161       op.own?(@artist).should == true
162     end
163     it '他人のならno' do
164       op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
165       op.own?(@artist).should == false
166     end
167   end
168   
169   describe '閲覧許可に於いて' do
170     before do
171       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
172     end
173     it '自分の原画を見るときは許可する' do
174       OriginalPicture.any_instance.stub(:own?).and_return(true)
175       r = @op.visible?(@artist)
176       r.should == true
177     end
178     it '他人の原画なら許可しない' do
179       OriginalPicture.any_instance.stub(:own?).and_return(false)
180       r = @op.visible?(@artist)
181       r.should == false
182     end
183   end
184   
185   describe 'ファイル名に於いて' do
186     before do
187       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
188     end
189     it 'id+拡張子のフォーマットで返す' do
190       r = @op.filename
191       r.should eq "#{@op.id}.png"
192     end
193   end
194   
195   describe 'MimeTypeに於いて' do
196     before do
197       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
198     end
199     it 'image/拡張子のフォーマットで返す' do
200       r = @op.mime_type
201       r.should eq "image/png"
202     end
203   end
204   
205   describe 'ファイルのurlに於いて' do
206     before do
207       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
208       OriginalPicture.any_instance.stub(:filename).and_return('3.gif')
209     end
210     it 'ファイル名取得を依頼している' do
211       OriginalPicture.any_instance.should_receive(:filename).exactly(1)
212       @op.url
213     end
214     it '/original_pictures/3.gifのフォーマットで返す' do
215       r = @op.url
216       r.should eq "/original_pictures/3.gif"
217     end
218   end
219   
220   describe '画像タグオプションに於いて' do
221     before do
222       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
223       OriginalPicture.any_instance.stub(:url).and_return('/original_pictures/3.gif')
224       ResourcePicture.stub(:fix_size_both).with(any_args).and_return([40, 30])
225     end
226     it 'サムネイル画像の幅高さ取得を依頼している' do
227       ResourcePicture.should_receive(:fix_size_both).with(any_args).exactly(1)
228       @op.opt_img_tag
229     end
230     it '戻り値はHashで返す' do
231       r = @op.opt_img_tag
232       r.is_a?(Hash).should be_true
233     end
234     it 'srcキーを含んでいる' do
235       r = @op.opt_img_tag
236       r.has_key?(:src).should be_true
237       r[:src].should eq '/original_pictures/3.gif'
238     end
239     it 'widthキーを含んでいる' do
240       r = @op.opt_img_tag
241       r.has_key?(:width).should be_true
242       r[:width].should eq 40
243     end
244     it 'heightキーを含んでいる' do
245       r = @op.opt_img_tag
246       r.has_key?(:height).should be_true
247       r[:height].should eq 30
248     end
249   end
250   
251   describe '一覧取得に於いて' do
252     before do
253       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
254     end
255     context 'page補正について' do
256       it '文字列から数値に変換される' do
257         OriginalPicture.page('8').should eq 8
258       end
259       it 'nilの場合は1になる' do
260         OriginalPicture.page().should eq 1
261       end
262       it '0以下の場合は1になる' do
263         OriginalPicture.page('0').should eq 1
264       end
265     end
266     context 'page_size補正について' do
267       it '文字列から数値に変換される' do
268         OriginalPicture.page_size('7').should eq 7
269       end
270       it 'nilの場合はOriginalPicture.default_page_sizeになる' do
271         OriginalPicture.page_size().should eq OriginalPicture.default_page_size
272       end
273       it '0以下の場合はOriginalPicture.default_page_sizeになる' do
274         OriginalPicture.page_size('0').should eq OriginalPicture.default_page_size
275       end
276       it 'OriginalPicture.max_page_sizeを超えた場合はOriginalPicture.max_page_sizeになる' do
277         OriginalPicture.page_size('1000').should eq OriginalPicture.max_page_size
278       end
279     end
280   end
281   describe 'list関連テーブルプションに於いて' do
282     it 'includeキーを含んでいる' do
283       r = OriginalPicture.list_opt
284       r.has_key?(:include).should be_true
285     end
286     it '2つの項目を含んでいる' do
287       r = OriginalPicture.list_opt[:include]
288       r.should have(2).items
289     end
290     it '素材を含んでいる' do
291       r = OriginalPicture.list_opt[:include]
292       r.has_key?(:resource_picture).should be_true
293     end
294     it '実素材を含んでいる' do
295       r = OriginalPicture.list_opt[:include]
296       r.has_key?(:pictures).should be_true
297     end
298   end
299   describe 'json一覧出力オプションに於いて' do
300     it 'includeキーを含んでいる' do
301       r = OriginalPicture.list_json_opt
302       r.has_key?(:include).should be_true
303     end
304     it '2つの項目を含んでいる' do
305       r = OriginalPicture.list_json_opt[:include]
306       r.should have(2).items
307     end
308     it '素材を含んでいる' do
309       r = OriginalPicture.list_json_opt[:include]
310       r.has_key?(:resource_picture).should be_true
311     end
312     it '実素材を含んでいる' do
313       r = OriginalPicture.list_json_opt[:include]
314       r.has_key?(:pictures).should be_true
315     end
316   end
317   
318   describe '自分のコミック一覧取得に於いて' do
319     before do
320       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
321     end
322     context 'つつがなく終わるとき' do
323       it '一覧取得オプションを利用している' do
324         OriginalPicture.stub(:list_opt).with(any_args).and_return({})
325         OriginalPicture.should_receive(:list_opt).with(any_args).exactly(1)
326         r = OriginalPicture.mylist @artist
327       end
328     end
329     it 'リストを返す' do
330       r = OriginalPicture.mylist @artist
331       r.should eq [@op]
332     end
333     it '時系列で並んでいる' do
334       nc = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
335       r = OriginalPicture.mylist @artist
336       r.should eq [nc, @op]
337     end
338     it '他人のコミックはxxxでも含まない' do
339       nc = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
340       r = OriginalPicture.mylist @artist
341       r.should eq [@op]
342     end
343     it '自分のコミックはxxxでも含んでいる' do
344       nc = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
345       r = OriginalPicture.mylist @artist
346       r.should eq [nc, @op]
347     end
348     context 'DBに5件あって1ページの件数を2件に変えたとして' do
349       before do
350         @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
351         @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200
352         @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300
353         @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400
354       end
355       it '通常は2件を返す' do
356         r = OriginalPicture.mylist @artist, 1, 2
357         r.should have(2).items 
358       end
359       it 'page=1なら末尾2件を返す' do
360         #時系列で並んでいる
361         r = OriginalPicture.mylist @artist, 1, 2
362         r.should eq [@op5, @op4]
363       end
364       it 'page=2なら中間2件を返す' do
365         r = OriginalPicture.mylist @artist, 2, 2
366         r.should eq [@op3, @op2]
367       end
368       it 'page=3なら先頭1件を返す' do
369         r = OriginalPicture.mylist @artist, 3, 2
370         r.should eq [@op]
371       end
372     end
373     context 'DBに5件あって1ページの件数を0件に変えたとして' do
374       before do
375         @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 100
376         @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200
377         @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300
378         @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400
379       end
380       it '通常は全件(5件)を返す' do
381         r = OriginalPicture.mylist @artist, 5, 0
382         r.should have(5).items 
383       end
384     end
385   end
386   
387   describe '更新履歴一覧取得に於いて' do
388     before do
389       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
390       @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
391         :original_picture_id => @op.id
392       @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
393     end
394     it 'リストを返す' do
395       r = @op.history
396       r.should eq [@p]
397     end
398     it '他の原画の実素材は含んでいない' do
399       @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
400         :original_picture_id => @op2.id
401       r = @op.history
402       r.should eq [@p]
403     end
404     it 'revisionで並んでいる' do
405       @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
406         :original_picture_id => @op.id
407       r = @op.history
408       r.should eq [@p2, @p]
409     end
410   end
411   
412   describe '単体取得に於いて' do
413     before do
414       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
415     end
416     context 'つつがなく終わるとき' do
417       it '単体取得オプションを利用している' do
418         OriginalPicture.stub(:show_opt).with(any_args).and_return({})
419         OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)
420         r = OriginalPicture.show @op.id, @artist
421       end
422       it '閲覧許可を問い合わせている' do
423         OriginalPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
424         OriginalPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
425         r = OriginalPicture.show @op.id, @artist
426       end
427     end
428     it '指定の原画を返す' do
429       pic = OriginalPicture.show @op.id, @artist
430       pic.should eq @op
431     end
432     context '他人の原画を開こうとしたとき' do
433       it '403Forbidden例外を返す' do
434         OriginalPicture.any_instance.stub(:visible?).and_return(false)
435         lambda{
436           pic = OriginalPicture.show @op.id, @other_artist
437         }.should raise_error(ActiveRecord::Forbidden)
438       end
439     end
440     context '存在しない原画を開こうとしたとき' do
441       it '404RecordNotFound例外を返す' do
442         lambda{
443           pic = OriginalPicture.show 0, @artist
444         }.should raise_error(ActiveRecord::RecordNotFound)
445       end
446     end
447   end
448   describe '編集取得に於いて' do
449     before do
450       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
451     end
452     context 'つつがなく終わるとき' do
453       it '単体取得オプションを利用している' do
454         OriginalPicture.stub(:show_opt).with(any_args).and_return({})
455         OriginalPicture.should_receive(:show_opt).with(any_args).exactly(1)
456         r = OriginalPicture.edit @op.id, @artist
457       end
458       it '所持判定を問い合わせている' do
459         OriginalPicture.any_instance.stub(:own?).with(any_args).and_return(true)
460         OriginalPicture.any_instance.should_receive(:own?).with(any_args).exactly(1)
461         r = OriginalPicture.edit @op.id, @artist
462       end
463     end
464     it '指定の原画を返す' do
465       pic = OriginalPicture.edit @op.id, @artist
466       pic.should eq @op
467     end
468     context '他人の原画を開こうとしたとき' do
469       it '403Forbidden例外を返す' do
470         OriginalPicture.any_instance.stub(:own?).and_return(false)
471         lambda{
472           r = OriginalPicture.edit @op.id, @other_artist
473         }.should raise_error(ActiveRecord::Forbidden)
474       end
475     end
476     context '存在しない原画を開こうとしたとき' do
477       it '404RecordNotFound例外を返す' do
478         lambda{
479           r = OriginalPicture.edit 0, @artist
480         }.should raise_error(ActiveRecord::RecordNotFound)
481       end
482     end
483   end
484   describe '単体出力オプションに於いて' do
485     it 'includeキーを含んでいる' do
486       r = OriginalPicture.show_opt
487       r.has_key?(:include).should be_true
488     end
489     it '2つの項目を含んでいる' do
490       r = OriginalPicture.show_opt[:include]
491       r.should have(2).items
492     end
493     it '素材を含んでいる' do
494       r = OriginalPicture.show_opt[:include]
495       r.has_key?(:resource_picture).should be_true
496     end
497     it '実素材を含んでいる' do
498       r = OriginalPicture.show_opt[:include]
499       r.has_key?(:pictures).should be_true
500     end
501   end
502   describe 'json単体出力オプションに於いて' do
503     it 'includeキーを含んでいる' do
504       r = OriginalPicture.show_json_opt
505       r.has_key?(:include).should be_true
506     end
507     it '2つの項目を含んでいる' do
508       r = OriginalPicture.show_json_opt[:include]
509       r.should have(2).items
510     end
511     it '素材を含んでいる' do
512       r = OriginalPicture.show_json_opt[:include]
513       r.has_key?(:resource_picture).should be_true
514     end
515     it '実素材を含んでいる' do
516       r = OriginalPicture.show_json_opt[:include]
517       r.has_key?(:pictures).should be_true
518     end
519   end
520   describe '作成・更新に於いて' do
521     before do
522       @op = FactoryGirl.build :original_picture, :artist_id => @artist.id
523       @imager = ImagerTest.load "abc\ndef\nghi"
524     end
525     context '事前チェック' do
526       before do
527         #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
528         #それで外部のメソッド呼び出しだけに着目してテストする。
529         OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
530         PictureIO.original_picture_io.stub(:put).with(any_args).and_return(true)
531       end
532       it '自身に属性をセットしている' do
533         OriginalPicture.any_instance.should_receive(:attributes=).exactly(1)
534         @op.store @imager
535       end
536       it '自身が保存されている' do
537         OriginalPicture.any_instance.should_receive(:save).exactly(1)
538         @op.store @imager
539       end
540       it 'PictureIoに画像データの保存を依頼している' do
541         PictureIO.original_picture_io.should_receive(:put).with(any_args).exactly(1)
542         @op.store @imager
543       end
544     end
545     context 'つつがなく終わるとき' do
546       before do
547       end
548       it '自身に属性をセットしている' do
549         @op.store @imager
550         @op.width.should eq 3
551         @op.height.should eq 3
552         @op.filesize.should eq 9
553       end
554       it '原画モデルが作成されている' do
555         lambda {
556           @op.store @imager
557         }.should change OriginalPicture, :count
558       end
559       it '原画が保存されている' do
560         @op.store @imager
561         OriginalPicture.find(@op).should_not be_nil
562       end
563       it 'Trueを返す' do
564         @op.store(@imager).should eq true
565       end
566     end
567     #以下から例外ケース。処理先頭から失敗させていく
568     context 'imagerが初期化に失敗したとき' do
569       before do
570       end
571       it 'falseを返す' do
572         @op.store(false).should be_false
573       end
574       it '自身の保存は呼ばれていない' do
575         OriginalPicture.any_instance.should_not_receive(:save)
576         @op.store(false)
577       end
578       it '全体エラーメッセージがセットされている' do
579         lambda {
580           @op.store(false)
581         }.should change(@op.errors[:base], :count)
582       end
583     end
584     context '自身の保存に失敗したとき' do
585       before do
586         OriginalPicture.any_instance.stub(:save).with(any_args).and_return(false)
587       end
588       it 'falseを返す' do
589         @op.store(@imager).should be_false
590       end
591       it '更新されていない' do
592         @op.store(@imager)
593         @op.should be_a_new OriginalPicture
594       end
595       it '原画の保存は呼ばれていない' do
596         PictureIO::LocalPicture.any_instance.should_not_receive(:put)
597       end
598     end
599     context '原画の保存に失敗したとき' do
600       before do
601         OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
602         PictureIO.original_picture_io.stub(:put).with(any_args).and_return(false)
603       end
604       it 'falseを返す' do
605         @op.store(@imager).should be_false
606       end
607       it '更新されていない' do
608         @op.store(@imager)
609         @op.should be_a_new OriginalPicture
610       end
611       it '全体エラーメッセージがセットされている' do
612         lambda {
613           @op.store(@imager)
614         }.should change(@op.errors[:base], :count)
615       end
616     end
617   end
618   
619 =begin
620   describe 'エクスポートに於いて' do
621     before do
622       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
623       @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :revision => 0
624       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
625       #他人の原画排除
626       @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
627     end
628     context 'つつがなく終わるとき' do
629       it 'ライセンスグループに依頼してリストを取得している' do
630         LicenseGroup.stub(:list).with(any_args).and_return([@lg])
631         LicenseGroup.should_receive(:list).with(any_args).exactly(1)
632         r = OriginalPicture.export(@artist)
633       end
634       it '原画に依頼してリストを取得している' do
635         OriginalPicture.stub(:list).with(any_args).and_return([@op])
636         OriginalPicture.should_receive(:list).with(any_args).exactly(1)
637         r = OriginalPicture.export(@artist)
638       end
639       it 'Hashを返す' do
640         r = OriginalPicture.export(@artist)
641         r.is_a?(Hash).should be_true
642       end
643       it 'Hashはライセンスグループを含んでいる' do
644         r = OriginalPicture.export(@artist)
645         r.include?(:license_groups).should be_true
646       end
647       it 'Hashは原画を含んでいる' do
648         r = OriginalPicture.export(@artist)
649         r.include?(:original_pictures).should be_true
650       end
651       #素材がライセンスされていないケースもある
652       it 'Hashの原画は素材を含んでいる' do
653         r = OriginalPicture.export(@artist)
654         r[:original_pictures].first.resource_picture.should_not be_nil
655       end
656       it 'Hashの原画は実素材を含んでいる' do
657         r = OriginalPicture.export(@artist)
658         r[:original_pictures].first.pictures.should be_nil
659       end
660     end
661     context '実データ単体のとき' do
662       it 'ライセンスは配列構造になっている' do
663         r = OriginalPicture.export(@artist)
664         r[:license_groups].is_a?(Array).should be_true
665       end
666       it 'ライセンスが全件出ている' do
667         r = OriginalPicture.export(@artist)
668         r[:license_groups].size.should eq 1
669         r[:license_groups].first.should eq @lg
670       end
671       it '原画は配列構造になっている' do
672         r = OriginalPicture.export(@artist)
673         r[:original_pictures].is_a?(Array).should be_true
674       end
675       it '原画が全件出ている' do
676         r = OriginalPicture.export(@artist)
677         r[:original_pictures].size.should eq 1
678         r[:original_pictures].first.should eq @op
679       end
680       it '原画に素材が関連付いている' do
681         r = OriginalPicture.export(@artist)
682         i = r[:original_pictures].first
683         i.resource_picture.should eq @rp
684       end
685       it '原画に実素材が関連付いている' do
686         r = OriginalPicture.export(@artist)
687         i = r[:original_pictures].first
688         i.picture.should eq @p
689       end
690     end
691     context '実データ複数のとき' do
692       before do
693         @lg2 = FactoryGirl.create :license_group, :name => 'export test', :url => 'http://export.test/'
694         @license2 = FactoryGirl.create :license, :license_group_id => @lg2.id, :system_picture_id => @sp.id, :name => 'export test license', :url => 'http://export.test/license'
695         @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
696         @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op2.id, :license_id => @license2.id, :revision => 0
697         @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op2.id, :license_id => @license2.id, :picture_id => @p2.id
698       end
699       it 'ライセンスは配列構造になっている' do
700         r = OriginalPicture.export(@artist)
701         r[:license_groups].is_a?(Array).should be_true
702       end
703       it 'ライセンスが全件出ている' do
704         r = OriginalPicture.export(@artist)
705         r[:license_groups].size.should eq 2
706         r[:license_groups].first.should eq @lg
707         r[:license_groups].last.should eq @lg2
708       end
709       it '原画は配列構造になっている' do
710         r = OriginalPicture.export(@artist)
711         r[:original_pictures].is_a?(Array).should be_true
712       end
713       it '原画が全件出ている' do
714         r = OriginalPicture.export(@artist)
715         r[:original_pictures].size.should eq 2
716         r[:original_pictures].first.should eq @op
717         r[:original_pictures].last.should eq @op2
718       end
719       it '原画に素材が関連付いている' do
720         r = OriginalPicture.export(@artist)
721         i = r[:original_pictures].first
722         i.resource_picture.should eq @rp
723         i2 = r[:original_pictures].last
724         i2.resource_picture.should eq @rp2
725       end
726       it '原画に実素材が関連付いている' do
727         r = OriginalPicture.export(@artist)
728         i = r[:original_pictures].first
729         i.picture.should eq @p
730         i2 = r[:original_pictures].last
731         i2.picture.should eq @p2
732       end
733     end
734   end
735   
736   describe 'エクスポートオプションに於いて' do
737   end
738   
739   describe 'インポートに於いて' do
740     before do
741       @imports = {:licenses => {}, :artist_id => @artist.id}
742     end
743     context '事前チェックしておく' do
744     end
745   end
746   
747 =end
748 end