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/)
692 context 'ファイルが指定されていないとき' do
695 PettanImager.stub(:load).and_return(nil)
697 it "未保存の原画を保持している" do
699 assigns(:original_picture).should be_a_new(OriginalPicture)
702 it 'ステータスコード200 OKを返す' do
704 response.status.should eq 200
708 response.should render_template("new")
713 @attr.merge!({:format => :json})
715 it 'ステータスコード422 unprocessable_entity を返す' do
717 response.status.should eq 422
719 it '応答メッセージUnprocessable Entityを返す' do
721 response.message.should match(/Unprocessable/)
727 describe '編集フォーム表示に於いて' do
729 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
731 OriginalPicture.stub(:show).and_return(@pic)
733 context 'つつがなく終わるとき' do
734 it 'ステータスコード200 OKを返す' do
735 get :edit, :id => @pic.id
736 response.should be_success
738 it '原画モデルに編集取得を問い合わせている' do
739 OriginalPicture.should_receive(:edit).exactly(1)
740 get :edit, :id => @pic.id
742 it '@original_pictureにデータを用意している' do
743 get :edit, :id => @pic.id
744 assigns(:original_picture).should eq @pic
747 it 'ページテンプレートeditを描画する' do
748 get :edit, :id => @pic.id
749 response.should render_template("edit")
753 it '部分テンプレートedit.jsを描画する' do
754 get :edit, :id => @pic.id, :format => :js
755 response.should render_template("edit")
759 context '作家権限がないとき' do
764 it 'ステータスコード302 Foundを返す' do
765 get :edit, :id => @pic.id
766 response.status.should eq 302
768 it 'サインインページへ遷移する' do
769 get :edit, :id => @pic.id
770 response.body.should redirect_to '/users/sign_in'
774 it 'ステータスコード401 Unauthorizedを返す' do
775 get :edit, :id => @pic.id, :format => :js
776 response.status.should eq 401
778 it '応答メッセージにUnauthorizedを返す' do
779 get :edit, :id => @pic.id, :format => :js
780 response.message.should match(/Unauthorized/)
784 context '作家が絵師でないとき' do
786 Author.any_instance.stub(:artist?).and_return(false)
789 it 'ステータスコード302 Foundを返す' do
790 get :edit, :id => @pic.id
791 response.status.should eq 302
794 get :edit, :id => @pic.id
795 response.should redirect_to new_artist_path
799 it 'ステータスコード200 Okを返す' do
800 get :edit, :id => @pic.id, :format => :js
801 response.status.should eq 200
803 it '絵師登録部分テンプレートartists/new.jsを描画する' do
804 get :edit, :id => @pic.id, :format => :js
805 response.should render_template("artists/new")
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")
817 @attr = {:file => "abc\ndef\nghi"}
818 @imager = ImagerTest.load("abc\ndef\nghi")
820 context '事前チェックしておく' do
822 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
823 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
825 it '画像ライブラリをロードする' do
826 PettanImager.should_receive(:load).with(any_args()).exactly(1)
827 put :update, :id => @op.id, :original_picture => @attr
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
833 it '原画モデルに上書き補充を依頼している' do
834 OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
835 put :update, :id => @op.id, :original_picture => @attr
838 OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
839 put :update, :id => @op.id, :original_picture => @attr
842 context 'つつがなく終わるとき' do
844 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
846 it '@original_pictureにアレを取得している' do
847 put :update, :id => @op.id, :original_picture => @attr
848 assigns(:original_picture).should eq(@op)
851 it 'ステータスコード302 Foundを返す' do
852 put :update, :id => @op.id, :original_picture => @attr
853 response.status.should eq 302
855 it '更新された原画の表示ページへ遷移する' do
856 put :update, :id => @op.id, :original_picture => @attr
857 response.should redirect_to(@pic)
861 it 'ステータスコード200 OKを返す' do
862 put :update, :id => @op.id, :original_picture => @attr, :format => :json
863 response.should be_success
866 put :update, :id => @op.id, :original_picture => @attr, :format => :json
867 response.body.should match /./
871 context '作家権限がないとき' do
876 it 'ステータスコード302 Foundを返す' do
877 put :update, :id => @op.id, :original_picture => @attr
878 response.status.should eq 302
880 it 'サインインページへ遷移する' do
881 put :update, :id => @op.id, :original_picture => @attr
882 response.body.should redirect_to '/users/sign_in'
886 it 'ステータスコード401 Unauthorizedを返す' do
887 put :update, :id => @op.id, :original_picture => @attr, :format => :json
888 response.status.should eq 401
890 it '応答メッセージにUnauthorizedを返す' do
891 put :update, :id => @op.id, :original_picture => @attr, :format => :json
892 response.message.should match(/Unauthorized/)
896 context '作家が絵師でないとき' do
898 Author.any_instance.stub(:artist?).and_return(false)
901 it 'ステータスコード302 Foundを返す' do
902 put :update, :id => @op.id, :original_picture => @attr
903 response.status.should eq 302
906 put :update, :id => @op.id, :original_picture => @attr
907 response.should redirect_to new_artist_path
911 it '例外403 forbiddenを返す' do
913 put :update, :id => @op.id, :original_picture => @attr, :format => :json
914 }.should raise_error(ActiveRecord::Forbidden)
918 context '検証、保存に失敗した' do
920 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
921 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
924 it 'ステータスコード200 Okを返す' do
925 put :update, :id => @op.id, :original_picture => @attr
926 response.status.should eq 200
929 put :update, :id => @op.id, :original_picture => @attr
930 response.should render_template("edit")
934 it 'ステータスコード422 unprocessable_entity を返す' do
935 put :update, :id => @op.id, :original_picture => @attr, :format => :json
936 response.status.should eq 422
938 it '応答メッセージUnprocessable Entityを返す' do
939 put :update, :id => @op.id, :original_picture => @attr, :format => :json
940 response.message.should match(/Unprocessable/)
944 context 'ファイルが指定されていないとき' do
947 PettanImager.stub(:load).and_return(nil)
950 it 'ステータスコード200 Okを返す' do
951 put :update, :id => @op.id, :original_picture => @attr
952 response.status.should eq 200
955 put :update, :id => @op.id, :original_picture => @attr
956 response.should render_template("edit")
960 it 'ステータスコード422 unprocessable_entity を返す' do
961 put :update, :id => @op.id, :original_picture => @attr, :format => :json
962 response.status.should eq 422
964 it '応答メッセージUnprocessable Entityを返す' do
965 put :update, :id => @op.id, :original_picture => @attr, :format => :json
966 response.message.should match(/Unprocessable/)
974 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
977 context '事前チェックしておく' 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)
982 it '原画モデルに編集取得を問い合わせている' do
983 OriginalPicture.should_receive(:edit).exactly(1)
984 delete :destroy, :id => @op.id
987 OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
988 delete :destroy, :id => @op.id
990 it '@original_pictureにアレを取得している' do
991 delete :destroy, :id => @op.id
992 assigns(:original_picture).id.should eq(@op.id)
995 context 'つつがなく終わるとき' do
997 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1000 it 'ステータスコード302 Foundを返す' do
1001 delete :destroy, :id => @op.id
1002 response.status.should eq 302
1004 it '原画の一覧ページへ遷移する' do
1005 delete :destroy, :id => @op.id
1006 response.should redirect_to(original_pictures_path)
1010 it 'ステータスコード200 OKを返す' do
1011 delete :destroy, :id => @op.id, :format => :json
1012 response.should be_success
1014 it 'ページ本体は特に返さない' do
1015 delete :destroy, :id => @op.id, :format => :json
1016 response.body.should match /./
1020 context '作家権限がないとき' do
1024 it 'ステータスコード302 Foundを返す' do
1025 delete :destroy, :id => @op.id
1026 response.status.should eq 302
1029 it 'サインインページへ遷移する' do
1030 delete :destroy, :id => @op.id
1031 response.body.should redirect_to '/users/sign_in'
1035 it '応答メッセージにUnauthorizedを返す' do
1036 delete :destroy, :id => @op.id, :format => :json
1037 response.message.should match(/Unauthorized/)
1041 context '削除に失敗したとき' do
1043 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
1046 it 'ステータスコード302 Foundを返す' do
1047 delete :destroy, :id => @op.id
1048 response.status.should eq 302
1050 it 'その原画の詳細ページへ遷移する' do
1051 delete :destroy, :id => @op.id
1052 response.should redirect_to(original_picture_path(@op))
1056 it 'ステータスコード422 unprocessable_entity を返す' do
1057 delete :destroy, :id => @op.id, :format => :json
1058 response.status.should eq 422
1060 it '応答メッセージUnprocessable Entityを返す' do
1061 delete :destroy, :id => @op.id, :format => :json
1062 response.message.should match(/Unprocessable/)
1069 describe '一覧表示に於いて' do
1071 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1073 OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
1075 context 'つつがなく終わるとき' do
1076 it 'ステータスコード200 OKを返す' do
1078 response.should be_success
1081 it 'indexテンプレートを描画する' do
1083 response.should render_template("index")
1088 get :index, :format => :json
1089 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1093 context '作家権限がないとき' do
1098 it 'ステータスコード302 Foundを返す' do
1100 response.status.should eq 302
1102 it 'サインインページへ遷移する' do
1104 response.should redirect_to '/users/sign_in'
1108 it 'ステータスコード401 Unauthorizedを返す' do
1109 get :index, :format => :json
1110 response.status.should eq 401
1112 it '応答メッセージにUnauthorizedを返す' do
1113 get :index, :format => :json
1114 response.message.should match(/Unauthorized/)
1120 describe '単体表示に於いて' do
1122 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
1124 OriginalPicture.stub(:show).and_return(@pic)
1126 context 'つつがなく終わるとき' do
1127 it 'ステータスコード200 OKを返す' do
1128 get :show, :id => @pic.id
1129 response.should be_success
1132 it 'showテンプレートを描画する' do
1133 get :show, :id => @pic.id
1134 response.should render_template("show")
1139 get :show, :id => @pic.id, :format => :json
1140 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1144 context '作家権限がないとき' do
1149 it 'ステータスコード302 Foundを返す' do
1150 get :show, :id => @pic.id
1151 response.status.should eq 302
1153 it 'サインインページへ遷移する' do
1154 get :show, :id => @pic.id
1155 response.body.should redirect_to '/users/sign_in'
1159 it 'ステータスコード401 Unauthorizedを返す' do
1160 get :show, :id => @pic.id, :format => :json
1161 response.status.should eq 401
1163 it '応答メッセージにUnauthorizedを返す' do
1164 get :show, :id => @pic.id, :format => :json
1165 response.message.should match(/Unauthorized/)
1171 describe '履歴一覧表示に於いて' 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
1177 OriginalPicture.stub(:show).and_return(@op)
1178 OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
1180 context 'つつがなく終わるとき' do
1181 it 'ステータスコード200 OKを返す' do
1182 get :history, :id => @op.id
1183 response.should be_success
1186 it 'historyテンプレートを描画する' do
1187 get :history, :id => @op.id
1188 response.should render_template("history")
1193 get :history, :id => @op.id, :format => :json
1194 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1198 context '作家権限がないとき' do
1203 it 'ステータスコード302 Foundを返す' do
1204 get :history, :id => @op.id
1205 response.status.should eq 302
1207 it 'サインインページへ遷移する' do
1208 get :history, :id => @op.id
1209 response.should redirect_to '/users/sign_in'
1213 it 'ステータスコード401 Unauthorizedを返す' do
1214 get :history, :id => @op.id, :format => :json
1215 response.status.should eq 401
1217 it '応答メッセージにUnauthorizedを返す' do
1218 get :history, :id => @op.id, :format => :json
1219 response.message.should match(/Unauthorized/)
1225 describe '新規作成フォーム表示に於いて' do
1229 context 'つつがなく終わるとき' do
1231 it 'ステータスコード200 OKを返す' do
1233 response.should be_success
1235 it 'ページテンプレートnewを描画する' do
1237 response.should render_template("new")
1241 it 'ステータスコード200 OKを返す' do
1242 get :new, :format => :js
1243 response.should be_success
1245 it '部分テンプレートnew.jsを描画する' do
1246 get :new, :format => :js
1247 response.should render_template("new")
1252 get :new, :format => :json
1253 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1257 context '作家権限がないとき' do
1262 it 'ステータスコード302 Foundを返す' do
1264 response.status.should eq 302
1266 it 'サインインページへ遷移する' do
1268 response.body.should redirect_to '/users/sign_in'
1272 it 'ステータスコード401 Unauthorizedを返す' do
1273 get :new, :format => :js
1274 response.status.should eq 401
1276 it '応答メッセージにUnauthorizedを返す' do
1277 get :new, :format => :js
1278 response.message.should match(/Unauthorized/)
1284 describe '新規作成に於いて' do
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")
1291 context 'つつがなく終わるとき' do
1293 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1296 it 'ステータスコード302 Foundを返す' do
1298 response.status.should eq 302
1300 it '作成された原画の表示ページへ遷移する' do
1302 response.should redirect_to(OriginalPicture.last)
1307 @attr.merge!({:format => :json})
1309 it 'ステータスコード200 OKを返す' do
1311 response.should be_success
1313 it '作成された原画をjsonデータで返す' do
1315 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1319 context '作家権限がないとき' do
1324 it 'ステータスコード302 Foundを返す' do
1326 response.status.should eq 302
1328 it 'サインインページへ遷移する' do
1330 response.body.should redirect_to '/users/sign_in'
1335 @attr.merge!({:format => :json})
1337 it 'ステータスコード401 Unauthorizedを返す' do
1339 response.status.should eq 401
1341 it '応答メッセージにUnauthorizedを返す' do
1343 response.message.should match(/Unauthorized/)
1349 describe '編集フォーム表示に於いて' do
1351 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
1353 OriginalPicture.stub(:show).and_return(@pic)
1355 context 'つつがなく終わるとき' do
1356 it 'ステータスコード200 OKを返す' do
1357 get :edit, :id => @pic.id
1358 response.should be_success
1361 it 'ページテンプレートeditを描画する' do
1362 get :edit, :id => @pic.id
1363 response.should render_template("edit")
1367 it '部分テンプレートedit.jsを描画する' do
1368 get :edit, :id => @pic.id, :format => :js
1369 response.should render_template("edit")
1373 context '作家権限がないとき' do
1378 it 'ステータスコード302 Foundを返す' do
1379 get :edit, :id => @pic.id
1380 response.status.should eq 302
1382 it 'サインインページへ遷移する' do
1383 get :edit, :id => @pic.id
1384 response.body.should redirect_to '/users/sign_in'
1388 it 'ステータスコード401 Unauthorizedを返す' do
1389 get :edit, :id => @pic.id, :format => :js
1390 response.status.should eq 401
1392 it '応答メッセージにUnauthorizedを返す' do
1393 get :edit, :id => @pic.id, :format => :js
1394 response.message.should match(/Unauthorized/)
1400 describe '更新に於いて' 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")
1406 @attr = {:file => "abc\ndef\nghi"}
1407 @imager = ImagerTest.load("abc\ndef\nghi")
1409 context 'つつがなく終わるとき' do
1411 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1414 it 'ステータスコード302 Foundを返す' do
1415 put :update, :id => @op.id, :original_picture => @attr
1416 response.status.should eq 302
1418 it '更新された原画の表示ページへ遷移する' do
1419 put :update, :id => @op.id, :original_picture => @attr
1420 response.should redirect_to(@pic)
1424 it 'ステータスコード200 OKを返す' do
1425 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1426 response.should be_success
1428 it 'ページ本体は特に返さない' do
1429 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1430 response.body.should match /./
1434 context '作家権限がないとき' do
1439 it 'ステータスコード302 Foundを返す' do
1440 put :update, :id => @op.id, :original_picture => @attr
1441 response.status.should eq 302
1443 it 'サインインページへ遷移する' do
1444 put :update, :id => @op.id, :original_picture => @attr
1445 response.body.should redirect_to '/users/sign_in'
1449 it 'ステータスコード401 Unauthorizedを返す' do
1450 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1451 response.status.should eq 401
1453 it '応答メッセージにUnauthorizedを返す' do
1454 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1455 response.message.should match(/Unauthorized/)
1459 context '作家が絵師でないとき' do
1461 Author.any_instance.stub(:artist?).and_return(false)
1464 it 'ステータスコード302 Foundを返す' do
1465 put :update, :id => @op.id, :original_picture => @attr
1466 response.status.should eq 302
1468 it '絵師登録ページへ遷移する' do
1469 put :update, :id => @op.id, :original_picture => @attr
1470 response.should redirect_to new_artist_path
1474 it '例外403 forbiddenを返す' do
1476 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1477 }.should raise_error(ActiveRecord::Forbidden)
1481 context '検証、保存に失敗した' do
1483 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1484 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
1487 it 'ステータスコード200 Okを返す' do
1488 put :update, :id => @op.id, :original_picture => @attr
1489 response.status.should eq 200
1492 put :update, :id => @op.id, :original_picture => @attr
1493 response.should render_template("edit")
1497 it 'ステータスコード422 unprocessable_entity を返す' do
1498 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1499 response.status.should eq 422
1501 it '応答メッセージUnprocessable Entityを返す' do
1502 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1503 response.message.should match(/Unprocessable/)
1509 describe '削除に於いて' do
1511 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1514 context '事前チェックしておく' 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)
1519 it '原画モデルに編集取得を問い合わせている' do
1520 OriginalPicture.should_receive(:edit).exactly(1)
1521 delete :destroy, :id => @op.id
1524 OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
1525 delete :destroy, :id => @op.id
1527 it '@original_pictureにアレを取得している' do
1528 delete :destroy, :id => @op.id
1529 assigns(:original_picture).id.should eq(@op.id)
1532 context 'つつがなく終わるとき' do
1534 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1537 it 'ステータスコード302 Foundを返す' do
1538 delete :destroy, :id => @op.id
1539 response.status.should eq 302
1541 it '原画の一覧ページへ遷移する' do
1542 delete :destroy, :id => @op.id
1543 response.should redirect_to(original_pictures_path)
1547 it 'ステータスコード200 OKを返す' do
1548 delete :destroy, :id => @op.id, :format => :json
1549 response.should be_success
1551 it 'ページ本体は特に返さない' do
1552 delete :destroy, :id => @op.id, :format => :json
1553 response.body.should match /./
1557 context '作家権限がないとき' do
1561 it 'ステータスコード302 Foundを返す' do
1562 delete :destroy, :id => @op.id
1563 response.status.should eq 302
1566 it 'サインインページへ遷移する' do
1567 delete :destroy, :id => @op.id
1568 response.body.should redirect_to '/users/sign_in'
1572 it '応答メッセージにUnauthorizedを返す' do
1573 delete :destroy, :id => @op.id, :format => :json
1574 response.message.should match(/Unauthorized/)
1578 context '削除に失敗したとき' do
1580 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
1583 it 'ステータスコード302 Foundを返す' do
1584 delete :destroy, :id => @op.id
1585 response.status.should eq 302
1587 it 'その原画の詳細ページへ遷移する' do
1588 delete :destroy, :id => @op.id
1589 response.should redirect_to(original_picture_path(@op))
1593 it 'ステータスコード422 unprocessable_entity を返す' do
1594 delete :destroy, :id => @op.id, :format => :json
1595 response.status.should eq 422
1597 it '応答メッセージUnprocessable Entityを返す' do
1598 delete :destroy, :id => @op.id, :format => :json
1599 response.message.should match(/Unprocessable/)