OSDN Git Service

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