1 # -*- encoding: utf-8 -*-
5 describe ArtistsController do
7 @admin = FactoryGirl.create :admin
8 @demand_user = FactoryGirl.create :demand_user
9 @sp = FactoryGirl.create :system_picture
10 @lg = FactoryGirl.create :license_group
11 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
12 @user = FactoryGirl.create( :user_yas)
13 @author = FactoryGirl.create :author, :user_id => @user.id
14 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
17 if MagicNumber['run_mode'] == 1
18 describe '一覧表示に於いて' do
20 Artist.stub(:list).and_return([@artist, @artist, @artist])
24 it '与えられたpageがセットされている' do
25 get :index, :page => 5
26 assigns(:page).should eq 5
28 it '省略されると@pageに1値が入る' do
30 assigns(:page).should eq 1
32 it '与えられたpage_sizeがセットされている' do
33 get :index, :page_size => 15
34 assigns(:page_size).should eq 15
36 it '省略されると@page_sizeにデフォルト値が入る' do
38 assigns(:page_size).should eq Artist.default_page_size
40 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
41 get :index, :page_size => 1500
42 assigns(:page_size).should eq Artist.max_page_size
44 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
45 get :index, :page_size => 0
46 assigns(:page_size).should eq Artist.default_page_size
49 context 'つつがなく終わるとき' do
50 it 'ステータスコード200 OKを返す' do
52 response.should be_success
54 it '絵師モデルに一覧を問い合わせている' do
55 Artist.should_receive(:list).exactly(1)
58 it '@artistsにリストを取得している' do
60 assigns(:artists).should have_at_least(3).items
63 it 'indexテンプレートを描画する' do
65 response.should render_template("index")
70 get :index, :format => :json
71 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
73 it '絵師モデルにjson一覧出力オプションを問い合わせている' do
74 Artist.should_receive(:list_json_opt).exactly(1)
75 get :index, :format => :json
77 it 'データがリスト構造になっている' do
78 get :index, :format => :json
79 json = JSON.parse response.body
80 json.should have_at_least(3).items
82 it 'リストの先頭くらいは絵師っぽいものであって欲しい' do
83 get :index, :format => :json
84 json = JSON.parse response.body
85 json.first.has_key?("name").should be_true
89 context 'ユーザ権限がないとき' do
94 it 'ステータスコード302 Foundを返す' do
96 response.status.should eq 302
100 response.should redirect_to '/users/sign_in'
104 it 'ステータスコード401 Unauthorizedを返す' do
105 get :index, :format => :json
106 response.status.should eq 401
108 it '応答メッセージにUnauthorizedを返す' do
109 get :index, :format => :json
110 response.message.should match(/Unauthorized/)
114 context 'ユーザ権限はないが管理者権限があるとき' do
119 it 'ステータスコード200 OKを返す' do
121 response.should be_success
124 context 'ユーザ権限はないが借手権限があるとき' do
129 it 'ステータスコード200 OKを返す' do
131 response.should be_success
134 context 'ユーザだが作家登録していないとき' do
138 it 'ステータスコード200 OKを返す' do
140 response.should be_success
147 Artist.stub(:show).and_return(@artist)
150 context 'つつがなく終わるとき' do
151 it 'ステータスコード200 OKを返す' do
152 get :show, :id => @artist.id
153 response.should be_success
155 it '絵師モデルに単体取得を問い合わせている' do
156 Artist.should_receive(:show).exactly(1)
159 it '@arにアレを取得している' do
160 get :show, :id => @artist.id
161 assigns(:ar).should eq(@artist)
164 it 'showテンプレートを描画する' do
165 get :show, :id => @artist.id
166 response.should render_template("show")
171 get :show, :id => @artist.id, :format => :json
172 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
174 it '絵師モデルにjson単体出力オプションを問い合わせている' do
175 Artist.should_receive(:show_json_opt).exactly(1)
176 get :show, :id => @artist.id, :format => :json
179 get :show, :id => @artist.id, :format => :json
180 json = JSON.parse response.body
181 json["name"].should match(/yas/)
185 context 'ユーザ権限がないとき' do
190 it 'ステータスコード302 Foundを返す' do
191 get :show, :id => @artist.id
192 response.status.should eq 302
194 it 'サインインページへ遷移する' do
195 get :show, :id => @artist.id
196 response.body.should redirect_to '/users/sign_in'
200 it 'ステータスコード401 Unauthorizedを返す' do
201 get :show, :id => @artist.id, :format => :json
202 response.status.should eq 401
204 it '応答メッセージにUnauthorizedを返す' do
205 get :show, :id => @artist.id, :format => :json
206 response.message.should match(/Unauthorized/)
210 context 'ユーザ権限はないが管理者権限があるとき' do
215 it 'ステータスコード200 OKを返す' do
216 get :show, :id => @artist.id
217 response.should be_success
220 context 'ユーザ権限はないが借手権限があるとき' do
225 it 'ステータスコード200 OKを返す' do
226 get :show, :id => @artist.id
227 response.should be_success
230 context 'ユーザだが作家登録していないとき' do
234 it 'ステータスコード200 OKを返す' do
235 get :show, :id => @artist.id
236 response.should be_success
240 context '対象作家がないとき' do
242 it '例外404 not_foundを返す' do
245 }.should raise_error(ActiveRecord::RecordNotFound)
249 it '例外404 not_foundを返す' do
251 get :show, :id => 0, :format => :json
252 }.should raise_error(ActiveRecord::RecordNotFound)
259 describe '対象絵師の素材一覧表示に於いて' do
261 @other_user = FactoryGirl.create( :user_yas)
262 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
263 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
264 @op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
265 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @other_artist.id
266 @rp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
267 ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp])
270 context 'パラメータpageについて' do
272 get :resource_pictures, :id => @other_artist.id, :page => 5
273 assigns(:page).should eq 5
275 it '省略されると@pageに1値が入る' do
276 get :resource_pictures, :id => @other_artist.id
277 assigns(:page).should eq 1
279 it '与えられたpage_sizeがセットされている' do
280 get :resource_pictures, :id => @other_artist.id, :page_size => 15
281 assigns(:page_size).should eq 15
283 it '省略されると@page_sizeにデフォルト値が入る' do
284 get :resource_pictures, :id => @other_artist.id
285 assigns(:page_size).should eq Author.default_resource_picture_page_size
287 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
288 get :resource_pictures, :id => @other_artist.id, :page_size => 1500
289 assigns(:page_size).should eq Author.resource_picture_max_page_size
291 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
292 get :resource_pictures, :id => @other_artist.id, :page_size => 0
293 assigns(:page_size).should eq Author.default_resource_picture_page_size
296 context 'つつがなく終わるとき' do
297 it 'ステータスコード200 OKを返す' do
298 get :resource_pictures, :id => @other_artist.id
299 response.should be_success
301 it '絵師モデルに単体取得を問い合わせている' do
302 Artist.should_receive(:show).exactly(1)
303 get :resource_pictures, :id => @other_artist.id
305 it '素材モデルに一覧を問い合わせている' do
306 ResourcePicture.should_receive(:mylist).exactly(1)
307 get :resource_pictures, :id => @other_artist.id
309 it '@resource_picturesにリストを取得している' do
310 get :resource_pictures, :id => @other_artist.id
311 assigns(:resource_pictures).should have_at_least(3).items
314 it 'resource_pictureテンプレートを描画する' do
315 get :resource_pictures, :id => @other_artist.id
316 response.should render_template("resource_pictures")
321 get :resource_pictures, :id => @other_artist.id, :format => :json
322 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
324 it '素材モデルにコマリストのjson出力を問い合わせている' do
325 ResourcePicture.should_receive(:list_json_opt).exactly(1)
326 get :resource_pictures, :id => @other_artist.id, :format => :json
328 it 'データがリスト構造になっている' do
329 get :resource_pictures, :id => @other_artist.id, :format => :json
330 json = JSON.parse response.body
331 json.should have_at_least(3).items
333 it 'リストの先頭くらいは素材っぽいものであって欲しい' do
334 get :resource_pictures, :id => @other_artist.id, :format => :json
335 json = JSON.parse response.body
336 json.first.has_key?("original_picture_id").should be_true
337 json.first.has_key?("license_id").should be_true
341 context 'ユーザ権限がないとき' do
346 it 'ステータスコード302 Foundを返す' do
347 get :resource_pictures, :id => @other_artist.id
348 response.status.should eq 302
350 it 'サインインページへ遷移する' do
351 get :resource_pictures, :id => @other_artist.id
352 response.should redirect_to '/users/sign_in'
356 it 'ステータスコード401 Unauthorizedを返す' do
357 get :resource_pictures, :id => @other_artist.id, :format => :json
358 response.status.should eq 401
360 it '応答メッセージにUnauthorizedを返す' do
361 get :resource_pictures, :id => @other_artist.id, :format => :json
362 response.message.should match(/Unauthorized/)
366 context 'ユーザ権限はないが管理者権限があるとき' do
371 it 'ステータスコード200 OKを返す' do
372 get :resource_pictures, :id => @other_artist.id
373 response.should be_success
376 context 'ユーザだが作家登録していないとき' do
380 it 'ステータスコード200 OKを返す' do
381 get :resource_pictures, :id => @other_artist.id
382 response.should be_success
387 describe '絵師数取得に於いて' do
389 Artist.should_receive(:visible_count).and_return(3)
392 context 'つつがなく終わるとき' do
393 it 'ステータスコード200 OKを返す' do
394 get :count, :format => :json
395 response.should be_success
399 get :count, :format => :json
400 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
402 it 'データがHash構造になっていて絵師数が3である' do
403 get :count, :format => :json
404 json = JSON.parse response.body
405 json["count"].should == 3
411 describe '新規作成フォーム表示に於いて' do
415 context 'つつがなく終わるとき' do
416 it 'ステータスコード200 OKを返す' do
418 response.should be_success
420 it '@artistに新規データを用意している' do
422 assigns(:ar).should be_a_new(Artist)
424 it '絵師モデルにデフォルト値補充を依頼している' do
425 Artist.any_instance.should_receive(:supply_default).exactly(1)
429 it 'newテンプレートを描画する' do
431 response.should render_template("new")
435 it 'new.jsテンプレートを描画する' do
436 get :new, :format => :js
437 response.should render_template("new")
442 get :new, :format => :json
443 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
445 it '絵師モデルにjson単体出力オプションを問い合わせている' do
446 Artist.should_receive(:show_json_opt).exactly(1)
447 get :new, :format => :json
451 context 'ユーザ権限がないとき' do
456 it 'ステータスコード302 Foundを返す' do
458 response.status.should eq 302
460 it 'サインインページへ遷移する' do
462 response.body.should redirect_to '/users/sign_in'
466 it 'ステータスコード401 Unauthorizedを返す' do
467 get :new, :format => :js
468 response.status.should eq 401
470 it '応答メッセージにUnauthorizedを返す' do
471 get :new, :format => :js
472 response.message.should match(/Unauthorized/)
476 it 'ステータスコード401 Unauthorizedを返す' do
477 get :new, :format => :json
478 response.status.should eq 401
480 it '応答メッセージにUnauthorizedを返す' do
481 get :new, :format => :json
482 response.message.should match(/Unauthorized/)
486 context 'ユーザ権限はないが管理者権限があるとき' do
492 it 'ステータスコード302 Foundを返す' do
494 response.status.should eq 302
496 it 'サインインページへ遷移する' do
498 response.body.should redirect_to '/users/sign_in'
502 context 'ユーザだが作家登録していないとき' do
507 it 'ステータスコード302 Foundを返す' do
509 response.status.should eq 302
513 response.body.should redirect_to new_author_path
519 describe '新規作成に於いて' do
522 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
524 context '事前チェックしておく' do
525 it '絵師モデルにデフォルト値補充を依頼している' do
526 Artist.any_instance.should_receive(:supply_default).exactly(1)
527 post :create, :artist => @attr
529 it '絵師モデルにカラム値復元を依頼している' do
530 Artist.any_instance.should_receive(:attributes=).exactly(1)
531 post :create, :artist => @attr
533 it '絵師モデルに上書き補充を依頼している' do
534 Artist.any_instance.should_receive(:overwrite).exactly(1)
535 post :create, :artist => @attr
538 Artist.any_instance.should_receive(:save).exactly(1)
539 post :create, :artist => @attr
542 context 'つつがなく終わるとき' do
543 it "@arに作成された絵師を保持していて、それがDBにある" do
544 post :create, :artist => @attr
545 assigns(:ar).should be_a(Artist)
546 assigns(:ar).should be_persisted
549 it 'ステータスコード302 Foundを返す' do
550 Artist.any_instance.stub(:save).and_return(true)
551 post :create, :artist => @attr
552 response.status.should eq 302
555 # Artist.any_instance.stub(:save).and_return(true)
556 post :create, :artist => @attr
557 response.should redirect_to(root_path)
561 it 'ステータスコード200 OKを返す' do
562 # Artist.any_instance.stub(:save).and_return(true)
563 post :create, :artist => @attr, :format => :json
564 response.should be_success
566 it '作成された絵師をjsonデータで返す' do
567 post :create, :artist => @attr, :format => :json
568 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
570 it '絵師モデルにjson単体出力オプションを問い合わせている' do
571 Artist.should_receive(:show_json_opt).exactly(1)
572 post :create, :artist => @attr, :format => :json
575 post :create, :artist => @attr, :format => :json
576 json = JSON.parse response.body
577 json["name"].should match(/ken/)
581 context 'ユーザ権限がないとき' do
586 it 'ステータスコード302 Foundを返す' do
587 post :create, :artist => @attr
588 response.status.should eq 302
590 it 'サインインページへ遷移する' do
591 post :create, :artist => @attr
592 response.body.should redirect_to '/users/sign_in'
596 it 'ステータスコード401 Unauthorizedを返す' do
597 post :create, :artist => @attr, :format => :json
598 response.status.should eq 401
600 it '応答メッセージにUnauthorizedを返す' do
601 post :create, :artist => @attr, :format => :json
602 response.message.should match(/Unauthorized/)
606 context 'ユーザ権限はないが管理者権限があるとき' do
612 it 'ステータスコード302 Foundを返す' do
613 post :create, :artist => @attr
614 response.status.should eq 302
616 it 'サインインページへ遷移する' do
617 post :create, :artist => @attr
618 response.body.should redirect_to '/users/sign_in'
622 context 'ユーザだが作家登録していないとき' do
627 it 'ステータスコード302 Foundを返す' do
628 post :create, :artist => @attr
629 response.status.should eq 302
632 post :create, :artist => @attr
633 response.body.should redirect_to new_author_path
637 context '検証、保存に失敗した' do
639 Artist.any_instance.stub(:save).and_return(false)
641 it "未保存の絵師を保持している" do
642 post :create, :artist => @attr
643 assigns(:ar).should be_a_new(Artist)
646 it 'ステータスコード200 OKを返す' do
647 post :create, :artist => @attr
648 response.status.should eq 200
651 post :create, :artist => @attr
652 response.should render_template("new")
656 it 'ステータスコード422 unprocessable_entity を返す' do
657 post :create, :artist => @attr, :format => :json
658 response.status.should eq 422
660 it '応答メッセージUnprocessable Entityを返す' do
661 post :create, :artist => @attr, :format => :json
662 response.message.should match(/Unprocessable/)
668 describe '編集フォーム表示に於いて' do
671 Artist.stub(:edit).and_return(@artist)
673 context 'つつがなく終わるとき' do
674 it 'ステータスコード200 OKを返す' do
675 get :edit, :id => @artist.id
676 response.should be_success
678 it '絵師モデルに編集取得を問い合わせている' do
679 Artist.should_receive(:edit).exactly(1)
680 get :edit, :id => @artist.id
682 it '@artistにデータを用意している' do
683 get :edit, :id => @artist.id
684 assigns(:artist).should eq @artist
687 it 'editテンプレートを描画する' do
688 get :edit, :id => @artist.id
689 response.should render_template("edit")
693 it 'edit.jsテンプレートを描画する' do
694 get :edit, :id => @artist.id, :format => :js
695 response.should render_template("edit")
699 context 'ユーザ権限がないとき' do
704 it 'ステータスコード302 Foundを返す' do
705 get :edit, :id => @artist.id
706 response.status.should eq 302
708 it 'サインインページへ遷移する' do
709 get :edit, :id => @artist.id
710 response.body.should redirect_to '/users/sign_in'
714 it 'ステータスコード401 Unauthorizedを返す' do
715 get :edit, :id => @artist.id, :format => :js
716 response.status.should eq 401
718 it '応答メッセージにUnauthorizedを返す' do
719 get :edit, :id => @artist.id, :format => :js
720 response.message.should match(/Unauthorized/)
724 context 'ユーザ権限はないが管理者権限があるとき' do
730 it 'ステータスコード302 Foundを返す' do
731 get :edit, :id => @artist.id
732 response.status.should eq 302
734 it 'サインインページへ遷移する' do
735 get :edit, :id => @artist.id
736 response.body.should redirect_to '/users/sign_in'
740 context 'ユーザだが作家登録していないとき' do
745 it 'ステータスコード302 Foundを返す' do
746 get :edit, :id => @artist.id
747 response.status.should eq 302
750 get :edit, :id => @artist.id
751 response.body.should redirect_to new_author_path
759 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
762 context '事前チェックしておく' do
763 it '絵師モデルに編集取得を問い合わせている' do
764 Artist.stub(:edit).with(any_args()).and_return @artist
765 Artist.should_receive(:edit).exactly(1)
766 put :update, :id => @artist.id, :artist => @attr
768 it '絵師モデルにカラム値復元を依頼している' do
769 Artist.any_instance.should_receive(:attributes=).exactly(1)
770 put :update, :id => @artist.id, :artist => @attr
772 it '絵師モデルに上書き補充を依頼している' do
773 Artist.any_instance.should_receive(:overwrite).exactly(1)
774 put :update, :id => @artist.id, :artist => @attr
777 Artist.any_instance.stub(:save).with(any_args).and_return true
778 Artist.any_instance.should_receive(:save).exactly(1)
779 put :update, :id => @artist.id, :artist => @attr
781 it '@arにアレを取得している' do
782 put :update, :id => @artist.id, :artist => @attr
783 assigns(:ar).should eq @artist
786 context 'つつがなく終わるとき' do
788 put :update, :id => @artist.id, :artist => @attr
789 Artist.find(@artist.id).name.should eq 'ryu'
792 it 'ステータスコード302 Foundを返す' do
793 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
794 put :update, :id => @artist.id, :artist => @attr
795 response.status.should eq 302
798 put :update, :id => @artist.id, :artist => @attr
799 response.should redirect_to('/home/configure')
803 it 'ステータスコード200 OKを返す' do
804 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
805 put :update, :id => @artist.id, :artist => @attr, :format => :json
806 response.should be_success
809 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
810 put :update, :id => @artist.id, :artist => @attr, :format => :json
811 response.body.should match /./
815 context 'ユーザ権限がないとき' do
820 it 'ステータスコード302 Foundを返す' do
821 put :update, :id => @artist.id, :artist => @attr
822 response.status.should eq 302
824 it 'サインインページへ遷移する' do
825 put :update, :id => @artist.id, :artist => @attr
826 response.body.should redirect_to '/users/sign_in'
830 it '応答メッセージにUnauthorizedを返す' do
831 put :update, :id => @artist.id, :artist => @attr, :format => :json
832 response.message.should match(/Unauthorized/)
836 context 'ユーザ権限はないが管理者権限があるとき' do
842 it 'ステータスコード302 Foundを返す' do
843 put :update, :id => @artist.id, :artist => @attr
844 response.status.should eq 302
846 it 'サインインページへ遷移する' do
847 put :update, :id => @artist.id, :artist => @attr
848 response.body.should redirect_to '/users/sign_in'
852 context 'ユーザだが作家登録していないとき' do
857 it 'ステータスコード302 Foundを返す' do
858 put :update, :id => @artist.id, :artist => @attr
859 response.status.should eq 302
862 put :update, :id => @artist.id, :artist => @attr
863 response.body.should redirect_to new_author_path
867 context '検証、保存に失敗したとき' do
869 Artist.any_instance.stub(:save).and_return(false)
872 it 'ステータスコード200 Okを返す' do
873 put :update, :id => @artist.id, :artist => @attr
874 response.status.should eq 200
877 put :update, :id => @artist.id, :artist => @attr
878 response.should render_template("edit")
882 it 'ステータスコード422 unprocessable_entity を返す' do
883 Artist.any_instance.stub(:save).and_return(false)
884 put :update, :id => @artist.id, :artist => @attr, :format => :json
885 response.status.should eq 422
887 it '応答メッセージUnprocessable Entityを返す' do
888 put :update, :id => @artist.id, :artist => @attr, :format => :json
889 response.message.should match(/Unprocessable/)
896 describe '一覧表示に於いて' do
898 Artist.stub(:list).and_return([@artist, @artist, @artist])
901 context 'つつがなく終わるとき' do
902 it 'ステータスコード200 OKを返す' do
904 response.should be_success
907 it 'indexテンプレートを描画する' do
909 response.should render_template("index")
914 get :index, :format => :json
915 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
919 context 'ユーザ権限がないとき' do
923 it 'ステータスコード200 OKを返す' do
925 response.should be_success
928 it 'indexテンプレートを描画する' do
930 response.should render_template("index")
935 get :index, :format => :json
936 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
944 Artist.stub(:show).and_return(@artist)
947 context 'つつがなく終わるとき' do
948 it 'ステータスコード200 OKを返す' do
949 get :show, :id => @artist.id
950 response.should be_success
953 it 'showテンプレートを描画する' do
954 get :show, :id => @artist.id
955 response.should render_template("show")
960 get :show, :id => @artist.id, :format => :json
961 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
965 context 'ユーザ権限がないとき' do
969 it 'ステータスコード200 OKを返す' do
970 get :show, :id => @artist.id
971 response.should be_success
974 it 'showテンプレートを描画する' do
975 get :show, :id => @artist.id
976 response.should render_template("show")
981 get :show, :id => @artist.id, :format => :json
982 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
988 describe '対象絵師の素材一覧表示に於いて' do
990 @other_user = FactoryGirl.create( :user_yas)
991 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
992 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
993 @op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
994 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @other_artist.id
995 @rp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
996 ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp])
999 context 'つつがなく終わるとき' do
1000 it 'ステータスコード200 OKを返す' do
1001 get :resource_pictures, :id => @other_artist.id
1002 response.should be_success
1005 it 'resource_pictureテンプレートを描画する' do
1006 get :resource_pictures, :id => @other_artist.id
1007 response.should render_template("resource_pictures")
1012 get :resource_pictures, :id => @other_artist.id, :format => :json
1013 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1017 context 'ユーザ権限がないとき' do
1021 it 'ステータスコード200 OKを返す' do
1022 get :resource_pictures, :id => @other_artist.id
1023 response.should be_success
1026 it 'resource_pictureテンプレートを描画する' do
1027 get :resource_pictures, :id => @other_artist.id
1028 response.should render_template("resource_pictures")
1033 get :resource_pictures, :id => @other_artist.id, :format => :json
1034 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1040 describe '絵師数取得に於いて' do
1042 Artist.should_receive(:visible_count).and_return(3)
1045 context 'つつがなく終わるとき' do
1046 it 'ステータスコード200 OKを返す' do
1047 get :count, :format => :json
1048 response.should be_success
1052 get :count, :format => :json
1053 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1059 describe '新規作成フォーム表示に於いて' do
1063 context 'つつがなく終わるとき' do
1064 it 'ステータスコード200 OKを返す' do
1066 response.should be_success
1069 it 'newテンプレートを描画する' do
1071 response.should render_template("new")
1075 it 'new.jsテンプレートを描画する' do
1076 get :new, :format => :js
1077 response.should render_template("new")
1082 get :new, :format => :json
1083 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1087 context 'ユーザ権限がないとき' do
1092 it 'ステータスコード302 Foundを返す' do
1094 response.status.should eq 302
1096 it 'サインインページへ遷移する' do
1098 response.body.should redirect_to '/users/sign_in'
1102 it 'ステータスコード401 Unauthorizedを返す' do
1103 get :new, :format => :js
1104 response.status.should eq 401
1106 it '応答メッセージにUnauthorizedを返す' do
1107 get :new, :format => :js
1108 response.message.should match(/Unauthorized/)
1112 it 'ステータスコード401 Unauthorizedを返す' do
1113 get :new, :format => :json
1114 response.status.should eq 401
1116 it '応答メッセージにUnauthorizedを返す' do
1117 get :new, :format => :json
1118 response.message.should match(/Unauthorized/)
1124 describe '新規作成に於いて' do
1127 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
1129 context 'つつがなく終わるとき' do
1131 it 'ステータスコード302 Foundを返す' do
1132 Artist.any_instance.stub(:save).and_return(true)
1133 post :create, :artist => @attr
1134 response.status.should eq 302
1137 # Artist.any_instance.stub(:save).and_return(true)
1138 post :create, :artist => @attr
1139 response.should redirect_to(root_path)
1143 it 'ステータスコード200 OKを返す' do
1144 # Artist.any_instance.stub(:save).and_return(true)
1145 post :create, :artist => @attr, :format => :json
1146 response.should be_success
1148 it '作成された絵師をjsonデータで返す' do
1149 post :create, :artist => @attr, :format => :json
1150 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1154 context 'ユーザ権限がないとき' do
1159 it 'ステータスコード302 Foundを返す' do
1160 post :create, :artist => @attr
1161 response.status.should eq 302
1163 it 'サインインページへ遷移する' do
1164 post :create, :artist => @attr
1165 response.body.should redirect_to '/users/sign_in'
1169 it 'ステータスコード401 Unauthorizedを返す' do
1170 post :create, :artist => @attr, :format => :json
1171 response.status.should eq 401
1173 it '応答メッセージにUnauthorizedを返す' do
1174 post :create, :artist => @attr, :format => :json
1175 response.message.should match(/Unauthorized/)
1181 describe '編集フォーム表示に於いて' do
1184 Artist.stub(:edit).and_return(@artist)
1186 context 'つつがなく終わるとき' do
1187 it 'ステータスコード200 OKを返す' do
1188 get :edit, :id => @artist.id
1189 response.should be_success
1192 it 'editテンプレートを描画する' do
1193 get :edit, :id => @artist.id
1194 response.should render_template("edit")
1198 it 'edit.jsテンプレートを描画する' do
1199 get :edit, :id => @artist.id, :format => :js
1200 response.should render_template("edit")
1204 context 'ユーザ権限がないとき' do
1209 it 'ステータスコード302 Foundを返す' do
1210 get :edit, :id => @artist.id
1211 response.status.should eq 302
1213 it 'サインインページへ遷移する' do
1214 get :edit, :id => @artist.id
1215 response.body.should redirect_to '/users/sign_in'
1219 it 'ステータスコード401 Unauthorizedを返す' do
1220 get :edit, :id => @artist.id, :format => :js
1221 response.status.should eq 401
1223 it '応答メッセージにUnauthorizedを返す' do
1224 get :edit, :id => @artist.id, :format => :js
1225 response.message.should match(/Unauthorized/)
1231 describe '更新に於いて' do
1233 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
1236 context 'つつがなく終わるとき' do
1238 it 'ステータスコード302 Foundを返す' do
1239 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
1240 put :update, :id => @artist.id, :artist => @attr
1241 response.status.should eq 302
1244 put :update, :id => @artist.id, :artist => @attr
1245 response.should redirect_to('/home/configure')
1249 it 'ステータスコード200 OKを返す' do
1250 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
1251 put :update, :id => @artist.id, :artist => @attr, :format => :json
1252 response.should be_success
1254 it 'ページ本体は特に返さない' do
1255 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
1256 put :update, :id => @artist.id, :artist => @attr, :format => :json
1257 response.body.should match /./
1261 context 'ユーザ権限がないとき' do
1265 it 'ステータスコード302 Foundを返す' do
1266 put :update, :id => @artist.id, :artist => @attr
1267 response.status.should eq 302
1270 it 'サインインページへ遷移する' do
1271 put :update, :id => @artist.id, :artist => @attr
1272 response.body.should redirect_to '/users/sign_in'
1276 it '応答メッセージにUnauthorizedを返す' do
1277 put :update, :id => @artist.id, :artist => @attr, :format => :json
1278 response.message.should match(/Unauthorized/)