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
123 it 'ステータスコード302 Foundを返す' do
125 response.status.should eq 302
127 it 'サインインページへ遷移する' do
129 response.should redirect_to '/users/sign_in'
133 context '作家が絵師でないとき' do
135 Author.any_instance.stub(:artist?).and_return(false)
138 it 'ステータスコード302 Foundを返す' do
140 response.status.should eq 302
144 response.should redirect_to new_artist_path
148 it '応答メッセージにUnauthorizedを返す' do
149 get :index, :format => :json
150 response.message.should match(/Unauthorized/)
156 describe '単体表示に於いて' do
158 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
160 OriginalPicture.stub(:show).and_return(@pic)
162 context 'つつがなく終わるとき' do
163 it 'ステータスコード200 OKを返す' do
164 get :show, :id => @pic.id
165 response.should be_success
167 it '原画モデルに単体取得を問い合わせている' do
168 OriginalPicture.should_receive(:show).exactly(1)
171 it '@original_pictureにアレを取得している' do
172 get :show, :id => @pic.id
173 assigns(:original_picture).id.should eq(@pic.id)
176 it 'showテンプレートを描画する' do
177 get :show, :id => @pic.id
178 response.should render_template("show")
183 get :show, :id => @pic.id, :format => :json
184 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
186 it '原画モデルにjson単体出力オプションを問い合わせている' do
187 OriginalPicture.should_receive(:show_json_opt).exactly(1)
188 get :show, :id => @pic.id, :format => :json
191 get :show, :id => @pic.id, :format => :json
192 json = JSON.parse response.body
193 json["ext"].should match(/png/)
194 json["md5"].should be_true
195 json["artist_id"].should be_true
196 json["width"].should be_true
199 #画像送信では、send_dataにスタブをおいてテストしたいが、ここに噛ませると
200 #renderが働かず、エラーとなってしまう。そこで、原画のファイル取得部分に
201 #スタブをおいてsend_dataがデータを返す体裁でテストする。
204 OriginalPicture.any_instance.stub(:mime_type).and_return('image/png')
205 OriginalPicture.any_instance.stub(:restore).and_return('aaa')
207 it '画像モデルに画像データを問い合わせる' do
208 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
209 get :show, :id => @pic.id, :format => :png
211 it '画像モデルにMimeTypeを問い合わせる' do
212 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
213 get :show, :id => @pic.id, :format => :png
216 get :show, :id => @pic.id, :format => :png
217 response.body.should eq 'aaa'
222 OriginalPicture.any_instance.stub(:mime_type).and_return('image/gif')
223 OriginalPicture.any_instance.stub(:restore).and_return('bbb')
225 it '画像モデルに画像データを問い合わせる' do
226 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
227 get :show, :id => @pic.id, :format => :gif
229 it '画像モデルにMimeTypeを問い合わせる' do
230 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
231 get :show, :id => @pic.id, :format => :gif
234 get :show, :id => @pic.id, :format => :gif
235 response.body.should eq 'bbb'
240 OriginalPicture.any_instance.stub(:mime_type).and_return('image/jpeg')
241 OriginalPicture.any_instance.stub(:restore).and_return('ccc')
243 it '画像モデルに画像データを問い合わせる' do
244 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
245 get :show, :id => @pic.id, :format => :jpeg
247 it '画像モデルにMimeTypeを問い合わせる' do
248 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
249 get :show, :id => @pic.id, :format => :jpeg
252 get :show, :id => @pic.id, :format => :jpeg
253 response.body.should eq 'ccc'
257 context '作家権限がないとき' do
262 it 'ステータスコード302 Foundを返す' do
263 get :show, :id => @pic.id
264 response.status.should eq 302
266 it 'サインインページへ遷移する' do
267 get :show, :id => @pic.id
268 response.body.should redirect_to '/users/sign_in'
272 it 'ステータスコード401 Unauthorizedを返す' do
273 get :show, :id => @pic.id, :format => :json
274 response.status.should eq 401
276 it '応答メッセージにUnauthorizedを返す' do
277 get :show, :id => @pic.id, :format => :json
278 response.message.should match(/Unauthorized/)
282 context '作家権限はないが管理者権限があるとき' do
287 it 'ステータスコード200 OKを返す' do
288 get :show, :id => @pic.id
289 response.should be_success
292 context '作家が絵師でないとき' do
294 Author.any_instance.stub(:artist?).and_return(false)
297 it 'ステータスコード302 Foundを返す' do
298 get :show, :id => @pic.id
299 response.status.should eq 302
302 get :show, :id => @pic.id
303 response.should redirect_to new_artist_path
307 it '応答メッセージにUnauthorizedを返す' do
308 get :show, :id => @pic.id, :format => :json
309 response.message.should match(/Unauthorized/)
314 context '対象原画がないとき' do
316 OriginalPicture.unstub(:show)
319 it '例外404 not_foundを返す' do
322 }.should raise_error(ActiveRecord::RecordNotFound)
326 it '例外404 not_foundを返す' do
328 get :show, :id => 0, :format => :json
329 }.should raise_error(ActiveRecord::RecordNotFound)
333 context '他人の原画を見ようとしたとき' do
335 OriginalPicture.stub(:show).and_return(@pic)
336 OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(false)
339 it '例外403 forbiddenを返す' do
341 get :show, :id => @pic.id
342 }.should raise_error(ActiveRecord::Forbidden)
346 it '例外403 forbiddenを返す' do
348 get :show, :id => @pic.id, :format => :json
349 }.should raise_error(ActiveRecord::Forbidden)
356 describe '履歴一覧表示に於いて' do
358 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
359 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
360 :original_picture_id => @op.id
362 OriginalPicture.stub(:show).and_return(@op)
363 OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
365 context 'つつがなく終わるとき' do
366 it 'ステータスコード200 OKを返す' do
367 get :history, :id => @op.id
368 response.should be_success
370 it '原画モデルに単体取得を問い合わせている' do
371 OriginalPicture.should_receive(:show).exactly(1)
372 get :history, :id => @op.id
374 it '自身に履歴一覧を問い合わせている' do
375 OriginalPicture.any_instance.should_receive(:history).exactly(1)
376 get :history, :id => @op.id
378 it '@historyにリストを取得している' do
379 get :history, :id => @op.id
380 assigns(:history).should have_at_least(3).items
383 it 'historyテンプレートを描画する' do
384 get :history, :id => @op.id
385 response.should render_template("history")
390 get :history, :id => @op.id, :format => :json
391 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
393 it 'データがリスト構造になっている' do
394 get :history, :id => @op.id, :format => :json
395 json = JSON.parse response.body
396 json.should have_at_least(3).items
398 it 'リストの先頭くらいは原画っぽいものであって欲しい' do
399 get :history, :id => @op.id, :format => :json
400 json = JSON.parse response.body
401 json.first.has_key?("ext").should be_true
405 context '作家権限がないとき' do
410 it 'ステータスコード302 Foundを返す' do
411 get :history, :id => @op.id
412 response.status.should eq 302
414 it 'サインインページへ遷移する' do
415 get :history, :id => @op.id
416 response.should redirect_to '/users/sign_in'
420 it 'ステータスコード401 Unauthorizedを返す' do
421 get :history, :id => @op.id, :format => :json
422 response.status.should eq 401
424 it '応答メッセージにUnauthorizedを返す' do
425 get :history, :id => @op.id, :format => :json
426 response.message.should match(/Unauthorized/)
430 context '作家権限はないが管理者権限があるとき' do
435 it 'ステータスコード200 OKを返す' do
436 get :history, :id => @op.id
437 response.should be_success
440 context '作家が絵師でないとき' do
442 Author.any_instance.stub(:artist?).and_return(false)
445 it 'ステータスコード302 Foundを返す' do
446 get :history, :id => @op.id
447 response.status.should eq 302
450 get :history, :id => @op.id
451 response.should redirect_to new_artist_path
455 it '応答メッセージにUnauthorizedを返す' do
456 get :history, :id => @op.id, :format => :json
457 response.message.should match(/Unauthorized/)
463 describe '新規作成フォーム表示に於いて' do
467 context 'つつがなく終わるとき' do
468 it '@original_pictureに新規データを用意している' do
470 assigns(:original_picture).should be_a_new(OriginalPicture)
472 it '原画モデルにデフォルト値補充を依頼している' do
473 OriginalPicture.any_instance.should_receive(:supply_default).exactly(1)
477 it 'ステータスコード200 OKを返す' do
479 response.should be_success
481 it 'ページテンプレートnewを描画する' do
483 response.should render_template("new")
487 it 'ステータスコード200 OKを返す' do
488 get :new, :format => :js
489 response.should be_success
491 it '部分テンプレートnew.jsを描画する' do
492 get :new, :format => :js
493 response.should render_template("new")
498 get :new, :format => :json
499 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
501 it '原画モデルにjson単体出力オプションを問い合わせている' do
502 OriginalPicture.should_receive(:show_json_opt).exactly(1)
503 get :new, :format => :json
507 context '作家権限がないとき' do
512 it 'ステータスコード302 Foundを返す' do
514 response.status.should eq 302
516 it 'サインインページへ遷移する' do
518 response.body.should redirect_to '/users/sign_in'
522 it 'ステータスコード401 Unauthorizedを返す' do
523 get :new, :format => :js
524 response.status.should eq 401
526 it '応答メッセージにUnauthorizedを返す' do
527 get :new, :format => :js
528 response.message.should match(/Unauthorized/)
532 context '作家権限はないが管理者権限があるとき' do
538 it 'ステータスコード302 Foundを返す' do
540 response.status.should eq 302
542 it 'サインインページへ遷移する' do
544 response.body.should redirect_to '/users/sign_in'
548 context '作家が絵師でないとき' do
550 Author.any_instance.stub(:artist?).and_return(false)
553 it 'ステータスコード302 Foundを返す' do
555 response.status.should eq 302
559 response.should redirect_to new_artist_path
563 it 'ステータスコード200 Okを返す' do
564 get :new, :format => :js
565 response.status.should eq 200
567 it '絵師登録部分テンプレートartists/new.jsを描画する' do
568 get :new, :format => :js
569 response.should render_template("artists/new")
573 it '応答メッセージにUnauthorizedを返す' do
574 get :new, :format => :json
575 response.message.should match(/Unauthorized/)
581 describe '新規作成に於いて' do
584 @attr = {:original_picture => {:file => "abc\ndef\nghi"}}
585 @imager = ImagerTest.load("abc\ndef\nghi")
586 OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
588 context '事前チェックしておく' do
590 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
591 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
593 it '画像ライブラリをロードする' do
594 PettanImager.should_receive(:load).with(any_args()).exactly(1)
597 it '原画モデルにデフォルト値補充を依頼している' do
598 OriginalPicture.any_instance.should_receive(:supply_default).with(any_args()).exactly(1)
601 it '原画モデルに上書き補充を依頼している' do
602 OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
606 OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
610 context 'つつがなく終わるとき' do
612 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
614 it "@original_pictureに作成された原画を保持している" do
616 assigns(:original_picture).should be_a(OriginalPicture)
619 it 'ステータスコード302 Foundを返す' do
621 response.status.should eq 302
623 it '作成された原画の表示ページへ遷移する' do
625 response.should redirect_to(OriginalPicture.last)
630 @attr.merge!({:format => :json})
632 it 'ステータスコード200 OKを返す' do
634 response.should be_success
636 it '作成された原画をjsonデータで返す' do
638 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
640 it '原画モデルにjson単体出力オプションを問い合わせている' do
641 OriginalPicture.should_receive(:show_json_opt).exactly(1)
646 json = JSON.parse response.body
647 json["ext"].should match(/png/)
648 json["md5"].should be_true
649 json["artist_id"].should be_true
650 json["width"].should be_true
654 context '作家権限がないとき' do
659 it 'ステータスコード302 Foundを返す' do
661 response.status.should eq 302
663 it 'サインインページへ遷移する' do
665 response.body.should redirect_to '/users/sign_in'
670 @attr.merge!({:format => :json})
672 it 'ステータスコード401 Unauthorizedを返す' do
674 response.status.should eq 401
676 it '応答メッセージにUnauthorizedを返す' do
678 response.message.should match(/Unauthorized/)
682 context '作家権限はないが管理者権限があるとき' do
688 it 'ステータスコード302 Foundを返す' do
690 response.status.should eq 302
692 it 'サインインページへ遷移する' do
694 response.body.should redirect_to '/users/sign_in'
698 context '作家が絵師でないとき' do
700 Author.any_instance.stub(:artist?).and_return(false)
703 it 'ステータスコード302 Foundを返す' do
705 response.status.should eq 302
709 response.should redirect_to new_artist_path
714 @attr.merge!({:format => :json})
716 it '応答メッセージにUnauthorizedを返す' do
718 response.message.should match(/Unauthorized/)
722 context '検証、保存に失敗した' do
724 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
725 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
727 it "未保存の原画を保持している" do
729 assigns(:original_picture).should be_a_new(OriginalPicture)
732 it 'ステータスコード200 OKを返す' do
734 response.status.should eq 200
738 response.should render_template("new")
743 @attr.merge!({:format => :json})
745 it 'ステータスコード422 unprocessable_entity を返す' do
747 response.status.should eq 422
749 it '応答メッセージUnprocessable Entityを返す' do
751 response.message.should match(/Unprocessable/)
755 context 'ファイルが指定されていないとき' do
758 PettanImager.stub(:load).and_return(nil)
760 it "未保存の原画を保持している" do
762 assigns(:original_picture).should be_a_new(OriginalPicture)
765 it 'ステータスコード200 OKを返す' do
767 response.status.should eq 200
771 response.should render_template("new")
776 @attr.merge!({:format => :json})
778 it 'ステータスコード422 unprocessable_entity を返す' do
780 response.status.should eq 422
782 it '応答メッセージUnprocessable Entityを返す' do
784 response.message.should match(/Unprocessable/)
790 describe '編集フォーム表示に於いて' do
792 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
794 OriginalPicture.stub(:show).and_return(@pic)
796 context 'つつがなく終わるとき' do
797 it 'ステータスコード200 OKを返す' do
798 get :edit, :id => @pic.id
799 response.should be_success
801 it '原画モデルに編集取得を問い合わせている' do
802 OriginalPicture.should_receive(:edit).exactly(1)
803 get :edit, :id => @pic.id
805 it '@original_pictureにデータを用意している' do
806 get :edit, :id => @pic.id
807 assigns(:original_picture).should eq @pic
810 it 'ページテンプレートeditを描画する' do
811 get :edit, :id => @pic.id
812 response.should render_template("edit")
816 it '部分テンプレートedit.jsを描画する' do
817 get :edit, :id => @pic.id, :format => :js
818 response.should render_template("edit")
822 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 it 'ステータスコード401 Unauthorizedを返す' do
838 get :edit, :id => @pic.id, :format => :js
839 response.status.should eq 401
841 it '応答メッセージにUnauthorizedを返す' do
842 get :edit, :id => @pic.id, :format => :js
843 response.message.should match(/Unauthorized/)
847 context '作家権限はないが管理者権限があるとき' do
853 it 'ステータスコード302 Foundを返す' do
854 get :edit, :id => @pic.id
855 response.status.should eq 302
857 it 'サインインページへ遷移する' do
858 get :edit, :id => @pic.id
859 response.body.should redirect_to '/users/sign_in'
863 context '作家が絵師でないとき' do
865 Author.any_instance.stub(:artist?).and_return(false)
868 it 'ステータスコード302 Foundを返す' do
869 get :edit, :id => @pic.id
870 response.status.should eq 302
873 get :edit, :id => @pic.id
874 response.should redirect_to new_artist_path
878 it 'ステータスコード200 Okを返す' do
879 get :edit, :id => @pic.id, :format => :js
880 response.status.should eq 200
882 it '絵師登録部分テンプレートartists/new.jsを描画する' do
883 get :edit, :id => @pic.id, :format => :js
884 response.should render_template("artists/new")
892 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
893 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
894 OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
896 @attr = {:file => "abc\ndef\nghi"}
897 @imager = ImagerTest.load("abc\ndef\nghi")
899 context '事前チェックしておく' do
901 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
902 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
904 it '画像ライブラリをロードする' do
905 PettanImager.should_receive(:load).with(any_args()).exactly(1)
906 put :update, :id => @op.id, :original_picture => @attr
908 it '原画モデルに編集取得を問い合わせている' do
909 OriginalPicture.should_receive(:edit).with(@op.id.to_s, @artist).exactly(1)
910 put :update, :id => @op.id, :original_picture => @attr
912 it '原画モデルに上書き補充を依頼している' do
913 OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
914 put :update, :id => @op.id, :original_picture => @attr
917 OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
918 put :update, :id => @op.id, :original_picture => @attr
921 context 'つつがなく終わるとき' do
923 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
925 it '@original_pictureにアレを取得している' do
926 put :update, :id => @op.id, :original_picture => @attr
927 assigns(:original_picture).should eq(@op)
930 it 'ステータスコード302 Foundを返す' do
931 put :update, :id => @op.id, :original_picture => @attr
932 response.status.should eq 302
934 it '更新された原画の表示ページへ遷移する' do
935 put :update, :id => @op.id, :original_picture => @attr
936 response.should redirect_to(@pic)
940 it 'ステータスコード200 OKを返す' do
941 put :update, :id => @op.id, :original_picture => @attr, :format => :json
942 response.should be_success
945 put :update, :id => @op.id, :original_picture => @attr, :format => :json
946 response.body.should match /./
950 context '作家権限がないとき' do
955 it 'ステータスコード302 Foundを返す' do
956 put :update, :id => @op.id, :original_picture => @attr
957 response.status.should eq 302
959 it 'サインインページへ遷移する' do
960 put :update, :id => @op.id, :original_picture => @attr
961 response.body.should redirect_to '/users/sign_in'
965 it 'ステータスコード401 Unauthorizedを返す' do
966 put :update, :id => @op.id, :original_picture => @attr, :format => :json
967 response.status.should eq 401
969 it '応答メッセージにUnauthorizedを返す' do
970 put :update, :id => @op.id, :original_picture => @attr, :format => :json
971 response.message.should match(/Unauthorized/)
975 context '作家権限はないが管理者権限があるとき' do
981 it 'ステータスコード302 Foundを返す' do
982 put :update, :id => @op.id, :original_picture => @attr
983 response.status.should eq 302
985 it 'サインインページへ遷移する' do
986 put :update, :id => @op.id, :original_picture => @attr
987 response.body.should redirect_to '/users/sign_in'
991 context '作家が絵師でないとき' do
993 Author.any_instance.stub(:artist?).and_return(false)
996 it 'ステータスコード302 Foundを返す' do
997 put :update, :id => @op.id, :original_picture => @attr
998 response.status.should eq 302
1000 it '絵師登録ページへ遷移する' do
1001 put :update, :id => @op.id, :original_picture => @attr
1002 response.should redirect_to new_artist_path
1006 it '応答メッセージにUnauthorizedを返す' do
1007 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1008 response.message.should match(/Unauthorized/)
1012 context '検証、保存に失敗した' do
1014 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1015 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
1018 it 'ステータスコード200 Okを返す' do
1019 put :update, :id => @op.id, :original_picture => @attr
1020 response.status.should eq 200
1023 put :update, :id => @op.id, :original_picture => @attr
1024 response.should render_template("edit")
1028 it 'ステータスコード422 unprocessable_entity を返す' do
1029 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1030 response.status.should eq 422
1032 it '応答メッセージUnprocessable Entityを返す' do
1033 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1034 response.message.should match(/Unprocessable/)
1038 context 'ファイルが指定されていないとき' do
1041 PettanImager.stub(:load).and_return(nil)
1044 it 'ステータスコード200 Okを返す' do
1045 put :update, :id => @op.id, :original_picture => @attr
1046 response.status.should eq 200
1049 put :update, :id => @op.id, :original_picture => @attr
1050 response.should render_template("edit")
1054 it 'ステータスコード422 unprocessable_entity を返す' do
1055 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1056 response.status.should eq 422
1058 it '応答メッセージUnprocessable Entityを返す' do
1059 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1060 response.message.should match(/Unprocessable/)
1066 describe '削除に於いて' do
1068 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1071 context '事前チェックしておく' do
1073 OriginalPicture.stub(:edit).with(any_args()).and_return @op
1074 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1076 it '原画モデルに編集取得を問い合わせている' do
1077 OriginalPicture.should_receive(:edit).exactly(1)
1078 delete :destroy, :id => @op.id
1081 OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
1082 delete :destroy, :id => @op.id
1084 it '@original_pictureにアレを取得している' do
1085 delete :destroy, :id => @op.id
1086 assigns(:original_picture).id.should eq(@op.id)
1089 context 'つつがなく終わるとき' do
1091 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1094 it 'ステータスコード302 Foundを返す' do
1095 delete :destroy, :id => @op.id
1096 response.status.should eq 302
1098 it '原画の一覧ページへ遷移する' do
1099 delete :destroy, :id => @op.id
1100 response.should redirect_to(original_pictures_path)
1104 it 'ステータスコード200 OKを返す' do
1105 delete :destroy, :id => @op.id, :format => :json
1106 response.should be_success
1108 it 'ページ本体は特に返さない' do
1109 delete :destroy, :id => @op.id, :format => :json
1110 response.body.should match /./
1114 context '作家権限がないとき' do
1119 it 'ステータスコード302 Foundを返す' do
1120 delete :destroy, :id => @op.id
1121 response.status.should eq 302
1123 it 'サインインページへ遷移する' do
1124 delete :destroy, :id => @op.id
1125 response.body.should redirect_to '/users/sign_in'
1129 it '応答メッセージにUnauthorizedを返す' do
1130 delete :destroy, :id => @op.id, :format => :json
1131 response.message.should match(/Unauthorized/)
1135 context '作家権限はないが管理者権限があるとき' do
1141 it 'ステータスコード302 Foundを返す' do
1142 delete :destroy, :id => @op.id
1143 response.status.should eq 302
1145 it 'サインインページへ遷移する' do
1146 delete :destroy, :id => @op.id
1147 response.body.should redirect_to '/users/sign_in'
1151 context '作家が絵師でないとき' do
1153 Author.any_instance.stub(:artist?).and_return(false)
1156 it 'ステータスコード302 Foundを返す' do
1157 delete :destroy, :id => @op.id
1158 response.status.should eq 302
1160 it '絵師登録ページへ遷移する' do
1161 delete :destroy, :id => @op.id
1162 response.should redirect_to new_artist_path
1166 it '応答メッセージにUnauthorizedを返す' do
1167 delete :destroy, :id => @op.id, :format => :json
1168 response.message.should match(/Unauthorized/)
1172 context '削除に失敗したとき' do
1174 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
1177 it 'ステータスコード302 Foundを返す' do
1178 delete :destroy, :id => @op.id
1179 response.status.should eq 302
1181 it 'その原画の詳細ページへ遷移する' do
1182 delete :destroy, :id => @op.id
1183 response.should redirect_to(original_picture_path(@op))
1187 it 'ステータスコード422 unprocessable_entity を返す' do
1188 delete :destroy, :id => @op.id, :format => :json
1189 response.status.should eq 422
1191 it '応答メッセージUnprocessable Entityを返す' do
1192 delete :destroy, :id => @op.id, :format => :json
1193 response.message.should match(/Unprocessable/)
1200 describe '一覧表示に於いて' do
1202 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1204 OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
1206 context 'つつがなく終わるとき' do
1207 it 'ステータスコード200 OKを返す' do
1209 response.should be_success
1212 it 'indexテンプレートを描画する' do
1214 response.should render_template("index")
1219 get :index, :format => :json
1220 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1224 context '作家権限がないとき' do
1229 it 'ステータスコード302 Foundを返す' do
1231 response.status.should eq 302
1233 it 'サインインページへ遷移する' do
1235 response.should redirect_to '/users/sign_in'
1239 it 'ステータスコード401 Unauthorizedを返す' do
1240 get :index, :format => :json
1241 response.status.should eq 401
1243 it '応答メッセージにUnauthorizedを返す' do
1244 get :index, :format => :json
1245 response.message.should match(/Unauthorized/)
1251 describe '単体表示に於いて' do
1253 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
1255 OriginalPicture.stub(:show).and_return(@pic)
1257 context 'つつがなく終わるとき' do
1258 it 'ステータスコード200 OKを返す' do
1259 get :show, :id => @pic.id
1260 response.should be_success
1263 it 'showテンプレートを描画する' do
1264 get :show, :id => @pic.id
1265 response.should render_template("show")
1270 get :show, :id => @pic.id, :format => :json
1271 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1275 context '作家権限がないとき' do
1280 it 'ステータスコード302 Foundを返す' do
1281 get :show, :id => @pic.id
1282 response.status.should eq 302
1284 it 'サインインページへ遷移する' do
1285 get :show, :id => @pic.id
1286 response.body.should redirect_to '/users/sign_in'
1290 it 'ステータスコード401 Unauthorizedを返す' do
1291 get :show, :id => @pic.id, :format => :json
1292 response.status.should eq 401
1294 it '応答メッセージにUnauthorizedを返す' do
1295 get :show, :id => @pic.id, :format => :json
1296 response.message.should match(/Unauthorized/)
1302 describe '履歴一覧表示に於いて' do
1304 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1305 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
1306 :original_picture_id => @op.id
1308 OriginalPicture.stub(:show).and_return(@op)
1309 OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
1311 context 'つつがなく終わるとき' do
1312 it 'ステータスコード200 OKを返す' do
1313 get :history, :id => @op.id
1314 response.should be_success
1317 it 'historyテンプレートを描画する' do
1318 get :history, :id => @op.id
1319 response.should render_template("history")
1324 get :history, :id => @op.id, :format => :json
1325 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1329 context '作家権限がないとき' do
1334 it 'ステータスコード302 Foundを返す' do
1335 get :history, :id => @op.id
1336 response.status.should eq 302
1338 it 'サインインページへ遷移する' do
1339 get :history, :id => @op.id
1340 response.should redirect_to '/users/sign_in'
1344 it 'ステータスコード401 Unauthorizedを返す' do
1345 get :history, :id => @op.id, :format => :json
1346 response.status.should eq 401
1348 it '応答メッセージにUnauthorizedを返す' do
1349 get :history, :id => @op.id, :format => :json
1350 response.message.should match(/Unauthorized/)
1356 describe '新規作成フォーム表示に於いて' do
1360 context 'つつがなく終わるとき' do
1362 it 'ステータスコード200 OKを返す' do
1364 response.should be_success
1366 it 'ページテンプレートnewを描画する' do
1368 response.should render_template("new")
1372 it 'ステータスコード200 OKを返す' do
1373 get :new, :format => :js
1374 response.should be_success
1376 it '部分テンプレートnew.jsを描画する' do
1377 get :new, :format => :js
1378 response.should render_template("new")
1383 get :new, :format => :json
1384 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1388 context '作家権限がないとき' do
1393 it 'ステータスコード302 Foundを返す' do
1395 response.status.should eq 302
1397 it 'サインインページへ遷移する' do
1399 response.body.should redirect_to '/users/sign_in'
1403 it 'ステータスコード401 Unauthorizedを返す' do
1404 get :new, :format => :js
1405 response.status.should eq 401
1407 it '応答メッセージにUnauthorizedを返す' do
1408 get :new, :format => :js
1409 response.message.should match(/Unauthorized/)
1415 describe '新規作成に於いて' do
1418 @attr = {:original_picture => {:file => "abc\ndef\nghi"}}
1419 @imager = ImagerTest.load("abc\ndef\nghi")
1420 OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
1422 context 'つつがなく終わるとき' do
1424 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1427 it 'ステータスコード302 Foundを返す' do
1429 response.status.should eq 302
1431 it '作成された原画の表示ページへ遷移する' do
1433 response.should redirect_to(OriginalPicture.last)
1438 @attr.merge!({:format => :json})
1440 it 'ステータスコード200 OKを返す' do
1442 response.should be_success
1444 it '作成された原画をjsonデータで返す' do
1446 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1450 context '作家権限がないとき' do
1455 it 'ステータスコード302 Foundを返す' do
1457 response.status.should eq 302
1459 it 'サインインページへ遷移する' do
1461 response.body.should redirect_to '/users/sign_in'
1466 @attr.merge!({:format => :json})
1468 it 'ステータスコード401 Unauthorizedを返す' do
1470 response.status.should eq 401
1472 it '応答メッセージにUnauthorizedを返す' do
1474 response.message.should match(/Unauthorized/)
1480 describe '編集フォーム表示に於いて' do
1482 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
1484 OriginalPicture.stub(:show).and_return(@pic)
1486 context 'つつがなく終わるとき' do
1487 it 'ステータスコード200 OKを返す' do
1488 get :edit, :id => @pic.id
1489 response.should be_success
1492 it 'ページテンプレートeditを描画する' do
1493 get :edit, :id => @pic.id
1494 response.should render_template("edit")
1498 it '部分テンプレートedit.jsを描画する' do
1499 get :edit, :id => @pic.id, :format => :js
1500 response.should render_template("edit")
1504 context '作家権限がないとき' do
1509 it 'ステータスコード302 Foundを返す' do
1510 get :edit, :id => @pic.id
1511 response.status.should eq 302
1513 it 'サインインページへ遷移する' do
1514 get :edit, :id => @pic.id
1515 response.body.should redirect_to '/users/sign_in'
1519 it 'ステータスコード401 Unauthorizedを返す' do
1520 get :edit, :id => @pic.id, :format => :js
1521 response.status.should eq 401
1523 it '応答メッセージにUnauthorizedを返す' do
1524 get :edit, :id => @pic.id, :format => :js
1525 response.message.should match(/Unauthorized/)
1531 describe '更新に於いて' do
1533 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1534 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
1535 OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
1537 @attr = {:file => "abc\ndef\nghi"}
1538 @imager = ImagerTest.load("abc\ndef\nghi")
1540 context 'つつがなく終わるとき' do
1542 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1545 it 'ステータスコード302 Foundを返す' do
1546 put :update, :id => @op.id, :original_picture => @attr
1547 response.status.should eq 302
1549 it '更新された原画の表示ページへ遷移する' do
1550 put :update, :id => @op.id, :original_picture => @attr
1551 response.should redirect_to(@pic)
1555 it 'ステータスコード200 OKを返す' do
1556 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1557 response.should be_success
1559 it 'ページ本体は特に返さない' do
1560 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1561 response.body.should match /./
1565 context '作家権限がないとき' do
1570 it 'ステータスコード302 Foundを返す' do
1571 put :update, :id => @op.id, :original_picture => @attr
1572 response.status.should eq 302
1574 it 'サインインページへ遷移する' do
1575 put :update, :id => @op.id, :original_picture => @attr
1576 response.body.should redirect_to '/users/sign_in'
1580 it 'ステータスコード401 Unauthorizedを返す' do
1581 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1582 response.status.should eq 401
1584 it '応答メッセージにUnauthorizedを返す' do
1585 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1586 response.message.should match(/Unauthorized/)
1590 context '作家が絵師でないとき' do
1592 Author.any_instance.stub(:artist?).and_return(false)
1595 it 'ステータスコード302 Foundを返す' do
1596 put :update, :id => @op.id, :original_picture => @attr
1597 response.status.should eq 302
1599 it '絵師登録ページへ遷移する' do
1600 put :update, :id => @op.id, :original_picture => @attr
1601 response.should redirect_to new_artist_path
1605 it '例外403 forbiddenを返す' do
1607 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1608 }.should raise_error(ActiveRecord::Forbidden)
1612 context '検証、保存に失敗した' do
1614 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1615 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
1618 it 'ステータスコード200 Okを返す' do
1619 put :update, :id => @op.id, :original_picture => @attr
1620 response.status.should eq 200
1623 put :update, :id => @op.id, :original_picture => @attr
1624 response.should render_template("edit")
1628 it 'ステータスコード422 unprocessable_entity を返す' do
1629 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1630 response.status.should eq 422
1632 it '応答メッセージUnprocessable Entityを返す' do
1633 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1634 response.message.should match(/Unprocessable/)
1640 describe '削除に於いて' do
1642 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1645 context '事前チェックしておく' do
1647 OriginalPicture.stub(:edit).with(any_args()).and_return @op
1648 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1650 it '原画モデルに編集取得を問い合わせている' do
1651 OriginalPicture.should_receive(:edit).exactly(1)
1652 delete :destroy, :id => @op.id
1655 OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
1656 delete :destroy, :id => @op.id
1658 it '@original_pictureにアレを取得している' do
1659 delete :destroy, :id => @op.id
1660 assigns(:original_picture).id.should eq(@op.id)
1663 context 'つつがなく終わるとき' do
1665 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1668 it 'ステータスコード302 Foundを返す' do
1669 delete :destroy, :id => @op.id
1670 response.status.should eq 302
1672 it '原画の一覧ページへ遷移する' do
1673 delete :destroy, :id => @op.id
1674 response.should redirect_to(original_pictures_path)
1678 it 'ステータスコード200 OKを返す' do
1679 delete :destroy, :id => @op.id, :format => :json
1680 response.should be_success
1682 it 'ページ本体は特に返さない' do
1683 delete :destroy, :id => @op.id, :format => :json
1684 response.body.should match /./
1688 context '作家権限がないとき' do
1692 it 'ステータスコード302 Foundを返す' do
1693 delete :destroy, :id => @op.id
1694 response.status.should eq 302
1697 it 'サインインページへ遷移する' do
1698 delete :destroy, :id => @op.id
1699 response.body.should redirect_to '/users/sign_in'
1703 it '応答メッセージにUnauthorizedを返す' do
1704 delete :destroy, :id => @op.id, :format => :json
1705 response.message.should match(/Unauthorized/)
1709 context '削除に失敗したとき' do
1711 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
1714 it 'ステータスコード302 Foundを返す' do
1715 delete :destroy, :id => @op.id
1716 response.status.should eq 302
1718 it 'その原画の詳細ページへ遷移する' do
1719 delete :destroy, :id => @op.id
1720 response.should redirect_to(original_picture_path(@op))
1724 it 'ステータスコード422 unprocessable_entity を返す' do
1725 delete :destroy, :id => @op.id, :format => :json
1726 response.status.should eq 422
1728 it '応答メッセージUnprocessable Entityを返す' do
1729 delete :destroy, :id => @op.id, :format => :json
1730 response.message.should match(/Unprocessable/)