OSDN Git Service

t#30328:create op import ...and pull
[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     context 'ファイルが指定されていないとき' do
693       before do
694         @attr = {}
695         PettanImager.stub(:load).and_return(nil)
696       end
697       it "未保存の原画を保持している" do
698         post :create, @attr
699         assigns(:original_picture).should be_a_new(OriginalPicture)
700       end
701       context 'html形式' do
702         it 'ステータスコード200 OKを返す' do
703           post :create, @attr
704           response.status.should eq 200
705         end
706         it '新規ページを描画する' do
707           post :create, @attr
708           response.should render_template("new")
709         end
710       end
711       context 'json形式' do
712         before do
713           @attr.merge!({:format => :json})
714         end
715         it 'ステータスコード422 unprocessable_entity を返す' do
716           post :create, @attr
717           response.status.should eq 422
718         end
719         it '応答メッセージUnprocessable Entityを返す' do
720           post :create, @attr
721           response.message.should match(/Unprocessable/)
722         end
723       end
724     end
725   end
726
727   describe '編集フォーム表示に於いて' do
728     before do
729       @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
730       sign_in @user
731       OriginalPicture.stub(:show).and_return(@pic)
732     end
733     context 'つつがなく終わるとき' do
734       it 'ステータスコード200 OKを返す' do
735         get :edit, :id => @pic.id
736         response.should be_success 
737       end
738       it '原画モデルに編集取得を問い合わせている' do
739         OriginalPicture.should_receive(:edit).exactly(1)
740         get :edit, :id => @pic.id
741       end
742       it '@original_pictureにデータを用意している' do
743         get :edit, :id => @pic.id
744         assigns(:original_picture).should eq @pic
745       end
746       context 'html形式' do
747         it 'ページテンプレートeditを描画する' do
748           get :edit, :id => @pic.id
749           response.should render_template("edit")
750         end
751       end
752       context 'js形式' do
753         it '部分テンプレートedit.jsを描画する' do
754           get :edit, :id => @pic.id, :format => :js
755           response.should render_template("edit")
756         end
757       end
758     end
759     context '作家権限がないとき' do
760       before do
761         sign_out @user
762       end
763       context 'html形式' do
764         it 'ステータスコード302 Foundを返す' do
765           get :edit, :id => @pic.id
766           response.status.should eq 302
767         end
768         it 'サインインページへ遷移する' do
769           get :edit, :id => @pic.id
770           response.body.should redirect_to '/users/sign_in'
771         end
772       end
773       context 'js形式' do
774         it 'ステータスコード401 Unauthorizedを返す' do
775           get :edit, :id => @pic.id, :format => :js
776           response.status.should eq 401
777         end
778         it '応答メッセージにUnauthorizedを返す' do
779           get :edit, :id => @pic.id, :format => :js
780           response.message.should match(/Unauthorized/)
781         end
782       end
783     end
784     context '作家が絵師でないとき' do
785       before do
786         Author.any_instance.stub(:artist?).and_return(false)
787       end
788       context 'html形式' do
789         it 'ステータスコード302 Foundを返す' do
790           get :edit, :id => @pic.id
791           response.status.should eq 302
792         end
793         it '絵師登録ページへ遷移する' do
794           get :edit, :id => @pic.id
795           response.should redirect_to new_artist_path
796         end
797       end
798       context 'js形式' do
799         it 'ステータスコード200 Okを返す' do
800           get :edit, :id => @pic.id, :format => :js
801           response.status.should eq 200
802         end
803         it '絵師登録部分テンプレートartists/new.jsを描画する' do
804           get :edit, :id => @pic.id, :format => :js
805           response.should render_template("artists/new")
806         end
807       end
808     end
809   end
810
811   describe '更新に於いて' do
812     before do
813       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
814       OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
815       OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
816       sign_in @user
817       @attr = {:file => "abc\ndef\nghi"}
818       @imager = ImagerTest.load("abc\ndef\nghi")
819     end
820     context '事前チェックしておく' do
821       before do
822         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
823         OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
824       end
825       it '画像ライブラリをロードする' do
826         PettanImager.should_receive(:load).with(any_args()).exactly(1)
827         put :update, :id => @op.id, :original_picture => @attr
828       end
829       it '原画モデルに編集取得を問い合わせている' do
830         OriginalPicture.should_receive(:edit).with(@op.id.to_s, @artist).exactly(1)
831         put :update, :id => @op.id, :original_picture => @attr
832       end
833       it '原画モデルに上書き補充を依頼している' do
834         OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
835         put :update, :id => @op.id, :original_picture => @attr
836       end
837       it 'モデルに更新を依頼する' do
838         OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
839         put :update, :id => @op.id, :original_picture => @attr
840       end
841     end
842     context 'つつがなく終わるとき' do
843       before do
844         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
845       end
846       it '@original_pictureにアレを取得している' do
847         put :update, :id => @op.id, :original_picture => @attr
848         assigns(:original_picture).should eq(@op)
849       end
850       context 'html形式' do
851         it 'ステータスコード302 Foundを返す' do
852           put :update, :id => @op.id, :original_picture => @attr
853           response.status.should eq 302
854         end
855         it '更新された原画の表示ページへ遷移する' do
856           put :update, :id => @op.id, :original_picture => @attr
857           response.should redirect_to(@pic)
858         end
859       end
860       context 'json形式' do
861         it 'ステータスコード200 OKを返す' do
862           put :update, :id => @op.id, :original_picture => @attr, :format => :json
863           response.should be_success 
864         end
865         it 'ページ本体は特に返さない' do
866           put :update, :id => @op.id, :original_picture => @attr, :format => :json
867           response.body.should match /./
868         end
869       end
870     end
871     context '作家権限がないとき' do
872       before do
873         sign_out @user
874       end
875       context 'html形式' do
876         it 'ステータスコード302 Foundを返す' do
877           put :update, :id => @op.id, :original_picture => @attr
878           response.status.should eq 302
879         end
880         it 'サインインページへ遷移する' do
881           put :update, :id => @op.id, :original_picture => @attr
882           response.body.should redirect_to '/users/sign_in'
883         end
884       end
885       context 'json形式' do
886         it 'ステータスコード401 Unauthorizedを返す' do
887           put :update, :id => @op.id, :original_picture => @attr, :format => :json
888           response.status.should eq 401
889         end
890         it '応答メッセージにUnauthorizedを返す' do
891           put :update, :id => @op.id, :original_picture => @attr, :format => :json
892           response.message.should match(/Unauthorized/)
893         end
894       end
895     end
896     context '作家が絵師でないとき' do
897       before do
898         Author.any_instance.stub(:artist?).and_return(false)
899       end
900       context 'html形式' do
901         it 'ステータスコード302 Foundを返す' do
902           put :update, :id => @op.id, :original_picture => @attr
903           response.status.should eq 302
904         end
905         it '絵師登録ページへ遷移する' do
906           put :update, :id => @op.id, :original_picture => @attr
907           response.should redirect_to new_artist_path
908         end
909       end
910       context 'json形式' do
911         it '例外403 forbiddenを返す' do
912           lambda{
913             put :update, :id => @op.id, :original_picture => @attr, :format => :json
914           }.should raise_error(ActiveRecord::Forbidden)
915         end
916       end
917     end
918     context '検証、保存に失敗した' do
919       before do
920         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
921         OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
922       end
923       context 'html形式' do
924         it 'ステータスコード200 Okを返す' do
925           put :update, :id => @op.id, :original_picture => @attr
926           response.status.should eq 200
927         end
928         it '編集ページを描画する' do
929           put :update, :id => @op.id, :original_picture => @attr
930           response.should render_template("edit")
931         end
932       end
933       context 'json形式' do
934         it 'ステータスコード422 unprocessable_entity を返す' do
935           put :update, :id => @op.id, :original_picture => @attr, :format => :json
936           response.status.should eq 422
937         end
938         it '応答メッセージUnprocessable Entityを返す' do
939           put :update, :id => @op.id, :original_picture => @attr, :format => :json
940           response.message.should match(/Unprocessable/)
941         end
942       end
943     end
944     context 'ファイルが指定されていないとき' do
945       before do
946         @attr = {}
947         PettanImager.stub(:load).and_return(nil)
948       end
949       context 'html形式' do
950         it 'ステータスコード200 Okを返す' do
951           put :update, :id => @op.id, :original_picture => @attr
952           response.status.should eq 200
953         end
954         it '編集ページを描画する' do
955           put :update, :id => @op.id, :original_picture => @attr
956           response.should render_template("edit")
957         end
958       end
959       context 'json形式' do
960         it 'ステータスコード422 unprocessable_entity を返す' do
961           put :update, :id => @op.id, :original_picture => @attr, :format => :json
962           response.status.should eq 422
963         end
964         it '応答メッセージUnprocessable Entityを返す' do
965           put :update, :id => @op.id, :original_picture => @attr, :format => :json
966           response.message.should match(/Unprocessable/)
967         end
968       end
969     end
970   end
971
972   describe '削除に於いて' do
973     before do
974       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
975       sign_in @user
976     end
977     context '事前チェックしておく' do
978       before do
979         OriginalPicture.stub(:edit).with(any_args()).and_return @op
980         OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
981       end
982       it '原画モデルに編集取得を問い合わせている' do
983         OriginalPicture.should_receive(:edit).exactly(1)
984         delete :destroy, :id => @op.id
985       end
986       it 'モデルに削除を依頼する' do
987         OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
988         delete :destroy, :id => @op.id
989       end
990       it '@original_pictureにアレを取得している' do
991         delete :destroy, :id => @op.id
992         assigns(:original_picture).id.should eq(@op.id)
993       end
994     end
995     context 'つつがなく終わるとき' do
996       before do
997         OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
998       end
999       context 'html形式' do
1000         it 'ステータスコード302 Foundを返す' do
1001           delete :destroy, :id => @op.id
1002           response.status.should eq 302
1003         end
1004         it '原画の一覧ページへ遷移する' do
1005           delete :destroy, :id => @op.id
1006           response.should redirect_to(original_pictures_path)
1007         end
1008       end
1009       context 'json形式' do
1010         it 'ステータスコード200 OKを返す' do
1011           delete :destroy, :id => @op.id, :format => :json
1012           response.should be_success 
1013         end
1014         it 'ページ本体は特に返さない' do
1015           delete :destroy, :id => @op.id, :format => :json
1016           response.body.should match /./
1017         end
1018       end
1019     end
1020     context '作家権限がないとき' do
1021       before do
1022         sign_out @user
1023       end
1024       it 'ステータスコード302 Foundを返す' do
1025         delete :destroy, :id => @op.id
1026         response.status.should eq 302
1027       end
1028       context 'html形式' do
1029         it 'サインインページへ遷移する' do
1030           delete :destroy, :id => @op.id
1031           response.body.should redirect_to '/users/sign_in'
1032         end
1033       end
1034       context 'json形式' do
1035         it '応答メッセージにUnauthorizedを返す' do
1036           delete :destroy, :id => @op.id, :format => :json
1037           response.message.should match(/Unauthorized/)
1038         end
1039       end
1040     end
1041     context '削除に失敗したとき' do
1042       before do
1043         OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
1044       end
1045       context 'html形式' do
1046         it 'ステータスコード302 Foundを返す' do
1047           delete :destroy, :id => @op.id
1048           response.status.should eq 302
1049         end
1050         it 'その原画の詳細ページへ遷移する' do
1051           delete :destroy, :id => @op.id
1052           response.should redirect_to(original_picture_path(@op))
1053         end
1054       end
1055       context 'json形式' do
1056         it 'ステータスコード422 unprocessable_entity を返す' do
1057           delete :destroy, :id => @op.id, :format => :json
1058           response.status.should eq 422
1059         end
1060         it '応答メッセージUnprocessable Entityを返す' do
1061           delete :destroy, :id => @op.id, :format => :json
1062           response.message.should match(/Unprocessable/)
1063         end
1064       end
1065     end
1066   end
1067
1068 else
1069   describe '一覧表示に於いて' do
1070     before do
1071       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1072       sign_in @user
1073       OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
1074     end
1075     context 'つつがなく終わるとき' do
1076       it 'ステータスコード200 OKを返す' do
1077         get :index
1078         response.should be_success 
1079       end
1080       context 'html形式' do
1081         it 'indexテンプレートを描画する' do
1082           get :index
1083           response.should render_template("index")
1084         end
1085       end
1086       context 'json形式' do
1087         it 'jsonデータを返す' do
1088           get :index, :format => :json
1089           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1090         end
1091       end
1092     end
1093     context '作家権限がないとき' do
1094       before do
1095         sign_out @user
1096       end
1097       context 'html形式' do
1098         it 'ステータスコード302 Foundを返す' do
1099           get :index
1100           response.status.should eq 302
1101         end
1102         it 'サインインページへ遷移する' do
1103           get :index
1104           response.should redirect_to '/users/sign_in'
1105         end
1106       end
1107       context 'json形式' do
1108         it 'ステータスコード401 Unauthorizedを返す' do
1109           get :index, :format => :json
1110           response.status.should eq 401
1111         end
1112         it '応答メッセージにUnauthorizedを返す' do
1113           get :index, :format => :json
1114           response.message.should match(/Unauthorized/)
1115         end
1116       end
1117     end
1118   end
1119   
1120   describe '単体表示に於いて' do
1121     before do
1122       @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
1123       sign_in @user
1124       OriginalPicture.stub(:show).and_return(@pic)
1125     end
1126     context 'つつがなく終わるとき' do
1127       it 'ステータスコード200 OKを返す' do
1128         get :show, :id => @pic.id
1129         response.should be_success
1130       end
1131       context 'html形式' do
1132         it 'showテンプレートを描画する' do
1133           get :show, :id => @pic.id
1134           response.should render_template("show")
1135         end
1136       end
1137       context 'json形式' do
1138         it 'jsonデータを返す' do
1139           get :show, :id => @pic.id, :format => :json
1140           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1141         end
1142       end
1143     end
1144     context '作家権限がないとき' do
1145       before do
1146         sign_out @user
1147       end
1148       context 'html形式' do
1149         it 'ステータスコード302 Foundを返す' do
1150           get :show, :id => @pic.id
1151           response.status.should eq 302
1152         end
1153         it 'サインインページへ遷移する' do
1154           get :show, :id => @pic.id
1155           response.body.should redirect_to '/users/sign_in'
1156         end
1157       end
1158       context 'json形式' do
1159         it 'ステータスコード401 Unauthorizedを返す' do
1160           get :show, :id => @pic.id, :format => :json
1161           response.status.should eq 401
1162         end
1163         it '応答メッセージにUnauthorizedを返す' do
1164           get :show, :id => @pic.id, :format => :json
1165           response.message.should match(/Unauthorized/)
1166         end
1167       end
1168     end
1169   end
1170
1171   describe '履歴一覧表示に於いて' do
1172     before do
1173       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1174       @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
1175         :original_picture_id => @op.id
1176       sign_in @user
1177       OriginalPicture.stub(:show).and_return(@op)
1178       OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
1179     end
1180     context 'つつがなく終わるとき' do
1181       it 'ステータスコード200 OKを返す' do
1182         get :history, :id => @op.id
1183         response.should be_success 
1184       end
1185       context 'html形式' do
1186         it 'historyテンプレートを描画する' do
1187           get :history, :id => @op.id
1188           response.should render_template("history")
1189         end
1190       end
1191       context 'json形式' do
1192         it 'jsonデータを返す' do
1193           get :history, :id => @op.id, :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 :history, :id => @op.id
1205           response.status.should eq 302
1206         end
1207         it 'サインインページへ遷移する' do
1208           get :history, :id => @op.id
1209           response.should redirect_to '/users/sign_in'
1210         end
1211       end
1212       context 'json形式' do
1213         it 'ステータスコード401 Unauthorizedを返す' do
1214           get :history, :id => @op.id, :format => :json
1215           response.status.should eq 401
1216         end
1217         it '応答メッセージにUnauthorizedを返す' do
1218           get :history, :id => @op.id, :format => :json
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     end
1229     context 'つつがなく終わるとき' do
1230       context 'html形式' do
1231         it 'ステータスコード200 OKを返す' do
1232           get :new
1233           response.should be_success 
1234         end
1235         it 'ページテンプレートnewを描画する' do
1236           get :new
1237           response.should render_template("new")
1238         end
1239       end
1240       context 'js形式' do
1241         it 'ステータスコード200 OKを返す' do
1242           get :new, :format => :js
1243           response.should be_success 
1244         end
1245         it '部分テンプレートnew.jsを描画する' do
1246           get :new, :format => :js
1247           response.should render_template("new")
1248         end
1249       end
1250       context 'json形式' do
1251         it 'jsonデータを返す' do
1252           get :new, :format => :json
1253           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1254         end
1255       end
1256     end
1257     context '作家権限がないとき' do
1258       before do
1259         sign_out @user
1260       end
1261       context 'html形式' do
1262         it 'ステータスコード302 Foundを返す' do
1263           get :new
1264           response.status.should eq 302
1265         end
1266         it 'サインインページへ遷移する' do
1267           get :new
1268           response.body.should redirect_to '/users/sign_in'
1269         end
1270       end
1271       context 'js形式' do
1272         it 'ステータスコード401 Unauthorizedを返す' do
1273           get :new, :format => :js
1274           response.status.should eq 401
1275         end
1276         it '応答メッセージにUnauthorizedを返す' do
1277           get :new, :format => :js
1278           response.message.should match(/Unauthorized/)
1279         end
1280       end
1281     end
1282   end
1283
1284   describe '新規作成に於いて' do
1285     before do
1286       sign_in @user
1287       @attr = {:original_picture => {:file => "abc\ndef\nghi"}}
1288       @imager = ImagerTest.load("abc\ndef\nghi")
1289       OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
1290     end
1291     context 'つつがなく終わるとき' do
1292       before do
1293         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1294       end
1295       context 'html形式' do
1296         it 'ステータスコード302 Foundを返す' do
1297           post :create, @attr
1298           response.status.should eq 302
1299         end
1300         it '作成された原画の表示ページへ遷移する' do
1301           post :create, @attr
1302           response.should redirect_to(OriginalPicture.last)
1303         end
1304       end
1305       context 'json形式' do
1306         before do
1307           @attr.merge!({:format => :json})
1308         end
1309         it 'ステータスコード200 OKを返す' do
1310           post :create, @attr
1311           response.should be_success 
1312         end
1313         it '作成された原画をjsonデータで返す' do
1314           post :create, @attr
1315           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1316         end
1317       end
1318     end
1319     context '作家権限がないとき' do
1320       before do
1321         sign_out @user
1322       end
1323       context 'html形式' do
1324         it 'ステータスコード302 Foundを返す' do
1325           post :create, @attr
1326           response.status.should eq 302
1327         end
1328         it 'サインインページへ遷移する' do
1329           post :create, @attr
1330           response.body.should redirect_to '/users/sign_in'
1331         end
1332       end
1333       context 'json形式' do
1334         before do
1335           @attr.merge!({:format => :json})
1336         end
1337         it 'ステータスコード401 Unauthorizedを返す' do
1338           post :create, @attr
1339           response.status.should eq 401
1340         end
1341         it '応答メッセージにUnauthorizedを返す' do
1342           post :create, @attr
1343           response.message.should match(/Unauthorized/)
1344         end
1345       end
1346     end
1347   end
1348
1349   describe '編集フォーム表示に於いて' do
1350     before do
1351       @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
1352       sign_in @user
1353       OriginalPicture.stub(:show).and_return(@pic)
1354     end
1355     context 'つつがなく終わるとき' do
1356       it 'ステータスコード200 OKを返す' do
1357         get :edit, :id => @pic.id
1358         response.should be_success 
1359       end
1360       context 'html形式' do
1361         it 'ページテンプレートeditを描画する' do
1362           get :edit, :id => @pic.id
1363           response.should render_template("edit")
1364         end
1365       end
1366       context 'js形式' do
1367         it '部分テンプレートedit.jsを描画する' do
1368           get :edit, :id => @pic.id, :format => :js
1369           response.should render_template("edit")
1370         end
1371       end
1372     end
1373     context '作家権限がないとき' do
1374       before do
1375         sign_out @user
1376       end
1377       context 'html形式' do
1378         it 'ステータスコード302 Foundを返す' do
1379           get :edit, :id => @pic.id
1380           response.status.should eq 302
1381         end
1382         it 'サインインページへ遷移する' do
1383           get :edit, :id => @pic.id
1384           response.body.should redirect_to '/users/sign_in'
1385         end
1386       end
1387       context 'js形式' do
1388         it 'ステータスコード401 Unauthorizedを返す' do
1389           get :edit, :id => @pic.id, :format => :js
1390           response.status.should eq 401
1391         end
1392         it '応答メッセージにUnauthorizedを返す' do
1393           get :edit, :id => @pic.id, :format => :js
1394           response.message.should match(/Unauthorized/)
1395         end
1396       end
1397     end
1398   end
1399
1400   describe '更新に於いて' do
1401     before do
1402       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1403       OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
1404       OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
1405       sign_in @user
1406       @attr = {:file => "abc\ndef\nghi"}
1407       @imager = ImagerTest.load("abc\ndef\nghi")
1408     end
1409     context 'つつがなく終わるとき' do
1410       before do
1411         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1412       end
1413       context 'html形式' do
1414         it 'ステータスコード302 Foundを返す' do
1415           put :update, :id => @op.id, :original_picture => @attr
1416           response.status.should eq 302
1417         end
1418         it '更新された原画の表示ページへ遷移する' do
1419           put :update, :id => @op.id, :original_picture => @attr
1420           response.should redirect_to(@pic)
1421         end
1422       end
1423       context 'json形式' do
1424         it 'ステータスコード200 OKを返す' do
1425           put :update, :id => @op.id, :original_picture => @attr, :format => :json
1426           response.should be_success 
1427         end
1428         it 'ページ本体は特に返さない' do
1429           put :update, :id => @op.id, :original_picture => @attr, :format => :json
1430           response.body.should match /./
1431         end
1432       end
1433     end
1434     context '作家権限がないとき' do
1435       before do
1436         sign_out @user
1437       end
1438       context 'html形式' do
1439         it 'ステータスコード302 Foundを返す' do
1440           put :update, :id => @op.id, :original_picture => @attr
1441           response.status.should eq 302
1442         end
1443         it 'サインインページへ遷移する' do
1444           put :update, :id => @op.id, :original_picture => @attr
1445           response.body.should redirect_to '/users/sign_in'
1446         end
1447       end
1448       context 'json形式' do
1449         it 'ステータスコード401 Unauthorizedを返す' do
1450           put :update, :id => @op.id, :original_picture => @attr, :format => :json
1451           response.status.should eq 401
1452         end
1453         it '応答メッセージにUnauthorizedを返す' do
1454           put :update, :id => @op.id, :original_picture => @attr, :format => :json
1455           response.message.should match(/Unauthorized/)
1456         end
1457       end
1458     end
1459     context '作家が絵師でないとき' do
1460       before do
1461         Author.any_instance.stub(:artist?).and_return(false)
1462       end
1463       context 'html形式' do
1464         it 'ステータスコード302 Foundを返す' do
1465           put :update, :id => @op.id, :original_picture => @attr
1466           response.status.should eq 302
1467         end
1468         it '絵師登録ページへ遷移する' do
1469           put :update, :id => @op.id, :original_picture => @attr
1470           response.should redirect_to new_artist_path
1471         end
1472       end
1473       context 'json形式' do
1474         it '例外403 forbiddenを返す' do
1475           lambda{
1476             put :update, :id => @op.id, :original_picture => @attr, :format => :json
1477           }.should raise_error(ActiveRecord::Forbidden)
1478         end
1479       end
1480     end
1481     context '検証、保存に失敗した' do
1482       before do
1483         PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1484         OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
1485       end
1486       context 'html形式' do
1487         it 'ステータスコード200 Okを返す' do
1488           put :update, :id => @op.id, :original_picture => @attr
1489           response.status.should eq 200
1490         end
1491         it '編集ページを描画する' do
1492           put :update, :id => @op.id, :original_picture => @attr
1493           response.should render_template("edit")
1494         end
1495       end
1496       context 'json形式' do
1497         it 'ステータスコード422 unprocessable_entity を返す' do
1498           put :update, :id => @op.id, :original_picture => @attr, :format => :json
1499           response.status.should eq 422
1500         end
1501         it '応答メッセージUnprocessable Entityを返す' do
1502           put :update, :id => @op.id, :original_picture => @attr, :format => :json
1503           response.message.should match(/Unprocessable/)
1504         end
1505       end
1506     end
1507   end
1508
1509   describe '削除に於いて' do
1510     before do
1511       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1512       sign_in @user
1513     end
1514     context '事前チェックしておく' do
1515       before do
1516         OriginalPicture.stub(:edit).with(any_args()).and_return @op
1517         OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1518       end
1519       it '原画モデルに編集取得を問い合わせている' do
1520         OriginalPicture.should_receive(:edit).exactly(1)
1521         delete :destroy, :id => @op.id
1522       end
1523       it 'モデルに削除を依頼する' do
1524         OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
1525         delete :destroy, :id => @op.id
1526       end
1527       it '@original_pictureにアレを取得している' do
1528         delete :destroy, :id => @op.id
1529         assigns(:original_picture).id.should eq(@op.id)
1530       end
1531     end
1532     context 'つつがなく終わるとき' do
1533       before do
1534         OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1535       end
1536       context 'html形式' do
1537         it 'ステータスコード302 Foundを返す' do
1538           delete :destroy, :id => @op.id
1539           response.status.should eq 302
1540         end
1541         it '原画の一覧ページへ遷移する' do
1542           delete :destroy, :id => @op.id
1543           response.should redirect_to(original_pictures_path)
1544         end
1545       end
1546       context 'json形式' do
1547         it 'ステータスコード200 OKを返す' do
1548           delete :destroy, :id => @op.id, :format => :json
1549           response.should be_success 
1550         end
1551         it 'ページ本体は特に返さない' do
1552           delete :destroy, :id => @op.id, :format => :json
1553           response.body.should match /./
1554         end
1555       end
1556     end
1557     context '作家権限がないとき' do
1558       before do
1559         sign_out @user
1560       end
1561       it 'ステータスコード302 Foundを返す' do
1562         delete :destroy, :id => @op.id
1563         response.status.should eq 302
1564       end
1565       context 'html形式' do
1566         it 'サインインページへ遷移する' do
1567           delete :destroy, :id => @op.id
1568           response.body.should redirect_to '/users/sign_in'
1569         end
1570       end
1571       context 'json形式' do
1572         it '応答メッセージにUnauthorizedを返す' do
1573           delete :destroy, :id => @op.id, :format => :json
1574           response.message.should match(/Unauthorized/)
1575         end
1576       end
1577     end
1578     context '削除に失敗したとき' do
1579       before do
1580         OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
1581       end
1582       context 'html形式' do
1583         it 'ステータスコード302 Foundを返す' do
1584           delete :destroy, :id => @op.id
1585           response.status.should eq 302
1586         end
1587         it 'その原画の詳細ページへ遷移する' do
1588           delete :destroy, :id => @op.id
1589           response.should redirect_to(original_picture_path(@op))
1590         end
1591       end
1592       context 'json形式' do
1593         it 'ステータスコード422 unprocessable_entity を返す' do
1594           delete :destroy, :id => @op.id, :format => :json
1595           response.status.should eq 422
1596         end
1597         it '応答メッセージUnprocessable Entityを返す' do
1598           delete :destroy, :id => @op.id, :format => :json
1599           response.message.should match(/Unprocessable/)
1600         end
1601       end
1602     end
1603   end
1604 end
1605
1606 end