1 # -*- encoding: utf-8 -*-
5 describe OriginalPicturesController do
7 FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
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 describe '一覧表示に於いて' do
18 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
20 OriginalPicture.stub(:mylist).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
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(:mylist).exactly(1)
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 '原画モデルにjson一覧出力オプションを問い合わせている' do
73 OriginalPicture.should_receive(:list_json_opt).exactly(1)
74 get :index, :format => :json
76 it 'データがリスト構造になっている' do
77 get :index, :format => :json
78 json = JSON.parse response.body
79 json.should have_at_least(3).items
81 it 'リストの先頭くらいは原画っぽいものであって欲しい' do
82 get :index, :format => :json
83 json = JSON.parse response.body
84 json.first.has_key?("ext").should be_true
85 json.first.has_key?("md5").should be_true
86 json.first.has_key?("artist_id").should be_true
87 json.first.has_key?("width").should be_true
91 context '作家権限がないとき' do
96 it 'ステータスコード302 Foundを返す' do
98 response.status.should eq 302
100 it 'サインインページへ遷移する' do
102 response.should redirect_to '/users/sign_in'
106 it 'ステータスコード401 Unauthorizedを返す' do
107 get :index, :format => :json
108 response.status.should eq 401
110 it '応答メッセージにUnauthorizedを返す' do
111 get :index, :format => :json
112 response.message.should match(/Unauthorized/)
116 context '作家が絵師でないとき' do
118 Author.any_instance.stub(:artist?).and_return(false)
121 it 'ステータスコード302 Foundを返す' do
123 response.status.should eq 302
127 response.should redirect_to new_artist_path
131 it '例外403 forbiddenを返す' do
133 get :index, :format => :json
134 }.should raise_error(ActiveRecord::Forbidden)
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)
171 get :show, :id => @pic.id, :format => :json
172 json = JSON.parse response.body
173 json["ext"].should match(/png/)
176 #画像送信では、send_dataにスタブをおいてテストしたいが、ここに噛ませると
177 #renderが働かず、エラーとなってしまう。そこで、原画のファイル取得部分に
178 #スタブをおいてsend_dataがデータを返す体裁でテストする。
180 it '画像モデルに画像データを問い合わせる' do
181 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
182 get :show, :id => @pic.id, :format => :png
184 it '画像モデルにMimeTypeを問い合わせる' do
185 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
186 get :show, :id => @pic.id, :format => :png
189 OriginalPicture.any_instance.stub(:restore).and_return('aaa')
190 get :show, :id => @pic.id, :format => :png
191 response.body.should eq 'aaa'
195 it '画像モデルに画像データを問い合わせる' do
196 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
197 get :show, :id => @pic.id, :format => :gif
199 it '画像モデルにMimeTypeを問い合わせる' do
200 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
201 get :show, :id => @pic.id, :format => :gif
204 OriginalPicture.any_instance.stub(:restore).and_return('bbb')
205 get :show, :id => @pic.id, :format => :gif
206 response.body.should eq 'bbb'
210 it '画像モデルに画像データを問い合わせる' do
211 OriginalPicture.any_instance.should_receive(:restore).exactly(1)
212 get :show, :id => @pic.id, :format => :jpeg
214 it '画像モデルにMimeTypeを問い合わせる' do
215 OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
216 get :show, :id => @pic.id, :format => :jpeg
219 OriginalPicture.any_instance.stub(:restore).and_return('ccc')
220 get :show, :id => @pic.id, :format => :jpeg
221 response.body.should eq 'ccc'
225 context '作家権限がないとき' do
230 it 'ステータスコード302 Foundを返す' do
231 get :show, :id => @pic.id
232 response.status.should eq 302
234 it 'サインインページへ遷移する' do
235 get :show, :id => @pic.id
236 response.body.should redirect_to '/users/sign_in'
240 it 'ステータスコード401 Unauthorizedを返す' do
241 get :show, :id => @pic.id, :format => :json
242 response.status.should eq 401
244 it '応答メッセージにUnauthorizedを返す' do
245 get :show, :id => @pic.id, :format => :json
246 response.message.should match(/Unauthorized/)
250 context '作家が絵師でないとき' do
252 Author.any_instance.stub(:artist?).and_return(false)
255 it 'ステータスコード302 Foundを返す' do
256 get :show, :id => @pic.id
257 response.status.should eq 302
260 get :show, :id => @pic.id
261 response.should redirect_to new_artist_path
265 it '例外403 forbiddenを返す' do
267 get :show, :id => @pic.id, :format => :json
268 }.should raise_error(ActiveRecord::Forbidden)
273 context '対象原画がないとき' do
275 OriginalPicture.unstub(:show)
278 it '例外404 not_foundを返す' do
281 }.should raise_error(ActiveRecord::RecordNotFound)
285 it '例外404 not_foundを返す' do
287 get :show, :id => 0, :format => :json
288 }.should raise_error(ActiveRecord::RecordNotFound)
292 context '他人の原画を見ようとしたとき' do
294 OriginalPicture.stub(:show).and_return(@pic)
295 OriginalPicture.any_instance.stub(:own?).with(any_args()).and_return(false)
298 it '例外403 forbiddenを返す' do
300 get :show, :id => @pic.id
301 }.should raise_error(ActiveRecord::Forbidden)
305 it '例外403 forbiddenを返す' do
307 get :show, :id => @pic.id, :format => :json
308 }.should raise_error(ActiveRecord::Forbidden)
315 describe '履歴一覧表示に於いて' do
317 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
318 @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
319 :original_picture_id => @op.id
321 OriginalPicture.stub(:show).and_return(@op)
322 OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
324 context 'つつがなく終わるとき' do
325 it 'ステータスコード200 OKを返す' do
326 get :history, :id => @op.id
327 response.should be_success
329 it '原画モデルに単体取得を問い合わせている' do
330 OriginalPicture.should_receive(:show).exactly(1)
331 get :history, :id => @op.id
333 it '自身に履歴一覧を問い合わせている' do
334 OriginalPicture.any_instance.should_receive(:history).exactly(1)
337 it '@historyにリストを取得している' do
338 get :history, :id => @op.id
339 assigns(:history).should have_at_least(3).items
342 it 'historyテンプレートを描画する' do
343 get :history, :id => @op.id
344 response.should render_template("history")
349 get :history, :id => @op.id, :format => :json
350 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
352 it 'データがリスト構造になっている' do
353 get :history, :id => @op.id, :format => :json
354 json = JSON.parse response.body
355 json.should have_at_least(3).items
357 it 'リストの先頭くらいは原画っぽいものであって欲しい' do
358 get :history, :id => @op.id, :format => :json
359 json = JSON.parse response.body
360 json.first.has_key?("ext").should be_true
364 context '作家権限がないとき' do
369 it 'ステータスコード302 Foundを返す' do
370 get :history, :id => @op.id
371 response.status.should eq 302
373 it 'サインインページへ遷移する' do
374 get :history, :id => @op.id
375 response.should redirect_to '/users/sign_in'
379 it 'ステータスコード401 Unauthorizedを返す' do
380 get :history, :id => @op.id, :format => :json
381 response.status.should eq 401
383 it '応答メッセージにUnauthorizedを返す' do
384 get :history, :id => @op.id, :format => :json
385 response.message.should match(/Unauthorized/)
389 context '作家が絵師でないとき' do
391 Author.any_instance.stub(:artist?).and_return(false)
394 it 'ステータスコード302 Foundを返す' do
395 get :history, :id => @op.id
396 response.status.should eq 302
399 get :history, :id => @op.id
400 response.should redirect_to new_artist_path
404 it '例外403 forbiddenを返す' do
406 get :history, :id => @op.id, :format => :json
407 }.should raise_error(ActiveRecord::Forbidden)
413 describe '新規作成フォーム表示に於いて' do
417 context 'つつがなく終わるとき' do
418 it 'ステータスコード200 OKを返す' do
420 response.should be_success
422 it '@original_pictureに新規データを用意している' do
424 assigns(:original_picture).should be_a_new(OriginalPicture)
426 it '原画モデルにデフォルト値補充を依頼している' do
427 OriginalPicture.any_instance.should_receive(:supply_default).exactly(1)
431 it 'ページテンプレートnewを描画する' do
433 response.should render_template("new")
437 it '部分テンプレートnew.jsを描画する' do
438 get :new, :format => :js
439 response.should render_template("new")
445 get :new, :format => :json
446 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
448 it '原画モデルにjson単体出力オプションを問い合わせている' do
449 OriginalPicture.should_receive(:show_json_opt).exactly(1)
450 get :new, :format => :json
453 context '作家権限がないとき' do
458 it 'ステータスコード302 Foundを返す' do
460 response.status.should eq 302
462 it 'サインインページへ遷移する' do
464 response.body.should redirect_to '/users/sign_in'
468 it 'ステータスコード401 Unauthorizedを返す' do
469 get :new, :format => :js
470 response.status.should eq 401
472 it '応答メッセージにUnauthorizedを返す' do
473 get :new, :format => :js
474 response.message.should match(/Unauthorized/)
478 context '作家が絵師でないとき' do
480 Author.any_instance.stub(:artist?).and_return(false)
483 it 'ステータスコード302 Foundを返す' do
485 response.status.should eq 302
489 response.should redirect_to new_artist_path
493 it 'ステータスコード200 Okを返す' do
494 get :new, :format => :js
495 response.status.should eq 200
497 it '絵師登録部分テンプレートartists/new.jsを描画する' do
498 get :new, :format => :js
499 response.should render_template("artists/new")
503 it '例外403 forbiddenを返す' do
505 get :new, :format => :json
506 }.should raise_error(ActiveRecord::Forbidden)
512 describe '新規作成に於いて' do
516 context '事前チェックしておく' do
518 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
521 OriginalPicture.any_instance.should_receive(:store).exactly(1)
522 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
524 it "@original_pictureに作成された原画を保持している" do
525 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
526 assigns(:original_picture).should be_a(OriginalPicture)
529 context 'つつがなく終わるとき' do
531 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return {
532 assigns(:original_picture).attributes = FactoryGirl.attributes_for(:original_picture, :artist_id => @artist.id, :ext => 'jpeg')
533 assigns(:original_picture).save
537 it "作成された原画がDBにある" do
538 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
539 assigns(:original_picture).should_not be_a_new OriginalPicture
542 it 'ステータスコード302 Foundを返す' do
543 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
544 response.status.should eq 302
546 it '作成された原画の表示ページへ遷移する' do
547 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
548 response.should redirect_to(OriginalPicture.last)
552 it 'ステータスコード200 OKを返す' do
553 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture), :format => :json
554 response.should be_success
556 it '作成された原画をjsonデータで返す' do
557 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture), :format => :json
558 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
561 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture, :ext => 'jpeg'), :format => :json
562 json = JSON.parse response.body
563 json["ext"].should match(/jpeg/)
567 context '作家権限がないとき' do
572 it 'ステータスコード302 Foundを返す' do
573 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
574 response.status.should eq 302
576 it 'サインインページへ遷移する' do
577 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
578 response.body.should redirect_to '/users/sign_in'
582 it 'ステータスコード401 Unauthorizedを返す' do
583 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture), :format => :json
584 response.status.should eq 401
586 it '応答メッセージにUnauthorizedを返す' do
587 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture), :format => :json
588 response.message.should match(/Unauthorized/)
592 context '作家が絵師でないとき' do
594 Author.any_instance.stub(:artist?).and_return(false)
597 it 'ステータスコード302 Foundを返す' do
598 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
599 response.status.should eq 302
602 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
603 response.should redirect_to new_artist_path
607 it '例外403 forbiddenを返す' do
609 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture), :format => :json
610 }.should raise_error(ActiveRecord::Forbidden)
614 context '検証、保存に失敗した' do
616 OriginalPicture.any_instance.stub(:store).and_return(false)
618 it "未保存のコミックを保持している" do
619 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
620 assigns(:original_picture).should be_a_new(OriginalPicture)
623 it 'ステータスコード200 OKを返す' do
624 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
625 response.status.should eq 200
628 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
629 response.should render_template("new")
633 it 'ステータスコード422 unprocessable_entity を返す' do
634 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture), :format => :json
635 response.status.should eq 422
637 it '応答メッセージUnprocessable Entityを返す' do
638 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture), :format => :json
639 response.message.should match(/Unprocessable/)
645 describe '編集フォーム表示に於いて' do
647 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
649 OriginalPicture.stub(:show).and_return(@pic)
651 context 'つつがなく終わるとき' do
652 it 'ステータスコード200 OKを返す' do
653 get :edit, :id => @pic.id
654 response.should be_success
656 it '原画モデルに編集取得を問い合わせている' do
657 OriginalPicture.should_receive(:edit).exactly(1)
658 get :edit, :id => @pic.id
660 it '@original_pictureにデータを用意している' do
661 get :edit, :id => @pic.id
662 assigns(:original_picture).should eq @pic
665 it 'ページテンプレートeditを描画する' do
666 get :edit, :id => @pic.id
667 response.should render_template("edit")
671 it '部分テンプレートedit.jsを描画する' do
672 get :edit, :id => @pic.id, :format => :js
673 response.should render_template("edit")
677 context '作家権限がないとき' do
682 it 'ステータスコード302 Foundを返す' do
683 get :edit, :id => @pic.id
684 response.status.should eq 302
686 it 'サインインページへ遷移する' do
687 get :edit, :id => @pic.id
688 response.body.should redirect_to '/users/sign_in'
692 it 'ステータスコード401 Unauthorizedを返す' do
693 get :edit, :id => @pic.id, :format => :js
694 response.status.should eq 401
696 it '応答メッセージにUnauthorizedを返す' do
697 get :edit, :id => @pic.id, :format => :js
698 response.message.should match(/Unauthorized/)
702 context '作家が絵師でないとき' do
704 Author.any_instance.stub(:artist?).and_return(false)
707 it 'ステータスコード302 Foundを返す' do
708 get :edit, :id => @pic.id
709 response.status.should eq 302
712 get :edit, :id => @pic.id
713 response.should redirect_to new_artist_path
717 it 'ステータスコード200 Okを返す' do
718 get :edit, :id => @pic.id, :format => :js
719 response.status.should eq 200
721 it '絵師登録部分テンプレートartists/new.jsを描画する' do
722 get :edit, :id => @pic.id, :format => :js
723 response.should render_template("artists/new")
731 @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
732 OriginalPicture.stub(:edit).with(any_args()).and_return(@pic)
735 context '事前チェックしておく' do
737 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
739 it '原画モデルに単体取得を問い合わせている' do
740 OriginalPicture.should_receive(:edit).exactly(1)
741 put :update, :id => @pic.id, :original_picture => FactoryGirl.attributes_for(:original_picture)
744 OriginalPicture.any_instance.should_receive(:store).exactly(1)
745 put :update, :id => @pic.id, :original_picture => FactoryGirl.attributes_for(:original_picture)
747 it '@original_pictureにアレを取得している' do
748 put :update, :id => @pic.id, :original_picture => FactoryGirl.attributes_for(:original_picture)
749 assigns(:original_picture).should eq(@pic)
752 context 'つつがなく終わるとき' do
754 OriginalPicture.any_instance.stub(:store).with(any_args()).and_return {
755 assigns(:original_picture).attributes = FactoryGirl.attributes_for(:original_picture, :artist_id => @artist.id, :ext => 'jpeg')
756 assigns(:original_picture).save
761 put :update, :id => @pic.id, :original_picture => FactoryGirl.attributes_for(:original_picture, :ext => 'jpeg')
762 OriginalPicture.find(@pic.id).ext.should eq 'jpeg'
765 it 'ステータスコード302 Foundを返す' do
766 put :update, :id => @pic.id, :original_picture => FactoryGirl.attributes_for(:original_picture)
767 response.status.should eq 302
769 it '更新された原画の表示ページへ遷移する' do
770 put :update, :id => @pic.id, :original_picture => FactoryGirl.attributes_for(:original_picture)
771 response.should redirect_to(@pic)
775 it 'ステータスコード200 OKを返す' do
776 put :update, :id => @pic.id, :original_picture => FactoryGirl.attributes_for(:original_picture), :format => :json
777 response.should be_success
780 put :update, :id => @pic.id, :original_picture => FactoryGirl.attributes_for(:original_picture), :format => :json
781 response.body.should match /./
785 context '作家権限がないとき' do
790 it 'ステータスコード302 Foundを返す' do
791 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
792 response.status.should eq 302
794 it 'サインインページへ遷移する' do
795 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
796 response.body.should redirect_to '/users/sign_in'
800 it 'ステータスコード401 Unauthorizedを返す' do
801 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture), :format => :json
802 response.status.should eq 401
804 it '応答メッセージにUnauthorizedを返す' do
805 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture), :format => :json
806 response.message.should match(/Unauthorized/)
810 context '作家が絵師でないとき' do
812 Author.any_instance.stub(:artist?).and_return(false)
815 it 'ステータスコード302 Foundを返す' do
816 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
817 response.status.should eq 302
820 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture)
821 response.should redirect_to new_artist_path
825 it '例外403 forbiddenを返す' do
827 post :create, :original_picture => FactoryGirl.attributes_for(:original_picture), :format => :json
828 }.should raise_error(ActiveRecord::Forbidden)
832 context '検証、保存に失敗した' do
834 OriginalPicture.any_instance.stub(:store).and_return(false)
837 it 'ステータスコード200 Okを返す' do
838 put :update, :id => @pic.id, :original_picture => FactoryGirl.attributes_for(:original_picture)
839 response.status.should eq 200
842 put :update, :id => @pic.id, :original_picture => FactoryGirl.attributes_for(:original_picture)
843 response.should render_template("edit")
847 it 'ステータスコード422 unprocessable_entity を返す' do
848 put :update, :id => @pic.id, :original_picture => FactoryGirl.attributes_for(:original_picture), :format => :json
849 response.status.should eq 422
851 it '応答メッセージUnprocessable Entityを返す' do
852 put :update, :id => @pic.id, :original_picture => FactoryGirl.attributes_for(:original_picture), :format => :json
853 response.message.should match(/Unprocessable/)