1 # -*- encoding: utf-8 -*-
5 describe ArtistsController do
7 SpeechBalloonTemplate.delete_all
8 @admin = FactoryGirl.create :admin
9 @demand_user = FactoryGirl.create :demand_user
10 @sp = FactoryGirl.create :system_picture
11 @lg = FactoryGirl.create :license_group
12 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
13 @user = FactoryGirl.create( :user_yas)
14 @author = FactoryGirl.create :author, :user_id => @user.id
15 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
18 if MagicNumber['run_mode'] == 1
19 describe '一覧表示に於いて' do
21 Artist.stub(:list).and_return([@artist, @artist, @artist])
25 it '与えられたpageがセットされている' do
26 get :index, :page => 5
27 assigns(:page).should eq 5
29 it '省略されると@pageに1値が入る' do
31 assigns(:page).should eq 1
33 it '与えられたpage_sizeがセットされている' do
34 get :index, :page_size => 15
35 assigns(:page_size).should eq 15
37 it '省略されると@page_sizeにデフォルト値が入る' do
39 assigns(:page_size).should eq Artist.default_page_size
41 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
42 get :index, :page_size => 1500
43 assigns(:page_size).should eq Artist.max_page_size
45 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
46 get :index, :page_size => 0
47 assigns(:page_size).should eq Artist.default_page_size
50 context 'つつがなく終わるとき' do
51 it 'ステータスコード200 OKを返す' do
53 response.should be_success
55 it '絵師モデルに一覧を問い合わせている' do
56 Artist.should_receive(:list).exactly(1)
59 it '@artistsにリストを取得している' do
61 assigns(:artists).should have_at_least(3).items
64 it '@paginateにページ制御を取得している' do
66 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
68 it 'indexテンプレートを描画する' do
70 response.should render_template("index")
75 get :index, :format => :json
76 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
78 it '絵師モデルにjson一覧出力オプションを問い合わせている' do
79 Artist.should_receive(:list_json_opt).exactly(1)
80 get :index, :format => :json
82 it 'データがリスト構造になっている' do
83 get :index, :format => :json
84 json = JSON.parse response.body
85 json.should have_at_least(3).items
87 it 'リストの先頭くらいは絵師っぽいものであって欲しい' do
88 get :index, :format => :json
89 json = JSON.parse response.body
90 json.first.has_key?("name").should be_true
94 context 'ユーザ権限がないとき' do
99 it 'ステータスコード302 Foundを返す' do
101 response.status.should eq 302
103 it 'サインインページへ遷移する' do
105 response.should redirect_to '/users/sign_in'
109 it 'ステータスコード401 Unauthorizedを返す' do
110 get :index, :format => :json
111 response.status.should eq 401
113 it '応答メッセージにUnauthorizedを返す' do
114 get :index, :format => :json
115 response.message.should match(/Unauthorized/)
119 context 'ユーザ権限はないが管理者権限があるとき' do
124 it 'ステータスコード200 OKを返す' do
126 response.should be_success
129 context 'ユーザ権限はないが借手権限があるとき' do
134 it 'ステータスコード200 OKを返す' do
136 response.should be_success
139 context 'ユーザだが作家登録していないとき' do
143 it 'ステータスコード200 OKを返す' do
145 response.should be_success
152 Artist.stub(:show).and_return(@artist)
155 context 'つつがなく終わるとき' do
156 it 'ステータスコード200 OKを返す' do
157 get :show, :id => @artist.id
158 response.should be_success
160 it '絵師モデルに単体取得を問い合わせている' do
161 Artist.should_receive(:show).exactly(1)
164 it '@arにアレを取得している' do
165 get :show, :id => @artist.id
166 assigns(:ar).should eq(@artist)
169 it 'showテンプレートを描画する' do
170 get :show, :id => @artist.id
171 response.should render_template("show")
176 get :show, :id => @artist.id, :format => :json
177 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
179 it '絵師モデルにjson単体出力オプションを問い合わせている' do
180 Artist.should_receive(:show_json_opt).exactly(1)
181 get :show, :id => @artist.id, :format => :json
184 get :show, :id => @artist.id, :format => :json
185 json = JSON.parse response.body
186 json["name"].should match(/yas/)
190 context 'ユーザ権限がないとき' do
195 it 'ステータスコード302 Foundを返す' do
196 get :show, :id => @artist.id
197 response.status.should eq 302
199 it 'サインインページへ遷移する' do
200 get :show, :id => @artist.id
201 response.body.should redirect_to '/users/sign_in'
205 it 'ステータスコード401 Unauthorizedを返す' do
206 get :show, :id => @artist.id, :format => :json
207 response.status.should eq 401
209 it '応答メッセージにUnauthorizedを返す' do
210 get :show, :id => @artist.id, :format => :json
211 response.message.should match(/Unauthorized/)
215 context 'ユーザ権限はないが管理者権限があるとき' do
220 it 'ステータスコード200 OKを返す' do
221 get :show, :id => @artist.id
222 response.should be_success
225 context 'ユーザ権限はないが借手権限があるとき' do
230 it 'ステータスコード200 OKを返す' do
231 get :show, :id => @artist.id
232 response.should be_success
235 context 'ユーザだが作家登録していないとき' do
239 it 'ステータスコード200 OKを返す' do
240 get :show, :id => @artist.id
241 response.should be_success
245 context '対象作家がないとき' do
247 it '例外404 not_foundを返す' do
250 }.should raise_error(ActiveRecord::RecordNotFound)
254 it '例外404 not_foundを返す' do
256 get :show, :id => 0, :format => :json
257 }.should raise_error(ActiveRecord::RecordNotFound)
264 describe '対象絵師の素材一覧表示に於いて' do
266 @other_user = FactoryGirl.create( :user_yas)
267 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
268 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
269 @op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
270 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @other_artist.id
271 @rp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
272 Artist.stub(:show).and_return(@artist)
273 ResourcePicture.stub(:himlist).and_return([@rp, @rp, @rp], [nil, nil, nil])
276 context 'パラメータpageについて' do
278 get :resource_pictures, :id => @other_artist.id, :page => 5
279 assigns(:page).should eq 5
281 it '省略されると@pageに1値が入る' do
282 get :resource_pictures, :id => @other_artist.id
283 assigns(:page).should eq 1
285 it '与えられたpage_sizeがセットされている' do
286 get :resource_pictures, :id => @other_artist.id, :page_size => 15
287 assigns(:page_size).should eq 15
289 it '省略されると@page_sizeにデフォルト値が入る' do
290 get :resource_pictures, :id => @other_artist.id
291 assigns(:page_size).should eq Author.default_resource_picture_page_size
293 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
294 get :resource_pictures, :id => @other_artist.id, :page_size => 1500
295 assigns(:page_size).should eq Author.resource_picture_max_page_size
297 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
298 get :resource_pictures, :id => @other_artist.id, :page_size => 0
299 assigns(:page_size).should eq Author.default_resource_picture_page_size
302 context 'つつがなく終わるとき' do
303 it 'ステータスコード200 OKを返す' do
304 get :resource_pictures, :id => @other_artist.id
305 response.should be_success
307 it '絵師モデルに単体取得を問い合わせている' do
308 Artist.should_receive(:show).exactly(1)
309 get :resource_pictures, :id => @other_artist.id
311 it '素材モデルに一覧を問い合わせている' do
312 ResourcePicture.should_receive(:himlist).exactly(1)
313 get :resource_pictures, :id => @other_artist.id
315 it '@resource_picturesにリストを取得している' do
316 get :resource_pictures, :id => @other_artist.id
317 assigns(:resource_pictures).should have_at_least(3).items
320 it '@paginateにページ制御を取得している' do
321 get :resource_pictures, :id => @other_artist.id
322 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
324 it 'resource_pictureテンプレートを描画する' do
325 get :resource_pictures, :id => @other_artist.id
326 response.should render_template("resource_pictures")
331 get :resource_pictures, :id => @other_artist.id, :format => :json
332 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
334 it '素材モデルにコマリストのjson出力を問い合わせている' do
335 ResourcePicture.should_receive(:list_json_opt).exactly(1)
336 get :resource_pictures, :id => @other_artist.id, :format => :json
338 it 'データがリスト構造になっている' do
339 get :resource_pictures, :id => @other_artist.id, :format => :json
340 json = JSON.parse response.body
341 json.should have_at_least(3).items
343 it 'リストの先頭くらいは素材っぽいものであって欲しい' do
344 get :resource_pictures, :id => @other_artist.id, :format => :json
345 json = JSON.parse response.body
346 json.first.has_key?("original_picture_id").should be_true
347 json.first.has_key?("license_id").should be_true
351 context 'ユーザ権限がないとき' do
356 it 'ステータスコード302 Foundを返す' do
357 get :resource_pictures, :id => @other_artist.id
358 response.status.should eq 302
360 it 'サインインページへ遷移する' do
361 get :resource_pictures, :id => @other_artist.id
362 response.should redirect_to '/users/sign_in'
366 it 'ステータスコード401 Unauthorizedを返す' do
367 get :resource_pictures, :id => @other_artist.id, :format => :json
368 response.status.should eq 401
370 it '応答メッセージにUnauthorizedを返す' do
371 get :resource_pictures, :id => @other_artist.id, :format => :json
372 response.message.should match(/Unauthorized/)
376 context 'ユーザ権限はないが管理者権限があるとき' do
381 it 'ステータスコード200 OKを返す' do
382 get :resource_pictures, :id => @other_artist.id
383 response.should be_success
386 context 'ユーザだが作家登録していないとき' do
390 it 'ステータスコード200 OKを返す' do
391 get :resource_pictures, :id => @other_artist.id
392 response.should be_success
397 describe '絵師数取得に於いて' do
399 Artist.should_receive(:visible_count).and_return(3)
402 context 'つつがなく終わるとき' do
403 it 'ステータスコード200 OKを返す' do
404 get :count, :format => :json
405 response.should be_success
409 get :count, :format => :json
410 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
412 it 'データがHash構造になっていて絵師数が3である' do
413 get :count, :format => :json
414 json = JSON.parse response.body
415 json["count"].should == 3
421 describe '新規作成フォーム表示に於いて' do
425 context 'つつがなく終わるとき' do
426 it 'ステータスコード200 OKを返す' do
428 response.should be_success
430 it '@artistに新規データを用意している' do
432 assigns(:ar).should be_a_new(Artist)
434 it '絵師モデルにデフォルト値補充を依頼している' do
435 Artist.any_instance.should_receive(:supply_default).exactly(1)
439 it 'newテンプレートを描画する' do
441 response.should render_template("new")
445 it 'new.jsテンプレートを描画する' do
446 get :new, :format => :js
447 response.should render_template("new")
452 get :new, :format => :json
453 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
455 it '絵師モデルにjson単体出力オプションを問い合わせている' do
456 Artist.should_receive(:show_json_opt).exactly(1)
457 get :new, :format => :json
461 context 'ユーザ権限がないとき' do
466 it 'ステータスコード302 Foundを返す' do
468 response.status.should eq 302
470 it 'サインインページへ遷移する' do
472 response.body.should redirect_to '/users/sign_in'
476 it 'ステータスコード401 Unauthorizedを返す' do
477 get :new, :format => :js
478 response.status.should eq 401
480 it '応答メッセージにUnauthorizedを返す' do
481 get :new, :format => :js
482 response.message.should match(/Unauthorized/)
486 it 'ステータスコード401 Unauthorizedを返す' do
487 get :new, :format => :json
488 response.status.should eq 401
490 it '応答メッセージにUnauthorizedを返す' do
491 get :new, :format => :json
492 response.message.should match(/Unauthorized/)
496 context 'ユーザ権限はないが管理者権限があるとき' do
502 it 'ステータスコード302 Foundを返す' do
504 response.status.should eq 302
506 it 'サインインページへ遷移する' do
508 response.body.should redirect_to '/users/sign_in'
512 context 'ユーザだが作家登録していないとき' do
517 it 'ステータスコード302 Foundを返す' do
519 response.status.should eq 302
523 response.body.should redirect_to new_author_path
529 describe '新規作成に於いて' do
532 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
534 context '事前チェックしておく' do
535 it '絵師モデルにデフォルト値補充を依頼している' do
536 Artist.any_instance.should_receive(:supply_default).exactly(1)
537 post :create, :artist => @attr
539 it '絵師モデルにカラム値復元を依頼している' do
540 Artist.any_instance.should_receive(:attributes=).exactly(1)
541 post :create, :artist => @attr
543 it '絵師モデルに上書き補充を依頼している' do
544 Artist.any_instance.should_receive(:overwrite).exactly(1)
545 post :create, :artist => @attr
548 Artist.any_instance.should_receive(:save).exactly(1)
549 post :create, :artist => @attr
552 context 'つつがなく終わるとき' do
553 it "@arに作成された絵師を保持していて、それがDBにある" do
554 post :create, :artist => @attr
555 assigns(:ar).should be_a(Artist)
556 assigns(:ar).should be_persisted
559 it 'ステータスコード302 Foundを返す' do
560 Artist.any_instance.stub(:save).and_return(true)
561 post :create, :artist => @attr
562 response.status.should eq 302
565 # Artist.any_instance.stub(:save).and_return(true)
566 post :create, :artist => @attr
567 response.should redirect_to(root_path)
571 it 'ステータスコード200 OKを返す' do
572 # Artist.any_instance.stub(:save).and_return(true)
573 post :create, :artist => @attr, :format => :json
574 response.should be_success
576 it '作成された絵師をjsonデータで返す' do
577 post :create, :artist => @attr, :format => :json
578 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
580 it '絵師モデルにjson単体出力オプションを問い合わせている' do
581 Artist.should_receive(:show_json_opt).exactly(1)
582 post :create, :artist => @attr, :format => :json
585 post :create, :artist => @attr, :format => :json
586 json = JSON.parse response.body
587 json["name"].should match(/ken/)
591 context 'ユーザ権限がないとき' do
596 it 'ステータスコード302 Foundを返す' do
597 post :create, :artist => @attr
598 response.status.should eq 302
600 it 'サインインページへ遷移する' do
601 post :create, :artist => @attr
602 response.body.should redirect_to '/users/sign_in'
606 it 'ステータスコード401 Unauthorizedを返す' do
607 post :create, :artist => @attr, :format => :json
608 response.status.should eq 401
610 it '応答メッセージにUnauthorizedを返す' do
611 post :create, :artist => @attr, :format => :json
612 response.message.should match(/Unauthorized/)
616 context 'ユーザ権限はないが管理者権限があるとき' do
622 it 'ステータスコード302 Foundを返す' do
623 post :create, :artist => @attr
624 response.status.should eq 302
626 it 'サインインページへ遷移する' do
627 post :create, :artist => @attr
628 response.body.should redirect_to '/users/sign_in'
632 context 'ユーザだが作家登録していないとき' do
637 it 'ステータスコード302 Foundを返す' do
638 post :create, :artist => @attr
639 response.status.should eq 302
642 post :create, :artist => @attr
643 response.body.should redirect_to new_author_path
647 context '検証、保存に失敗した' do
649 Artist.any_instance.stub(:save).and_return(false)
651 it "未保存の絵師を保持している" do
652 post :create, :artist => @attr
653 assigns(:ar).should be_a_new(Artist)
656 it 'ステータスコード200 OKを返す' do
657 post :create, :artist => @attr
658 response.status.should eq 200
661 post :create, :artist => @attr
662 response.should render_template("new")
666 it 'ステータスコード422 unprocessable_entity を返す' do
667 post :create, :artist => @attr, :format => :json
668 response.status.should eq 422
670 it '応答メッセージUnprocessable Entityを返す' do
671 post :create, :artist => @attr, :format => :json
672 response.message.should match(/Unprocessable/)
678 describe '編集フォーム表示に於いて' do
681 Artist.stub(:edit).and_return(@artist)
683 context 'つつがなく終わるとき' do
684 it 'ステータスコード200 OKを返す' do
685 get :edit, :id => @artist.id
686 response.should be_success
688 it '絵師モデルに編集取得を問い合わせている' do
689 Artist.should_receive(:edit).exactly(1)
690 get :edit, :id => @artist.id
692 it '@artistにデータを用意している' do
693 get :edit, :id => @artist.id
694 assigns(:artist).should eq @artist
697 it 'editテンプレートを描画する' do
698 get :edit, :id => @artist.id
699 response.should render_template("edit")
703 it 'edit.jsテンプレートを描画する' do
704 get :edit, :id => @artist.id, :format => :js
705 response.should render_template("edit")
709 context 'ユーザ権限がないとき' do
714 it 'ステータスコード302 Foundを返す' do
715 get :edit, :id => @artist.id
716 response.status.should eq 302
718 it 'サインインページへ遷移する' do
719 get :edit, :id => @artist.id
720 response.body.should redirect_to '/users/sign_in'
724 it 'ステータスコード401 Unauthorizedを返す' do
725 get :edit, :id => @artist.id, :format => :js
726 response.status.should eq 401
728 it '応答メッセージにUnauthorizedを返す' do
729 get :edit, :id => @artist.id, :format => :js
730 response.message.should match(/Unauthorized/)
734 context 'ユーザ権限はないが管理者権限があるとき' do
740 it 'ステータスコード302 Foundを返す' do
741 get :edit, :id => @artist.id
742 response.status.should eq 302
744 it 'サインインページへ遷移する' do
745 get :edit, :id => @artist.id
746 response.body.should redirect_to '/users/sign_in'
750 context 'ユーザだが作家登録していないとき' do
755 it 'ステータスコード302 Foundを返す' do
756 get :edit, :id => @artist.id
757 response.status.should eq 302
760 get :edit, :id => @artist.id
761 response.body.should redirect_to new_author_path
769 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
772 context '事前チェックしておく' do
773 it '絵師モデルに編集取得を問い合わせている' do
774 Artist.stub(:edit).with(any_args()).and_return @artist
775 Artist.should_receive(:edit).exactly(1)
776 put :update, :id => @artist.id, :artist => @attr
778 it '絵師モデルにカラム値復元を依頼している' do
779 Artist.any_instance.should_receive(:attributes=).exactly(1)
780 put :update, :id => @artist.id, :artist => @attr
782 it '絵師モデルに上書き補充を依頼している' do
783 Artist.any_instance.should_receive(:overwrite).exactly(1)
784 put :update, :id => @artist.id, :artist => @attr
787 Artist.any_instance.stub(:save).with(any_args).and_return true
788 Artist.any_instance.should_receive(:save).exactly(1)
789 put :update, :id => @artist.id, :artist => @attr
791 it '@arにアレを取得している' do
792 put :update, :id => @artist.id, :artist => @attr
793 assigns(:ar).should eq @artist
796 context 'つつがなく終わるとき' do
798 put :update, :id => @artist.id, :artist => @attr
799 Artist.find(@artist.id).name.should eq 'ryu'
802 it 'ステータスコード302 Foundを返す' do
803 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
804 put :update, :id => @artist.id, :artist => @attr
805 response.status.should eq 302
808 put :update, :id => @artist.id, :artist => @attr
809 response.should redirect_to('/home/configure')
813 it 'ステータスコード200 OKを返す' do
814 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
815 put :update, :id => @artist.id, :artist => @attr, :format => :json
816 response.should be_success
819 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
820 put :update, :id => @artist.id, :artist => @attr, :format => :json
821 response.body.should match /./
825 context 'ユーザ権限がないとき' do
830 it 'ステータスコード302 Foundを返す' do
831 put :update, :id => @artist.id, :artist => @attr
832 response.status.should eq 302
834 it 'サインインページへ遷移する' do
835 put :update, :id => @artist.id, :artist => @attr
836 response.body.should redirect_to '/users/sign_in'
840 it '応答メッセージにUnauthorizedを返す' do
841 put :update, :id => @artist.id, :artist => @attr, :format => :json
842 response.message.should match(/Unauthorized/)
846 context 'ユーザ権限はないが管理者権限があるとき' do
852 it 'ステータスコード302 Foundを返す' do
853 put :update, :id => @artist.id, :artist => @attr
854 response.status.should eq 302
856 it 'サインインページへ遷移する' do
857 put :update, :id => @artist.id, :artist => @attr
858 response.body.should redirect_to '/users/sign_in'
862 context 'ユーザだが作家登録していないとき' do
867 it 'ステータスコード302 Foundを返す' do
868 put :update, :id => @artist.id, :artist => @attr
869 response.status.should eq 302
872 put :update, :id => @artist.id, :artist => @attr
873 response.body.should redirect_to new_author_path
877 context '検証、保存に失敗したとき' do
879 Artist.any_instance.stub(:save).and_return(false)
882 it 'ステータスコード200 Okを返す' do
883 put :update, :id => @artist.id, :artist => @attr
884 response.status.should eq 200
887 put :update, :id => @artist.id, :artist => @attr
888 response.should render_template("edit")
892 it 'ステータスコード422 unprocessable_entity を返す' do
893 Artist.any_instance.stub(:save).and_return(false)
894 put :update, :id => @artist.id, :artist => @attr, :format => :json
895 response.status.should eq 422
897 it '応答メッセージUnprocessable Entityを返す' do
898 put :update, :id => @artist.id, :artist => @attr, :format => :json
899 response.message.should match(/Unprocessable/)
906 describe '一覧表示に於いて' do
908 Artist.stub(:list).and_return([@artist, @artist, @artist])
911 context 'つつがなく終わるとき' do
912 it 'ステータスコード200 OKを返す' do
914 response.should be_success
917 it 'indexテンプレートを描画する' do
919 response.should render_template("index")
924 get :index, :format => :json
925 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
929 context 'ユーザ権限がないとき' do
933 it 'ステータスコード200 OKを返す' do
935 response.should be_success
938 it 'indexテンプレートを描画する' do
940 response.should render_template("index")
945 get :index, :format => :json
946 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
954 Artist.stub(:show).and_return(@artist)
957 context 'つつがなく終わるとき' do
958 it 'ステータスコード200 OKを返す' do
959 get :show, :id => @artist.id
960 response.should be_success
963 it 'showテンプレートを描画する' do
964 get :show, :id => @artist.id
965 response.should render_template("show")
970 get :show, :id => @artist.id, :format => :json
971 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
975 context 'ユーザ権限がないとき' do
979 it 'ステータスコード200 OKを返す' do
980 get :show, :id => @artist.id
981 response.should be_success
984 it 'showテンプレートを描画する' do
985 get :show, :id => @artist.id
986 response.should render_template("show")
991 get :show, :id => @artist.id, :format => :json
992 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
998 describe '対象絵師の素材一覧表示に於いて' do
1000 @other_user = FactoryGirl.create( :user_yas)
1001 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1002 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1003 @op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
1004 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @other_artist.id
1005 @rp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
1006 ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp])
1009 context 'つつがなく終わるとき' do
1010 it 'ステータスコード200 OKを返す' do
1011 get :resource_pictures, :id => @other_artist.id
1012 response.should be_success
1015 it 'resource_pictureテンプレートを描画する' do
1016 get :resource_pictures, :id => @other_artist.id
1017 response.should render_template("resource_pictures")
1022 get :resource_pictures, :id => @other_artist.id, :format => :json
1023 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1027 context 'ユーザ権限がないとき' do
1031 it 'ステータスコード200 OKを返す' do
1032 get :resource_pictures, :id => @other_artist.id
1033 response.should be_success
1036 it 'resource_pictureテンプレートを描画する' do
1037 get :resource_pictures, :id => @other_artist.id
1038 response.should render_template("resource_pictures")
1043 get :resource_pictures, :id => @other_artist.id, :format => :json
1044 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1050 describe '絵師数取得に於いて' do
1052 Artist.should_receive(:visible_count).and_return(3)
1055 context 'つつがなく終わるとき' do
1056 it 'ステータスコード200 OKを返す' do
1057 get :count, :format => :json
1058 response.should be_success
1062 get :count, :format => :json
1063 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1069 describe '新規作成フォーム表示に於いて' do
1073 context 'つつがなく終わるとき' do
1074 it 'ステータスコード200 OKを返す' do
1076 response.should be_success
1079 it 'newテンプレートを描画する' do
1081 response.should render_template("new")
1085 it 'new.jsテンプレートを描画する' do
1086 get :new, :format => :js
1087 response.should render_template("new")
1092 get :new, :format => :json
1093 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1097 context 'ユーザ権限がないとき' do
1102 it 'ステータスコード302 Foundを返す' do
1104 response.status.should eq 302
1106 it 'サインインページへ遷移する' do
1108 response.body.should redirect_to '/users/sign_in'
1112 it 'ステータスコード401 Unauthorizedを返す' do
1113 get :new, :format => :js
1114 response.status.should eq 401
1116 it '応答メッセージにUnauthorizedを返す' do
1117 get :new, :format => :js
1118 response.message.should match(/Unauthorized/)
1122 it 'ステータスコード401 Unauthorizedを返す' do
1123 get :new, :format => :json
1124 response.status.should eq 401
1126 it '応答メッセージにUnauthorizedを返す' do
1127 get :new, :format => :json
1128 response.message.should match(/Unauthorized/)
1134 describe '新規作成に於いて' do
1137 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
1139 context 'つつがなく終わるとき' do
1141 it 'ステータスコード302 Foundを返す' do
1142 Artist.any_instance.stub(:save).and_return(true)
1143 post :create, :artist => @attr
1144 response.status.should eq 302
1147 # Artist.any_instance.stub(:save).and_return(true)
1148 post :create, :artist => @attr
1149 response.should redirect_to(root_path)
1153 it 'ステータスコード200 OKを返す' do
1154 # Artist.any_instance.stub(:save).and_return(true)
1155 post :create, :artist => @attr, :format => :json
1156 response.should be_success
1158 it '作成された絵師をjsonデータで返す' do
1159 post :create, :artist => @attr, :format => :json
1160 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1164 context 'ユーザ権限がないとき' do
1169 it 'ステータスコード302 Foundを返す' do
1170 post :create, :artist => @attr
1171 response.status.should eq 302
1173 it 'サインインページへ遷移する' do
1174 post :create, :artist => @attr
1175 response.body.should redirect_to '/users/sign_in'
1179 it 'ステータスコード401 Unauthorizedを返す' do
1180 post :create, :artist => @attr, :format => :json
1181 response.status.should eq 401
1183 it '応答メッセージにUnauthorizedを返す' do
1184 post :create, :artist => @attr, :format => :json
1185 response.message.should match(/Unauthorized/)
1191 describe '編集フォーム表示に於いて' do
1194 Artist.stub(:edit).and_return(@artist)
1196 context 'つつがなく終わるとき' do
1197 it 'ステータスコード200 OKを返す' do
1198 get :edit, :id => @artist.id
1199 response.should be_success
1202 it 'editテンプレートを描画する' do
1203 get :edit, :id => @artist.id
1204 response.should render_template("edit")
1208 it 'edit.jsテンプレートを描画する' do
1209 get :edit, :id => @artist.id, :format => :js
1210 response.should render_template("edit")
1214 context 'ユーザ権限がないとき' do
1219 it 'ステータスコード302 Foundを返す' do
1220 get :edit, :id => @artist.id
1221 response.status.should eq 302
1223 it 'サインインページへ遷移する' do
1224 get :edit, :id => @artist.id
1225 response.body.should redirect_to '/users/sign_in'
1229 it 'ステータスコード401 Unauthorizedを返す' do
1230 get :edit, :id => @artist.id, :format => :js
1231 response.status.should eq 401
1233 it '応答メッセージにUnauthorizedを返す' do
1234 get :edit, :id => @artist.id, :format => :js
1235 response.message.should match(/Unauthorized/)
1241 describe '更新に於いて' do
1243 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
1246 context 'つつがなく終わるとき' do
1248 it 'ステータスコード302 Foundを返す' do
1249 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
1250 put :update, :id => @artist.id, :artist => @attr
1251 response.status.should eq 302
1254 put :update, :id => @artist.id, :artist => @attr
1255 response.should redirect_to('/home/configure')
1259 it 'ステータスコード200 OKを返す' do
1260 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
1261 put :update, :id => @artist.id, :artist => @attr, :format => :json
1262 response.should be_success
1264 it 'ページ本体は特に返さない' do
1265 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
1266 put :update, :id => @artist.id, :artist => @attr, :format => :json
1267 response.body.should match /./
1271 context 'ユーザ権限がないとき' do
1275 it 'ステータスコード302 Foundを返す' do
1276 put :update, :id => @artist.id, :artist => @attr
1277 response.status.should eq 302
1280 it 'サインインページへ遷移する' do
1281 put :update, :id => @artist.id, :artist => @attr
1282 response.body.should redirect_to '/users/sign_in'
1286 it '応答メッセージにUnauthorizedを返す' do
1287 put :update, :id => @artist.id, :artist => @attr, :format => :json
1288 response.message.should match(/Unauthorized/)