1 # -*- encoding: utf-8 -*-
5 describe ArtistsController do
7 @admin = FactoryGirl.create :admin
8 @sp = FactoryGirl.create :system_picture
9 @lg = FactoryGirl.create :license_group
10 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
11 @user = FactoryGirl.create( :user_yas)
12 @author = FactoryGirl.create :author, :user_id => @user.id
13 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
16 if MagicNumber['run_mode'] == 1
17 describe '一覧表示に於いて' do
19 Artist.stub(:list).and_return([@artist, @artist, @artist])
23 it '与えられた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 Artist.default_page_size
39 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
40 get :index, :page_size => 1500
41 assigns(:page_size).should eq Artist.max_page_size
43 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
44 get :index, :page_size => 0
45 assigns(:page_size).should eq Artist.default_page_size
48 context 'つつがなく終わるとき' do
49 it 'ステータスコード200 OKを返す' do
51 response.should be_success
53 it '絵師モデルに一覧を問い合わせている' do
54 Artist.should_receive(:list).exactly(1)
57 it '@artistsにリストを取得している' do
59 assigns(:artists).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 Artist.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?("name").should be_true
88 context '作家権限がないとき' do
93 it 'ステータスコード302 Foundを返す' do
95 response.status.should eq 302
99 response.should redirect_to '/users/sign_in'
103 it 'ステータスコード401 Unauthorizedを返す' do
104 get :index, :format => :json
105 response.status.should eq 401
107 it '応答メッセージにUnauthorizedを返す' do
108 get :index, :format => :json
109 response.message.should match(/Unauthorized/)
113 context '作家権限はないが管理者権限があるとき' do
118 it 'ステータスコード200 OKを返す' do
120 response.should be_success
127 Artist.stub(:show).and_return(@artist)
130 context 'つつがなく終わるとき' do
131 it 'ステータスコード200 OKを返す' do
132 get :show, :id => @artist.id
133 response.should be_success
135 it '絵師モデルに単体取得を問い合わせている' do
136 Artist.should_receive(:show).exactly(1)
139 it '@arにアレを取得している' do
140 get :show, :id => @artist.id
141 assigns(:ar).should eq(@artist)
144 it 'showテンプレートを描画する' do
145 get :show, :id => @artist.id
146 response.should render_template("show")
151 get :show, :id => @artist.id, :format => :json
152 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
154 it '絵師モデルにjson単体出力オプションを問い合わせている' do
155 Artist.should_receive(:show_json_opt).exactly(1)
156 get :show, :id => @artist.id, :format => :json
159 get :show, :id => @artist.id, :format => :json
160 json = JSON.parse response.body
161 json["name"].should match(/yas/)
165 context '作家権限がないとき' do
170 it 'ステータスコード302 Foundを返す' do
171 get :show, :id => @artist.id
172 response.status.should eq 302
174 it 'サインインページへ遷移する' do
175 get :show, :id => @artist.id
176 response.body.should redirect_to '/users/sign_in'
180 it 'ステータスコード401 Unauthorizedを返す' do
181 get :show, :id => @artist.id, :format => :json
182 response.status.should eq 401
184 it '応答メッセージにUnauthorizedを返す' do
185 get :show, :id => @artist.id, :format => :json
186 response.message.should match(/Unauthorized/)
190 context '作家権限はないが管理者権限があるとき' do
195 it 'ステータスコード200 OKを返す' do
196 get :show, :id => @artist.id
197 response.should be_success
201 context '対象作家がないとき' do
203 it '例外404 not_foundを返す' do
206 }.should raise_error(ActiveRecord::RecordNotFound)
210 it '例外404 not_foundを返す' do
212 get :show, :id => 0, :format => :json
213 }.should raise_error(ActiveRecord::RecordNotFound)
220 describe '絵師数取得に於いて' do
222 Artist.should_receive(:visible_count).and_return(3)
225 context 'つつがなく終わるとき' do
226 it 'ステータスコード200 OKを返す' do
227 get :count, :format => :json
228 response.should be_success
232 get :count, :format => :json
233 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
235 it 'データがHash構造になっていて絵師数が3である' do
236 get :count, :format => :json
237 json = JSON.parse response.body
238 json["count"].should == 3
244 describe '新規作成フォーム表示に於いて' do
248 context 'つつがなく終わるとき' do
249 it 'ステータスコード200 OKを返す' do
251 response.should be_success
253 it '@artistに新規データを用意している' do
255 assigns(:ar).should be_a_new(Artist)
257 it '絵師モデルにデフォルト値補充を依頼している' do
258 Artist.any_instance.should_receive(:supply_default).exactly(1)
262 it 'newテンプレートを描画する' do
264 response.should render_template("new")
268 it 'new.jsテンプレートを描画する' do
269 get :new, :format => :js
270 response.should render_template("new")
275 get :new, :format => :json
276 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
278 it '絵師モデルにjson単体出力オプションを問い合わせている' do
279 Artist.should_receive(:show_json_opt).exactly(1)
280 get :new, :format => :json
284 context '作家権限がないとき' do
289 it 'ステータスコード302 Foundを返す' do
291 response.status.should eq 302
293 it 'サインインページへ遷移する' do
295 response.body.should redirect_to '/users/sign_in'
299 it 'ステータスコード401 Unauthorizedを返す' do
300 get :new, :format => :js
301 response.status.should eq 401
303 it '応答メッセージにUnauthorizedを返す' do
304 get :new, :format => :js
305 response.message.should match(/Unauthorized/)
309 it 'ステータスコード401 Unauthorizedを返す' do
310 get :new, :format => :json
311 response.status.should eq 401
313 it '応答メッセージにUnauthorizedを返す' do
314 get :new, :format => :json
315 response.message.should match(/Unauthorized/)
319 context '作家権限はないが管理者権限があるとき' do
325 it 'ステータスコード302 Foundを返す' do
327 response.status.should eq 302
329 it 'サインインページへ遷移する' do
331 response.body.should redirect_to '/users/sign_in'
337 describe '新規作成に於いて' do
340 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
342 context '事前チェックしておく' do
343 it '絵師モデルにデフォルト値補充を依頼している' do
344 Artist.any_instance.should_receive(:supply_default).exactly(1)
345 post :create, :artist => @attr
347 it '絵師モデルにカラム値復元を依頼している' do
348 Artist.any_instance.should_receive(:attributes=).exactly(1)
349 post :create, :artist => @attr
351 it '絵師モデルに上書き補充を依頼している' do
352 Artist.any_instance.should_receive(:overwrite).exactly(1)
353 post :create, :artist => @attr
356 Artist.any_instance.should_receive(:save).exactly(1)
357 post :create, :artist => @attr
360 context 'つつがなく終わるとき' do
361 it "@arに作成された絵師を保持していて、それがDBにある" do
362 post :create, :artist => @attr
363 assigns(:ar).should be_a(Artist)
364 assigns(:ar).should be_persisted
367 it 'ステータスコード302 Foundを返す' do
368 Artist.any_instance.stub(:save).and_return(true)
369 post :create, :artist => @attr
370 response.status.should eq 302
373 # Artist.any_instance.stub(:save).and_return(true)
374 post :create, :artist => @attr
375 response.should redirect_to(root_path)
379 it 'ステータスコード200 OKを返す' do
380 # Artist.any_instance.stub(:save).and_return(true)
381 post :create, :artist => @attr, :format => :json
382 response.should be_success
384 it '作成された絵師をjsonデータで返す' do
385 post :create, :artist => @attr, :format => :json
386 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
388 it '絵師モデルにjson単体出力オプションを問い合わせている' do
389 Artist.should_receive(:show_json_opt).exactly(1)
390 post :create, :artist => @attr, :format => :json
393 post :create, :artist => @attr, :format => :json
394 json = JSON.parse response.body
395 json["name"].should match(/ken/)
399 context '作家権限がないとき' do
404 it 'ステータスコード302 Foundを返す' do
405 post :create, :artist => @attr
406 response.status.should eq 302
408 it 'サインインページへ遷移する' do
409 post :create, :artist => @attr
410 response.body.should redirect_to '/users/sign_in'
414 it 'ステータスコード401 Unauthorizedを返す' do
415 post :create, :artist => @attr, :format => :json
416 response.status.should eq 401
418 it '応答メッセージにUnauthorizedを返す' do
419 post :create, :artist => @attr, :format => :json
420 response.message.should match(/Unauthorized/)
424 context '作家権限はないが管理者権限があるとき' do
430 it 'ステータスコード302 Foundを返す' do
431 post :create, :artist => @attr
432 response.status.should eq 302
434 it 'サインインページへ遷移する' do
435 post :create, :artist => @attr
436 response.body.should redirect_to '/users/sign_in'
440 context '検証、保存に失敗した' do
442 Artist.any_instance.stub(:save).and_return(false)
444 it "未保存の絵師を保持している" do
445 post :create, :artist => @attr
446 assigns(:ar).should be_a_new(Artist)
449 it 'ステータスコード200 OKを返す' do
450 post :create, :artist => @attr
451 response.status.should eq 200
454 post :create, :artist => @attr
455 response.should render_template("new")
459 it 'ステータスコード422 unprocessable_entity を返す' do
460 post :create, :artist => @attr, :format => :json
461 response.status.should eq 422
463 it '応答メッセージUnprocessable Entityを返す' do
464 post :create, :artist => @attr, :format => :json
465 response.message.should match(/Unprocessable/)
471 describe '編集フォーム表示に於いて' do
474 Artist.stub(:edit).and_return(@artist)
476 context 'つつがなく終わるとき' do
477 it 'ステータスコード200 OKを返す' do
478 get :edit, :id => @artist.id
479 response.should be_success
481 it '絵師モデルに編集取得を問い合わせている' do
482 Artist.should_receive(:edit).exactly(1)
483 get :edit, :id => @artist.id
485 it '@artistにデータを用意している' do
486 get :edit, :id => @artist.id
487 assigns(:artist).should eq @artist
490 it 'editテンプレートを描画する' do
491 get :edit, :id => @artist.id
492 response.should render_template("edit")
496 it 'edit.jsテンプレートを描画する' do
497 get :edit, :id => @artist.id, :format => :js
498 response.should render_template("edit")
502 context '作家権限がないとき' do
507 it 'ステータスコード302 Foundを返す' do
508 get :edit, :id => @artist.id
509 response.status.should eq 302
511 it 'サインインページへ遷移する' do
512 get :edit, :id => @artist.id
513 response.body.should redirect_to '/users/sign_in'
517 it 'ステータスコード401 Unauthorizedを返す' do
518 get :edit, :id => @artist.id, :format => :js
519 response.status.should eq 401
521 it '応答メッセージにUnauthorizedを返す' do
522 get :edit, :id => @artist.id, :format => :js
523 response.message.should match(/Unauthorized/)
527 context '作家権限はないが管理者権限があるとき' do
533 it 'ステータスコード302 Foundを返す' do
534 get :edit, :id => @artist.id
535 response.status.should eq 302
537 it 'サインインページへ遷移する' do
538 get :edit, :id => @artist.id
539 response.body.should redirect_to '/users/sign_in'
547 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
550 context '事前チェックしておく' do
551 it '絵師モデルに編集取得を問い合わせている' do
552 Artist.stub(:edit).with(any_args()).and_return @artist
553 Artist.should_receive(:edit).exactly(1)
554 put :update, :id => @artist.id, :artist => @attr
556 it '絵師モデルにカラム値復元を依頼している' do
557 Artist.any_instance.should_receive(:attributes=).exactly(1)
558 put :update, :id => @artist.id, :artist => @attr
560 it '絵師モデルに上書き補充を依頼している' do
561 Artist.any_instance.should_receive(:overwrite).exactly(1)
562 put :update, :id => @artist.id, :artist => @attr
565 Artist.any_instance.stub(:save).with(any_args).and_return true
566 Artist.any_instance.should_receive(:save).exactly(1)
567 put :update, :id => @artist.id, :artist => @attr
569 it '@arにアレを取得している' do
570 put :update, :id => @artist.id, :artist => @attr
571 assigns(:ar).should eq @artist
574 context 'つつがなく終わるとき' do
576 put :update, :id => @artist.id, :artist => @attr
577 Artist.find(@artist.id).name.should eq 'ryu'
580 it 'ステータスコード302 Foundを返す' do
581 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
582 put :update, :id => @artist.id, :artist => @attr
583 response.status.should eq 302
586 put :update, :id => @artist.id, :artist => @attr
587 response.should redirect_to('/home/configure')
591 it 'ステータスコード200 OKを返す' do
592 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
593 put :update, :id => @artist.id, :artist => @attr, :format => :json
594 response.should be_success
597 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
598 put :update, :id => @artist.id, :artist => @attr, :format => :json
599 response.body.should match /./
603 context '作家権限がないとき' do
608 it 'ステータスコード302 Foundを返す' do
609 put :update, :id => @artist.id, :artist => @attr
610 response.status.should eq 302
612 it 'サインインページへ遷移する' do
613 put :update, :id => @artist.id, :artist => @attr
614 response.body.should redirect_to '/users/sign_in'
618 it '応答メッセージにUnauthorizedを返す' do
619 put :update, :id => @artist.id, :artist => @attr, :format => :json
620 response.message.should match(/Unauthorized/)
624 context '作家権限はないが管理者権限があるとき' do
630 it 'ステータスコード302 Foundを返す' do
631 put :update, :id => @artist.id, :artist => @attr
632 response.status.should eq 302
634 it 'サインインページへ遷移する' do
635 put :update, :id => @artist.id, :artist => @attr
636 response.body.should redirect_to '/users/sign_in'
640 context '検証、保存に失敗したとき' do
642 Artist.any_instance.stub(:save).and_return(false)
645 it 'ステータスコード200 Okを返す' do
646 put :update, :id => @artist.id, :artist => @attr
647 response.status.should eq 200
650 put :update, :id => @artist.id, :artist => @attr
651 response.should render_template("edit")
655 it 'ステータスコード422 unprocessable_entity を返す' do
656 Artist.any_instance.stub(:save).and_return(false)
657 put :update, :id => @artist.id, :artist => @attr, :format => :json
658 response.status.should eq 422
660 it '応答メッセージUnprocessable Entityを返す' do
661 put :update, :id => @artist.id, :artist => @attr, :format => :json
662 response.message.should match(/Unprocessable/)
669 describe '一覧表示に於いて' do
671 Artist.stub(:list).and_return([@artist, @artist, @artist])
674 context 'つつがなく終わるとき' do
675 it 'ステータスコード200 OKを返す' do
677 response.should be_success
680 it 'indexテンプレートを描画する' do
682 response.should render_template("index")
687 get :index, :format => :json
688 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
692 context '作家権限がないとき' do
696 it 'ステータスコード200 OKを返す' do
698 response.should be_success
701 it 'indexテンプレートを描画する' do
703 response.should render_template("index")
708 get :index, :format => :json
709 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
717 Artist.stub(:show).and_return(@artist)
720 context 'つつがなく終わるとき' do
721 it 'ステータスコード200 OKを返す' do
722 get :show, :id => @artist.id
723 response.should be_success
726 it 'showテンプレートを描画する' do
727 get :show, :id => @artist.id
728 response.should render_template("show")
733 get :show, :id => @artist.id, :format => :json
734 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
738 context '作家権限がないとき' do
742 it 'ステータスコード200 OKを返す' do
743 get :show, :id => @artist.id
744 response.should be_success
747 it 'showテンプレートを描画する' do
748 get :show, :id => @artist.id
749 response.should render_template("show")
754 get :show, :id => @artist.id, :format => :json
755 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
761 describe '絵師数取得に於いて' do
763 Artist.should_receive(:visible_count).and_return(3)
766 context 'つつがなく終わるとき' do
767 it 'ステータスコード200 OKを返す' do
768 get :count, :format => :json
769 response.should be_success
773 get :count, :format => :json
774 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
780 describe '新規作成フォーム表示に於いて' do
784 context 'つつがなく終わるとき' do
785 it 'ステータスコード200 OKを返す' do
787 response.should be_success
790 it 'newテンプレートを描画する' do
792 response.should render_template("new")
796 it 'new.jsテンプレートを描画する' do
797 get :new, :format => :js
798 response.should render_template("new")
803 get :new, :format => :json
804 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
808 context '作家権限がないとき' do
813 it 'ステータスコード302 Foundを返す' do
815 response.status.should eq 302
817 it 'サインインページへ遷移する' do
819 response.body.should redirect_to '/users/sign_in'
823 it 'ステータスコード401 Unauthorizedを返す' do
824 get :new, :format => :js
825 response.status.should eq 401
827 it '応答メッセージにUnauthorizedを返す' do
828 get :new, :format => :js
829 response.message.should match(/Unauthorized/)
833 it 'ステータスコード401 Unauthorizedを返す' do
834 get :new, :format => :json
835 response.status.should eq 401
837 it '応答メッセージにUnauthorizedを返す' do
838 get :new, :format => :json
839 response.message.should match(/Unauthorized/)
845 describe '新規作成に於いて' do
848 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
850 context 'つつがなく終わるとき' do
852 it 'ステータスコード302 Foundを返す' do
853 Artist.any_instance.stub(:save).and_return(true)
854 post :create, :artist => @attr
855 response.status.should eq 302
858 # Artist.any_instance.stub(:save).and_return(true)
859 post :create, :artist => @attr
860 response.should redirect_to(root_path)
864 it 'ステータスコード200 OKを返す' do
865 # Artist.any_instance.stub(:save).and_return(true)
866 post :create, :artist => @attr, :format => :json
867 response.should be_success
869 it '作成された絵師をjsonデータで返す' do
870 post :create, :artist => @attr, :format => :json
871 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
875 context '作家権限がないとき' do
880 it 'ステータスコード302 Foundを返す' do
881 post :create, :artist => @attr
882 response.status.should eq 302
884 it 'サインインページへ遷移する' do
885 post :create, :artist => @attr
886 response.body.should redirect_to '/users/sign_in'
890 it 'ステータスコード401 Unauthorizedを返す' do
891 post :create, :artist => @attr, :format => :json
892 response.status.should eq 401
894 it '応答メッセージにUnauthorizedを返す' do
895 post :create, :artist => @attr, :format => :json
896 response.message.should match(/Unauthorized/)
902 describe '編集フォーム表示に於いて' do
905 Artist.stub(:edit).and_return(@artist)
907 context 'つつがなく終わるとき' do
908 it 'ステータスコード200 OKを返す' do
909 get :edit, :id => @artist.id
910 response.should be_success
913 it 'editテンプレートを描画する' do
914 get :edit, :id => @artist.id
915 response.should render_template("edit")
919 it 'edit.jsテンプレートを描画する' do
920 get :edit, :id => @artist.id, :format => :js
921 response.should render_template("edit")
925 context '作家権限がないとき' do
930 it 'ステータスコード302 Foundを返す' do
931 get :edit, :id => @artist.id
932 response.status.should eq 302
934 it 'サインインページへ遷移する' do
935 get :edit, :id => @artist.id
936 response.body.should redirect_to '/users/sign_in'
940 it 'ステータスコード401 Unauthorizedを返す' do
941 get :edit, :id => @artist.id, :format => :js
942 response.status.should eq 401
944 it '応答メッセージにUnauthorizedを返す' do
945 get :edit, :id => @artist.id, :format => :js
946 response.message.should match(/Unauthorized/)
954 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
957 context 'つつがなく終わるとき' do
959 it 'ステータスコード302 Foundを返す' do
960 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
961 put :update, :id => @artist.id, :artist => @attr
962 response.status.should eq 302
965 put :update, :id => @artist.id, :artist => @attr
966 response.should redirect_to('/home/configure')
970 it 'ステータスコード200 OKを返す' do
971 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
972 put :update, :id => @artist.id, :artist => @attr, :format => :json
973 response.should be_success
976 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
977 put :update, :id => @artist.id, :artist => @attr, :format => :json
978 response.body.should match /./
982 context '作家権限がないとき' do
986 it 'ステータスコード302 Foundを返す' do
987 put :update, :id => @artist.id, :artist => @attr
988 response.status.should eq 302
991 it 'サインインページへ遷移する' do
992 put :update, :id => @artist.id, :artist => @attr
993 response.body.should redirect_to '/users/sign_in'
997 it '応答メッセージにUnauthorizedを返す' do
998 put :update, :id => @artist.id, :artist => @attr, :format => :json
999 response.message.should match(/Unauthorized/)