OSDN Git Service

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