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 '@paginateにページ制御を取得している' do
65 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
67 it 'indexテンプレートを描画する' do
69 response.should render_template("index")
74 get :index, :format => :json
75 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
77 it '原画モデルにjson一覧出力オプションを問い合わせている' do
78 OriginalPicture.should_receive(:list_json_opt).exactly(1)
79 get :index, :format => :json
81 it 'データがリスト構造になっている' do
82 get :index, :format => :json
83 json = JSON.parse response.body
84 json.should have_at_least(3).items
86 it 'リストの先頭くらいは原画っぽいものであって欲しい' do
87 get :index, :format => :json
88 json = JSON.parse response.body
89 json.first.has_key?("ext").should be_true
90 json.first.has_key?("md5").should be_true
91 json.first.has_key?("artist_id").should be_true
92 json.first.has_key?("width").should be_true
96 context 'ユーザ権限がないとき' do
101 it 'ステータスコード302 Foundを返す' do
103 response.status.should eq 302
105 it 'サインインページへ遷移する' do
107 response.should redirect_to '/users/sign_in'
111 it 'ステータスコード401 Unauthorizedを返す' do
112 get :index, :format => :json
113 response.status.should eq 401
115 it '応答メッセージにUnauthorizedを返す' do
116 get :index, :format => :json
117 response.message.should match(/Unauthorized/)
121 context 'ユーザ権限はないが管理者権限があるとき' do
127 it 'ステータスコード302 Foundを返す' do
129 response.status.should eq 302
131 it 'サインインページへ遷移する' do
133 response.should redirect_to '/users/sign_in'
137 context 'ユーザが絵師でないとき' do
142 it 'ステータスコード302 Foundを返す' do
144 response.status.should eq 302
148 response.should redirect_to new_artist_path
152 it '例外403 forbiddenを返す' do
154 get :index, :format => :json
155 }.should raise_error(ActiveRecord::Forbidden)
161 describe '単体表示に於いて' do
163 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
165 OriginalPicture.stub(:show).and_return(@pic)
167 context 'つつがなく終わるとき' do
168 it 'ステータスコード200 OKを返す' do
169 get :show, :id => @pic.id
170 response.should be_success
172 it '原画モデルに単体取得を問い合わせている' do
173 OriginalPicture.should_receive(:show).exactly(1)
176 it '@original_pictureにアレを取得している' do
177 get :show, :id => @pic.id
178 assigns(:original_picture).id.should eq(@pic.id)
181 it 'showテンプレートを描画する' do
182 get :show, :id => @pic.id
183 response.should render_template("show")
188 get :show, :id => @pic.id, :format => :json
189 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
191 it '原画モデルにjson単体出力オプションを問い合わせている' do
192 OriginalPicture.should_receive(:show_json_opt).exactly(1)
193 get :show, :id => @pic.id, :format => :json
196 get :show, :id => @pic.id, :format => :json
197 json = JSON.parse response.body
198 json["ext"].should match(/png/)
199 json["md5"].should be_true
200 json["artist_id"].should be_true
201 json["width"].should be_true
204 #画像送信では、send_dataにスタブをおいてテストしたいが、ここに噛ませると
205 #renderが働かず、エラーとなってしまう。そこで、原画のファイル取得部分に
206 #スタブをおいてsend_dataがデータを返す体裁でテストする。
209 OriginalPicture.any_instance.stub(:mime_type).and_return('image/png')
210 OriginalPicture.any_instance.stub(:restore).and_return('aaa')
212 it '画像モデルに画像データを問い合わせる' do
213 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
214 get :show, :id => @pic.id, :format => :png
216 it '画像モデルにMimeTypeを問い合わせる' do
217 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
218 get :show, :id => @pic.id, :format => :png
221 get :show, :id => @pic.id, :format => :png
222 response.body.should eq 'aaa'
227 OriginalPicture.any_instance.stub(:mime_type).and_return('image/gif')
228 OriginalPicture.any_instance.stub(:restore).and_return('bbb')
230 it '画像モデルに画像データを問い合わせる' do
231 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
232 get :show, :id => @pic.id, :format => :gif
234 it '画像モデルにMimeTypeを問い合わせる' do
235 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
236 get :show, :id => @pic.id, :format => :gif
239 get :show, :id => @pic.id, :format => :gif
240 response.body.should eq 'bbb'
245 OriginalPicture.any_instance.stub(:mime_type).and_return('image/jpeg')
246 OriginalPicture.any_instance.stub(:restore).and_return('ccc')
248 it '画像モデルに画像データを問い合わせる' do
249 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
250 get :show, :id => @pic.id, :format => :jpeg
252 it '画像モデルにMimeTypeを問い合わせる' do
253 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
254 get :show, :id => @pic.id, :format => :jpeg
257 get :show, :id => @pic.id, :format => :jpeg
258 response.body.should eq 'ccc'
262 context 'ユーザ権限がないとき' do
267 it 'ステータスコード302 Foundを返す' do
268 get :show, :id => @pic.id
269 response.status.should eq 302
271 it 'サインインページへ遷移する' do
272 get :show, :id => @pic.id
273 response.body.should redirect_to '/users/sign_in'
277 it 'ステータスコード401 Unauthorizedを返す' do
278 get :show, :id => @pic.id, :format => :json
279 response.status.should eq 401
281 it '応答メッセージにUnauthorizedを返す' do
282 get :show, :id => @pic.id, :format => :json
283 response.message.should match(/Unauthorized/)
287 context 'ユーザ権限はないが管理者権限があるとき' do
292 it 'ステータスコード200 OKを返す' do
293 get :show, :id => @pic.id
294 response.should be_success
297 context 'ユーザが絵師でないとき' do
301 it 'ステータスコード200 OKを返す' do
302 get :show, :id => @pic.id
303 response.should be_success
307 context '対象原画がないとき' do
309 OriginalPicture.unstub(:show)
312 it '例外404 not_foundを返す' do
315 }.should raise_error(ActiveRecord::RecordNotFound)
319 it '例外404 not_foundを返す' do
321 get :show, :id => 0, :format => :json
322 }.should raise_error(ActiveRecord::RecordNotFound)
326 context '他人の原画を見ようとしたとき' do
328 OriginalPicture.stub(:show).and_return(@pic)
329 OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(false)
332 it '例外403 forbiddenを返す' do
334 get :show, :id => @pic.id
335 }.should raise_error(ActiveRecord::Forbidden)
339 it '例外403 forbiddenを返す' do
341 get :show, :id => @pic.id, :format => :json
342 }.should raise_error(ActiveRecord::Forbidden)
349 describe '履歴一覧表示に於いて' do
351 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
352 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
353 :original_picture_id => @op.id
355 OriginalPicture.stub(:show).and_return(@op)
356 OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
358 context 'つつがなく終わるとき' do
359 it 'ステータスコード200 OKを返す' do
360 get :history, :id => @op.id
361 response.should be_success
363 it '原画モデルに単体取得を問い合わせている' do
364 OriginalPicture.should_receive(:show).exactly(1)
365 get :history, :id => @op.id
367 it '自身に履歴一覧を問い合わせている' do
368 OriginalPicture.any_instance.should_receive(:history).exactly(1)
369 get :history, :id => @op.id
371 it '@historyにリストを取得している' do
372 get :history, :id => @op.id
373 assigns(:history).should have_at_least(3).items
376 it 'historyテンプレートを描画する' do
377 get :history, :id => @op.id
378 response.should render_template("history")
383 get :history, :id => @op.id, :format => :json
384 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
386 it 'データがリスト構造になっている' do
387 get :history, :id => @op.id, :format => :json
388 json = JSON.parse response.body
389 json.should have_at_least(3).items
391 it 'リストの先頭くらいは原画っぽいものであって欲しい' do
392 get :history, :id => @op.id, :format => :json
393 json = JSON.parse response.body
394 json.first.has_key?("ext").should be_true
398 context 'ユーザ権限がないとき' do
403 it 'ステータスコード302 Foundを返す' do
404 get :history, :id => @op.id
405 response.status.should eq 302
407 it 'サインインページへ遷移する' do
408 get :history, :id => @op.id
409 response.should redirect_to '/users/sign_in'
413 it 'ステータスコード401 Unauthorizedを返す' do
414 get :history, :id => @op.id, :format => :json
415 response.status.should eq 401
417 it '応答メッセージにUnauthorizedを返す' do
418 get :history, :id => @op.id, :format => :json
419 response.message.should match(/Unauthorized/)
423 context 'ユーザ権限はないが管理者権限があるとき' do
428 it 'ステータスコード200 OKを返す' do
429 get :history, :id => @op.id
430 response.should be_success
433 context 'ユーザが絵師でないとき' do
437 it 'ステータスコード200 OKを返す' do
438 get :history, :id => @op.id
439 response.should be_success
444 describe '新規作成フォーム表示に於いて' do
448 context 'つつがなく終わるとき' do
449 it '@original_pictureに新規データを用意している' do
451 assigns(:original_picture).should be_a_new(OriginalPicture)
453 it '原画モデルにデフォルト値補充を依頼している' do
454 OriginalPicture.any_instance.should_receive(:supply_default).exactly(1)
458 it 'ステータスコード200 OKを返す' do
460 response.should be_success
462 it 'ページテンプレートnewを描画する' do
464 response.should render_template("new")
468 it 'ステータスコード200 OKを返す' do
469 get :new, :format => :js
470 response.should be_success
472 it '部分テンプレートnew.jsを描画する' do
473 get :new, :format => :js
474 response.should render_template("new")
479 get :new, :format => :json
480 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
482 it '原画モデルにjson単体出力オプションを問い合わせている' do
483 OriginalPicture.should_receive(:show_json_opt).exactly(1)
484 get :new, :format => :json
488 context 'ユーザ権限がないとき' do
493 it 'ステータスコード302 Foundを返す' do
495 response.status.should eq 302
497 it 'サインインページへ遷移する' do
499 response.body.should redirect_to '/users/sign_in'
503 it 'ステータスコード401 Unauthorizedを返す' do
504 get :new, :format => :js
505 response.status.should eq 401
507 it '応答メッセージにUnauthorizedを返す' do
508 get :new, :format => :js
509 response.message.should match(/Unauthorized/)
513 context 'ユーザ権限はないが管理者権限があるとき' do
519 it 'ステータスコード302 Foundを返す' do
521 response.status.should eq 302
523 it 'サインインページへ遷移する' do
525 response.body.should redirect_to '/users/sign_in'
529 context 'ユーザが絵師でないとき' do
534 it 'ステータスコード302 Foundを返す' do
536 response.status.should eq 302
540 response.should redirect_to new_artist_path
544 it '例外403 forbiddenを返す' do
546 get :new, :format => :json
547 }.should raise_error(ActiveRecord::Forbidden)
553 describe '新規作成に於いて' do
556 @attr = {:original_picture => {:file => "abc\ndef\nghi"}}
557 @imager = ImagerTest.load("abc\ndef\nghi")
558 OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
560 context '事前チェックしておく' do
562 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
563 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
565 it '画像ライブラリをロードする' do
566 PettanImager.should_receive(:load).with(any_args()).exactly(1)
569 it '原画モデルにデフォルト値補充を依頼している' do
570 OriginalPicture.any_instance.should_receive(:supply_default).with(any_args()).exactly(1)
573 it '原画モデルに上書き補充を依頼している' do
574 OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
578 OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
582 context 'つつがなく終わるとき' do
584 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
586 it "@original_pictureに作成された原画を保持している" do
588 assigns(:original_picture).should be_a(OriginalPicture)
591 it 'ステータスコード302 Foundを返す' do
593 response.status.should eq 302
595 it '作成された原画の表示ページへ遷移する' do
597 response.should redirect_to(OriginalPicture.last)
602 @attr.merge!({:format => :json})
604 it 'ステータスコード200 OKを返す' do
606 response.should be_success
608 it '作成された原画をjsonデータで返す' do
610 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
612 it '原画モデルにjson単体出力オプションを問い合わせている' do
613 OriginalPicture.should_receive(:show_json_opt).exactly(1)
618 json = JSON.parse response.body
619 json["ext"].should match(/png/)
620 json["md5"].should be_true
621 json["artist_id"].should be_true
622 json["width"].should be_true
626 context 'ユーザ権限がないとき' do
631 it 'ステータスコード302 Foundを返す' do
633 response.status.should eq 302
635 it 'サインインページへ遷移する' do
637 response.body.should redirect_to '/users/sign_in'
642 @attr.merge!({:format => :json})
644 it 'ステータスコード401 Unauthorizedを返す' do
646 response.status.should eq 401
648 it '応答メッセージにUnauthorizedを返す' do
650 response.message.should match(/Unauthorized/)
654 context 'ユーザ権限はないが管理者権限があるとき' do
660 it 'ステータスコード302 Foundを返す' do
662 response.status.should eq 302
664 it 'サインインページへ遷移する' do
666 response.body.should redirect_to '/users/sign_in'
670 context 'ユーザが絵師でないとき' do
675 it 'ステータスコード302 Foundを返す' do
677 response.status.should eq 302
681 response.should redirect_to new_artist_path
686 @attr.merge!({:format => :json})
688 it '例外403 forbiddenを返す' do
689 @attr.merge!({:format => :json})
692 }.should raise_error(ActiveRecord::Forbidden)
696 context '検証、保存に失敗した' do
698 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
699 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
701 it "未保存の原画を保持している" do
703 assigns(:original_picture).should be_a_new(OriginalPicture)
706 it 'ステータスコード200 OKを返す' do
708 response.status.should eq 200
712 response.should render_template("new")
717 @attr.merge!({:format => :json})
719 it 'ステータスコード422 unprocessable_entity を返す' do
721 response.status.should eq 422
723 it '応答メッセージUnprocessable Entityを返す' do
725 response.message.should match(/Unprocessable/)
729 context 'ファイルが指定されていないとき' do
732 PettanImager.stub(:load).and_return(nil)
734 it "未保存の原画を保持している" do
736 assigns(:original_picture).should be_a_new(OriginalPicture)
739 it 'ステータスコード200 OKを返す' do
741 response.status.should eq 200
745 response.should render_template("new")
750 @attr.merge!({:format => :json})
752 it 'ステータスコード422 unprocessable_entity を返す' do
754 response.status.should eq 422
756 it '応答メッセージUnprocessable Entityを返す' do
758 response.message.should match(/Unprocessable/)
764 describe '編集フォーム表示に於いて' do
766 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
768 OriginalPicture.stub(:show).and_return(@pic)
770 context 'つつがなく終わるとき' do
771 it 'ステータスコード200 OKを返す' do
772 get :edit, :id => @pic.id
773 response.should be_success
775 it '原画モデルに編集取得を問い合わせている' do
776 OriginalPicture.should_receive(:edit).exactly(1)
777 get :edit, :id => @pic.id
779 it '@original_pictureにデータを用意している' do
780 get :edit, :id => @pic.id
781 assigns(:original_picture).should eq @pic
784 it 'ページテンプレートeditを描画する' do
785 get :edit, :id => @pic.id
786 response.should render_template("edit")
790 it '部分テンプレートedit.jsを描画する' do
791 get :edit, :id => @pic.id, :format => :js
792 response.should render_template("edit")
796 context 'ユーザ権限がないとき' do
801 it 'ステータスコード302 Foundを返す' do
802 get :edit, :id => @pic.id
803 response.status.should eq 302
805 it 'サインインページへ遷移する' do
806 get :edit, :id => @pic.id
807 response.body.should redirect_to '/users/sign_in'
811 it 'ステータスコード401 Unauthorizedを返す' do
812 get :edit, :id => @pic.id, :format => :js
813 response.status.should eq 401
815 it '応答メッセージにUnauthorizedを返す' do
816 get :edit, :id => @pic.id, :format => :js
817 response.message.should match(/Unauthorized/)
821 context 'ユーザ権限はないが管理者権限があるとき' do
827 it 'ステータスコード302 Foundを返す' do
828 get :edit, :id => @pic.id
829 response.status.should eq 302
831 it 'サインインページへ遷移する' do
832 get :edit, :id => @pic.id
833 response.body.should redirect_to '/users/sign_in'
837 context 'ユーザが絵師でないとき' do
842 it 'ステータスコード302 Foundを返す' do
843 get :edit, :id => @pic.id
844 response.status.should eq 302
847 get :edit, :id => @pic.id
848 response.should redirect_to new_artist_path
852 it '例外403 forbiddenを返す' do
854 get :edit, :id => @pic.id, :format => :json
855 }.should raise_error(ActiveRecord::Forbidden)
863 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
864 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
865 OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
867 @attr = {:file => "abc\ndef\nghi"}
868 @imager = ImagerTest.load("abc\ndef\nghi")
870 context '事前チェックしておく' do
872 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
873 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
875 it '画像ライブラリをロードする' do
876 PettanImager.should_receive(:load).with(any_args()).exactly(1)
877 put :update, :id => @op.id, :original_picture => @attr
879 it '原画モデルに編集取得を問い合わせている' do
880 OriginalPicture.should_receive(:edit).with(@op.id.to_s, @artist).exactly(1)
881 put :update, :id => @op.id, :original_picture => @attr
883 it '原画モデルに上書き補充を依頼している' do
884 OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
885 put :update, :id => @op.id, :original_picture => @attr
888 OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
889 put :update, :id => @op.id, :original_picture => @attr
892 context 'つつがなく終わるとき' do
894 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
896 it '@original_pictureにアレを取得している' do
897 put :update, :id => @op.id, :original_picture => @attr
898 assigns(:original_picture).should eq(@op)
901 it 'ステータスコード302 Foundを返す' do
902 put :update, :id => @op.id, :original_picture => @attr
903 response.status.should eq 302
905 it '更新された原画の表示ページへ遷移する' do
906 put :update, :id => @op.id, :original_picture => @attr
907 response.should redirect_to(@pic)
911 it 'ステータスコード200 OKを返す' do
912 put :update, :id => @op.id, :original_picture => @attr, :format => :json
913 response.should be_success
916 put :update, :id => @op.id, :original_picture => @attr, :format => :json
917 response.body.should match /./
921 context 'ユーザ権限がないとき' do
926 it 'ステータスコード302 Foundを返す' do
927 put :update, :id => @op.id, :original_picture => @attr
928 response.status.should eq 302
930 it 'サインインページへ遷移する' do
931 put :update, :id => @op.id, :original_picture => @attr
932 response.body.should redirect_to '/users/sign_in'
936 it 'ステータスコード401 Unauthorizedを返す' do
937 put :update, :id => @op.id, :original_picture => @attr, :format => :json
938 response.status.should eq 401
940 it '応答メッセージにUnauthorizedを返す' do
941 put :update, :id => @op.id, :original_picture => @attr, :format => :json
942 response.message.should match(/Unauthorized/)
946 context 'ユーザ権限はないが管理者権限があるとき' do
952 it 'ステータスコード302 Foundを返す' do
953 put :update, :id => @op.id, :original_picture => @attr
954 response.status.should eq 302
956 it 'サインインページへ遷移する' do
957 put :update, :id => @op.id, :original_picture => @attr
958 response.body.should redirect_to '/users/sign_in'
962 context 'ユーザが絵師でないとき' do
967 it 'ステータスコード302 Foundを返す' do
968 put :update, :id => @op.id, :original_picture => @attr
969 response.status.should eq 302
972 put :update, :id => @op.id, :original_picture => @attr
973 response.should redirect_to new_artist_path
977 it '例外403 forbiddenを返す' do
979 put :update, :id => @op.id, :original_picture => @attr, :format => :json
980 }.should raise_error(ActiveRecord::Forbidden)
984 context '検証、保存に失敗した' do
986 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
987 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
990 it 'ステータスコード200 Okを返す' do
991 put :update, :id => @op.id, :original_picture => @attr
992 response.status.should eq 200
995 put :update, :id => @op.id, :original_picture => @attr
996 response.should render_template("edit")
1000 it 'ステータスコード422 unprocessable_entity を返す' do
1001 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1002 response.status.should eq 422
1004 it '応答メッセージUnprocessable Entityを返す' do
1005 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1006 response.message.should match(/Unprocessable/)
1010 context 'ファイルが指定されていないとき' do
1013 PettanImager.stub(:load).and_return(nil)
1016 it 'ステータスコード200 Okを返す' do
1017 put :update, :id => @op.id, :original_picture => @attr
1018 response.status.should eq 200
1021 put :update, :id => @op.id, :original_picture => @attr
1022 response.should render_template("edit")
1026 it 'ステータスコード422 unprocessable_entity を返す' do
1027 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1028 response.status.should eq 422
1030 it '応答メッセージUnprocessable Entityを返す' do
1031 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1032 response.message.should match(/Unprocessable/)
1038 describe '削除に於いて' do
1040 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1043 context '事前チェックしておく' do
1045 OriginalPicture.stub(:edit).with(any_args()).and_return @op
1046 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1048 it '原画モデルに編集取得を問い合わせている' do
1049 OriginalPicture.should_receive(:edit).exactly(1)
1050 delete :destroy, :id => @op.id
1053 OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
1054 delete :destroy, :id => @op.id
1056 it '@original_pictureにアレを取得している' do
1057 delete :destroy, :id => @op.id
1058 assigns(:original_picture).id.should eq(@op.id)
1061 context 'つつがなく終わるとき' do
1063 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1066 it 'ステータスコード302 Foundを返す' do
1067 delete :destroy, :id => @op.id
1068 response.status.should eq 302
1070 it '原画の一覧ページへ遷移する' do
1071 delete :destroy, :id => @op.id
1072 response.should redirect_to(original_pictures_path)
1076 it 'ステータスコード200 OKを返す' do
1077 delete :destroy, :id => @op.id, :format => :json
1078 response.should be_success
1080 it 'ページ本体は特に返さない' do
1081 delete :destroy, :id => @op.id, :format => :json
1082 response.body.should match /./
1086 context 'ユーザ権限がないとき' do
1091 it 'ステータスコード302 Foundを返す' do
1092 delete :destroy, :id => @op.id
1093 response.status.should eq 302
1095 it 'サインインページへ遷移する' do
1096 delete :destroy, :id => @op.id
1097 response.body.should redirect_to '/users/sign_in'
1101 it '応答メッセージにUnauthorizedを返す' do
1102 delete :destroy, :id => @op.id, :format => :json
1103 response.message.should match(/Unauthorized/)
1107 context 'ユーザ権限はないが管理者権限があるとき' do
1113 it 'ステータスコード302 Foundを返す' do
1114 delete :destroy, :id => @op.id
1115 response.status.should eq 302
1117 it 'サインインページへ遷移する' do
1118 delete :destroy, :id => @op.id
1119 response.body.should redirect_to '/users/sign_in'
1123 context 'ユーザが絵師でないとき' do
1128 it 'ステータスコード302 Foundを返す' do
1129 delete :destroy, :id => @op.id
1130 response.status.should eq 302
1132 it '絵師登録ページへ遷移する' do
1133 delete :destroy, :id => @op.id
1134 response.should redirect_to new_artist_path
1138 it '例外403 forbiddenを返す' do
1140 delete :destroy, :id => @op.id, :format => :json
1141 }.should raise_error(ActiveRecord::Forbidden)
1145 context '削除に失敗したとき' do
1147 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
1150 it 'ステータスコード302 Foundを返す' do
1151 delete :destroy, :id => @op.id
1152 response.status.should eq 302
1154 it 'その原画の詳細ページへ遷移する' do
1155 delete :destroy, :id => @op.id
1156 response.should redirect_to(original_picture_path(@op))
1160 it 'ステータスコード422 unprocessable_entity を返す' do
1161 delete :destroy, :id => @op.id, :format => :json
1162 response.status.should eq 422
1164 it '応答メッセージUnprocessable Entityを返す' do
1165 delete :destroy, :id => @op.id, :format => :json
1166 response.message.should match(/Unprocessable/)
1173 describe '一覧表示に於いて' do
1175 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1177 OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
1179 context 'つつがなく終わるとき' do
1180 it 'ステータスコード200 OKを返す' do
1182 response.should be_success
1185 it 'indexテンプレートを描画する' do
1187 response.should render_template("index")
1192 get :index, :format => :json
1193 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1197 context 'ユーザ権限がないとき' do
1202 it 'ステータスコード302 Foundを返す' do
1204 response.status.should eq 302
1206 it 'サインインページへ遷移する' do
1208 response.should redirect_to '/users/sign_in'
1212 it 'ステータスコード401 Unauthorizedを返す' do
1213 get :index, :format => :json
1214 response.status.should eq 401
1216 it '応答メッセージにUnauthorizedを返す' do
1217 get :index, :format => :json
1218 response.message.should match(/Unauthorized/)
1224 describe '単体表示に於いて' do
1226 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
1228 OriginalPicture.stub(:show).and_return(@pic)
1230 context 'つつがなく終わるとき' do
1231 it 'ステータスコード200 OKを返す' do
1232 get :show, :id => @pic.id
1233 response.should be_success
1236 it 'showテンプレートを描画する' do
1237 get :show, :id => @pic.id
1238 response.should render_template("show")
1243 get :show, :id => @pic.id, :format => :json
1244 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1248 context 'ユーザ権限がないとき' do
1253 it 'ステータスコード302 Foundを返す' do
1254 get :show, :id => @pic.id
1255 response.status.should eq 302
1257 it 'サインインページへ遷移する' do
1258 get :show, :id => @pic.id
1259 response.body.should redirect_to '/users/sign_in'
1263 it 'ステータスコード401 Unauthorizedを返す' do
1264 get :show, :id => @pic.id, :format => :json
1265 response.status.should eq 401
1267 it '応答メッセージにUnauthorizedを返す' do
1268 get :show, :id => @pic.id, :format => :json
1269 response.message.should match(/Unauthorized/)
1275 describe '履歴一覧表示に於いて' do
1277 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1278 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
1279 :original_picture_id => @op.id
1281 OriginalPicture.stub(:show).and_return(@op)
1282 OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
1284 context 'つつがなく終わるとき' do
1285 it 'ステータスコード200 OKを返す' do
1286 get :history, :id => @op.id
1287 response.should be_success
1290 it 'historyテンプレートを描画する' do
1291 get :history, :id => @op.id
1292 response.should render_template("history")
1297 get :history, :id => @op.id, :format => :json
1298 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1302 context 'ユーザ権限がないとき' do
1307 it 'ステータスコード302 Foundを返す' do
1308 get :history, :id => @op.id
1309 response.status.should eq 302
1311 it 'サインインページへ遷移する' do
1312 get :history, :id => @op.id
1313 response.should redirect_to '/users/sign_in'
1317 it 'ステータスコード401 Unauthorizedを返す' do
1318 get :history, :id => @op.id, :format => :json
1319 response.status.should eq 401
1321 it '応答メッセージにUnauthorizedを返す' do
1322 get :history, :id => @op.id, :format => :json
1323 response.message.should match(/Unauthorized/)
1329 describe '新規作成フォーム表示に於いて' do
1333 context 'つつがなく終わるとき' do
1335 it 'ステータスコード200 OKを返す' do
1337 response.should be_success
1339 it 'ページテンプレートnewを描画する' do
1341 response.should render_template("new")
1345 it 'ステータスコード200 OKを返す' do
1346 get :new, :format => :js
1347 response.should be_success
1349 it '部分テンプレートnew.jsを描画する' do
1350 get :new, :format => :js
1351 response.should render_template("new")
1356 get :new, :format => :json
1357 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1361 context 'ユーザ権限がないとき' do
1366 it 'ステータスコード302 Foundを返す' do
1368 response.status.should eq 302
1370 it 'サインインページへ遷移する' do
1372 response.body.should redirect_to '/users/sign_in'
1376 it 'ステータスコード401 Unauthorizedを返す' do
1377 get :new, :format => :js
1378 response.status.should eq 401
1380 it '応答メッセージにUnauthorizedを返す' do
1381 get :new, :format => :js
1382 response.message.should match(/Unauthorized/)
1388 describe '新規作成に於いて' do
1391 @attr = {:original_picture => {:file => "abc\ndef\nghi"}}
1392 @imager = ImagerTest.load("abc\ndef\nghi")
1393 OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
1395 context 'つつがなく終わるとき' do
1397 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1400 it 'ステータスコード302 Foundを返す' do
1402 response.status.should eq 302
1404 it '作成された原画の表示ページへ遷移する' do
1406 response.should redirect_to(OriginalPicture.last)
1411 @attr.merge!({:format => :json})
1413 it 'ステータスコード200 OKを返す' do
1415 response.should be_success
1417 it '作成された原画をjsonデータで返す' do
1419 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1423 context 'ユーザ権限がないとき' do
1428 it 'ステータスコード302 Foundを返す' do
1430 response.status.should eq 302
1432 it 'サインインページへ遷移する' do
1434 response.body.should redirect_to '/users/sign_in'
1439 @attr.merge!({:format => :json})
1441 it 'ステータスコード401 Unauthorizedを返す' do
1443 response.status.should eq 401
1445 it '応答メッセージにUnauthorizedを返す' do
1447 response.message.should match(/Unauthorized/)
1453 describe '編集フォーム表示に於いて' do
1455 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
1457 OriginalPicture.stub(:show).and_return(@pic)
1459 context 'つつがなく終わるとき' do
1460 it 'ステータスコード200 OKを返す' do
1461 get :edit, :id => @pic.id
1462 response.should be_success
1465 it 'ページテンプレートeditを描画する' do
1466 get :edit, :id => @pic.id
1467 response.should render_template("edit")
1471 it '部分テンプレートedit.jsを描画する' do
1472 get :edit, :id => @pic.id, :format => :js
1473 response.should render_template("edit")
1477 context 'ユーザ権限がないとき' do
1482 it 'ステータスコード302 Foundを返す' do
1483 get :edit, :id => @pic.id
1484 response.status.should eq 302
1486 it 'サインインページへ遷移する' do
1487 get :edit, :id => @pic.id
1488 response.body.should redirect_to '/users/sign_in'
1492 it 'ステータスコード401 Unauthorizedを返す' do
1493 get :edit, :id => @pic.id, :format => :js
1494 response.status.should eq 401
1496 it '応答メッセージにUnauthorizedを返す' do
1497 get :edit, :id => @pic.id, :format => :js
1498 response.message.should match(/Unauthorized/)
1504 describe '更新に於いて' do
1506 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1507 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
1508 OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
1510 @attr = {:file => "abc\ndef\nghi"}
1511 @imager = ImagerTest.load("abc\ndef\nghi")
1513 context 'つつがなく終わるとき' do
1515 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1518 it 'ステータスコード302 Foundを返す' do
1519 put :update, :id => @op.id, :original_picture => @attr
1520 response.status.should eq 302
1522 it '更新された原画の表示ページへ遷移する' do
1523 put :update, :id => @op.id, :original_picture => @attr
1524 response.should redirect_to(@pic)
1528 it 'ステータスコード200 OKを返す' do
1529 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1530 response.should be_success
1532 it 'ページ本体は特に返さない' do
1533 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1534 response.body.should match /./
1538 context 'ユーザ権限がないとき' do
1543 it 'ステータスコード302 Foundを返す' do
1544 put :update, :id => @op.id, :original_picture => @attr
1545 response.status.should eq 302
1547 it 'サインインページへ遷移する' do
1548 put :update, :id => @op.id, :original_picture => @attr
1549 response.body.should redirect_to '/users/sign_in'
1553 it 'ステータスコード401 Unauthorizedを返す' do
1554 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1555 response.status.should eq 401
1557 it '応答メッセージにUnauthorizedを返す' do
1558 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1559 response.message.should match(/Unauthorized/)
1563 context '検証、保存に失敗した' do
1565 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1566 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
1569 it 'ステータスコード200 Okを返す' do
1570 put :update, :id => @op.id, :original_picture => @attr
1571 response.status.should eq 200
1574 put :update, :id => @op.id, :original_picture => @attr
1575 response.should render_template("edit")
1579 it 'ステータスコード422 unprocessable_entity を返す' do
1580 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1581 response.status.should eq 422
1583 it '応答メッセージUnprocessable Entityを返す' do
1584 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1585 response.message.should match(/Unprocessable/)
1591 describe '削除に於いて' do
1593 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1596 context '事前チェックしておく' do
1598 OriginalPicture.stub(:edit).with(any_args()).and_return @op
1599 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1601 it '原画モデルに編集取得を問い合わせている' do
1602 OriginalPicture.should_receive(:edit).exactly(1)
1603 delete :destroy, :id => @op.id
1606 OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
1607 delete :destroy, :id => @op.id
1609 it '@original_pictureにアレを取得している' do
1610 delete :destroy, :id => @op.id
1611 assigns(:original_picture).id.should eq(@op.id)
1614 context 'つつがなく終わるとき' do
1616 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1619 it 'ステータスコード302 Foundを返す' do
1620 delete :destroy, :id => @op.id
1621 response.status.should eq 302
1623 it '原画の一覧ページへ遷移する' do
1624 delete :destroy, :id => @op.id
1625 response.should redirect_to(original_pictures_path)
1629 it 'ステータスコード200 OKを返す' do
1630 delete :destroy, :id => @op.id, :format => :json
1631 response.should be_success
1633 it 'ページ本体は特に返さない' do
1634 delete :destroy, :id => @op.id, :format => :json
1635 response.body.should match /./
1639 context 'ユーザ権限がないとき' do
1643 it 'ステータスコード302 Foundを返す' do
1644 delete :destroy, :id => @op.id
1645 response.status.should eq 302
1648 it 'サインインページへ遷移する' do
1649 delete :destroy, :id => @op.id
1650 response.body.should redirect_to '/users/sign_in'
1654 it '応答メッセージにUnauthorizedを返す' do
1655 delete :destroy, :id => @op.id, :format => :json
1656 response.message.should match(/Unauthorized/)
1660 context '削除に失敗したとき' do
1662 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
1665 it 'ステータスコード302 Foundを返す' do
1666 delete :destroy, :id => @op.id
1667 response.status.should eq 302
1669 it 'その原画の詳細ページへ遷移する' do
1670 delete :destroy, :id => @op.id
1671 response.should redirect_to(original_picture_path(@op))
1675 it 'ステータスコード422 unprocessable_entity を返す' do
1676 delete :destroy, :id => @op.id, :format => :json
1677 response.status.should eq 422
1679 it '応答メッセージUnprocessable Entityを返す' do
1680 delete :destroy, :id => @op.id, :format => :json
1681 response.message.should match(/Unprocessable/)