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 '応答メッセージにUnauthorizedを返す' do
133 get :index, :format => :json
134 response.message.should match(/Unauthorized/)
140 describe '単体表示に於いて' do
142 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
144 OriginalPicture.stub(:show).and_return(@pic)
146 context 'つつがなく終わるとき' do
147 it 'ステータスコード200 OKを返す' do
148 get :show, :id => @pic.id
149 response.should be_success
151 it '原画モデルに単体取得を問い合わせている' do
152 OriginalPicture.should_receive(:show).exactly(1)
155 it '@original_pictureにアレを取得している' do
156 get :show, :id => @pic.id
157 assigns(:original_picture).id.should eq(@pic.id)
160 it 'showテンプレートを描画する' do
161 get :show, :id => @pic.id
162 response.should render_template("show")
167 get :show, :id => @pic.id, :format => :json
168 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
170 it '原画モデルにjson単体出力オプションを問い合わせている' do
171 OriginalPicture.should_receive(:show_json_opt).exactly(1)
172 get :show, :id => @pic.id, :format => :json
175 get :show, :id => @pic.id, :format => :json
176 json = JSON.parse response.body
177 json["ext"].should match(/png/)
178 json["md5"].should be_true
179 json["artist_id"].should be_true
180 json["width"].should be_true
183 #画像送信では、send_dataにスタブをおいてテストしたいが、ここに噛ませると
184 #renderが働かず、エラーとなってしまう。そこで、原画のファイル取得部分に
185 #スタブをおいてsend_dataがデータを返す体裁でテストする。
188 OriginalPicture.any_instance.stub(:mime_type).and_return('image/png')
189 OriginalPicture.any_instance.stub(:restore).and_return('aaa')
191 it '画像モデルに画像データを問い合わせる' do
192 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
193 get :show, :id => @pic.id, :format => :png
195 it '画像モデルにMimeTypeを問い合わせる' do
196 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
197 get :show, :id => @pic.id, :format => :png
200 get :show, :id => @pic.id, :format => :png
201 response.body.should eq 'aaa'
206 OriginalPicture.any_instance.stub(:mime_type).and_return('image/gif')
207 OriginalPicture.any_instance.stub(:restore).and_return('bbb')
209 it '画像モデルに画像データを問い合わせる' do
210 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
211 get :show, :id => @pic.id, :format => :gif
213 it '画像モデルにMimeTypeを問い合わせる' do
214 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
215 get :show, :id => @pic.id, :format => :gif
218 get :show, :id => @pic.id, :format => :gif
219 response.body.should eq 'bbb'
224 OriginalPicture.any_instance.stub(:mime_type).and_return('image/jpeg')
225 OriginalPicture.any_instance.stub(:restore).and_return('ccc')
227 it '画像モデルに画像データを問い合わせる' do
228 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
229 get :show, :id => @pic.id, :format => :jpeg
231 it '画像モデルにMimeTypeを問い合わせる' do
232 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
233 get :show, :id => @pic.id, :format => :jpeg
236 get :show, :id => @pic.id, :format => :jpeg
237 response.body.should eq 'ccc'
241 context '作家権限がないとき' do
246 it 'ステータスコード302 Foundを返す' do
247 get :show, :id => @pic.id
248 response.status.should eq 302
250 it 'サインインページへ遷移する' do
251 get :show, :id => @pic.id
252 response.body.should redirect_to '/users/sign_in'
256 it 'ステータスコード401 Unauthorizedを返す' do
257 get :show, :id => @pic.id, :format => :json
258 response.status.should eq 401
260 it '応答メッセージにUnauthorizedを返す' do
261 get :show, :id => @pic.id, :format => :json
262 response.message.should match(/Unauthorized/)
266 context '作家が絵師でないとき' do
268 Author.any_instance.stub(:artist?).and_return(false)
271 it 'ステータスコード302 Foundを返す' do
272 get :show, :id => @pic.id
273 response.status.should eq 302
276 get :show, :id => @pic.id
277 response.should redirect_to new_artist_path
281 it '応答メッセージにUnauthorizedを返す' do
282 get :show, :id => @pic.id, :format => :json
283 response.message.should match(/Unauthorized/)
288 context '対象原画がないとき' do
290 OriginalPicture.unstub(:show)
293 it '例外404 not_foundを返す' do
296 }.should raise_error(ActiveRecord::RecordNotFound)
300 it '例外404 not_foundを返す' do
302 get :show, :id => 0, :format => :json
303 }.should raise_error(ActiveRecord::RecordNotFound)
307 context '他人の原画を見ようとしたとき' do
309 OriginalPicture.stub(:show).and_return(@pic)
310 OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(false)
313 it '例外403 forbiddenを返す' do
315 get :show, :id => @pic.id
316 }.should raise_error(ActiveRecord::Forbidden)
320 it '例外403 forbiddenを返す' do
322 get :show, :id => @pic.id, :format => :json
323 }.should raise_error(ActiveRecord::Forbidden)
330 describe '履歴一覧表示に於いて' do
332 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
333 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
334 :original_picture_id => @op.id
336 OriginalPicture.stub(:show).and_return(@op)
337 OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
339 context 'つつがなく終わるとき' do
340 it 'ステータスコード200 OKを返す' do
341 get :history, :id => @op.id
342 response.should be_success
344 it '原画モデルに単体取得を問い合わせている' do
345 OriginalPicture.should_receive(:show).exactly(1)
346 get :history, :id => @op.id
348 it '自身に履歴一覧を問い合わせている' do
349 OriginalPicture.any_instance.should_receive(:history).exactly(1)
350 get :history, :id => @op.id
352 it '@historyにリストを取得している' do
353 get :history, :id => @op.id
354 assigns(:history).should have_at_least(3).items
357 it 'historyテンプレートを描画する' do
358 get :history, :id => @op.id
359 response.should render_template("history")
364 get :history, :id => @op.id, :format => :json
365 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
367 it 'データがリスト構造になっている' do
368 get :history, :id => @op.id, :format => :json
369 json = JSON.parse response.body
370 json.should have_at_least(3).items
372 it 'リストの先頭くらいは原画っぽいものであって欲しい' do
373 get :history, :id => @op.id, :format => :json
374 json = JSON.parse response.body
375 json.first.has_key?("ext").should be_true
379 context '作家権限がないとき' do
384 it 'ステータスコード302 Foundを返す' do
385 get :history, :id => @op.id
386 response.status.should eq 302
388 it 'サインインページへ遷移する' do
389 get :history, :id => @op.id
390 response.should redirect_to '/users/sign_in'
394 it 'ステータスコード401 Unauthorizedを返す' do
395 get :history, :id => @op.id, :format => :json
396 response.status.should eq 401
398 it '応答メッセージにUnauthorizedを返す' do
399 get :history, :id => @op.id, :format => :json
400 response.message.should match(/Unauthorized/)
404 context '作家が絵師でないとき' do
406 Author.any_instance.stub(:artist?).and_return(false)
409 it 'ステータスコード302 Foundを返す' do
410 get :history, :id => @op.id
411 response.status.should eq 302
414 get :history, :id => @op.id
415 response.should redirect_to new_artist_path
419 it '応答メッセージにUnauthorizedを返す' do
420 get :history, :id => @op.id, :format => :json
421 response.message.should match(/Unauthorized/)
427 describe '新規作成フォーム表示に於いて' do
431 context 'つつがなく終わるとき' do
432 it '@original_pictureに新規データを用意している' do
434 assigns(:original_picture).should be_a_new(OriginalPicture)
436 it '原画モデルにデフォルト値補充を依頼している' do
437 OriginalPicture.any_instance.should_receive(:supply_default).exactly(1)
441 it 'ステータスコード200 OKを返す' do
443 response.should be_success
445 it 'ページテンプレートnewを描画する' do
447 response.should render_template("new")
451 it 'ステータスコード200 OKを返す' do
452 get :new, :format => :js
453 response.should be_success
455 it '部分テンプレートnew.jsを描画する' do
456 get :new, :format => :js
457 response.should render_template("new")
462 get :new, :format => :json
463 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
465 it '原画モデルにjson単体出力オプションを問い合わせている' do
466 OriginalPicture.should_receive(:show_json_opt).exactly(1)
467 get :new, :format => :json
471 context '作家権限がないとき' do
476 it 'ステータスコード302 Foundを返す' do
478 response.status.should eq 302
480 it 'サインインページへ遷移する' do
482 response.body.should redirect_to '/users/sign_in'
486 it 'ステータスコード401 Unauthorizedを返す' do
487 get :new, :format => :js
488 response.status.should eq 401
490 it '応答メッセージにUnauthorizedを返す' do
491 get :new, :format => :js
492 response.message.should match(/Unauthorized/)
496 context '作家が絵師でないとき' do
498 Author.any_instance.stub(:artist?).and_return(false)
501 it 'ステータスコード302 Foundを返す' do
503 response.status.should eq 302
507 response.should redirect_to new_artist_path
511 it 'ステータスコード200 Okを返す' do
512 get :new, :format => :js
513 response.status.should eq 200
515 it '絵師登録部分テンプレートartists/new.jsを描画する' do
516 get :new, :format => :js
517 response.should render_template("artists/new")
521 it '応答メッセージにUnauthorizedを返す' do
522 get :new, :format => :json
523 response.message.should match(/Unauthorized/)
529 describe '新規作成に於いて' do
532 @attr = {:original_picture => {:file => "abc\ndef\nghi"}}
533 @imager = ImagerTest.load("abc\ndef\nghi")
534 OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
536 context '事前チェックしておく' do
538 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
539 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
541 it '画像ライブラリをロードする' do
542 PettanImager.should_receive(:load).with(any_args()).exactly(1)
545 it '原画モデルにデフォルト値補充を依頼している' do
546 OriginalPicture.any_instance.should_receive(:supply_default).with(any_args()).exactly(1)
549 it '原画モデルに上書き補充を依頼している' do
550 OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
554 OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
558 context 'つつがなく終わるとき' do
560 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
562 it "@original_pictureに作成された原画を保持している" do
564 assigns(:original_picture).should be_a(OriginalPicture)
567 it 'ステータスコード302 Foundを返す' do
569 response.status.should eq 302
571 it '作成された原画の表示ページへ遷移する' do
573 response.should redirect_to(OriginalPicture.last)
578 @attr.merge!({:format => :json})
580 it 'ステータスコード200 OKを返す' do
582 response.should be_success
584 it '作成された原画をjsonデータで返す' do
586 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
588 it '原画モデルにjson単体出力オプションを問い合わせている' do
589 OriginalPicture.should_receive(:show_json_opt).exactly(1)
594 json = JSON.parse response.body
595 json["ext"].should match(/png/)
596 json["md5"].should be_true
597 json["artist_id"].should be_true
598 json["width"].should be_true
602 context '作家権限がないとき' do
607 it 'ステータスコード302 Foundを返す' do
609 response.status.should eq 302
611 it 'サインインページへ遷移する' do
613 response.body.should redirect_to '/users/sign_in'
618 @attr.merge!({:format => :json})
620 it 'ステータスコード401 Unauthorizedを返す' do
622 response.status.should eq 401
624 it '応答メッセージにUnauthorizedを返す' do
626 response.message.should match(/Unauthorized/)
630 context '作家が絵師でないとき' do
632 Author.any_instance.stub(:artist?).and_return(false)
635 it 'ステータスコード302 Foundを返す' do
637 response.status.should eq 302
641 response.should redirect_to new_artist_path
646 @attr.merge!({:format => :json})
648 it '応答メッセージにUnauthorizedを返す' do
650 response.message.should match(/Unauthorized/)
654 context '検証、保存に失敗した' do
656 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
657 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
659 it "未保存の原画を保持している" do
661 assigns(:original_picture).should be_a_new(OriginalPicture)
664 it 'ステータスコード200 OKを返す' do
666 response.status.should eq 200
670 response.should render_template("new")
675 @attr.merge!({:format => :json})
677 it 'ステータスコード422 unprocessable_entity を返す' do
679 response.status.should eq 422
681 it '応答メッセージUnprocessable Entityを返す' do
683 response.message.should match(/Unprocessable/)
687 context 'ファイルが指定されていないとき' do
690 PettanImager.stub(:load).and_return(nil)
692 it "未保存の原画を保持している" do
694 assigns(:original_picture).should be_a_new(OriginalPicture)
697 it 'ステータスコード200 OKを返す' do
699 response.status.should eq 200
703 response.should render_template("new")
708 @attr.merge!({:format => :json})
710 it 'ステータスコード422 unprocessable_entity を返す' do
712 response.status.should eq 422
714 it '応答メッセージUnprocessable Entityを返す' do
716 response.message.should match(/Unprocessable/)
722 describe '編集フォーム表示に於いて' do
724 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
726 OriginalPicture.stub(:show).and_return(@pic)
728 context 'つつがなく終わるとき' do
729 it 'ステータスコード200 OKを返す' do
730 get :edit, :id => @pic.id
731 response.should be_success
733 it '原画モデルに編集取得を問い合わせている' do
734 OriginalPicture.should_receive(:edit).exactly(1)
735 get :edit, :id => @pic.id
737 it '@original_pictureにデータを用意している' do
738 get :edit, :id => @pic.id
739 assigns(:original_picture).should eq @pic
742 it 'ページテンプレートeditを描画する' do
743 get :edit, :id => @pic.id
744 response.should render_template("edit")
748 it '部分テンプレートedit.jsを描画する' do
749 get :edit, :id => @pic.id, :format => :js
750 response.should render_template("edit")
754 context '作家権限がないとき' do
759 it 'ステータスコード302 Foundを返す' do
760 get :edit, :id => @pic.id
761 response.status.should eq 302
763 it 'サインインページへ遷移する' do
764 get :edit, :id => @pic.id
765 response.body.should redirect_to '/users/sign_in'
769 it 'ステータスコード401 Unauthorizedを返す' do
770 get :edit, :id => @pic.id, :format => :js
771 response.status.should eq 401
773 it '応答メッセージにUnauthorizedを返す' do
774 get :edit, :id => @pic.id, :format => :js
775 response.message.should match(/Unauthorized/)
779 context '作家が絵師でないとき' do
781 Author.any_instance.stub(:artist?).and_return(false)
784 it 'ステータスコード302 Foundを返す' do
785 get :edit, :id => @pic.id
786 response.status.should eq 302
789 get :edit, :id => @pic.id
790 response.should redirect_to new_artist_path
794 it 'ステータスコード200 Okを返す' do
795 get :edit, :id => @pic.id, :format => :js
796 response.status.should eq 200
798 it '絵師登録部分テンプレートartists/new.jsを描画する' do
799 get :edit, :id => @pic.id, :format => :js
800 response.should render_template("artists/new")
808 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
809 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
810 OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
812 @attr = {:file => "abc\ndef\nghi"}
813 @imager = ImagerTest.load("abc\ndef\nghi")
815 context '事前チェックしておく' do
817 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
818 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
820 it '画像ライブラリをロードする' do
821 PettanImager.should_receive(:load).with(any_args()).exactly(1)
822 put :update, :id => @op.id, :original_picture => @attr
824 it '原画モデルに編集取得を問い合わせている' do
825 OriginalPicture.should_receive(:edit).with(@op.id.to_s, @artist).exactly(1)
826 put :update, :id => @op.id, :original_picture => @attr
828 it '原画モデルに上書き補充を依頼している' do
829 OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
830 put :update, :id => @op.id, :original_picture => @attr
833 OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
834 put :update, :id => @op.id, :original_picture => @attr
837 context 'つつがなく終わるとき' do
839 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
841 it '@original_pictureにアレを取得している' do
842 put :update, :id => @op.id, :original_picture => @attr
843 assigns(:original_picture).should eq(@op)
846 it 'ステータスコード302 Foundを返す' do
847 put :update, :id => @op.id, :original_picture => @attr
848 response.status.should eq 302
850 it '更新された原画の表示ページへ遷移する' do
851 put :update, :id => @op.id, :original_picture => @attr
852 response.should redirect_to(@pic)
856 it 'ステータスコード200 OKを返す' do
857 put :update, :id => @op.id, :original_picture => @attr, :format => :json
858 response.should be_success
861 put :update, :id => @op.id, :original_picture => @attr, :format => :json
862 response.body.should match /./
866 context '作家権限がないとき' do
871 it 'ステータスコード302 Foundを返す' do
872 put :update, :id => @op.id, :original_picture => @attr
873 response.status.should eq 302
875 it 'サインインページへ遷移する' do
876 put :update, :id => @op.id, :original_picture => @attr
877 response.body.should redirect_to '/users/sign_in'
881 it 'ステータスコード401 Unauthorizedを返す' do
882 put :update, :id => @op.id, :original_picture => @attr, :format => :json
883 response.status.should eq 401
885 it '応答メッセージにUnauthorizedを返す' do
886 put :update, :id => @op.id, :original_picture => @attr, :format => :json
887 response.message.should match(/Unauthorized/)
891 context '作家が絵師でないとき' do
893 Author.any_instance.stub(:artist?).and_return(false)
896 it 'ステータスコード302 Foundを返す' do
897 put :update, :id => @op.id, :original_picture => @attr
898 response.status.should eq 302
901 put :update, :id => @op.id, :original_picture => @attr
902 response.should redirect_to new_artist_path
906 it '応答メッセージにUnauthorizedを返す' do
907 put :update, :id => @op.id, :original_picture => @attr, :format => :json
908 response.message.should match(/Unauthorized/)
912 context '検証、保存に失敗した' do
914 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
915 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
918 it 'ステータスコード200 Okを返す' do
919 put :update, :id => @op.id, :original_picture => @attr
920 response.status.should eq 200
923 put :update, :id => @op.id, :original_picture => @attr
924 response.should render_template("edit")
928 it 'ステータスコード422 unprocessable_entity を返す' do
929 put :update, :id => @op.id, :original_picture => @attr, :format => :json
930 response.status.should eq 422
932 it '応答メッセージUnprocessable Entityを返す' do
933 put :update, :id => @op.id, :original_picture => @attr, :format => :json
934 response.message.should match(/Unprocessable/)
938 context 'ファイルが指定されていないとき' do
941 PettanImager.stub(:load).and_return(nil)
944 it 'ステータスコード200 Okを返す' do
945 put :update, :id => @op.id, :original_picture => @attr
946 response.status.should eq 200
949 put :update, :id => @op.id, :original_picture => @attr
950 response.should render_template("edit")
954 it 'ステータスコード422 unprocessable_entity を返す' do
955 put :update, :id => @op.id, :original_picture => @attr, :format => :json
956 response.status.should eq 422
958 it '応答メッセージUnprocessable Entityを返す' do
959 put :update, :id => @op.id, :original_picture => @attr, :format => :json
960 response.message.should match(/Unprocessable/)
968 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
971 context '事前チェックしておく' do
973 OriginalPicture.stub(:edit).with(any_args()).and_return @op
974 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
976 it '原画モデルに編集取得を問い合わせている' do
977 OriginalPicture.should_receive(:edit).exactly(1)
978 delete :destroy, :id => @op.id
981 OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
982 delete :destroy, :id => @op.id
984 it '@original_pictureにアレを取得している' do
985 delete :destroy, :id => @op.id
986 assigns(:original_picture).id.should eq(@op.id)
989 context 'つつがなく終わるとき' do
991 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
994 it 'ステータスコード302 Foundを返す' do
995 delete :destroy, :id => @op.id
996 response.status.should eq 302
998 it '原画の一覧ページへ遷移する' do
999 delete :destroy, :id => @op.id
1000 response.should redirect_to(original_pictures_path)
1004 it 'ステータスコード200 OKを返す' do
1005 delete :destroy, :id => @op.id, :format => :json
1006 response.should be_success
1008 it 'ページ本体は特に返さない' do
1009 delete :destroy, :id => @op.id, :format => :json
1010 response.body.should match /./
1014 context '作家権限がないとき' do
1018 it 'ステータスコード302 Foundを返す' do
1019 delete :destroy, :id => @op.id
1020 response.status.should eq 302
1023 it 'サインインページへ遷移する' do
1024 delete :destroy, :id => @op.id
1025 response.body.should redirect_to '/users/sign_in'
1029 it '応答メッセージにUnauthorizedを返す' do
1030 delete :destroy, :id => @op.id, :format => :json
1031 response.message.should match(/Unauthorized/)
1035 context '作家が絵師でないとき' do
1037 Author.any_instance.stub(:artist?).and_return(false)
1040 it 'ステータスコード302 Foundを返す' do
1041 delete :destroy, :id => @op.id
1042 response.status.should eq 302
1044 it '絵師登録ページへ遷移する' do
1045 delete :destroy, :id => @op.id
1046 response.should redirect_to new_artist_path
1050 it '応答メッセージにUnauthorizedを返す' do
1051 delete :destroy, :id => @op.id, :format => :json
1052 response.message.should match(/Unauthorized/)
1056 context '削除に失敗したとき' do
1058 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
1061 it 'ステータスコード302 Foundを返す' do
1062 delete :destroy, :id => @op.id
1063 response.status.should eq 302
1065 it 'その原画の詳細ページへ遷移する' do
1066 delete :destroy, :id => @op.id
1067 response.should redirect_to(original_picture_path(@op))
1071 it 'ステータスコード422 unprocessable_entity を返す' do
1072 delete :destroy, :id => @op.id, :format => :json
1073 response.status.should eq 422
1075 it '応答メッセージUnprocessable Entityを返す' do
1076 delete :destroy, :id => @op.id, :format => :json
1077 response.message.should match(/Unprocessable/)
1084 describe '一覧表示に於いて' do
1086 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1088 OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
1090 context 'つつがなく終わるとき' do
1091 it 'ステータスコード200 OKを返す' do
1093 response.should be_success
1096 it 'indexテンプレートを描画する' do
1098 response.should render_template("index")
1103 get :index, :format => :json
1104 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1108 context '作家権限がないとき' do
1113 it 'ステータスコード302 Foundを返す' do
1115 response.status.should eq 302
1117 it 'サインインページへ遷移する' do
1119 response.should redirect_to '/users/sign_in'
1123 it 'ステータスコード401 Unauthorizedを返す' do
1124 get :index, :format => :json
1125 response.status.should eq 401
1127 it '応答メッセージにUnauthorizedを返す' do
1128 get :index, :format => :json
1129 response.message.should match(/Unauthorized/)
1135 describe '単体表示に於いて' do
1137 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
1139 OriginalPicture.stub(:show).and_return(@pic)
1141 context 'つつがなく終わるとき' do
1142 it 'ステータスコード200 OKを返す' do
1143 get :show, :id => @pic.id
1144 response.should be_success
1147 it 'showテンプレートを描画する' do
1148 get :show, :id => @pic.id
1149 response.should render_template("show")
1154 get :show, :id => @pic.id, :format => :json
1155 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1159 context '作家権限がないとき' do
1164 it 'ステータスコード302 Foundを返す' do
1165 get :show, :id => @pic.id
1166 response.status.should eq 302
1168 it 'サインインページへ遷移する' do
1169 get :show, :id => @pic.id
1170 response.body.should redirect_to '/users/sign_in'
1174 it 'ステータスコード401 Unauthorizedを返す' do
1175 get :show, :id => @pic.id, :format => :json
1176 response.status.should eq 401
1178 it '応答メッセージにUnauthorizedを返す' do
1179 get :show, :id => @pic.id, :format => :json
1180 response.message.should match(/Unauthorized/)
1186 describe '履歴一覧表示に於いて' do
1188 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1189 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
1190 :original_picture_id => @op.id
1192 OriginalPicture.stub(:show).and_return(@op)
1193 OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
1195 context 'つつがなく終わるとき' do
1196 it 'ステータスコード200 OKを返す' do
1197 get :history, :id => @op.id
1198 response.should be_success
1201 it 'historyテンプレートを描画する' do
1202 get :history, :id => @op.id
1203 response.should render_template("history")
1208 get :history, :id => @op.id, :format => :json
1209 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1213 context '作家権限がないとき' do
1218 it 'ステータスコード302 Foundを返す' do
1219 get :history, :id => @op.id
1220 response.status.should eq 302
1222 it 'サインインページへ遷移する' do
1223 get :history, :id => @op.id
1224 response.should redirect_to '/users/sign_in'
1228 it 'ステータスコード401 Unauthorizedを返す' do
1229 get :history, :id => @op.id, :format => :json
1230 response.status.should eq 401
1232 it '応答メッセージにUnauthorizedを返す' do
1233 get :history, :id => @op.id, :format => :json
1234 response.message.should match(/Unauthorized/)
1240 describe '新規作成フォーム表示に於いて' do
1244 context 'つつがなく終わるとき' do
1246 it 'ステータスコード200 OKを返す' do
1248 response.should be_success
1250 it 'ページテンプレートnewを描画する' do
1252 response.should render_template("new")
1256 it 'ステータスコード200 OKを返す' do
1257 get :new, :format => :js
1258 response.should be_success
1260 it '部分テンプレートnew.jsを描画する' do
1261 get :new, :format => :js
1262 response.should render_template("new")
1267 get :new, :format => :json
1268 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1272 context '作家権限がないとき' do
1277 it 'ステータスコード302 Foundを返す' do
1279 response.status.should eq 302
1281 it 'サインインページへ遷移する' do
1283 response.body.should redirect_to '/users/sign_in'
1287 it 'ステータスコード401 Unauthorizedを返す' do
1288 get :new, :format => :js
1289 response.status.should eq 401
1291 it '応答メッセージにUnauthorizedを返す' do
1292 get :new, :format => :js
1293 response.message.should match(/Unauthorized/)
1299 describe '新規作成に於いて' do
1302 @attr = {:original_picture => {:file => "abc\ndef\nghi"}}
1303 @imager = ImagerTest.load("abc\ndef\nghi")
1304 OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
1306 context 'つつがなく終わるとき' do
1308 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1311 it 'ステータスコード302 Foundを返す' do
1313 response.status.should eq 302
1315 it '作成された原画の表示ページへ遷移する' do
1317 response.should redirect_to(OriginalPicture.last)
1322 @attr.merge!({:format => :json})
1324 it 'ステータスコード200 OKを返す' do
1326 response.should be_success
1328 it '作成された原画をjsonデータで返す' do
1330 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1334 context '作家権限がないとき' do
1339 it 'ステータスコード302 Foundを返す' do
1341 response.status.should eq 302
1343 it 'サインインページへ遷移する' do
1345 response.body.should redirect_to '/users/sign_in'
1350 @attr.merge!({:format => :json})
1352 it 'ステータスコード401 Unauthorizedを返す' do
1354 response.status.should eq 401
1356 it '応答メッセージにUnauthorizedを返す' do
1358 response.message.should match(/Unauthorized/)
1364 describe '編集フォーム表示に於いて' do
1366 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
1368 OriginalPicture.stub(:show).and_return(@pic)
1370 context 'つつがなく終わるとき' do
1371 it 'ステータスコード200 OKを返す' do
1372 get :edit, :id => @pic.id
1373 response.should be_success
1376 it 'ページテンプレートeditを描画する' do
1377 get :edit, :id => @pic.id
1378 response.should render_template("edit")
1382 it '部分テンプレートedit.jsを描画する' do
1383 get :edit, :id => @pic.id, :format => :js
1384 response.should render_template("edit")
1388 context '作家権限がないとき' do
1393 it 'ステータスコード302 Foundを返す' do
1394 get :edit, :id => @pic.id
1395 response.status.should eq 302
1397 it 'サインインページへ遷移する' do
1398 get :edit, :id => @pic.id
1399 response.body.should redirect_to '/users/sign_in'
1403 it 'ステータスコード401 Unauthorizedを返す' do
1404 get :edit, :id => @pic.id, :format => :js
1405 response.status.should eq 401
1407 it '応答メッセージにUnauthorizedを返す' do
1408 get :edit, :id => @pic.id, :format => :js
1409 response.message.should match(/Unauthorized/)
1415 describe '更新に於いて' do
1417 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1418 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
1419 OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
1421 @attr = {:file => "abc\ndef\nghi"}
1422 @imager = ImagerTest.load("abc\ndef\nghi")
1424 context 'つつがなく終わるとき' do
1426 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1429 it 'ステータスコード302 Foundを返す' do
1430 put :update, :id => @op.id, :original_picture => @attr
1431 response.status.should eq 302
1433 it '更新された原画の表示ページへ遷移する' do
1434 put :update, :id => @op.id, :original_picture => @attr
1435 response.should redirect_to(@pic)
1439 it 'ステータスコード200 OKを返す' do
1440 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1441 response.should be_success
1443 it 'ページ本体は特に返さない' do
1444 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1445 response.body.should match /./
1449 context '作家権限がないとき' do
1454 it 'ステータスコード302 Foundを返す' do
1455 put :update, :id => @op.id, :original_picture => @attr
1456 response.status.should eq 302
1458 it 'サインインページへ遷移する' do
1459 put :update, :id => @op.id, :original_picture => @attr
1460 response.body.should redirect_to '/users/sign_in'
1464 it 'ステータスコード401 Unauthorizedを返す' do
1465 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1466 response.status.should eq 401
1468 it '応答メッセージにUnauthorizedを返す' do
1469 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1470 response.message.should match(/Unauthorized/)
1474 context '作家が絵師でないとき' do
1476 Author.any_instance.stub(:artist?).and_return(false)
1479 it 'ステータスコード302 Foundを返す' do
1480 put :update, :id => @op.id, :original_picture => @attr
1481 response.status.should eq 302
1483 it '絵師登録ページへ遷移する' do
1484 put :update, :id => @op.id, :original_picture => @attr
1485 response.should redirect_to new_artist_path
1489 it '例外403 forbiddenを返す' do
1491 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1492 }.should raise_error(ActiveRecord::Forbidden)
1496 context '検証、保存に失敗した' do
1498 PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
1499 OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
1502 it 'ステータスコード200 Okを返す' do
1503 put :update, :id => @op.id, :original_picture => @attr
1504 response.status.should eq 200
1507 put :update, :id => @op.id, :original_picture => @attr
1508 response.should render_template("edit")
1512 it 'ステータスコード422 unprocessable_entity を返す' do
1513 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1514 response.status.should eq 422
1516 it '応答メッセージUnprocessable Entityを返す' do
1517 put :update, :id => @op.id, :original_picture => @attr, :format => :json
1518 response.message.should match(/Unprocessable/)
1524 describe '削除に於いて' do
1526 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1529 context '事前チェックしておく' do
1531 OriginalPicture.stub(:edit).with(any_args()).and_return @op
1532 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1534 it '原画モデルに編集取得を問い合わせている' do
1535 OriginalPicture.should_receive(:edit).exactly(1)
1536 delete :destroy, :id => @op.id
1539 OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
1540 delete :destroy, :id => @op.id
1542 it '@original_pictureにアレを取得している' do
1543 delete :destroy, :id => @op.id
1544 assigns(:original_picture).id.should eq(@op.id)
1547 context 'つつがなく終わるとき' do
1549 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
1552 it 'ステータスコード302 Foundを返す' do
1553 delete :destroy, :id => @op.id
1554 response.status.should eq 302
1556 it '原画の一覧ページへ遷移する' do
1557 delete :destroy, :id => @op.id
1558 response.should redirect_to(original_pictures_path)
1562 it 'ステータスコード200 OKを返す' do
1563 delete :destroy, :id => @op.id, :format => :json
1564 response.should be_success
1566 it 'ページ本体は特に返さない' do
1567 delete :destroy, :id => @op.id, :format => :json
1568 response.body.should match /./
1572 context '作家権限がないとき' do
1576 it 'ステータスコード302 Foundを返す' do
1577 delete :destroy, :id => @op.id
1578 response.status.should eq 302
1581 it 'サインインページへ遷移する' do
1582 delete :destroy, :id => @op.id
1583 response.body.should redirect_to '/users/sign_in'
1587 it '応答メッセージにUnauthorizedを返す' do
1588 delete :destroy, :id => @op.id, :format => :json
1589 response.message.should match(/Unauthorized/)
1593 context '削除に失敗したとき' do
1595 OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
1598 it 'ステータスコード302 Foundを返す' do
1599 delete :destroy, :id => @op.id
1600 response.status.should eq 302
1602 it 'その原画の詳細ページへ遷移する' do
1603 delete :destroy, :id => @op.id
1604 response.should redirect_to(original_picture_path(@op))
1608 it 'ステータスコード422 unprocessable_entity を返す' do
1609 delete :destroy, :id => @op.id, :format => :json
1610 response.status.should eq 422
1612 it '応答メッセージUnprocessable Entityを返す' do
1613 delete :destroy, :id => @op.id, :format => :json
1614 response.message.should match(/Unprocessable/)