1 # -*- encoding: utf-8 -*-
5 describe OriginalPicturesController do
8 @user = Factory( :user_yas)
10 @artist = Factory :artist_yas, :author_id => @author.id
11 @sp = Factory :system_picture
12 @lg = Factory :license_group
13 @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
16 describe '一覧表示に於いて' do
18 @op = Factory :original_picture, :artist_id => @artist.id
20 OriginalPicture.stub(:list).and_return([@op, @op, @op])
22 context 'パラメータpageについて' do
24 get :index, :page => 5
25 assigns(:page).should eq 5
27 it '省略されると@pageに1値が入る' do
29 assigns(:page).should eq 1
31 it '与えられたpage_sizeがセットされている' do
32 get :index, :page_size => 15
33 assigns(:page_size).should eq 15
35 it '省略されると@page_sizeにデフォルト値が入る' do
37 assigns(:page_size).should eq OriginalPicture.default_page_size
\r
39 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
40 get :index, :page_size => 1500
41 assigns(:page_size).should eq OriginalPicture.max_page_size
43 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
44 get :index, :page_size => 0
45 assigns(:page_size).should eq OriginalPicture.default_page_size
48 context 'つつがなく終わるとき' do
49 it 'ステータスコード200 OKを返す' do
51 response.should be_success
53 it '原画モデルに一覧を問い合わせている' do
54 OriginalPicture.should_receive(:list).exactly(1)
\r
57 it '@original_picturesにリストを取得している' do
59 assigns(:original_pictures).should have_at_least(3).items
62 it 'indexテンプレートを描画する' do
64 response.should render_template("index")
69 get :index, :format => :json
70 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
72 it 'データがリスト構造になっている' do
73 get :index, :format => :json
74 json = JSON.parse response.body
75 json.should have_at_least(3).items
77 it 'リストの先頭くらいは原画っぽいものであって欲しい' do
78 get :index, :format => :json
79 json = JSON.parse response.body
80 json.first.has_key?("ext").should be_true
84 context '作家権限がないとき' do
89 it 'ステータスコード302 Foundを返す' do
91 response.status.should eq 302
95 response.should redirect_to '/users/sign_in'
99 it 'ステータスコード401 Unauthorizedを返す' do
100 get :index, :format => :json
101 response.status.should eq 401
103 it '応答メッセージにUnauthorizedを返す' do
104 get :index, :format => :json
105 response.message.should match(/Unauthorized/)
109 context '作家が絵師でないとき' do
111 Author.any_instance.stub(:artist?).and_return(false)
114 it 'ステータスコード302 Foundを返す' do
116 response.status.should eq 302
120 response.should redirect_to new_artist_path
124 it '例外403 forbiddenを返す' do
126 get :index, :format => :json
127 }.should raise_error(ActiveRecord::Forbidden)
133 describe '単体表示に於いて' do
135 @pic = Factory :original_picture, :artist_id => @artist.id
137 OriginalPicture.stub(:show).and_return(@pic)
139 context 'つつがなく終わるとき' do
140 it 'ステータスコード200 OKを返す' do
141 get :show, :id => @pic.id
142 response.should be_success
144 it '原画モデルに単体取得を問い合わせている' do
145 OriginalPicture.should_receive(:show).exactly(1)
\r
148 it '@original_pictureにアレを取得している' do
149 get :show, :id => @pic.id
150 assigns(:original_picture).id.should eq(@pic.id)
153 it 'showテンプレートを描画する' do
154 get :show, :id => @pic.id
155 response.should render_template("show")
160 get :show, :id => @pic.id, :format => :json
161 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
164 get :show, :id => @pic.id, :format => :json
165 json = JSON.parse response.body
166 json["ext"].should match(/png/)
169 #画像送信では、send_dataにスタブをおいてテストしたいが、ここに噛ませると
170 #renderが働かず、エラーとなってしまう。そこで、原画のファイル取得部分に
171 #スタブをおいてsend_dataがデータを返す体裁でテストする。
173 it '画像モデルに画像データを問い合わせる' do
174 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
\r
175 get :show, :id => @pic.id, :format => :png
178 OriginalPicture.any_instance.stub(:restore).and_return('aaa')
\r
179 get :show, :id => @pic.id, :format => :png
180 response.body.should eq 'aaa'
184 it '画像モデルに画像データを問い合わせる' do
185 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
\r
186 get :show, :id => @pic.id, :format => :gif
189 OriginalPicture.any_instance.stub(:restore).and_return('bbb')
\r
190 get :show, :id => @pic.id, :format => :gif
191 response.body.should eq 'bbb'
195 it '画像モデルに画像データを問い合わせる' do
196 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
\r
197 get :show, :id => @pic.id, :format => :jpeg
200 OriginalPicture.any_instance.stub(:restore).and_return('ccc')
\r
201 get :show, :id => @pic.id, :format => :jpeg
202 response.body.should eq 'ccc'
206 context '作家権限がないとき' do
211 it 'ステータスコード302 Foundを返す' do
212 get :show, :id => @pic.id
213 response.status.should eq 302
215 it 'サインインページへ遷移する' do
216 get :show, :id => @pic.id
217 response.body.should redirect_to '/users/sign_in'
221 it 'ステータスコード401 Unauthorizedを返す' do
222 get :show, :id => @pic.id, :format => :json
223 response.status.should eq 401
225 it '応答メッセージにUnauthorizedを返す' do
226 get :show, :id => @pic.id, :format => :json
227 response.message.should match(/Unauthorized/)
231 context '作家が絵師でないとき' do
233 Author.any_instance.stub(:artist?).and_return(false)
236 it 'ステータスコード302 Foundを返す' do
237 get :show, :id => @pic.id
238 response.status.should eq 302
241 get :show, :id => @pic.id
242 response.should redirect_to new_artist_path
246 it '例外403 forbiddenを返す' do
248 get :show, :id => @pic.id, :format => :json
249 }.should raise_error(ActiveRecord::Forbidden)
254 context '対象原画がないとき' do
256 OriginalPicture.unstub(:show)
259 it '例外404 not_foundを返す' do
262 }.should raise_error(ActiveRecord::RecordNotFound)
266 it '例外404 not_foundを返す' do
268 get :show, :id => 0, :format => :json
269 }.should raise_error(ActiveRecord::RecordNotFound)
273 context '他人の原画を見ようとしたとき' do
275 OriginalPicture.stub(:show).and_return(@pic)
276 OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(false)
279 it '例外403 forbiddenを返す' do
281 get :show, :id => @pic.id
282 }.should raise_error(ActiveRecord::Forbidden)
286 it '例外403 forbiddenを返す' do
288 get :show, :id => @pic.id, :format => :json
289 }.should raise_error(ActiveRecord::Forbidden)
296 describe '新規作成フォーム表示に於いて' do
300 context 'つつがなく終わるとき' do
301 it 'ステータスコード200 OKを返す' do
303 response.should be_success
305 it '@original_pictureに新規データを用意している' do
307 assigns(:original_picture).should be_a_new(OriginalPicture)
309 it '原画モデルにデフォルト値補充を依頼している' do
310 OriginalPicture.any_instance.should_receive(:supply_default).exactly(1)
\r
314 it 'ページテンプレートnewを描画する' do
316 response.should render_template("new")
320 it '部分テンプレートnew.jsを描画する' do
321 get :new, :format => :js
322 response.should render_template("new")
326 context '作家権限がないとき' do
331 it 'ステータスコード302 Foundを返す' do
333 response.status.should eq 302
335 it 'サインインページへ遷移する' do
337 response.body.should redirect_to '/users/sign_in'
341 it 'ステータスコード401 Unauthorizedを返す' do
342 get :new, :format => :js
343 response.status.should eq 401
345 it '応答メッセージにUnauthorizedを返す' do
346 get :new, :format => :js
347 response.message.should match(/Unauthorized/)
351 context '作家が絵師でないとき' do
353 Author.any_instance.stub(:artist?).and_return(false)
356 it 'ステータスコード302 Foundを返す' do
358 response.status.should eq 302
362 response.should redirect_to new_artist_path
366 it 'ステータスコード200 Okを返す' do
367 get :new, :format => :js
368 response.status.should eq 200
370 it '絵師登録部分テンプレートartists/new.jsを描画する' do
371 get :new, :format => :js
372 response.should render_template("artists/new")
378 describe '新規作成に於いて' do
382 context '事前チェックしておく' do
384 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
387 OriginalPicture.any_instance.should_receive(:store).exactly(1)
388 post :create, :original_picture => Factory.attributes_for(:original_picture)
390 it "@original_pictureに作成された原画を保持している" do
391 post :create, :original_picture => Factory.attributes_for(:original_picture)
392 assigns(:original_picture).should be_a(OriginalPicture)
395 context 'つつがなく終わるとき' do
397 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return {
398 assigns(:original_picture).attributes = Factory.attributes_for(:original_picture, :artist_id => @artist.id, :ext => 'jpeg')
399 assigns(:original_picture).save
403 it "作成された原画がDBにある" do
404 post :create, :original_picture => Factory.attributes_for(:original_picture)
405 assigns(:original_picture).should_not be_a_new OriginalPicture
408 it 'ステータスコード302 Foundを返す' do
409 post :create, :original_picture => Factory.attributes_for(:original_picture)
410 response.status.should eq 302
412 it '作成された原画の表示ページへ遷移する' do
413 post :create, :original_picture => Factory.attributes_for(:original_picture)
414 response.should redirect_to(OriginalPicture.last)
418 it 'ステータスコード200 OKを返す' do
419 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
420 response.should be_success
422 it '作成された原画をjsonデータで返す' do
423 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
424 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
427 post :create, :original_picture => Factory.attributes_for(:original_picture, :ext => 'jpeg'), :format => :json
428 json = JSON.parse response.body
429 json["ext"].should match(/jpeg/)
433 context '作家権限がないとき' do
438 it 'ステータスコード302 Foundを返す' do
439 post :create, :original_picture => Factory.attributes_for(:original_picture)
440 response.status.should eq 302
442 it 'サインインページへ遷移する' do
443 post :create, :original_picture => Factory.attributes_for(:original_picture)
444 response.body.should redirect_to '/users/sign_in'
448 it 'ステータスコード401 Unauthorizedを返す' do
449 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
450 response.status.should eq 401
452 it '応答メッセージにUnauthorizedを返す' do
453 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
454 response.message.should match(/Unauthorized/)
458 context '作家が絵師でないとき' do
460 Author.any_instance.stub(:artist?).and_return(false)
463 it 'ステータスコード302 Foundを返す' do
464 post :create, :original_picture => Factory.attributes_for(:original_picture)
465 response.status.should eq 302
468 post :create, :original_picture => Factory.attributes_for(:original_picture)
469 response.should redirect_to new_artist_path
473 it '例外403 forbiddenを返す' do
475 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
476 }.should raise_error(ActiveRecord::Forbidden)
480 context '検証、保存に失敗した' do
482 OriginalPicture.any_instance.stub(:store).and_return(false)
484 it "未保存のコミックを保持している" do
485 post :create, :original_picture => Factory.attributes_for(:original_picture)
486 assigns(:original_picture).should be_a_new(OriginalPicture)
489 it 'ステータスコード200 OKを返す' do
490 post :create, :original_picture => Factory.attributes_for(:original_picture)
491 response.status.should eq 200
494 post :create, :original_picture => Factory.attributes_for(:original_picture)
495 response.should render_template("new")
499 it 'ステータスコード422 unprocessable_entity を返す' do
500 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
501 response.status.should eq 422
503 it '応答メッセージUnprocessable Entityを返す' do
504 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
505 response.message.should match(/Unprocessable/)
511 describe '編集フォーム表示に於いて' do
513 @pic = Factory :original_picture, :artist_id => @artist.id
515 OriginalPicture.stub(:show).and_return(@pic)
517 context 'つつがなく終わるとき' do
518 it 'ステータスコード200 OKを返す' do
519 get :edit, :id => @pic.id
520 response.should be_success
522 it '原画モデルに単体取得を問い合わせている' do
523 OriginalPicture.should_receive(:show).exactly(1)
\r
524 get :edit, :id => @pic.id
526 it '@original_pictureにデータを用意している' do
527 get :edit, :id => @pic.id
528 assigns(:original_picture).should eq @pic
531 it 'ページテンプレートeditを描画する' do
532 get :edit, :id => @pic.id
533 response.should render_template("edit")
537 it '部分テンプレートedit.jsを描画する' do
538 get :edit, :id => @pic.id, :format => :js
539 response.should render_template("edit")
543 context '作家権限がないとき' do
548 it 'ステータスコード302 Foundを返す' do
549 get :edit, :id => @pic.id
550 response.status.should eq 302
552 it 'サインインページへ遷移する' do
553 get :edit, :id => @pic.id
554 response.body.should redirect_to '/users/sign_in'
558 it 'ステータスコード401 Unauthorizedを返す' do
559 get :edit, :id => @pic.id, :format => :js
560 response.status.should eq 401
562 it '応答メッセージにUnauthorizedを返す' do
563 get :edit, :id => @pic.id, :format => :js
564 response.message.should match(/Unauthorized/)
568 context '作家が絵師でないとき' do
570 Author.any_instance.stub(:artist?).and_return(false)
573 it 'ステータスコード302 Foundを返す' do
574 get :edit, :id => @pic.id
575 response.status.should eq 302
578 get :edit, :id => @pic.id
579 response.should redirect_to new_artist_path
583 it 'ステータスコード200 Okを返す' do
584 get :edit, :id => @pic.id, :format => :js
585 response.status.should eq 200
587 it '絵師登録部分テンプレートartists/new.jsを描画する' do
588 get :edit, :id => @pic.id, :format => :js
589 response.should render_template("artists/new")
597 @pic = Factory :original_picture, :artist_id => @artist.id
598 OriginalPicture.stub(:show).with(any_args()).and_return(@pic)
601 context '事前チェックしておく' do
603 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
605 it '原画モデルに単体取得を問い合わせている' do
606 OriginalPicture.should_receive(:show).exactly(1)
\r
607 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
610 OriginalPicture.any_instance.should_receive(:store).exactly(1)
611 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
613 it '@original_pictureにアレを取得している' do
614 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
615 assigns(:original_picture).should eq(@pic)
618 context 'つつがなく終わるとき' do
620 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return {
621 assigns(:original_picture).attributes = Factory.attributes_for(:original_picture, :artist_id => @artist.id, :ext => 'jpeg')
622 assigns(:original_picture).save
627 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture, :ext => 'jpeg')
628 OriginalPicture.find(@pic.id).ext.should eq 'jpeg'
631 it 'ステータスコード302 Foundを返す' do
632 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
633 response.status.should eq 302
635 it '更新された原画の表示ページへ遷移する' do
636 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
637 response.should redirect_to(@pic)
641 it 'ステータスコード200 OKを返す' do
642 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
643 response.should be_success
646 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
647 response.body.should match /./
651 context '作家権限がないとき' do
656 it 'ステータスコード302 Foundを返す' do
657 post :create, :original_picture => Factory.attributes_for(:original_picture)
658 response.status.should eq 302
660 it 'サインインページへ遷移する' do
661 post :create, :original_picture => Factory.attributes_for(:original_picture)
662 response.body.should redirect_to '/users/sign_in'
666 it 'ステータスコード401 Unauthorizedを返す' do
667 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
668 response.status.should eq 401
670 it '応答メッセージにUnauthorizedを返す' do
671 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
672 response.message.should match(/Unauthorized/)
676 context '作家が絵師でないとき' do
678 Author.any_instance.stub(:artist?).and_return(false)
681 it 'ステータスコード302 Foundを返す' do
682 post :create, :original_picture => Factory.attributes_for(:original_picture)
683 response.status.should eq 302
686 post :create, :original_picture => Factory.attributes_for(:original_picture)
687 response.should redirect_to new_artist_path
691 it '例外403 forbiddenを返す' do
693 post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
694 }.should raise_error(ActiveRecord::Forbidden)
698 context '検証、保存に失敗した' do
700 OriginalPicture.any_instance.stub(:store).and_return(false)
703 it 'ステータスコード200 Okを返す' do
704 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
705 response.status.should eq 200
708 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
709 response.should render_template("edit")
713 it 'ステータスコード422 unprocessable_entity を返す' do
714 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
715 response.status.should eq 422
717 it '応答メッセージUnprocessable Entityを返す' do
718 put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
719 response.message.should match(/Unprocessable/)