1 # -*- encoding: utf-8 -*-
5 describe OriginalPicturesController 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
16 if MagicNumber['run_mode'] == 1
17 describe '一覧表示に於いて' do
19 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
21 OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
23 context 'パラメータpageについて' do
25 get :index, :page => 5
26 assigns(:page).should eq 5
28 it '省略されると@pageに1値が入る' do
30 assigns(:page).should eq 1
32 it '与えられたpage_sizeがセットされている' do
33 get :index, :page_size => 15
34 assigns(:page_size).should eq 15
36 it '省略されると@page_sizeにデフォルト値が入る' do
38 assigns(:page_size).should eq OriginalPicture.default_page_size
40 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
41 get :index, :page_size => 1500
42 assigns(:page_size).should eq OriginalPicture.max_page_size
44 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
45 get :index, :page_size => 0
46 assigns(:page_size).should eq OriginalPicture.default_page_size
49 context 'つつがなく終わるとき' do
50 it 'ステータスコード200 OKを返す' do
52 response.should be_success
54 it '原画モデルにマイリストを問い合わせている' do
55 OriginalPicture.should_receive(:mylist).exactly(1)
58 it '@original_picturesにリストを取得している' do
60 assigns(:original_pictures).should have_at_least(3).items
63 it 'indexテンプレートを描画する' do
65 response.should render_template("index")
70 get :index, :format => :json
71 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
73 it '原画モデルにjson一覧出力オプションを問い合わせている' do
74 OriginalPicture.should_receive(:list_json_opt).exactly(1)
75 get :index, :format => :json
77 it 'データがリスト構造になっている' do
78 get :index, :format => :json
79 json = JSON.parse response.body
80 json.should have_at_least(3).items
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
92 context '作家権限がないとき' do
97 it 'ステータスコード302 Foundを返す' do
99 response.status.should eq 302
101 it 'サインインページへ遷移する' do
103 response.should redirect_to '/users/sign_in'
107 it 'ステータスコード401 Unauthorizedを返す' do
108 get :index, :format => :json
109 response.status.should eq 401
111 it '応答メッセージにUnauthorizedを返す' do
112 get :index, :format => :json
113 response.message.should match(/Unauthorized/)
117 context '作家が絵師でないとき' do
119 Author.any_instance.stub(:artist?).and_return(false)
122 it 'ステータスコード302 Foundを返す' do
124 response.status.should eq 302
128 response.should redirect_to new_artist_path
132 it '例外403 forbiddenを返す' do
134 get :index, :format => :json
135 }.should raise_error(ActiveRecord::Forbidden)
141 describe '単体表示に於いて' do
143 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
145 OriginalPicture.stub(:show).and_return(@pic)
147 context 'つつがなく終わるとき' do
148 it 'ステータスコード200 OKを返す' do
149 get :show, :id => @pic.id
150 response.should be_success
152 it '原画モデルに単体取得を問い合わせている' do
153 OriginalPicture.should_receive(:show).exactly(1)
156 it '@original_pictureにアレを取得している' do
157 get :show, :id => @pic.id
158 assigns(:original_picture).id.should eq(@pic.id)
161 it 'showテンプレートを描画する' do
162 get :show, :id => @pic.id
163 response.should render_template("show")
168 get :show, :id => @pic.id, :format => :json
169 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
171 it '原画モデルにjson単体出力オプションを問い合わせている' do
172 OriginalPicture.should_receive(:show_json_opt).exactly(1)
173 get :show, :id => @pic.id, :format => :json
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
184 #画像送信では、send_dataにスタブをおいてテストしたいが、ここに噛ませると
185 #renderが働かず、エラーとなってしまう。そこで、原画のファイル取得部分に
186 #スタブをおいてsend_dataがデータを返す体裁でテストする。
189 OriginalPicture.any_instance.stub(:mime_type).and_return('image/png')
190 OriginalPicture.any_instance.stub(:restore).and_return('aaa')
192 it '画像モデルに画像データを問い合わせる' do
193 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
194 get :show, :id => @pic.id, :format => :png
196 it '画像モデルにMimeTypeを問い合わせる' do
197 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
198 get :show, :id => @pic.id, :format => :png
201 get :show, :id => @pic.id, :format => :png
202 response.body.should eq 'aaa'
207 OriginalPicture.any_instance.stub(:mime_type).and_return('image/gif')
208 OriginalPicture.any_instance.stub(:restore).and_return('bbb')
210 it '画像モデルに画像データを問い合わせる' do
211 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
212 get :show, :id => @pic.id, :format => :gif
214 it '画像モデルにMimeTypeを問い合わせる' do
215 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
216 get :show, :id => @pic.id, :format => :gif
219 get :show, :id => @pic.id, :format => :gif
220 response.body.should eq 'bbb'
225 OriginalPicture.any_instance.stub(:mime_type).and_return('image/jpeg')
226 OriginalPicture.any_instance.stub(:restore).and_return('ccc')
228 it '画像モデルに画像データを問い合わせる' do
229 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
230 get :show, :id => @pic.id, :format => :jpeg
232 it '画像モデルにMimeTypeを問い合わせる' do
233 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
234 get :show, :id => @pic.id, :format => :jpeg
237 get :show, :id => @pic.id, :format => :jpeg
238 response.body.should eq 'ccc'
242 context '作家権限がないとき' do
247 it 'ステータスコード302 Foundを返す' do
248 get :show, :id => @pic.id
249 response.status.should eq 302
251 it 'サインインページへ遷移する' do
252 get :show, :id => @pic.id
253 response.body.should redirect_to '/users/sign_in'
257 it 'ステータスコード401 Unauthorizedを返す' do
258 get :show, :id => @pic.id, :format => :json
259 response.status.should eq 401
261 it '応答メッセージにUnauthorizedを返す' do
262 get :show, :id => @pic.id, :format => :json
263 response.message.should match(/Unauthorized/)
267 context '作家が絵師でないとき' do
269 Author.any_instance.stub(:artist?).and_return(false)
272 it 'ステータスコード302 Foundを返す' do
273 get :show, :id => @pic.id
274 response.status.should eq 302
277 get :show, :id => @pic.id
278 response.should redirect_to new_artist_path
282 it '例外403 forbiddenを返す' do
284 get :show, :id => @pic.id, :format => :json
285 }.should raise_error(ActiveRecord::Forbidden)
290 context '対象原画がないとき' do
292 OriginalPicture.unstub(:show)
295 it '例外404 not_foundを返す' do
298 }.should raise_error(ActiveRecord::RecordNotFound)
302 it '例外404 not_foundを返す' do
304 get :show, :id => 0, :format => :json
305 }.should raise_error(ActiveRecord::RecordNotFound)
309 context '他人の原画を見ようとしたとき' do
311 OriginalPicture.stub(:show).and_return(@pic)
312 OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(false)
315 it '例外403 forbiddenを返す' do
317 get :show, :id => @pic.id
318 }.should raise_error(ActiveRecord::Forbidden)
322 it '例外403 forbiddenを返す' do
324 get :show, :id => @pic.id, :format => :json
325 }.should raise_error(ActiveRecord::Forbidden)
332 describe '履歴一覧表示に於いて' 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
338 OriginalPicture.stub(:show).and_return(@op)
339 OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
341 context 'つつがなく終わるとき' do
342 it 'ステータスコード200 OKを返す' do
343 get :history, :id => @op.id
344 response.should be_success
346 it '原画モデルに単体取得を問い合わせている' do
347 OriginalPicture.should_receive(:show).exactly(1)
348 get :history, :id => @op.id
350 it '自身に履歴一覧を問い合わせている' do
351 OriginalPicture.any_instance.should_receive(:history).exactly(1)
352 get :history, :id => @op.id
354 it '@historyにリストを取得している' do
355 get :history, :id => @op.id
356 assigns(:history).should have_at_least(3).items
359 it 'historyテンプレートを描画する' do
360 get :history, :id => @op.id
361 response.should render_template("history")
366 get :history, :id => @op.id, :format => :json
367 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
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
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
381 context '作家権限がないとき' do
386 it 'ステータスコード302 Foundを返す' do
387 get :history, :id => @op.id
388 response.status.should eq 302
390 it 'サインインページへ遷移する' do
391 get :history, :id => @op.id
392 response.should redirect_to '/users/sign_in'
396 it 'ステータスコード401 Unauthorizedを返す' do
397 get :history, :id => @op.id, :format => :json
398 response.status.should eq 401
400 it '応答メッセージにUnauthorizedを返す' do
401 get :history, :id => @op.id, :format => :json
402 response.message.should match(/Unauthorized/)
406 context '作家が絵師でないとき' do
408 Author.any_instance.stub(:artist?).and_return(false)
411 it 'ステータスコード302 Foundを返す' do
412 get :history, :id => @op.id
413 response.status.should eq 302
416 get :history, :id => @op.id
417 response.should redirect_to new_artist_path
421 it '例外403 forbiddenを返す' do
423 get :history, :id => @op.id, :format => :json
424 }.should raise_error(ActiveRecord::Forbidden)
430 describe '新規作成フォーム表示に於いて' do
434 context 'つつがなく終わるとき' do
435 it '@original_pictureに新規データを用意している' do
437 assigns(:original_picture).should be_a_new(OriginalPicture)
439 it '原画モデルにデフォルト値補充を依頼している' do
440 OriginalPicture.any_instance.should_receive(:supply_default).exactly(1)
444 it 'ステータスコード200 OKを返す' do
446 response.should be_success
448 it 'ページテンプレートnewを描画する' do
450 response.should render_template("new")
454 it 'ステータスコード200 OKを返す' do
455 get :new, :format => :js
456 response.should be_success
458 it '部分テンプレートnew.jsを描画する' do
459 get :new, :format => :js
460 response.should render_template("new")
465 get :new, :format => :json
466 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
468 it '原画モデルにjson単体出力オプションを問い合わせている' do
469 OriginalPicture.should_receive(:show_json_opt).exactly(1)
470 get :new, :format => :json
474 context '作家権限がないとき' do
479 it 'ステータスコード302 Foundを返す' do
481 response.status.should eq 302
483 it 'サインインページへ遷移する' do
485 response.body.should redirect_to '/users/sign_in'
489 it 'ステータスコード401 Unauthorizedを返す' do
490 get :new, :format => :js
491 response.status.should eq 401
493 it '応答メッセージにUnauthorizedを返す' do
494 get :new, :format => :js
495 response.message.should match(/Unauthorized/)
499 context '作家が絵師でないとき' do
501 Author.any_instance.stub(:artist?).and_return(false)
504 it 'ステータスコード302 Foundを返す' do
506 response.status.should eq 302
510 response.should redirect_to new_artist_path
514 it 'ステータスコード200 Okを返す' do
515 get :new, :format => :js
516 response.status.should eq 200
518 it '絵師登録部分テンプレートartists/new.jsを描画する' do
519 get :new, :format => :js
520 response.should render_template("artists/new")
524 it '例外403 forbiddenを返す' do
526 get :new, :format => :json
527 }.should raise_error(ActiveRecord::Forbidden)
533 describe '新規作成に於いて' do
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")
540 context '事前チェックしておく' do
542 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
543 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
545 it '画像ライブラリをロードする' do
546 PettanImager.should_receive(:load).with(any_args()).exactly(1)
549 it '原画モデルにデフォルト値補充を依頼している' do
550 OriginalPicture.any_instance.should_receive(:supply_default).with(any_args()).exactly(1)
553 it '原画モデルに上書き補充を依頼している' do
554 OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
558 OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
562 context 'つつがなく終わるとき' do
564 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
566 it "@original_pictureに作成された原画を保持している" do
568 assigns(:original_picture).should be_a(OriginalPicture)
571 it 'ステータスコード302 Foundを返す' do
573 response.status.should eq 302
575 it '作成された原画の表示ページへ遷移する' do
577 response.should redirect_to(OriginalPicture.last)
582 @attr.merge!({:format => :json})
584 it 'ステータスコード200 OKを返す' do
586 response.should be_success
588 it '作成された原画をjsonデータで返す' do
590 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
592 it '原画モデルにjson単体出力オプションを問い合わせている' do
593 OriginalPicture.should_receive(:show_json_opt).exactly(1)
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
606 context '作家権限がないとき' do
611 it 'ステータスコード302 Foundを返す' do
613 response.status.should eq 302
615 it 'サインインページへ遷移する' do
617 response.body.should redirect_to '/users/sign_in'
622 @attr.merge!({:format => :json})
624 it 'ステータスコード401 Unauthorizedを返す' do
626 response.status.should eq 401
628 it '応答メッセージにUnauthorizedを返す' do
630 response.message.should match(/Unauthorized/)
634 context '作家が絵師でないとき' do
636 Author.any_instance.stub(:artist?).and_return(false)
639 it 'ステータスコード302 Foundを返す' do
641 response.status.should eq 302
645 response.should redirect_to new_artist_path
650 @attr.merge!({:format => :json})
652 it '例外403 forbiddenを返す' do
655 }.should raise_error(ActiveRecord::Forbidden)
659 context '検証、保存に失敗した' do
661 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
662 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
664 it "未保存の原画を保持している" do
666 assigns(:original_picture).should be_a_new(OriginalPicture)
669 it 'ステータスコード200 OKを返す' do
671 response.status.should eq 200
675 response.should render_template("new")
680 @attr.merge!({:format => :json})
682 it 'ステータスコード422 unprocessable_entity を返す' do
684 response.status.should eq 422
686 it '応答メッセージUnprocessable Entityを返す' do
688 response.message.should match(/Unprocessable/)
694 describe '編集フォーム表示に於いて' do
696 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
698 OriginalPicture.stub(:show).and_return(@pic)
700 context 'つつがなく終わるとき' do
701 it 'ステータスコード200 OKを返す' do
702 get :edit, :id => @pic.id
703 response.should be_success
705 it '原画モデルに編集取得を問い合わせている' do
706 OriginalPicture.should_receive(:edit).exactly(1)
707 get :edit, :id => @pic.id
709 it '@original_pictureにデータを用意している' do
710 get :edit, :id => @pic.id
711 assigns(:original_picture).should eq @pic
714 it 'ページテンプレートeditを描画する' do
715 get :edit, :id => @pic.id
716 response.should render_template("edit")
720 it '部分テンプレートedit.jsを描画する' do
721 get :edit, :id => @pic.id, :format => :js
722 response.should render_template("edit")
726 context '作家権限がないとき' do
731 it 'ステータスコード302 Foundを返す' do
732 get :edit, :id => @pic.id
733 response.status.should eq 302
735 it 'サインインページへ遷移する' do
736 get :edit, :id => @pic.id
737 response.body.should redirect_to '/users/sign_in'
741 it 'ステータスコード401 Unauthorizedを返す' do
742 get :edit, :id => @pic.id, :format => :js
743 response.status.should eq 401
745 it '応答メッセージにUnauthorizedを返す' do
746 get :edit, :id => @pic.id, :format => :js
747 response.message.should match(/Unauthorized/)
751 context '作家が絵師でないとき' do
753 Author.any_instance.stub(:artist?).and_return(false)
756 it 'ステータスコード302 Foundを返す' do
757 get :edit, :id => @pic.id
758 response.status.should eq 302
761 get :edit, :id => @pic.id
762 response.should redirect_to new_artist_path
766 it 'ステータスコード200 Okを返す' do
767 get :edit, :id => @pic.id, :format => :js
768 response.status.should eq 200
770 it '絵師登録部分テンプレートartists/new.jsを描画する' do
771 get :edit, :id => @pic.id, :format => :js
772 response.should render_template("artists/new")
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")
784 @attr = {:file => "abc\ndef\nghi"}
785 @imager = ImagerTest.load("abc\ndef\nghi")
787 context '事前チェックしておく' do
789 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
790 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
792 it '画像ライブラリをロードする' do
793 PettanImager.should_receive(:load).with(any_args()).exactly(1)
794 put :update, :id => @op.id, :original_picture => @attr
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
800 it '原画モデルに上書き補充を依頼している' do
801 OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
802 put :update, :id => @op.id, :original_picture => @attr
805 OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
806 put :update, :id => @op.id, :original_picture => @attr
809 context 'つつがなく終わるとき' do
811 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
813 it '@original_pictureにアレを取得している' do
814 put :update, :id => @op.id, :original_picture => @attr
815 assigns(:original_picture).should eq(@op)
818 it 'ステータスコード302 Foundを返す' do
819 put :update, :id => @op.id, :original_picture => @attr
820 response.status.should eq 302
822 it '更新された原画の表示ページへ遷移する' do
823 put :update, :id => @op.id, :original_picture => @attr
824 response.should redirect_to(@pic)
828 it 'ステータスコード200 OKを返す' do
829 put :update, :id => @op.id, :original_picture => @attr, :format => :json
830 response.should be_success
833 put :update, :id => @op.id, :original_picture => @attr, :format => :json
834 response.body.should match /./
838 context '作家権限がないとき' do
843 it 'ステータスコード302 Foundを返す' do
844 put :update, :id => @op.id, :original_picture => @attr
845 response.status.should eq 302
847 it 'サインインページへ遷移する' do
848 put :update, :id => @op.id, :original_picture => @attr
849 response.body.should redirect_to '/users/sign_in'
853 it 'ステータスコード401 Unauthorizedを返す' do
854 put :update, :id => @op.id, :original_picture => @attr, :format => :json
855 response.status.should eq 401
857 it '応答メッセージにUnauthorizedを返す' do
858 put :update, :id => @op.id, :original_picture => @attr, :format => :json
859 response.message.should match(/Unauthorized/)
863 context '作家が絵師でないとき' do
865 Author.any_instance.stub(:artist?).and_return(false)
868 it 'ステータスコード302 Foundを返す' do
869 put :update, :id => @op.id, :original_picture => @attr
870 response.status.should eq 302
873 put :update, :id => @op.id, :original_picture => @attr
874 response.should redirect_to new_artist_path
878 it '例外403 forbiddenを返す' do
880 put :update, :id => @op.id, :original_picture => @attr, :format => :json
881 }.should raise_error(ActiveRecord::Forbidden)
885 context '検証、保存に失敗した' do
887 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
888 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
891 it 'ステータスコード200 Okを返す' do
892 put :update, :id => @op.id, :original_picture => @attr
893 response.status.should eq 200
896 put :update, :id => @op.id, :original_picture => @attr
897 response.should render_template("edit")
901 it 'ステータスコード422 unprocessable_entity を返す' do
902 put :update, :id => @op.id, :original_picture => @attr, :format => :json
903 response.status.should eq 422
905 it '応答メッセージUnprocessable Entityを返す' do
906 put :update, :id => @op.id, :original_picture => @attr, :format => :json
907 response.message.should match(/Unprocessable/)
915 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
918 context '事前チェックしておく' 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)
923 it '原画モデルに編集取得を問い合わせている' do
924 OriginalPicture.should_receive(:edit).exactly(1)
925 delete :destroy, :id => @op.id
928 OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
929 delete :destroy, :id => @op.id
931 it '@original_pictureにアレを取得している' do
932 delete :destroy, :id => @op.id
933 assigns(:original_picture).id.should eq(@op.id)
936 context 'つつがなく終わるとき' do
938 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
941 it 'ステータスコード302 Foundを返す' do
942 delete :destroy, :id => @op.id
943 response.status.should eq 302
945 it '原画の一覧ページへ遷移する' do
946 delete :destroy, :id => @op.id
947 response.should redirect_to(original_pictures_path)
951 it 'ステータスコード200 OKを返す' do
952 delete :destroy, :id => @op.id, :format => :json
953 response.should be_success
956 delete :destroy, :id => @op.id, :format => :json
957 response.body.should match /./
961 context '作家権限がないとき' do
965 it 'ステータスコード302 Foundを返す' do
966 delete :destroy, :id => @op.id
967 response.status.should eq 302
970 it 'サインインページへ遷移する' do
971 delete :destroy, :id => @op.id
972 response.body.should redirect_to '/users/sign_in'
976 it '応答メッセージにUnauthorizedを返す' do
977 delete :destroy, :id => @op.id, :format => :json
978 response.message.should match(/Unauthorized/)
982 context '削除に失敗したとき' do
984 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
987 it 'ステータスコード302 Foundを返す' do
988 delete :destroy, :id => @op.id
989 response.status.should eq 302
991 it 'その原画の詳細ページへ遷移する' do
992 delete :destroy, :id => @op.id
993 response.should redirect_to(original_picture_path(@op))
997 it 'ステータスコード422 unprocessable_entity を返す' do
998 delete :destroy, :id => @op.id, :format => :json
999 response.status.should eq 422
1001 it '応答メッセージUnprocessable Entityを返す' do
1002 delete :destroy, :id => @op.id, :format => :json
1003 response.message.should match(/Unprocessable/)
1010 describe '一覧表示に於いて' do
1012 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1014 OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
1016 context 'つつがなく終わるとき' do
1017 it 'ステータスコード200 OKを返す' do
1019 response.should be_success
1022 it 'indexテンプレートを描画する' do
1024 response.should render_template("index")
1029 get :index, :format => :json
1030 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1034 context '作家権限がないとき' do
1039 it 'ステータスコード302 Foundを返す' do
1041 response.status.should eq 302
1043 it 'サインインページへ遷移する' do
1045 response.should redirect_to '/users/sign_in'
1049 it 'ステータスコード401 Unauthorizedを返す' do
1050 get :index, :format => :json
1051 response.status.should eq 401
1053 it '応答メッセージにUnauthorizedを返す' do
1054 get :index, :format => :json
1055 response.message.should match(/Unauthorized/)
1061 describe '単体表示に於いて' do
1063 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
1065 OriginalPicture.stub(:show).and_return(@pic)
1067 context 'つつがなく終わるとき' do
1068 it 'ステータスコード200 OKを返す' do
1069 get :show, :id => @pic.id
1070 response.should be_success
1073 it 'showテンプレートを描画する' do
1074 get :show, :id => @pic.id
1075 response.should render_template("show")
1080 get :show, :id => @pic.id, :format => :json
1081 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1085 context '作家権限がないとき' do
1090 it 'ステータスコード302 Foundを返す' do
1091 get :show, :id => @pic.id
1092 response.status.should eq 302
1094 it 'サインインページへ遷移する' do
1095 get :show, :id => @pic.id
1096 response.body.should redirect_to '/users/sign_in'
1100 it 'ステータスコード401 Unauthorizedを返す' do
1101 get :show, :id => @pic.id, :format => :json
1102 response.status.should eq 401
1104 it '応答メッセージにUnauthorizedを返す' do
1105 get :show, :id => @pic.id, :format => :json
1106 response.message.should match(/Unauthorized/)
1112 describe '履歴一覧表示に於いて' 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
1118 OriginalPicture.stub(:show).and_return(@op)
1119 OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
1121 context 'つつがなく終わるとき' do
1122 it 'ステータスコード200 OKを返す' do
1123 get :history, :id => @op.id
1124 response.should be_success
1127 it 'historyテンプレートを描画する' do
1128 get :history, :id => @op.id
1129 response.should render_template("history")
1134 get :history, :id => @op.id, :format => :json
1135 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1139 context '作家権限がないとき' do
1144 it 'ステータスコード302 Foundを返す' do
1145 get :history, :id => @op.id
1146 response.status.should eq 302
1148 it 'サインインページへ遷移する' do
1149 get :history, :id => @op.id
1150 response.should redirect_to '/users/sign_in'
1154 it 'ステータスコード401 Unauthorizedを返す' do
1155 get :history, :id => @op.id, :format => :json
1156 response.status.should eq 401
1158 it '応答メッセージにUnauthorizedを返す' do
1159 get :history, :id => @op.id, :format => :json
1160 response.message.should match(/Unauthorized/)
1166 describe '新規作成フォーム表示に於いて' do
1170 context 'つつがなく終わるとき' do
1172 it 'ステータスコード200 OKを返す' do
1174 response.should be_success
1176 it 'ページテンプレートnewを描画する' do
1178 response.should render_template("new")
1182 it 'ステータスコード200 OKを返す' do
1183 get :new, :format => :js
1184 response.should be_success
1186 it '部分テンプレートnew.jsを描画する' do
1187 get :new, :format => :js
1188 response.should render_template("new")
1193 get :new, :format => :json
1194 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1198 context '作家権限がないとき' do
1203 it 'ステータスコード302 Foundを返す' do
1205 response.status.should eq 302
1207 it 'サインインページへ遷移する' do
1209 response.body.should redirect_to '/users/sign_in'
1213 it 'ステータスコード401 Unauthorizedを返す' do
1214 get :new, :format => :js
1215 response.status.should eq 401
1217 it '応答メッセージにUnauthorizedを返す' do
1218 get :new, :format => :js
1219 response.message.should match(/Unauthorized/)
1225 describe '新規作成に於いて' do
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")
1232 context 'つつがなく終わるとき' do
1234 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1237 it 'ステータスコード302 Foundを返す' do
1239 response.status.should eq 302
1241 it '作成された原画の表示ページへ遷移する' do
1243 response.should redirect_to(OriginalPicture.last)
1248 @attr.merge!({:format => :json})
1250 it 'ステータスコード200 OKを返す' do
1252 response.should be_success
1254 it '作成された原画をjsonデータで返す' do
1256 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1260 context '作家権限がないとき' do
1265 it 'ステータスコード302 Foundを返す' do
1267 response.status.should eq 302
1269 it 'サインインページへ遷移する' do
1271 response.body.should redirect_to '/users/sign_in'
1276 @attr.merge!({:format => :json})
1278 it 'ステータスコード401 Unauthorizedを返す' do
1280 response.status.should eq 401
1282 it '応答メッセージにUnauthorizedを返す' do
1284 response.message.should match(/Unauthorized/)
1290 describe '編集フォーム表示に於いて' do
1292 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
1294 OriginalPicture.stub(:show).and_return(@pic)
1296 context 'つつがなく終わるとき' do
1297 it 'ステータスコード200 OKを返す' do
1298 get :edit, :id => @pic.id
1299 response.should be_success
1302 it 'ページテンプレートeditを描画する' do
1303 get :edit, :id => @pic.id
1304 response.should render_template("edit")
1308 it '部分テンプレートedit.jsを描画する' do
1309 get :edit, :id => @pic.id, :format => :js
1310 response.should render_template("edit")
1314 context '作家権限がないとき' do
1319 it 'ステータスコード302 Foundを返す' do
1320 get :edit, :id => @pic.id
1321 response.status.should eq 302
1323 it 'サインインページへ遷移する' do
1324 get :edit, :id => @pic.id
1325 response.body.should redirect_to '/users/sign_in'
1329 it 'ステータスコード401 Unauthorizedを返す' do
1330 get :edit, :id => @pic.id, :format => :js
1331 response.status.should eq 401
1333 it '応答メッセージにUnauthorizedを返す' do
1334 get :edit, :id => @pic.id, :format => :js
1335 response.message.should match(/Unauthorized/)
1341 describe '更新に於いて' 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")
1347 @attr = {:file => "abc\ndef\nghi"}
1348 @imager = ImagerTest.load("abc\ndef\nghi")
1350 context 'つつがなく終わるとき' do
1352 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1355 it 'ステータスコード302 Foundを返す' do
1356 put :update, :id => @op.id, :original_picture => @attr
1357 response.status.should eq 302
1359 it '更新された原画の表示ページへ遷移する' do
1360 put :update, :id => @op.id, :original_picture => @attr
1361 response.should redirect_to(@pic)
1365 it 'ステータスコード200 OKを返す' do
1366 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1367 response.should be_success
1369 it 'ページ本体は特に返さない' do
1370 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1371 response.body.should match /./
1375 context '作家権限がないとき' do
1380 it 'ステータスコード302 Foundを返す' do
1381 put :update, :id => @op.id, :original_picture => @attr
1382 response.status.should eq 302
1384 it 'サインインページへ遷移する' do
1385 put :update, :id => @op.id, :original_picture => @attr
1386 response.body.should redirect_to '/users/sign_in'
1390 it 'ステータスコード401 Unauthorizedを返す' do
1391 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1392 response.status.should eq 401
1394 it '応答メッセージにUnauthorizedを返す' do
1395 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1396 response.message.should match(/Unauthorized/)
1400 context '作家が絵師でないとき' do
1402 Author.any_instance.stub(:artist?).and_return(false)
1405 it 'ステータスコード302 Foundを返す' do
1406 put :update, :id => @op.id, :original_picture => @attr
1407 response.status.should eq 302
1409 it '絵師登録ページへ遷移する' do
1410 put :update, :id => @op.id, :original_picture => @attr
1411 response.should redirect_to new_artist_path
1415 it '例外403 forbiddenを返す' do
1417 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1418 }.should raise_error(ActiveRecord::Forbidden)
1422 context '検証、保存に失敗した' do
1424 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1425 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
1428 it 'ステータスコード200 Okを返す' do
1429 put :update, :id => @op.id, :original_picture => @attr
1430 response.status.should eq 200
1433 put :update, :id => @op.id, :original_picture => @attr
1434 response.should render_template("edit")
1438 it 'ステータスコード422 unprocessable_entity を返す' do
1439 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1440 response.status.should eq 422
1442 it '応答メッセージUnprocessable Entityを返す' do
1443 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1444 response.message.should match(/Unprocessable/)
1450 describe '削除に於いて' do
1452 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1455 context '事前チェックしておく' 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)
1460 it '原画モデルに編集取得を問い合わせている' do
1461 OriginalPicture.should_receive(:edit).exactly(1)
1462 delete :destroy, :id => @op.id
1465 OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
1466 delete :destroy, :id => @op.id
1468 it '@original_pictureにアレを取得している' do
1469 delete :destroy, :id => @op.id
1470 assigns(:original_picture).id.should eq(@op.id)
1473 context 'つつがなく終わるとき' do
1475 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1478 it 'ステータスコード302 Foundを返す' do
1479 delete :destroy, :id => @op.id
1480 response.status.should eq 302
1482 it '原画の一覧ページへ遷移する' do
1483 delete :destroy, :id => @op.id
1484 response.should redirect_to(original_pictures_path)
1488 it 'ステータスコード200 OKを返す' do
1489 delete :destroy, :id => @op.id, :format => :json
1490 response.should be_success
1492 it 'ページ本体は特に返さない' do
1493 delete :destroy, :id => @op.id, :format => :json
1494 response.body.should match /./
1498 context '作家権限がないとき' do
1502 it 'ステータスコード302 Foundを返す' do
1503 delete :destroy, :id => @op.id
1504 response.status.should eq 302
1507 it 'サインインページへ遷移する' do
1508 delete :destroy, :id => @op.id
1509 response.body.should redirect_to '/users/sign_in'
1513 it '応答メッセージにUnauthorizedを返す' do
1514 delete :destroy, :id => @op.id, :format => :json
1515 response.message.should match(/Unauthorized/)
1519 context '削除に失敗したとき' do
1521 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
1524 it 'ステータスコード302 Foundを返す' do
1525 delete :destroy, :id => @op.id
1526 response.status.should eq 302
1528 it 'その原画の詳細ページへ遷移する' do
1529 delete :destroy, :id => @op.id
1530 response.should redirect_to(original_picture_path(@op))
1534 it 'ステータスコード422 unprocessable_entity を返す' do
1535 delete :destroy, :id => @op.id, :format => :json
1536 response.status.should eq 422
1538 it '応答メッセージUnprocessable Entityを返す' do
1539 delete :destroy, :id => @op.id, :format => :json
1540 response.message.should match(/Unprocessable/)