OSDN Git Service

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