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/)
117 Artist.stub(:show).and_return(@artist)
120 context 'つつがなく終わるとき' do
121 it 'ステータスコード200 OKを返す' do
122 get :show, :id => @artist.id
123 response.should be_success
125 it '絵師モデルに単体取得を問い合わせている' do
126 Artist.should_receive(:show).exactly(1)
129 it '@arにアレを取得している' do
130 get :show, :id => @artist.id
131 assigns(:ar).should eq(@artist)
134 it 'showテンプレートを描画する' do
135 get :show, :id => @artist.id
136 response.should render_template("show")
141 get :show, :id => @artist.id, :format => :json
142 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
144 it '絵師モデルにjson単体出力オプションを問い合わせている' do
145 Artist.should_receive(:show_json_opt).exactly(1)
146 get :show, :id => @artist.id, :format => :json
149 get :show, :id => @artist.id, :format => :json
150 json = JSON.parse response.body
151 json["name"].should match(/yas/)
155 context '作家権限がないとき' do
160 it 'ステータスコード302 Foundを返す' do
161 get :show, :id => @artist.id
162 response.status.should eq 302
164 it 'サインインページへ遷移する' do
165 get :show, :id => @artist.id
166 response.body.should redirect_to '/users/sign_in'
170 it 'ステータスコード401 Unauthorizedを返す' do
171 get :show, :id => @artist.id, :format => :json
172 response.status.should eq 401
174 it '応答メッセージにUnauthorizedを返す' do
175 get :show, :id => @artist.id, :format => :json
176 response.message.should match(/Unauthorized/)
181 context '対象作家がないとき' do
183 it '例外404 not_foundを返す' do
186 }.should raise_error(ActiveRecord::RecordNotFound)
190 it '例外404 not_foundを返す' do
192 get :show, :id => 0, :format => :json
193 }.should raise_error(ActiveRecord::RecordNotFound)
200 describe '絵師数取得に於いて' do
202 Artist.should_receive(:visible_count).and_return(3)
205 context 'つつがなく終わるとき' do
206 it 'ステータスコード200 OKを返す' do
207 get :count, :format => :json
208 response.should be_success
212 get :count, :format => :json
213 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
215 it 'データがHash構造になっていて絵師数が3である' do
216 get :count, :format => :json
217 json = JSON.parse response.body
218 json["count"].should == 3
224 describe '新規作成フォーム表示に於いて' do
228 context 'つつがなく終わるとき' do
229 it 'ステータスコード200 OKを返す' do
231 response.should be_success
233 it '@artistに新規データを用意している' do
235 assigns(:ar).should be_a_new(Artist)
237 it '絵師モデルにデフォルト値補充を依頼している' do
238 Artist.any_instance.should_receive(:supply_default).exactly(1)
242 it 'newテンプレートを描画する' do
244 response.should render_template("new")
248 it 'new.jsテンプレートを描画する' do
249 get :new, :format => :js
250 response.should render_template("new")
255 get :new, :format => :json
256 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
258 it '絵師モデルにjson単体出力オプションを問い合わせている' do
259 Artist.should_receive(:show_json_opt).exactly(1)
260 get :new, :format => :json
264 context '作家権限がないとき' do
269 it 'ステータスコード302 Foundを返す' do
271 response.status.should eq 302
273 it 'サインインページへ遷移する' do
275 response.body.should redirect_to '/users/sign_in'
279 it 'ステータスコード401 Unauthorizedを返す' do
280 get :new, :format => :js
281 response.status.should eq 401
283 it '応答メッセージにUnauthorizedを返す' do
284 get :new, :format => :js
285 response.message.should match(/Unauthorized/)
289 it 'ステータスコード401 Unauthorizedを返す' do
290 get :new, :format => :json
291 response.status.should eq 401
293 it '応答メッセージにUnauthorizedを返す' do
294 get :new, :format => :json
295 response.message.should match(/Unauthorized/)
301 describe '新規作成に於いて' do
304 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
306 context '事前チェックしておく' do
307 it '絵師モデルにデフォルト値補充を依頼している' do
308 Artist.any_instance.should_receive(:supply_default).exactly(1)
309 post :create, :artist => @attr
311 it '絵師モデルにカラム値復元を依頼している' do
312 Artist.any_instance.should_receive(:attributes=).exactly(1)
313 post :create, :artist => @attr
315 it '絵師モデルに上書き補充を依頼している' do
316 Artist.any_instance.should_receive(:overwrite).exactly(1)
317 post :create, :artist => @attr
320 Artist.any_instance.should_receive(:save).exactly(1)
321 post :create, :artist => @attr
324 context 'つつがなく終わるとき' do
325 it "@arに作成された絵師を保持していて、それがDBにある" do
326 post :create, :artist => @attr
327 assigns(:ar).should be_a(Artist)
328 assigns(:ar).should be_persisted
331 it 'ステータスコード302 Foundを返す' do
332 Artist.any_instance.stub(:save).and_return(true)
333 post :create, :artist => @attr
334 response.status.should eq 302
337 # Artist.any_instance.stub(:save).and_return(true)
338 post :create, :artist => @attr
339 response.should redirect_to(root_path)
343 it 'ステータスコード200 OKを返す' do
344 # Artist.any_instance.stub(:save).and_return(true)
345 post :create, :artist => @attr, :format => :json
346 response.should be_success
348 it '作成された絵師をjsonデータで返す' do
349 post :create, :artist => @attr, :format => :json
350 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
352 it '絵師モデルにjson単体出力オプションを問い合わせている' do
353 Artist.should_receive(:show_json_opt).exactly(1)
354 post :create, :artist => @attr, :format => :json
357 post :create, :artist => @attr, :format => :json
358 json = JSON.parse response.body
359 json["name"].should match(/ken/)
363 context '作家権限がないとき' do
368 it 'ステータスコード302 Foundを返す' do
369 post :create, :artist => @attr
370 response.status.should eq 302
372 it 'サインインページへ遷移する' do
373 post :create, :artist => @attr
374 response.body.should redirect_to '/users/sign_in'
378 it 'ステータスコード401 Unauthorizedを返す' do
379 post :create, :artist => @attr, :format => :json
380 response.status.should eq 401
382 it '応答メッセージにUnauthorizedを返す' do
383 post :create, :artist => @attr, :format => :json
384 response.message.should match(/Unauthorized/)
388 context '検証、保存に失敗した' do
390 Artist.any_instance.stub(:save).and_return(false)
392 it "未保存の絵師を保持している" do
393 post :create, :artist => @attr
394 assigns(:ar).should be_a_new(Artist)
397 it 'ステータスコード200 OKを返す' do
398 post :create, :artist => @attr
399 response.status.should eq 200
402 post :create, :artist => @attr
403 response.should render_template("new")
407 it 'ステータスコード422 unprocessable_entity を返す' do
408 post :create, :artist => @attr, :format => :json
409 response.status.should eq 422
411 it '応答メッセージUnprocessable Entityを返す' do
412 post :create, :artist => @attr, :format => :json
413 response.message.should match(/Unprocessable/)
419 describe '編集フォーム表示に於いて' do
422 Artist.stub(:edit).and_return(@artist)
424 context 'つつがなく終わるとき' do
425 it 'ステータスコード200 OKを返す' do
426 get :edit, :id => @artist.id
427 response.should be_success
429 it '絵師モデルに編集取得を問い合わせている' do
430 Artist.should_receive(:edit).exactly(1)
431 get :edit, :id => @artist.id
433 it '@artistにデータを用意している' do
434 get :edit, :id => @artist.id
435 assigns(:artist).should eq @artist
438 it 'editテンプレートを描画する' do
439 get :edit, :id => @artist.id
440 response.should render_template("edit")
444 it 'edit.jsテンプレートを描画する' do
445 get :edit, :id => @artist.id, :format => :js
446 response.should render_template("edit")
450 context '作家権限がないとき' do
455 it 'ステータスコード302 Foundを返す' do
456 get :edit, :id => @artist.id
457 response.status.should eq 302
459 it 'サインインページへ遷移する' do
460 get :edit, :id => @artist.id
461 response.body.should redirect_to '/users/sign_in'
465 it 'ステータスコード401 Unauthorizedを返す' do
466 get :edit, :id => @artist.id, :format => :js
467 response.status.should eq 401
469 it '応答メッセージにUnauthorizedを返す' do
470 get :edit, :id => @artist.id, :format => :js
471 response.message.should match(/Unauthorized/)
479 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
482 context '事前チェックしておく' do
483 it '絵師モデルに編集取得を問い合わせている' do
484 Artist.stub(:edit).with(any_args()).and_return @artist
485 Artist.should_receive(:edit).exactly(1)
486 put :update, :id => @artist.id, :artist => @attr
488 it '絵師モデルにカラム値復元を依頼している' do
489 Artist.any_instance.should_receive(:attributes=).exactly(1)
490 put :update, :id => @artist.id, :artist => @attr
492 it '絵師モデルに上書き補充を依頼している' do
493 Artist.any_instance.should_receive(:overwrite).exactly(1)
494 put :update, :id => @artist.id, :artist => @attr
497 Artist.any_instance.stub(:save).with(any_args).and_return true
498 Artist.any_instance.should_receive(:save).exactly(1)
499 put :update, :id => @artist.id, :artist => @attr
501 it '@arにアレを取得している' do
502 put :update, :id => @artist.id, :artist => @attr
503 assigns(:ar).should eq @artist
506 context 'つつがなく終わるとき' do
508 put :update, :id => @artist.id, :artist => @attr
509 Artist.find(@artist.id).name.should eq 'ryu'
512 it 'ステータスコード302 Foundを返す' do
513 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
514 put :update, :id => @artist.id, :artist => @attr
515 response.status.should eq 302
518 put :update, :id => @artist.id, :artist => @attr
519 response.should redirect_to('/home/configure')
523 it 'ステータスコード200 OKを返す' do
524 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
525 put :update, :id => @artist.id, :artist => @attr, :format => :json
526 response.should be_success
529 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
530 put :update, :id => @artist.id, :artist => @attr, :format => :json
531 response.body.should match /./
535 context '作家権限がないとき' do
539 it 'ステータスコード302 Foundを返す' do
540 put :update, :id => @artist.id, :artist => @attr
541 response.status.should eq 302
544 it 'サインインページへ遷移する' do
545 put :update, :id => @artist.id, :artist => @attr
546 response.body.should redirect_to '/users/sign_in'
550 it '応答メッセージにUnauthorizedを返す' do
551 put :update, :id => @artist.id, :artist => @attr, :format => :json
552 response.message.should match(/Unauthorized/)
556 context '検証、保存に失敗したとき' do
558 Artist.any_instance.stub(:save).and_return(false)
561 it 'ステータスコード200 Okを返す' do
562 put :update, :id => @artist.id, :artist => @attr
563 response.status.should eq 200
566 put :update, :id => @artist.id, :artist => @attr
567 response.should render_template("edit")
571 it 'ステータスコード422 unprocessable_entity を返す' do
572 Artist.any_instance.stub(:save).and_return(false)
573 put :update, :id => @artist.id, :artist => @attr, :format => :json
574 response.status.should eq 422
576 it '応答メッセージUnprocessable Entityを返す' do
577 put :update, :id => @artist.id, :artist => @attr, :format => :json
578 response.message.should match(/Unprocessable/)
585 describe '一覧表示に於いて' do
587 Artist.stub(:list).and_return([@artist, @artist, @artist])
590 context 'つつがなく終わるとき' do
591 it 'ステータスコード200 OKを返す' do
593 response.should be_success
596 it 'indexテンプレートを描画する' do
598 response.should render_template("index")
603 get :index, :format => :json
604 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
608 context '作家権限がないとき' do
612 it 'ステータスコード200 OKを返す' do
614 response.should be_success
617 it 'indexテンプレートを描画する' do
619 response.should render_template("index")
624 get :index, :format => :json
625 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
633 Artist.stub(:show).and_return(@artist)
636 context 'つつがなく終わるとき' do
637 it 'ステータスコード200 OKを返す' do
638 get :show, :id => @artist.id
639 response.should be_success
642 it 'showテンプレートを描画する' do
643 get :show, :id => @artist.id
644 response.should render_template("show")
649 get :show, :id => @artist.id, :format => :json
650 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
654 context '作家権限がないとき' do
658 it 'ステータスコード200 OKを返す' do
659 get :show, :id => @artist.id
660 response.should be_success
663 it 'showテンプレートを描画する' do
664 get :show, :id => @artist.id
665 response.should render_template("show")
670 get :show, :id => @artist.id, :format => :json
671 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
677 describe '絵師数取得に於いて' do
679 Artist.should_receive(:visible_count).and_return(3)
682 context 'つつがなく終わるとき' do
683 it 'ステータスコード200 OKを返す' do
684 get :count, :format => :json
685 response.should be_success
689 get :count, :format => :json
690 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
696 describe '新規作成フォーム表示に於いて' do
700 context 'つつがなく終わるとき' do
701 it 'ステータスコード200 OKを返す' do
703 response.should be_success
706 it 'newテンプレートを描画する' do
708 response.should render_template("new")
712 it 'new.jsテンプレートを描画する' do
713 get :new, :format => :js
714 response.should render_template("new")
719 get :new, :format => :json
720 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
724 context '作家権限がないとき' do
729 it 'ステータスコード302 Foundを返す' do
731 response.status.should eq 302
733 it 'サインインページへ遷移する' do
735 response.body.should redirect_to '/users/sign_in'
739 it 'ステータスコード401 Unauthorizedを返す' do
740 get :new, :format => :js
741 response.status.should eq 401
743 it '応答メッセージにUnauthorizedを返す' do
744 get :new, :format => :js
745 response.message.should match(/Unauthorized/)
749 it 'ステータスコード401 Unauthorizedを返す' do
750 get :new, :format => :json
751 response.status.should eq 401
753 it '応答メッセージにUnauthorizedを返す' do
754 get :new, :format => :json
755 response.message.should match(/Unauthorized/)
761 describe '新規作成に於いて' do
764 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
766 context 'つつがなく終わるとき' do
768 it 'ステータスコード302 Foundを返す' do
769 Artist.any_instance.stub(:save).and_return(true)
770 post :create, :artist => @attr
771 response.status.should eq 302
774 # Artist.any_instance.stub(:save).and_return(true)
775 post :create, :artist => @attr
776 response.should redirect_to(root_path)
780 it 'ステータスコード200 OKを返す' do
781 # Artist.any_instance.stub(:save).and_return(true)
782 post :create, :artist => @attr, :format => :json
783 response.should be_success
785 it '作成された絵師をjsonデータで返す' do
786 post :create, :artist => @attr, :format => :json
787 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
791 context '作家権限がないとき' do
796 it 'ステータスコード302 Foundを返す' do
797 post :create, :artist => @attr
798 response.status.should eq 302
800 it 'サインインページへ遷移する' do
801 post :create, :artist => @attr
802 response.body.should redirect_to '/users/sign_in'
806 it 'ステータスコード401 Unauthorizedを返す' do
807 post :create, :artist => @attr, :format => :json
808 response.status.should eq 401
810 it '応答メッセージにUnauthorizedを返す' do
811 post :create, :artist => @attr, :format => :json
812 response.message.should match(/Unauthorized/)
818 describe '編集フォーム表示に於いて' do
821 Artist.stub(:edit).and_return(@artist)
823 context 'つつがなく終わるとき' do
824 it 'ステータスコード200 OKを返す' do
825 get :edit, :id => @artist.id
826 response.should be_success
829 it 'editテンプレートを描画する' do
830 get :edit, :id => @artist.id
831 response.should render_template("edit")
835 it 'edit.jsテンプレートを描画する' do
836 get :edit, :id => @artist.id, :format => :js
837 response.should render_template("edit")
841 context '作家権限がないとき' do
846 it 'ステータスコード302 Foundを返す' do
847 get :edit, :id => @artist.id
848 response.status.should eq 302
850 it 'サインインページへ遷移する' do
851 get :edit, :id => @artist.id
852 response.body.should redirect_to '/users/sign_in'
856 it 'ステータスコード401 Unauthorizedを返す' do
857 get :edit, :id => @artist.id, :format => :js
858 response.status.should eq 401
860 it '応答メッセージにUnauthorizedを返す' do
861 get :edit, :id => @artist.id, :format => :js
862 response.message.should match(/Unauthorized/)
870 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
873 context 'つつがなく終わるとき' do
875 it 'ステータスコード302 Foundを返す' do
876 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
877 put :update, :id => @artist.id, :artist => @attr
878 response.status.should eq 302
881 put :update, :id => @artist.id, :artist => @attr
882 response.should redirect_to('/home/configure')
886 it 'ステータスコード200 OKを返す' do
887 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
888 put :update, :id => @artist.id, :artist => @attr, :format => :json
889 response.should be_success
892 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
893 put :update, :id => @artist.id, :artist => @attr, :format => :json
894 response.body.should match /./
898 context '作家権限がないとき' do
902 it 'ステータスコード302 Foundを返す' do
903 put :update, :id => @artist.id, :artist => @attr
904 response.status.should eq 302
907 it 'サインインページへ遷移する' do
908 put :update, :id => @artist.id, :artist => @attr
909 response.body.should redirect_to '/users/sign_in'
913 it '応答メッセージにUnauthorizedを返す' do
914 put :update, :id => @artist.id, :artist => @attr, :format => :json
915 response.message.should match(/Unauthorized/)