1 # -*- encoding: utf-8 -*-
4 describe OriginalPicturesController do
7 @user = Factory( :user_yas)
9 @artist = Factory :artist_yas, :author_id => @author.id
12 describe '一覧表示に於いて' do
14 @op = Factory :original_picture, :artist_id => @artist.id
16 OriginalPicture.stub(:list).and_return([@op, @op, @op])
18 context 'パラメータpageについて' do
20 get :index, :page => 5
21 assigns(:page).should eq 5
23 it '省略されると@pageに1値が入る' do
25 assigns(:page).should eq 1
28 context 'つつがなく終わるとき' do
29 it 'ステータスコード200 OKを返す' do
31 response.should be_success
33 it '原画モデルに一覧を問い合わせている' do
34 OriginalPicture.should_receive(:list).exactly(1)
\r
37 it '@original_picturesにリストを取得している' do
39 assigns(:original_pictures).should have_at_least(3).items
42 it 'indexテンプレートを描画する' do
44 response.should render_template("index")
49 get :index, :format => :json
50 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
52 it 'データがリスト構造になっている' do
53 get :index, :format => :json
54 json = JSON.parse response.body
55 json.should have_at_least(3).items
57 it 'リストの先頭くらいは原画っぽいものであって欲しい' do
58 get :index, :format => :json
59 json = JSON.parse response.body
60 json.first.has_key?("ext").should be_true
64 context '作家権限がないとき' do
69 it 'ステータスコード302 Foundを返す' do
71 response.status.should eq 302
75 response.should redirect_to '/users/sign_in'
79 it 'ステータスコード401 Unauthorizedを返す' do
80 get :index, :format => :json
81 response.status.should eq 401
83 it '応答メッセージにUnauthorizedを返す' do
84 get :index, :format => :json
85 response.message.should match(/Unauthorized/)
89 context '作家が絵師でないとき' do
91 Author.any_instance.stub(:artist?).and_return(false)
94 it 'ステータスコード302 Foundを返す' do
96 response.status.should eq 302
100 response.should redirect_to new_artist_path
104 it '例外403 forbiddenを返す' do
106 get :index, :format => :json
107 }.should raise_error(ActiveRecord::Forbidden)
113 describe '単体表示に於いて' do
115 @pic = Factory :original_picture, :artist_id => @artist.id
117 OriginalPicture.stub(:show).and_return(@pic)
119 context 'つつがなく終わるとき' do
120 it 'ステータスコード200 OKを返す' do
121 get :show, :id => @pic.id
122 response.should be_success
124 it '原画モデルに単体取得を問い合わせている' do
125 OriginalPicture.should_receive(:show).exactly(1)
\r
128 it '@original_pictureにアレを取得している' do
129 get :show, :id => @pic.id
130 assigns(:original_picture).id.should eq(@pic.id)
133 it 'showテンプレートを描画する' do
134 get :show, :id => @pic.id
135 response.should render_template("show")
140 get :show, :id => @pic.id, :format => :json
141 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
144 get :show, :id => @pic.id, :format => :json
145 json = JSON.parse response.body
146 json["ext"].should match(/png/)
149 #画像送信では、send_dataにスタブをおいてテストしたいが、ここに噛ませると
150 #renderが働かず、エラーとなってしまう。そこで、原画のファイル取得部分に
151 #スタブをおいてsend_dataがデータを返す体裁でテストする。
153 it '画像モデルに画像データを問い合わせる' do
154 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
\r
155 get :show, :id => @pic.id, :format => :png
158 OriginalPicture.any_instance.stub(:restore).and_return('aaa')
\r
159 get :show, :id => @pic.id, :format => :png
160 response.body.should eq 'aaa'
164 it '画像モデルに画像データを問い合わせる' do
165 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
\r
166 get :show, :id => @pic.id, :format => :gif
169 OriginalPicture.any_instance.stub(:restore).and_return('bbb')
\r
170 get :show, :id => @pic.id, :format => :gif
171 response.body.should eq 'bbb'
175 it '画像モデルに画像データを問い合わせる' do
176 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
\r
177 get :show, :id => @pic.id, :format => :jpeg
180 OriginalPicture.any_instance.stub(:restore).and_return('ccc')
\r
181 get :show, :id => @pic.id, :format => :jpeg
182 response.body.should eq 'ccc'
186 context '作家権限がないとき' do
191 it 'ステータスコード302 Foundを返す' do
192 get :show, :id => @pic.id
193 response.status.should eq 302
195 it 'サインインページへ遷移する' do
196 get :show, :id => @pic.id
197 response.body.should redirect_to '/users/sign_in'
201 it 'ステータスコード401 Unauthorizedを返す' do
202 get :show, :id => @pic.id, :format => :json
203 response.status.should eq 401
205 it '応答メッセージにUnauthorizedを返す' do
206 get :show, :id => @pic.id, :format => :json
207 response.message.should match(/Unauthorized/)
211 context '作家が絵師でないとき' do
213 Author.any_instance.stub(:artist?).and_return(false)
216 it 'ステータスコード302 Foundを返す' do
217 get :show, :id => @pic.id
218 response.status.should eq 302
221 get :show, :id => @pic.id
222 response.should redirect_to new_artist_path
226 it '例外403 forbiddenを返す' do
228 get :show, :id => @pic.id, :format => :json
229 }.should raise_error(ActiveRecord::Forbidden)
234 context '対象原画がないとき' do
236 OriginalPicture.unstub(:show)
239 it '例外404 not_foundを返す' do
242 }.should raise_error(ActiveRecord::RecordNotFound)
246 it '例外404 not_foundを返す' do
248 get :show, :id => 0, :format => :json
249 }.should raise_error(ActiveRecord::RecordNotFound)
253 context '他人の原画を見ようとしたとき' do
255 OriginalPicture.stub(:show).and_return(@pic)
256 OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(false)
259 it '例外403 forbiddenを返す' do
261 get :show, :id => @pic.id
262 }.should raise_error(ActiveRecord::Forbidden)
266 it '例外403 forbiddenを返す' do
268 get :show, :id => @pic.id, :format => :json
269 }.should raise_error(ActiveRecord::Forbidden)
276 describe '新規作成フォーム表示に於いて' do
280 context 'つつがなく終わるとき' do
281 it 'ステータスコード200 OKを返す' do
283 response.should be_success
285 it '@original_pictureに新規データを用意している' do
287 assigns(:original_picture).should be_a_new(OriginalPicture)
289 it '原画モデルにデフォルト値補充を依頼している' do
290 OriginalPicture.any_instance.should_receive(:supply_default).exactly(1)
\r
294 it 'ページテンプレートnewを描画する' do
296 response.should render_template("new")
300 it '部分テンプレートnew.jsを描画する' do
301 get :new, :format => :js
302 response.should render_template("new")
306 context '作家権限がないとき' do
311 it 'ステータスコード302 Foundを返す' do
313 response.status.should eq 302
315 it 'サインインページへ遷移する' do
317 response.body.should redirect_to '/users/sign_in'
321 it 'ステータスコード401 Unauthorizedを返す' do
322 get :new, :format => :js
323 response.status.should eq 401
325 it '応答メッセージにUnauthorizedを返す' do
326 get :new, :format => :js
327 response.message.should match(/Unauthorized/)
331 context '作家が絵師でないとき' do
333 Author.any_instance.stub(:artist?).and_return(false)
336 it 'ステータスコード302 Foundを返す' do
338 response.status.should eq 302
342 response.should redirect_to new_artist_path
346 it 'ステータスコード200 Okを返す' do
347 get :new, :format => :js
348 response.status.should eq 200
350 it '絵師登録部分テンプレートartists/new.jsを描画する' do
351 get :new, :format => :js
352 response.should render_template("artists/new")
358 describe '新規作成に於いて' do
362 context 'つつがなく終わるとき' do
364 OriginalPicture.any_instance.should_receive(:save).exactly(1)
365 post :create, :original_picture => Factory.attributes_for(:original_picture)
367 it "@original_pictureに作成された原画を保持していて、それがDBにある" do
368 post :create, :original_picture => Factory.attributes_for(:original_picture)
369 assigns(:original_picture).should be_a(OriginalPicture)
370 assigns(:original_picture).should be_persisted
373 it 'ステータスコード302 Foundを返す' do
374 OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
375 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
376 post :create, :original_picture => Factory.attributes_for(:original_picture)
377 response.status.should eq 302
379 it '作成された原画の表示ページへ遷移する' do
380 OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
381 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
382 post :create, :original_picture => Factory.attributes_for(:original_picture)
383 response.should redirect_to(OriginalPicture.last)
387 it 'ステータスコード200 OKを返す' do
388 OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
389 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
390 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
391 response.should be_success
393 it '作成された原画をjsonデータで返す' do
394 OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
395 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
396 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
397 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
400 OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
401 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
402 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
403 json = JSON.parse response.body
404 json["ext"].should match(/png/)
408 context '作家権限がないとき' do
413 it 'ステータスコード302 Foundを返す' do
414 post :create, :original_picture => Factory.attributes_for(:original_picture)
415 response.status.should eq 302
417 it 'サインインページへ遷移する' do
418 post :create, :original_picture => Factory.attributes_for(:original_picture)
419 response.body.should redirect_to '/users/sign_in'
423 it 'ステータスコード401 Unauthorizedを返す' do
424 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
425 response.status.should eq 401
427 it '応答メッセージにUnauthorizedを返す' do
428 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
429 response.message.should match(/Unauthorized/)
433 context '作家が絵師でないとき' do
435 Author.any_instance.stub(:artist?).and_return(false)
438 it 'ステータスコード302 Foundを返す' do
439 post :create, :original_picture => Factory.attributes_for(:original_picture)
440 response.status.should eq 302
443 post :create, :original_picture => Factory.attributes_for(:original_picture)
444 response.should redirect_to new_artist_path
448 it '例外403 forbiddenを返す' do
450 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
451 }.should raise_error(ActiveRecord::Forbidden)
455 context '検証、保存に失敗した' do
457 OriginalPicture.any_instance.stub(:save).and_return(false)
459 it "未保存のコミックを保持している" do
460 post :create, :original_picture => Factory.attributes_for(:original_picture)
461 assigns(:original_picture).should be_a_new(OriginalPicture)
464 it 'ステータスコード200 OKを返す' do
465 post :create, :original_picture => Factory.attributes_for(:original_picture)
466 response.status.should eq 200
469 post :create, :original_picture => Factory.attributes_for(:original_picture)
470 response.should render_template("new")
474 it 'ステータスコード422 unprocessable_entity を返す' do
475 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
476 response.status.should eq 422
478 it '応答メッセージUnprocessable Entityを返す' do
479 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
480 response.message.should match(/Unprocessable/)
486 describe '編集フォーム表示に於いて' do
488 @pic = Factory :original_picture, :artist_id => @artist.id
490 OriginalPicture.stub(:show).and_return(@pic)
492 context 'つつがなく終わるとき' do
493 it 'ステータスコード200 OKを返す' do
494 get :edit, :id => @pic.id
495 response.should be_success
497 it '原画モデルに単体取得を問い合わせている' do
498 OriginalPicture.should_receive(:show).exactly(1)
\r
501 it '@original_pictureにデータを用意している' do
502 get :edit, :id => @pic.id
503 assigns(:original_picture).should eq @pic
506 it 'ページテンプレートeditを描画する' do
507 get :edit, :id => @pic.id
508 response.should render_template("edit")
512 it '部分テンプレートedit.jsを描画する' do
513 get :edit, :id => @pic.id, :format => :js
514 response.should render_template("edit")
518 context '作家権限がないとき' do
523 it 'ステータスコード302 Foundを返す' do
524 get :edit, :id => @pic.id
525 response.status.should eq 302
527 it 'サインインページへ遷移する' do
528 get :edit, :id => @pic.id
529 response.body.should redirect_to '/users/sign_in'
533 it 'ステータスコード401 Unauthorizedを返す' do
534 get :edit, :id => @pic.id, :format => :js
535 response.status.should eq 401
537 it '応答メッセージにUnauthorizedを返す' do
538 get :edit, :id => @pic.id, :format => :js
539 response.message.should match(/Unauthorized/)
543 context '作家が絵師でないとき' do
545 Author.any_instance.stub(:artist?).and_return(false)
548 it 'ステータスコード302 Foundを返す' do
549 get :edit, :id => @pic.id
550 response.status.should eq 302
553 get :edit, :id => @pic.id
554 response.should redirect_to new_artist_path
558 it 'ステータスコード200 Okを返す' do
559 get :edit, :id => @pic.id, :format => :js
560 response.status.should eq 200
562 it '絵師登録部分テンプレートartists/new.jsを描画する' do
563 get :edit, :id => @pic.id, :format => :js
564 response.should render_template("artists/new")
572 @pic = Factory :original_picture, :artist_id => @artist.id
575 context '事前チェックしておく' do
576 it '原画モデルに単体取得を問い合わせている' do
577 OriginalPicture.should_receive(:show).exactly(1)
\r
578 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
581 OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(true)
582 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
583 OriginalPicture.any_instance.should_receive(:save).exactly(1)
584 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
586 it '@original_pictureにアレを取得している' do
587 OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(true)
588 OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
589 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
590 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
591 assigns(:original_picture).id.should eq(@pic.id)
594 context 'つつがなく終わるとき' do
596 OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(true)
597 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
598 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture, :ext => 'jpeg')
599 OriginalPicture.find(@pic.id).ext.should eq 'jpeg'
602 it 'ステータスコード302 Foundを返す' do
603 OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(true)
604 OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
605 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
606 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
607 response.status.should eq 302
609 it '更新された原画の表示ページへ遷移する' do
610 OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(true)
611 OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
612 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
613 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
614 response.should redirect_to(@pic)
618 it 'ステータスコード200 OKを返す' do
619 OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(true)
620 OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
621 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
622 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
623 response.should be_success
626 OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(true)
627 OriginalPicture.any_instance.stub(:save).with(any_args()).and_return(true)
628 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
629 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
630 response.body.should match /./
634 context '作家権限がないとき' do
639 it 'ステータスコード302 Foundを返す' do
640 post :create, :original_picture => Factory.attributes_for(:original_picture)
641 response.status.should eq 302
643 it 'サインインページへ遷移する' do
644 post :create, :original_picture => Factory.attributes_for(:original_picture)
645 response.body.should redirect_to '/users/sign_in'
649 it 'ステータスコード401 Unauthorizedを返す' do
650 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
651 response.status.should eq 401
653 it '応答メッセージにUnauthorizedを返す' do
654 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
655 response.message.should match(/Unauthorized/)
659 context '作家が絵師でないとき' do
661 Author.any_instance.stub(:artist?).and_return(false)
664 it 'ステータスコード302 Foundを返す' do
665 post :create, :original_picture => Factory.attributes_for(:original_picture)
666 response.status.should eq 302
669 post :create, :original_picture => Factory.attributes_for(:original_picture)
670 response.should redirect_to new_artist_path
674 it '例外403 forbiddenを返す' do
676 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
677 }.should raise_error(ActiveRecord::Forbidden)
681 context '検証、保存に失敗した' do
683 OriginalPicture.any_instance.stub(:save).and_return(false)
686 it 'ステータスコード200 Okを返す' do
687 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
688 response.status.should eq 200
691 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
692 response.should render_template("edit")
696 it 'ステータスコード422 unprocessable_entity を返す' do
697 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
698 response.status.should eq 422
700 it '応答メッセージUnprocessable Entityを返す' do
701 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
702 response.message.should match(/Unprocessable/)