OSDN Git Service

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