OSDN Git Service

t#30443:add test for open mode
[pettanr/pettanr.git] / spec / controllers / original_pictures_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 #原画
3 require 'spec_helper'
4
5 describe OriginalPicturesController do
6   before do
7     @admin = FactoryGirl.create :admin
8     @user = FactoryGirl.create( :user_yas)
9     @author = FactoryGirl.create :author, :user_id => @user.id
10     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
11     @sp = FactoryGirl.create :system_picture
12     @lg = FactoryGirl.create :license_group
13     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
14   end
15
16 if MagicNumber['run_mode'] == 1
17   describe '一覧表示に於いて' do
18     before do
19       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
20       sign_in @user
21       OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
22     end
23     context 'パラメータpageについて' do
24       it '@pageに値が入る' do
25         get :index, :page => 5
26         assigns(:page).should eq 5
27       end
28       it '省略されると@pageに1値が入る' do
29         get :index
30         assigns(:page).should eq 1
31       end
32       it '与えられたpage_sizeがセットされている' do
33         get :index, :page_size => 15
34         assigns(:page_size).should eq 15
35       end
36       it '省略されると@page_sizeにデフォルト値が入る' do
37         get :index
38         assigns(:page_size).should eq OriginalPicture.default_page_size
39       end
40       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
41         get :index, :page_size => 1500
42         assigns(:page_size).should eq OriginalPicture.max_page_size
43       end
44       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
45         get :index, :page_size => 0
46         assigns(:page_size).should eq OriginalPicture.default_page_size
47       end
48     end
49     context 'つつがなく終わるとき' do
50       it 'ステータスコード200 OKを返す' do
51         get :index
52         response.should be_success 
53       end
54       it '原画モデルにマイリストを問い合わせている' do
55         OriginalPicture.should_receive(:mylist).exactly(1)
56         get :index
57       end
58       it '@original_picturesにリストを取得している' do
59         get :index
60         assigns(:original_pictures).should have_at_least(3).items
61       end
62       context 'html形式' do
63         it 'indexテンプレートを描画する' do
64           get :index
65           response.should render_template("index")
66         end
67       end
68       context 'json形式' do
69         it 'jsonデータを返す' do
70           get :index, :format => :json
71           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
72         end
73         it '原画モデルにjson一覧出力オプションを問い合わせている' do
74           OriginalPicture.should_receive(:list_json_opt).exactly(1)
75           get :index, :format => :json
76         end
77         it 'データがリスト構造になっている' do
78           get :index, :format => :json
79           json = JSON.parse response.body
80           json.should have_at_least(3).items
81         end
82         it 'リストの先頭くらいは原画っぽいものであって欲しい' do
83           get :index, :format => :json
84           json = JSON.parse response.body
85           json.first.has_key?("ext").should be_true
86           json.first.has_key?("md5").should be_true
87           json.first.has_key?("artist_id").should be_true
88           json.first.has_key?("width").should be_true
89         end
90       end
91     end
92     context '作家権限がないとき' do
93       before do
94         sign_out @user
95       end
96       context 'html形式' do
97         it 'ステータスコード302 Foundを返す' do
98           get :index
99           response.status.should eq 302
100         end
101         it 'サインインページへ遷移する' do
102           get :index
103           response.should redirect_to '/users/sign_in'
104         end
105       end
106       context 'json形式' do
107         it 'ステータスコード401 Unauthorizedを返す' do
108           get :index, :format => :json
109           response.status.should eq 401
110         end
111         it '応答メッセージにUnauthorizedを返す' do
112           get :index, :format => :json
113           response.message.should match(/Unauthorized/)
114         end
115       end
116     end
117     context '作家が絵師でないとき' do
118       before do
119         Author.any_instance.stub(:artist?).and_return(false)
120       end
121       context 'html形式' do
122         it 'ステータスコード302 Foundを返す' do
123           get :index
124           response.status.should eq 302
125         end
126         it '絵師登録ページへ遷移する' do
127           get :index
128           response.should redirect_to new_artist_path
129         end
130       end
131       context 'json形式' do
132         it '例外403 forbiddenを返す' do
133           lambda{
134             get :index, :format => :json
135           }.should raise_error(ActiveRecord::Forbidden)
136         end
137       end
138     end
139   end
140   
141   describe '単体表示に於いて' do
142     before do
143       @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
144       sign_in @user
145       OriginalPicture.stub(:show).and_return(@pic)
146     end
147     context 'つつがなく終わるとき' do
148       it 'ステータスコード200 OKを返す' do
149         get :show, :id => @pic.id
150         response.should be_success
151       end
152       it '原画モデルに単体取得を問い合わせている' do
153         OriginalPicture.should_receive(:show).exactly(1)
154         get :show
155       end
156       it '@original_pictureにアレを取得している' do
157         get :show, :id => @pic.id
158         assigns(:original_picture).id.should eq(@pic.id)
159       end
160       context 'html形式' do
161         it 'showテンプレートを描画する' do
162           get :show, :id => @pic.id
163           response.should render_template("show")
164         end
165       end
166       context 'json形式' do
167         it 'jsonデータを返す' do
168           get :show, :id => @pic.id, :format => :json
169           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
170         end
171         it '原画モデルにjson単体出力オプションを問い合わせている' do
172           OriginalPicture.should_receive(:show_json_opt).exactly(1)
173           get :show, :id => @pic.id, :format => :json
174         end
175         it 'データがアレになっている' do
176           get :show, :id => @pic.id, :format => :json
177           json = JSON.parse response.body
178           json["ext"].should match(/png/)
179           json["md5"].should be_true
180           json["artist_id"].should be_true
181           json["width"].should be_true
182         end
183       end
184       #画像送信では、send_dataにスタブをおいてテストしたいが、ここに噛ませると
185       #renderが働かず、エラーとなってしまう。そこで、原画のファイル取得部分に
186       #スタブをおいてsend_dataがデータを返す体裁でテストする。
187       context 'png形式' do
188         before do
189           OriginalPicture.any_instance.stub(:mime_type).and_return('image/png')
190           OriginalPicture.any_instance.stub(:restore).and_return('aaa')
191         end
192         it '画像モデルに画像データを問い合わせる' do
193           OriginalPicture.any_instance.should_receive(:restore).exactly(1)
194           get :show, :id => @pic.id, :format => :png
195         end
196         it '画像モデルにMimeTypeを問い合わせる' do
197           OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
198           get :show, :id => @pic.id, :format => :png
199         end
200         it '画像を送信する' do
201           get :show, :id => @pic.id, :format => :png
202           response.body.should eq 'aaa'
203         end
204       end
205       context 'gif形式' do
206         before do
207           OriginalPicture.any_instance.stub(:mime_type).and_return('image/gif')
208           OriginalPicture.any_instance.stub(:restore).and_return('bbb')
209         end
210         it '画像モデルに画像データを問い合わせる' do
211           OriginalPicture.any_instance.should_receive(:restore).exactly(1)
212           get :show, :id => @pic.id, :format => :gif
213         end
214         it '画像モデルにMimeTypeを問い合わせる' do
215           OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
216           get :show, :id => @pic.id, :format => :gif
217         end
218         it '画像を送信する' do
219           get :show, :id => @pic.id, :format => :gif
220           response.body.should eq 'bbb'
221         end
222       end
223       context 'jpeg形式' do
224         before do
225           OriginalPicture.any_instance.stub(:mime_type).and_return('image/jpeg')
226           OriginalPicture.any_instance.stub(:restore).and_return('ccc')
227         end
228         it '画像モデルに画像データを問い合わせる' do
229           OriginalPicture.any_instance.should_receive(:restore).exactly(1)
230           get :show, :id => @pic.id, :format => :jpeg
231         end
232         it '画像モデルにMimeTypeを問い合わせる' do
233           OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
234           get :show, :id => @pic.id, :format => :jpeg
235         end
236         it '画像を送信する' do
237           get :show, :id => @pic.id, :format => :jpeg
238           response.body.should eq 'ccc'
239         end
240       end
241     end
242     context '作家権限がないとき' do
243       before do
244         sign_out @user
245       end
246       context 'html形式' do
247         it 'ステータスコード302 Foundを返す' do
248           get :show, :id => @pic.id
249           response.status.should eq 302
250         end
251         it 'サインインページへ遷移する' do
252           get :show, :id => @pic.id
253           response.body.should redirect_to '/users/sign_in'
254         end
255       end
256       context 'json形式' do
257         it 'ステータスコード401 Unauthorizedを返す' do
258           get :show, :id => @pic.id, :format => :json
259           response.status.should eq 401
260         end
261         it '応答メッセージにUnauthorizedを返す' do
262           get :show, :id => @pic.id, :format => :json
263           response.message.should match(/Unauthorized/)
264         end
265       end
266     end
267     context '作家が絵師でないとき' do
268       before do
269         Author.any_instance.stub(:artist?).and_return(false)
270       end
271       context 'html形式' do
272         it 'ステータスコード302 Foundを返す' do
273           get :show, :id => @pic.id
274           response.status.should eq 302
275         end
276         it '絵師登録ページへ遷移する' do
277           get :show, :id => @pic.id
278           response.should redirect_to new_artist_path
279         end
280       end
281       context 'json形式' do
282         it '例外403 forbiddenを返す' do
283           lambda{
284             get :show, :id => @pic.id, :format => :json
285           }.should raise_error(ActiveRecord::Forbidden)
286         end
287       end
288     end
289 =begin
290     context '対象原画がないとき' do
291       before do
292         OriginalPicture.unstub(:show)
293       end
294       context 'html形式' do
295         it '例外404 not_foundを返す' do
296           lambda{
297             get :show, :id => 0
298           }.should raise_error(ActiveRecord::RecordNotFound)
299         end
300       end
301       context 'json形式' do
302         it '例外404 not_foundを返す' do
303           lambda{ 
304             get :show, :id => 0, :format => :json
305           }.should raise_error(ActiveRecord::RecordNotFound)
306         end
307       end
308     end
309     context '他人の原画を見ようとしたとき' do
310       before do
311         OriginalPicture.stub(:show).and_return(@pic)
312         OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(false)
313       end
314       context 'html形式' do
315         it '例外403 forbiddenを返す' do
316           lambda{
317             get :show, :id => @pic.id
318           }.should raise_error(ActiveRecord::Forbidden)
319         end
320       end
321       context 'json形式' do
322         it '例外403 forbiddenを返す' do
323           lambda{
324             get :show, :id => @pic.id, :format => :json
325           }.should raise_error(ActiveRecord::Forbidden)
326         end
327       end
328     end
329 =end
330   end
331
332   describe '履歴一覧表示に於いて' do
333     before do
334       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
335       @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
336         :original_picture_id => @op.id
337       sign_in @user
338       OriginalPicture.stub(:show).and_return(@op)
339       OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
340     end
341     context 'つつがなく終わるとき' do
342       it 'ステータスコード200 OKを返す' do
343         get :history, :id => @op.id
344         response.should be_success 
345       end
346       it '原画モデルに単体取得を問い合わせている' do
347         OriginalPicture.should_receive(:show).exactly(1)
348         get :history, :id => @op.id
349       end
350       it '自身に履歴一覧を問い合わせている' do
351         OriginalPicture.any_instance.should_receive(:history).exactly(1)
352         get :history, :id => @op.id
353       end
354       it '@historyにリストを取得している' do
355         get :history, :id => @op.id
356         assigns(:history).should have_at_least(3).items
357       end
358       context 'html形式' do
359         it 'historyテンプレートを描画する' do
360           get :history, :id => @op.id
361           response.should render_template("history")
362         end
363       end
364       context 'json形式' do
365         it 'jsonデータを返す' do
366           get :history, :id => @op.id, :format => :json
367           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
368         end
369         it 'データがリスト構造になっている' do
370           get :history, :id => @op.id, :format => :json
371           json = JSON.parse response.body
372           json.should have_at_least(3).items
373         end
374         it 'リストの先頭くらいは原画っぽいものであって欲しい' do
375           get :history, :id => @op.id, :format => :json
376           json = JSON.parse response.body
377           json.first.has_key?("ext").should be_true
378         end
379       end
380     end
381     context '作家権限がないとき' do
382       before do
383         sign_out @user
384       end
385       context 'html形式' do
386         it 'ステータスコード302 Foundを返す' do
387           get :history, :id => @op.id
388           response.status.should eq 302
389         end
390         it 'サインインページへ遷移する' do
391           get :history, :id => @op.id
392           response.should redirect_to '/users/sign_in'
393         end
394       end
395       context 'json形式' do
396         it 'ステータスコード401 Unauthorizedを返す' do
397           get :history, :id => @op.id, :format => :json
398           response.status.should eq 401
399         end
400         it '応答メッセージにUnauthorizedを返す' do
401           get :history, :id => @op.id, :format => :json
402           response.message.should match(/Unauthorized/)
403         end
404       end
405     end
406     context '作家が絵師でないとき' do
407       before do
408         Author.any_instance.stub(:artist?).and_return(false)
409       end
410       context 'html形式' do
411         it 'ステータスコード302 Foundを返す' do
412           get :history, :id => @op.id
413           response.status.should eq 302
414         end
415         it '絵師登録ページへ遷移する' do
416           get :history, :id => @op.id
417           response.should redirect_to new_artist_path
418         end
419       end
420       context 'json形式' do
421         it '例外403 forbiddenを返す' do
422           lambda{
423             get :history, :id => @op.id, :format => :json
424           }.should raise_error(ActiveRecord::Forbidden)
425         end
426       end
427     end
428   end
429   
430   describe '新規作成フォーム表示に於いて' do
431     before do
432       sign_in @user
433     end
434     context 'つつがなく終わるとき' do
435       it '@original_pictureに新規データを用意している' do
436         get :new
437         assigns(:original_picture).should be_a_new(OriginalPicture)
438       end
439       it '原画モデルにデフォルト値補充を依頼している' do
440         OriginalPicture.any_instance.should_receive(:supply_default).exactly(1)
441         get :new
442       end
443       context 'html形式' do
444         it 'ステータスコード200 OKを返す' do
445           get :new
446           response.should be_success 
447         end
448         it 'ページテンプレートnewを描画する' do
449           get :new
450           response.should render_template("new")
451         end
452       end
453       context 'js形式' do
454         it 'ステータスコード200 OKを返す' do
455           get :new, :format => :js
456           response.should be_success 
457         end
458         it '部分テンプレートnew.jsを描画する' do
459           get :new, :format => :js
460           response.should render_template("new")
461         end
462       end
463       context 'json形式' do
464         it 'jsonデータを返す' do
465           get :new, :format => :json
466           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
467         end
468         it '原画モデルにjson単体出力オプションを問い合わせている' do
469           OriginalPicture.should_receive(:show_json_opt).exactly(1)
470           get :new, :format => :json
471         end
472       end
473     end
474     context '作家権限がないとき' do
475       before do
476         sign_out @user
477       end
478       context 'html形式' do
479         it 'ステータスコード302 Foundを返す' do
480           get :new
481           response.status.should eq 302
482         end
483         it 'サインインページへ遷移する' do
484           get :new
485           response.body.should redirect_to '/users/sign_in'
486         end
487       end
488       context 'js形式' do
489         it 'ステータスコード401 Unauthorizedを返す' do
490           get :new, :format => :js
491           response.status.should eq 401
492         end
493         it '応答メッセージにUnauthorizedを返す' do
494           get :new, :format => :js
495           response.message.should match(/Unauthorized/)
496         end
497       end
498     end
499     context '作家が絵師でないとき' do
500       before do
501         Author.any_instance.stub(:artist?).and_return(false)
502       end
503       context 'html形式' do
504         it 'ステータスコード302 Foundを返す' do
505           get :new
506           response.status.should eq 302
507         end
508         it '絵師登録ページへ遷移する' do
509           get :new
510           response.should redirect_to new_artist_path
511         end
512       end
513       context 'js形式' do
514         it 'ステータスコード200 Okを返す' do
515           get :new, :format => :js
516           response.status.should eq 200
517         end
518         it '絵師登録部分テンプレートartists/new.jsを描画する' do
519           get :new, :format => :js
520           response.should render_template("artists/new")
521         end
522       end
523       context 'json形式' do
524         it '例外403 forbiddenを返す' do
525           lambda{
526           get :new, :format => :json
527           }.should raise_error(ActiveRecord::Forbidden)
528         end
529       end
530     end
531   end
532
533   describe '新規作成に於いて' do
534     before do
535       sign_in @user
536       @attr = {:original_picture => {:file => "abc\ndef\nghi"}}
537       @imager = ImagerTest.load("abc\ndef\nghi")
538       OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
539     end
540     context '事前チェックしておく' do
541       before do
542         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
543         OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
544       end
545       it '画像ライブラリをロードする' do
546         PettanImager.should_receive(:load).with(any_args()).exactly(1)
547         post :create, @attr
548       end
549       it '原画モデルにデフォルト値補充を依頼している' do
550         OriginalPicture.any_instance.should_receive(:supply_default).with(any_args()).exactly(1)
551         post :create, @attr
552       end
553       it '原画モデルに上書き補充を依頼している' do
554         OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
555         post :create, @attr
556       end
557       it 'モデルに保存依頼する' do
558         OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
559         post :create, @attr
560       end
561     end
562     context 'つつがなく終わるとき' do
563       before do
564         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
565       end
566       it "@original_pictureに作成された原画を保持している" do
567         post :create, @attr
568         assigns(:original_picture).should be_a(OriginalPicture)
569       end
570       context 'html形式' do
571         it 'ステータスコード302 Foundを返す' do
572           post :create, @attr
573           response.status.should eq 302
574         end
575         it '作成された原画の表示ページへ遷移する' do
576           post :create, @attr
577           response.should redirect_to(OriginalPicture.last)
578         end
579       end
580       context 'json形式' do
581         before do
582           @attr.merge!({:format => :json})
583         end
584         it 'ステータスコード200 OKを返す' do
585           post :create, @attr
586           response.should be_success 
587         end
588         it '作成された原画をjsonデータで返す' do
589           post :create, @attr
590           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
591         end
592         it '原画モデルにjson単体出力オプションを問い合わせている' do
593           OriginalPicture.should_receive(:show_json_opt).exactly(1)
594           post :create, @attr
595         end
596         it 'データがアレになっている' do
597           post :create, @attr
598           json = JSON.parse response.body
599           json["ext"].should match(/png/)
600           json["md5"].should be_true
601           json["artist_id"].should be_true
602           json["width"].should be_true
603         end
604       end
605     end
606     context '作家権限がないとき' do
607       before do
608         sign_out @user
609       end
610       context 'html形式' do
611         it 'ステータスコード302 Foundを返す' do
612           post :create, @attr
613           response.status.should eq 302
614         end
615         it 'サインインページへ遷移する' do
616           post :create, @attr
617           response.body.should redirect_to '/users/sign_in'
618         end
619       end
620       context 'json形式' do
621         before do
622           @attr.merge!({:format => :json})
623         end
624         it 'ステータスコード401 Unauthorizedを返す' do
625           post :create, @attr
626           response.status.should eq 401
627         end
628         it '応答メッセージにUnauthorizedを返す' do
629           post :create, @attr
630           response.message.should match(/Unauthorized/)
631         end
632       end
633     end
634     context '作家が絵師でないとき' do
635       before do
636         Author.any_instance.stub(:artist?).and_return(false)
637       end
638       context 'html形式' do
639         it 'ステータスコード302 Foundを返す' do
640           post :create, @attr
641           response.status.should eq 302
642         end
643         it '絵師登録ページへ遷移する' do
644           post :create, @attr
645           response.should redirect_to new_artist_path
646         end
647       end
648       context 'json形式' do
649         before do
650           @attr.merge!({:format => :json})
651         end
652         it '例外403 forbiddenを返す' do
653           lambda{
654             post :create, @attr
655           }.should raise_error(ActiveRecord::Forbidden)
656         end
657       end
658     end
659     context '検証、保存に失敗した' do
660       before do
661         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
662         OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
663       end
664       it "未保存の原画を保持している" do
665         post :create, @attr
666         assigns(:original_picture).should be_a_new(OriginalPicture)
667       end
668       context 'html形式' do
669         it 'ステータスコード200 OKを返す' do
670           post :create, @attr
671           response.status.should eq 200
672         end
673         it '新規ページを描画する' do
674           post :create, @attr
675           response.should render_template("new")
676         end
677       end
678       context 'json形式' do
679         before do
680           @attr.merge!({:format => :json})
681         end
682         it 'ステータスコード422 unprocessable_entity を返す' do
683           post :create, @attr
684           response.status.should eq 422
685         end
686         it '応答メッセージUnprocessable Entityを返す' do
687           post :create, @attr
688           response.message.should match(/Unprocessable/)
689         end
690       end
691     end
692   end
693
694   describe '編集フォーム表示に於いて' do
695     before do
696       @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
697       sign_in @user
698       OriginalPicture.stub(:show).and_return(@pic)
699     end
700     context 'つつがなく終わるとき' do
701       it 'ステータスコード200 OKを返す' do
702         get :edit, :id => @pic.id
703         response.should be_success 
704       end
705       it '原画モデルに編集取得を問い合わせている' do
706         OriginalPicture.should_receive(:edit).exactly(1)
707         get :edit, :id => @pic.id
708       end
709       it '@original_pictureにデータを用意している' do
710         get :edit, :id => @pic.id
711         assigns(:original_picture).should eq @pic
712       end
713       context 'html形式' do
714         it 'ページテンプレートeditを描画する' do
715           get :edit, :id => @pic.id
716           response.should render_template("edit")
717         end
718       end
719       context 'js形式' do
720         it '部分テンプレートedit.jsを描画する' do
721           get :edit, :id => @pic.id, :format => :js
722           response.should render_template("edit")
723         end
724       end
725     end
726     context '作家権限がないとき' do
727       before do
728         sign_out @user
729       end
730       context 'html形式' do
731         it 'ステータスコード302 Foundを返す' do
732           get :edit, :id => @pic.id
733           response.status.should eq 302
734         end
735         it 'サインインページへ遷移する' do
736           get :edit, :id => @pic.id
737           response.body.should redirect_to '/users/sign_in'
738         end
739       end
740       context 'js形式' do
741         it 'ステータスコード401 Unauthorizedを返す' do
742           get :edit, :id => @pic.id, :format => :js
743           response.status.should eq 401
744         end
745         it '応答メッセージにUnauthorizedを返す' do
746           get :edit, :id => @pic.id, :format => :js
747           response.message.should match(/Unauthorized/)
748         end
749       end
750     end
751     context '作家が絵師でないとき' do
752       before do
753         Author.any_instance.stub(:artist?).and_return(false)
754       end
755       context 'html形式' do
756         it 'ステータスコード302 Foundを返す' do
757           get :edit, :id => @pic.id
758           response.status.should eq 302
759         end
760         it '絵師登録ページへ遷移する' do
761           get :edit, :id => @pic.id
762           response.should redirect_to new_artist_path
763         end
764       end
765       context 'js形式' do
766         it 'ステータスコード200 Okを返す' do
767           get :edit, :id => @pic.id, :format => :js
768           response.status.should eq 200
769         end
770         it '絵師登録部分テンプレートartists/new.jsを描画する' do
771           get :edit, :id => @pic.id, :format => :js
772           response.should render_template("artists/new")
773         end
774       end
775     end
776   end
777
778   describe '更新に於いて' do
779     before do
780       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
781       OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
782       OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
783       sign_in @user
784       @attr = {:file => "abc\ndef\nghi"}
785       @imager = ImagerTest.load("abc\ndef\nghi")
786     end
787     context '事前チェックしておく' do
788       before do
789         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
790         OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
791       end
792       it '画像ライブラリをロードする' do
793         PettanImager.should_receive(:load).with(any_args()).exactly(1)
794         put :update, :id => @op.id, :original_picture => @attr
795       end
796       it '原画モデルに編集取得を問い合わせている' do
797         OriginalPicture.should_receive(:edit).with(@op.id.to_s, @artist).exactly(1)
798         put :update, :id => @op.id, :original_picture => @attr
799       end
800       it '原画モデルに上書き補充を依頼している' do
801         OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
802         put :update, :id => @op.id, :original_picture => @attr
803       end
804       it 'モデルに更新を依頼する' do
805         OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
806         put :update, :id => @op.id, :original_picture => @attr
807       end
808     end
809     context 'つつがなく終わるとき' do
810       before do
811         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
812       end
813       it '@original_pictureにアレを取得している' do
814         put :update, :id => @op.id, :original_picture => @attr
815         assigns(:original_picture).should eq(@op)
816       end
817       context 'html形式' do
818         it 'ステータスコード302 Foundを返す' do
819           put :update, :id => @op.id, :original_picture => @attr
820           response.status.should eq 302
821         end
822         it '更新された原画の表示ページへ遷移する' do
823           put :update, :id => @op.id, :original_picture => @attr
824           response.should redirect_to(@pic)
825         end
826       end
827       context 'json形式' do
828         it 'ステータスコード200 OKを返す' do
829           put :update, :id => @op.id, :original_picture => @attr, :format => :json
830           response.should be_success 
831         end
832         it 'ページ本体は特に返さない' do
833           put :update, :id => @op.id, :original_picture => @attr, :format => :json
834           response.body.should match /./
835         end
836       end
837     end
838     context '作家権限がないとき' do
839       before do
840         sign_out @user
841       end
842       context 'html形式' do
843         it 'ステータスコード302 Foundを返す' do
844           put :update, :id => @op.id, :original_picture => @attr
845           response.status.should eq 302
846         end
847         it 'サインインページへ遷移する' do
848           put :update, :id => @op.id, :original_picture => @attr
849           response.body.should redirect_to '/users/sign_in'
850         end
851       end
852       context 'json形式' do
853         it 'ステータスコード401 Unauthorizedを返す' do
854           put :update, :id => @op.id, :original_picture => @attr, :format => :json
855           response.status.should eq 401
856         end
857         it '応答メッセージにUnauthorizedを返す' do
858           put :update, :id => @op.id, :original_picture => @attr, :format => :json
859           response.message.should match(/Unauthorized/)
860         end
861       end
862     end
863     context '作家が絵師でないとき' do
864       before do
865         Author.any_instance.stub(:artist?).and_return(false)
866       end
867       context 'html形式' do
868         it 'ステータスコード302 Foundを返す' do
869           put :update, :id => @op.id, :original_picture => @attr
870           response.status.should eq 302
871         end
872         it '絵師登録ページへ遷移する' do
873           put :update, :id => @op.id, :original_picture => @attr
874           response.should redirect_to new_artist_path
875         end
876       end
877       context 'json形式' do
878         it '例外403 forbiddenを返す' do
879           lambda{
880             put :update, :id => @op.id, :original_picture => @attr, :format => :json
881           }.should raise_error(ActiveRecord::Forbidden)
882         end
883       end
884     end
885     context '検証、保存に失敗した' do
886       before do
887         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
888         OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
889       end
890       context 'html形式' do
891         it 'ステータスコード200 Okを返す' do
892           put :update, :id => @op.id, :original_picture => @attr
893           response.status.should eq 200
894         end
895         it '編集ページを描画する' do
896           put :update, :id => @op.id, :original_picture => @attr
897           response.should render_template("edit")
898         end
899       end
900       context 'json形式' do
901         it 'ステータスコード422 unprocessable_entity を返す' do
902           put :update, :id => @op.id, :original_picture => @attr, :format => :json
903           response.status.should eq 422
904         end
905         it '応答メッセージUnprocessable Entityを返す' do
906           put :update, :id => @op.id, :original_picture => @attr, :format => :json
907           response.message.should match(/Unprocessable/)
908         end
909       end
910     end
911   end
912
913   describe '削除に於いて' do
914     before do
915       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
916       sign_in @user
917     end
918     context '事前チェックしておく' do
919       before do
920         OriginalPicture.stub(:edit).with(any_args()).and_return @op
921         OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
922       end
923       it '原画モデルに編集取得を問い合わせている' do
924         OriginalPicture.should_receive(:edit).exactly(1)
925         delete :destroy, :id => @op.id
926       end
927       it 'モデルに削除を依頼する' do
928         OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
929         delete :destroy, :id => @op.id
930       end
931       it '@original_pictureにアレを取得している' do
932         delete :destroy, :id => @op.id
933         assigns(:original_picture).id.should eq(@op.id)
934       end
935     end
936     context 'つつがなく終わるとき' do
937       before do
938         OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
939       end
940       context 'html形式' do
941         it 'ステータスコード302 Foundを返す' do
942           delete :destroy, :id => @op.id
943           response.status.should eq 302
944         end
945         it '原画の一覧ページへ遷移する' do
946           delete :destroy, :id => @op.id
947           response.should redirect_to(original_pictures_path)
948         end
949       end
950       context 'json形式' do
951         it 'ステータスコード200 OKを返す' do
952           delete :destroy, :id => @op.id, :format => :json
953           response.should be_success 
954         end
955         it 'ページ本体は特に返さない' do
956           delete :destroy, :id => @op.id, :format => :json
957           response.body.should match /./
958         end
959       end
960     end
961     context '作家権限がないとき' do
962       before do
963         sign_out @user
964       end
965       it 'ステータスコード302 Foundを返す' do
966         delete :destroy, :id => @op.id
967         response.status.should eq 302
968       end
969       context 'html形式' do
970         it 'サインインページへ遷移する' do
971           delete :destroy, :id => @op.id
972           response.body.should redirect_to '/users/sign_in'
973         end
974       end
975       context 'json形式' do
976         it '応答メッセージにUnauthorizedを返す' do
977           delete :destroy, :id => @op.id, :format => :json
978           response.message.should match(/Unauthorized/)
979         end
980       end
981     end
982     context '削除に失敗したとき' do
983       before do
984         OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
985       end
986       context 'html形式' do
987         it 'ステータスコード302 Foundを返す' do
988           delete :destroy, :id => @op.id
989           response.status.should eq 302
990         end
991         it 'その原画の詳細ページへ遷移する' do
992           delete :destroy, :id => @op.id
993           response.should redirect_to(original_picture_path(@op))
994         end
995       end
996       context 'json形式' do
997         it 'ステータスコード422 unprocessable_entity を返す' do
998           delete :destroy, :id => @op.id, :format => :json
999           response.status.should eq 422
1000         end
1001         it '応答メッセージUnprocessable Entityを返す' do
1002           delete :destroy, :id => @op.id, :format => :json
1003           response.message.should match(/Unprocessable/)
1004         end
1005       end
1006     end
1007   end
1008
1009 else
1010   describe '一覧表示に於いて' do
1011     before do
1012       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1013       sign_in @user
1014       OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
1015     end
1016     context 'つつがなく終わるとき' do
1017       it 'ステータスコード200 OKを返す' do
1018         get :index
1019         response.should be_success 
1020       end
1021       context 'html形式' do
1022         it 'indexテンプレートを描画する' do
1023           get :index
1024           response.should render_template("index")
1025         end
1026       end
1027       context 'json形式' do
1028         it 'jsonデータを返す' do
1029           get :index, :format => :json
1030           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1031         end
1032       end
1033     end
1034     context '作家権限がないとき' do
1035       before do
1036         sign_out @user
1037       end
1038       context 'html形式' do
1039         it 'ステータスコード302 Foundを返す' do
1040           get :index
1041           response.status.should eq 302
1042         end
1043         it 'サインインページへ遷移する' do
1044           get :index
1045           response.should redirect_to '/users/sign_in'
1046         end
1047       end
1048       context 'json形式' do
1049         it 'ステータスコード401 Unauthorizedを返す' do
1050           get :index, :format => :json
1051           response.status.should eq 401
1052         end
1053         it '応答メッセージにUnauthorizedを返す' do
1054           get :index, :format => :json
1055           response.message.should match(/Unauthorized/)
1056         end
1057       end
1058     end
1059   end
1060   
1061   describe '単体表示に於いて' do
1062     before do
1063       @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
1064       sign_in @user
1065       OriginalPicture.stub(:show).and_return(@pic)
1066     end
1067     context 'つつがなく終わるとき' do
1068       it 'ステータスコード200 OKを返す' do
1069         get :show, :id => @pic.id
1070         response.should be_success
1071       end
1072       context 'html形式' do
1073         it 'showテンプレートを描画する' do
1074           get :show, :id => @pic.id
1075           response.should render_template("show")
1076         end
1077       end
1078       context 'json形式' do
1079         it 'jsonデータを返す' do
1080           get :show, :id => @pic.id, :format => :json
1081           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1082         end
1083       end
1084     end
1085     context '作家権限がないとき' do
1086       before do
1087         sign_out @user
1088       end
1089       context 'html形式' do
1090         it 'ステータスコード302 Foundを返す' do
1091           get :show, :id => @pic.id
1092           response.status.should eq 302
1093         end
1094         it 'サインインページへ遷移する' do
1095           get :show, :id => @pic.id
1096           response.body.should redirect_to '/users/sign_in'
1097         end
1098       end
1099       context 'json形式' do
1100         it 'ステータスコード401 Unauthorizedを返す' do
1101           get :show, :id => @pic.id, :format => :json
1102           response.status.should eq 401
1103         end
1104         it '応答メッセージにUnauthorizedを返す' do
1105           get :show, :id => @pic.id, :format => :json
1106           response.message.should match(/Unauthorized/)
1107         end
1108       end
1109     end
1110   end
1111
1112   describe '履歴一覧表示に於いて' do
1113     before do
1114       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1115       @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
1116         :original_picture_id => @op.id
1117       sign_in @user
1118       OriginalPicture.stub(:show).and_return(@op)
1119       OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
1120     end
1121     context 'つつがなく終わるとき' do
1122       it 'ステータスコード200 OKを返す' do
1123         get :history, :id => @op.id
1124         response.should be_success 
1125       end
1126       context 'html形式' do
1127         it 'historyテンプレートを描画する' do
1128           get :history, :id => @op.id
1129           response.should render_template("history")
1130         end
1131       end
1132       context 'json形式' do
1133         it 'jsonデータを返す' do
1134           get :history, :id => @op.id, :format => :json
1135           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1136         end
1137       end
1138     end
1139     context '作家権限がないとき' do
1140       before do
1141         sign_out @user
1142       end
1143       context 'html形式' do
1144         it 'ステータスコード302 Foundを返す' do
1145           get :history, :id => @op.id
1146           response.status.should eq 302
1147         end
1148         it 'サインインページへ遷移する' do
1149           get :history, :id => @op.id
1150           response.should redirect_to '/users/sign_in'
1151         end
1152       end
1153       context 'json形式' do
1154         it 'ステータスコード401 Unauthorizedを返す' do
1155           get :history, :id => @op.id, :format => :json
1156           response.status.should eq 401
1157         end
1158         it '応答メッセージにUnauthorizedを返す' do
1159           get :history, :id => @op.id, :format => :json
1160           response.message.should match(/Unauthorized/)
1161         end
1162       end
1163     end
1164   end
1165   
1166   describe '新規作成フォーム表示に於いて' do
1167     before do
1168       sign_in @user
1169     end
1170     context 'つつがなく終わるとき' do
1171       context 'html形式' do
1172         it 'ステータスコード200 OKを返す' do
1173           get :new
1174           response.should be_success 
1175         end
1176         it 'ページテンプレートnewを描画する' do
1177           get :new
1178           response.should render_template("new")
1179         end
1180       end
1181       context 'js形式' do
1182         it 'ステータスコード200 OKを返す' do
1183           get :new, :format => :js
1184           response.should be_success 
1185         end
1186         it '部分テンプレートnew.jsを描画する' do
1187           get :new, :format => :js
1188           response.should render_template("new")
1189         end
1190       end
1191       context 'json形式' do
1192         it 'jsonデータを返す' do
1193           get :new, :format => :json
1194           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1195         end
1196       end
1197     end
1198     context '作家権限がないとき' do
1199       before do
1200         sign_out @user
1201       end
1202       context 'html形式' do
1203         it 'ステータスコード302 Foundを返す' do
1204           get :new
1205           response.status.should eq 302
1206         end
1207         it 'サインインページへ遷移する' do
1208           get :new
1209           response.body.should redirect_to '/users/sign_in'
1210         end
1211       end
1212       context 'js形式' do
1213         it 'ステータスコード401 Unauthorizedを返す' do
1214           get :new, :format => :js
1215           response.status.should eq 401
1216         end
1217         it '応答メッセージにUnauthorizedを返す' do
1218           get :new, :format => :js
1219           response.message.should match(/Unauthorized/)
1220         end
1221       end
1222     end
1223   end
1224
1225   describe '新規作成に於いて' do
1226     before do
1227       sign_in @user
1228       @attr = {:original_picture => {:file => "abc\ndef\nghi"}}
1229       @imager = ImagerTest.load("abc\ndef\nghi")
1230       OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
1231     end
1232     context 'つつがなく終わるとき' do
1233       before do
1234         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1235       end
1236       context 'html形式' do
1237         it 'ステータスコード302 Foundを返す' do
1238           post :create, @attr
1239           response.status.should eq 302
1240         end
1241         it '作成された原画の表示ページへ遷移する' do
1242           post :create, @attr
1243           response.should redirect_to(OriginalPicture.last)
1244         end
1245       end
1246       context 'json形式' do
1247         before do
1248           @attr.merge!({:format => :json})
1249         end
1250         it 'ステータスコード200 OKを返す' do
1251           post :create, @attr
1252           response.should be_success 
1253         end
1254         it '作成された原画をjsonデータで返す' do
1255           post :create, @attr
1256           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1257         end
1258       end
1259     end
1260     context '作家権限がないとき' do
1261       before do
1262         sign_out @user
1263       end
1264       context 'html形式' do
1265         it 'ステータスコード302 Foundを返す' do
1266           post :create, @attr
1267           response.status.should eq 302
1268         end
1269         it 'サインインページへ遷移する' do
1270           post :create, @attr
1271           response.body.should redirect_to '/users/sign_in'
1272         end
1273       end
1274       context 'json形式' do
1275         before do
1276           @attr.merge!({:format => :json})
1277         end
1278         it 'ステータスコード401 Unauthorizedを返す' do
1279           post :create, @attr
1280           response.status.should eq 401
1281         end
1282         it '応答メッセージにUnauthorizedを返す' do
1283           post :create, @attr
1284           response.message.should match(/Unauthorized/)
1285         end
1286       end
1287     end
1288   end
1289
1290   describe '編集フォーム表示に於いて' do
1291     before do
1292       @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
1293       sign_in @user
1294       OriginalPicture.stub(:show).and_return(@pic)
1295     end
1296     context 'つつがなく終わるとき' do
1297       it 'ステータスコード200 OKを返す' do
1298         get :edit, :id => @pic.id
1299         response.should be_success 
1300       end
1301       context 'html形式' do
1302         it 'ページテンプレートeditを描画する' do
1303           get :edit, :id => @pic.id
1304           response.should render_template("edit")
1305         end
1306       end
1307       context 'js形式' do
1308         it '部分テンプレートedit.jsを描画する' do
1309           get :edit, :id => @pic.id, :format => :js
1310           response.should render_template("edit")
1311         end
1312       end
1313     end
1314     context '作家権限がないとき' do
1315       before do
1316         sign_out @user
1317       end
1318       context 'html形式' do
1319         it 'ステータスコード302 Foundを返す' do
1320           get :edit, :id => @pic.id
1321           response.status.should eq 302
1322         end
1323         it 'サインインページへ遷移する' do
1324           get :edit, :id => @pic.id
1325           response.body.should redirect_to '/users/sign_in'
1326         end
1327       end
1328       context 'js形式' do
1329         it 'ステータスコード401 Unauthorizedを返す' do
1330           get :edit, :id => @pic.id, :format => :js
1331           response.status.should eq 401
1332         end
1333         it '応答メッセージにUnauthorizedを返す' do
1334           get :edit, :id => @pic.id, :format => :js
1335           response.message.should match(/Unauthorized/)
1336         end
1337       end
1338     end
1339   end
1340
1341   describe '更新に於いて' do
1342     before do
1343       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1344       OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
1345       OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
1346       sign_in @user
1347       @attr = {:file => "abc\ndef\nghi"}
1348       @imager = ImagerTest.load("abc\ndef\nghi")
1349     end
1350     context 'つつがなく終わるとき' do
1351       before do
1352         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1353       end
1354       context 'html形式' do
1355         it 'ステータスコード302 Foundを返す' do
1356           put :update, :id => @op.id, :original_picture => @attr
1357           response.status.should eq 302
1358         end
1359         it '更新された原画の表示ページへ遷移する' do
1360           put :update, :id => @op.id, :original_picture => @attr
1361           response.should redirect_to(@pic)
1362         end
1363       end
1364       context 'json形式' do
1365         it 'ステータスコード200 OKを返す' do
1366           put :update, :id => @op.id, :original_picture => @attr, :format => :json
1367           response.should be_success 
1368         end
1369         it 'ページ本体は特に返さない' do
1370           put :update, :id => @op.id, :original_picture => @attr, :format => :json
1371           response.body.should match /./
1372         end
1373       end
1374     end
1375     context '作家権限がないとき' do
1376       before do
1377         sign_out @user
1378       end
1379       context 'html形式' do
1380         it 'ステータスコード302 Foundを返す' do
1381           put :update, :id => @op.id, :original_picture => @attr
1382           response.status.should eq 302
1383         end
1384         it 'サインインページへ遷移する' do
1385           put :update, :id => @op.id, :original_picture => @attr
1386           response.body.should redirect_to '/users/sign_in'
1387         end
1388       end
1389       context 'json形式' do
1390         it 'ステータスコード401 Unauthorizedを返す' do
1391           put :update, :id => @op.id, :original_picture => @attr, :format => :json
1392           response.status.should eq 401
1393         end
1394         it '応答メッセージにUnauthorizedを返す' do
1395           put :update, :id => @op.id, :original_picture => @attr, :format => :json
1396           response.message.should match(/Unauthorized/)
1397         end
1398       end
1399     end
1400     context '作家が絵師でないとき' do
1401       before do
1402         Author.any_instance.stub(:artist?).and_return(false)
1403       end
1404       context 'html形式' do
1405         it 'ステータスコード302 Foundを返す' do
1406           put :update, :id => @op.id, :original_picture => @attr
1407           response.status.should eq 302
1408         end
1409         it '絵師登録ページへ遷移する' do
1410           put :update, :id => @op.id, :original_picture => @attr
1411           response.should redirect_to new_artist_path
1412         end
1413       end
1414       context 'json形式' do
1415         it '例外403 forbiddenを返す' do
1416           lambda{
1417             put :update, :id => @op.id, :original_picture => @attr, :format => :json
1418           }.should raise_error(ActiveRecord::Forbidden)
1419         end
1420       end
1421     end
1422     context '検証、保存に失敗した' do
1423       before do
1424         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1425         OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
1426       end
1427       context 'html形式' do
1428         it 'ステータスコード200 Okを返す' do
1429           put :update, :id => @op.id, :original_picture => @attr
1430           response.status.should eq 200
1431         end
1432         it '編集ページを描画する' do
1433           put :update, :id => @op.id, :original_picture => @attr
1434           response.should render_template("edit")
1435         end
1436       end
1437       context 'json形式' do
1438         it 'ステータスコード422 unprocessable_entity を返す' do
1439           put :update, :id => @op.id, :original_picture => @attr, :format => :json
1440           response.status.should eq 422
1441         end
1442         it '応答メッセージUnprocessable Entityを返す' do
1443           put :update, :id => @op.id, :original_picture => @attr, :format => :json
1444           response.message.should match(/Unprocessable/)
1445         end
1446       end
1447     end
1448   end
1449
1450   describe '削除に於いて' do
1451     before do
1452       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1453       sign_in @user
1454     end
1455     context '事前チェックしておく' do
1456       before do
1457         OriginalPicture.stub(:edit).with(any_args()).and_return @op
1458         OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1459       end
1460       it '原画モデルに編集取得を問い合わせている' do
1461         OriginalPicture.should_receive(:edit).exactly(1)
1462         delete :destroy, :id => @op.id
1463       end
1464       it 'モデルに削除を依頼する' do
1465         OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
1466         delete :destroy, :id => @op.id
1467       end
1468       it '@original_pictureにアレを取得している' do
1469         delete :destroy, :id => @op.id
1470         assigns(:original_picture).id.should eq(@op.id)
1471       end
1472     end
1473     context 'つつがなく終わるとき' do
1474       before do
1475         OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1476       end
1477       context 'html形式' do
1478         it 'ステータスコード302 Foundを返す' do
1479           delete :destroy, :id => @op.id
1480           response.status.should eq 302
1481         end
1482         it '原画の一覧ページへ遷移する' do
1483           delete :destroy, :id => @op.id
1484           response.should redirect_to(original_pictures_path)
1485         end
1486       end
1487       context 'json形式' do
1488         it 'ステータスコード200 OKを返す' do
1489           delete :destroy, :id => @op.id, :format => :json
1490           response.should be_success 
1491         end
1492         it 'ページ本体は特に返さない' do
1493           delete :destroy, :id => @op.id, :format => :json
1494           response.body.should match /./
1495         end
1496       end
1497     end
1498     context '作家権限がないとき' do
1499       before do
1500         sign_out @user
1501       end
1502       it 'ステータスコード302 Foundを返す' do
1503         delete :destroy, :id => @op.id
1504         response.status.should eq 302
1505       end
1506       context 'html形式' do
1507         it 'サインインページへ遷移する' do
1508           delete :destroy, :id => @op.id
1509           response.body.should redirect_to '/users/sign_in'
1510         end
1511       end
1512       context 'json形式' do
1513         it '応答メッセージにUnauthorizedを返す' do
1514           delete :destroy, :id => @op.id, :format => :json
1515           response.message.should match(/Unauthorized/)
1516         end
1517       end
1518     end
1519     context '削除に失敗したとき' do
1520       before do
1521         OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
1522       end
1523       context 'html形式' do
1524         it 'ステータスコード302 Foundを返す' do
1525           delete :destroy, :id => @op.id
1526           response.status.should eq 302
1527         end
1528         it 'その原画の詳細ページへ遷移する' do
1529           delete :destroy, :id => @op.id
1530           response.should redirect_to(original_picture_path(@op))
1531         end
1532       end
1533       context 'json形式' do
1534         it 'ステータスコード422 unprocessable_entity を返す' do
1535           delete :destroy, :id => @op.id, :format => :json
1536           response.status.should eq 422
1537         end
1538         it '応答メッセージUnprocessable Entityを返す' do
1539           delete :destroy, :id => @op.id, :format => :json
1540           response.message.should match(/Unprocessable/)
1541         end
1542       end
1543     end
1544   end
1545 end
1546
1547 end