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 Artist.stub(:show).and_return(@artist)
268 ResourcePicture.stub(:himlist).and_return([@rp, @rp, @rp], [nil, nil, nil])
271 context 'パラメータpageについて' do
273 get :resource_pictures, :id => @other_artist.id, :page => 5
274 assigns(:page).should eq 5
276 it '省略されると@pageに1値が入る' do
277 get :resource_pictures, :id => @other_artist.id
278 assigns(:page).should eq 1
280 it '与えられたpage_sizeがセットされている' do
281 get :resource_pictures, :id => @other_artist.id, :page_size => 15
282 assigns(:page_size).should eq 15
284 it '省略されると@page_sizeにデフォルト値が入る' do
285 get :resource_pictures, :id => @other_artist.id
286 assigns(:page_size).should eq Author.default_resource_picture_page_size
288 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
289 get :resource_pictures, :id => @other_artist.id, :page_size => 1500
290 assigns(:page_size).should eq Author.resource_picture_max_page_size
292 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
293 get :resource_pictures, :id => @other_artist.id, :page_size => 0
294 assigns(:page_size).should eq Author.default_resource_picture_page_size
297 context 'つつがなく終わるとき' do
298 it 'ステータスコード200 OKを返す' do
299 get :resource_pictures, :id => @other_artist.id
300 response.should be_success
302 it '絵師モデルに単体取得を問い合わせている' do
303 Artist.should_receive(:show).exactly(1)
304 get :resource_pictures, :id => @other_artist.id
306 it '素材モデルに一覧を問い合わせている' do
307 ResourcePicture.should_receive(:himlist).exactly(1)
308 get :resource_pictures, :id => @other_artist.id
310 it '@resource_picturesにリストを取得している' do
311 get :resource_pictures, :id => @other_artist.id
312 assigns(:resource_pictures).should have_at_least(3).items
315 it '@paginateにページ制御を取得している' do
316 get :resource_pictures, :id => @other_artist.id
317 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
319 it 'resource_pictureテンプレートを描画する' do
320 get :resource_pictures, :id => @other_artist.id
321 response.should render_template("resource_pictures")
326 get :resource_pictures, :id => @other_artist.id, :format => :json
327 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
329 it '素材モデルにコマリストのjson出力を問い合わせている' do
330 ResourcePicture.should_receive(:list_json_opt).exactly(1)
331 get :resource_pictures, :id => @other_artist.id, :format => :json
333 it 'データがリスト構造になっている' do
334 get :resource_pictures, :id => @other_artist.id, :format => :json
335 json = JSON.parse response.body
336 json.should have_at_least(3).items
338 it 'リストの先頭くらいは素材っぽいものであって欲しい' do
339 get :resource_pictures, :id => @other_artist.id, :format => :json
340 json = JSON.parse response.body
341 json.first.has_key?("original_picture_id").should be_true
342 json.first.has_key?("license_id").should be_true
346 context 'ユーザ権限がないとき' do
351 it 'ステータスコード302 Foundを返す' do
352 get :resource_pictures, :id => @other_artist.id
353 response.status.should eq 302
355 it 'サインインページへ遷移する' do
356 get :resource_pictures, :id => @other_artist.id
357 response.should redirect_to '/users/sign_in'
361 it 'ステータスコード401 Unauthorizedを返す' do
362 get :resource_pictures, :id => @other_artist.id, :format => :json
363 response.status.should eq 401
365 it '応答メッセージにUnauthorizedを返す' do
366 get :resource_pictures, :id => @other_artist.id, :format => :json
367 response.message.should match(/Unauthorized/)
371 context 'ユーザ権限はないが管理者権限があるとき' do
376 it 'ステータスコード200 OKを返す' do
377 get :resource_pictures, :id => @other_artist.id
378 response.should be_success
381 context 'ユーザだが作家登録していないとき' do
385 it 'ステータスコード200 OKを返す' do
386 get :resource_pictures, :id => @other_artist.id
387 response.should be_success
392 describe '絵師数取得に於いて' do
394 Artist.should_receive(:visible_count).and_return(3)
397 context 'つつがなく終わるとき' do
398 it 'ステータスコード200 OKを返す' do
399 get :count, :format => :json
400 response.should be_success
404 get :count, :format => :json
405 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
407 it 'データがHash構造になっていて絵師数が3である' do
408 get :count, :format => :json
409 json = JSON.parse response.body
410 json["count"].should == 3
416 describe '新規作成フォーム表示に於いて' do
420 context 'つつがなく終わるとき' do
421 it 'ステータスコード200 OKを返す' do
423 response.should be_success
425 it '@artistに新規データを用意している' do
427 assigns(:ar).should be_a_new(Artist)
429 it '絵師モデルにデフォルト値補充を依頼している' do
430 Artist.any_instance.should_receive(:supply_default).exactly(1)
434 it 'newテンプレートを描画する' do
436 response.should render_template("new")
440 it 'new.jsテンプレートを描画する' do
441 get :new, :format => :js
442 response.should render_template("new")
447 get :new, :format => :json
448 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
450 it '絵師モデルにjson単体出力オプションを問い合わせている' do
451 Artist.should_receive(:show_json_opt).exactly(1)
452 get :new, :format => :json
456 context 'ユーザ権限がないとき' do
461 it 'ステータスコード302 Foundを返す' do
463 response.status.should eq 302
465 it 'サインインページへ遷移する' do
467 response.body.should redirect_to '/users/sign_in'
471 it 'ステータスコード401 Unauthorizedを返す' do
472 get :new, :format => :js
473 response.status.should eq 401
475 it '応答メッセージにUnauthorizedを返す' do
476 get :new, :format => :js
477 response.message.should match(/Unauthorized/)
481 it 'ステータスコード401 Unauthorizedを返す' do
482 get :new, :format => :json
483 response.status.should eq 401
485 it '応答メッセージにUnauthorizedを返す' do
486 get :new, :format => :json
487 response.message.should match(/Unauthorized/)
491 context 'ユーザ権限はないが管理者権限があるとき' do
497 it 'ステータスコード302 Foundを返す' do
499 response.status.should eq 302
501 it 'サインインページへ遷移する' do
503 response.body.should redirect_to '/users/sign_in'
507 context 'ユーザだが作家登録していないとき' do
512 it 'ステータスコード302 Foundを返す' do
514 response.status.should eq 302
518 response.body.should redirect_to new_author_path
524 describe '新規作成に於いて' do
527 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
529 context '事前チェックしておく' do
530 it '絵師モデルにデフォルト値補充を依頼している' do
531 Artist.any_instance.should_receive(:supply_default).exactly(1)
532 post :create, :artist => @attr
534 it '絵師モデルにカラム値復元を依頼している' do
535 Artist.any_instance.should_receive(:attributes=).exactly(1)
536 post :create, :artist => @attr
538 it '絵師モデルに上書き補充を依頼している' do
539 Artist.any_instance.should_receive(:overwrite).exactly(1)
540 post :create, :artist => @attr
543 Artist.any_instance.should_receive(:save).exactly(1)
544 post :create, :artist => @attr
547 context 'つつがなく終わるとき' do
548 it "@arに作成された絵師を保持していて、それがDBにある" do
549 post :create, :artist => @attr
550 assigns(:ar).should be_a(Artist)
551 assigns(:ar).should be_persisted
554 it 'ステータスコード302 Foundを返す' do
555 Artist.any_instance.stub(:save).and_return(true)
556 post :create, :artist => @attr
557 response.status.should eq 302
560 # Artist.any_instance.stub(:save).and_return(true)
561 post :create, :artist => @attr
562 response.should redirect_to(root_path)
566 it 'ステータスコード200 OKを返す' do
567 # Artist.any_instance.stub(:save).and_return(true)
568 post :create, :artist => @attr, :format => :json
569 response.should be_success
571 it '作成された絵師をjsonデータで返す' do
572 post :create, :artist => @attr, :format => :json
573 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
575 it '絵師モデルにjson単体出力オプションを問い合わせている' do
576 Artist.should_receive(:show_json_opt).exactly(1)
577 post :create, :artist => @attr, :format => :json
580 post :create, :artist => @attr, :format => :json
581 json = JSON.parse response.body
582 json["name"].should match(/ken/)
586 context 'ユーザ権限がないとき' do
591 it 'ステータスコード302 Foundを返す' do
592 post :create, :artist => @attr
593 response.status.should eq 302
595 it 'サインインページへ遷移する' do
596 post :create, :artist => @attr
597 response.body.should redirect_to '/users/sign_in'
601 it 'ステータスコード401 Unauthorizedを返す' do
602 post :create, :artist => @attr, :format => :json
603 response.status.should eq 401
605 it '応答メッセージにUnauthorizedを返す' do
606 post :create, :artist => @attr, :format => :json
607 response.message.should match(/Unauthorized/)
611 context 'ユーザ権限はないが管理者権限があるとき' do
617 it 'ステータスコード302 Foundを返す' do
618 post :create, :artist => @attr
619 response.status.should eq 302
621 it 'サインインページへ遷移する' do
622 post :create, :artist => @attr
623 response.body.should redirect_to '/users/sign_in'
627 context 'ユーザだが作家登録していないとき' do
632 it 'ステータスコード302 Foundを返す' do
633 post :create, :artist => @attr
634 response.status.should eq 302
637 post :create, :artist => @attr
638 response.body.should redirect_to new_author_path
642 context '検証、保存に失敗した' do
644 Artist.any_instance.stub(:save).and_return(false)
646 it "未保存の絵師を保持している" do
647 post :create, :artist => @attr
648 assigns(:ar).should be_a_new(Artist)
651 it 'ステータスコード200 OKを返す' do
652 post :create, :artist => @attr
653 response.status.should eq 200
656 post :create, :artist => @attr
657 response.should render_template("new")
661 it 'ステータスコード422 unprocessable_entity を返す' do
662 post :create, :artist => @attr, :format => :json
663 response.status.should eq 422
665 it '応答メッセージUnprocessable Entityを返す' do
666 post :create, :artist => @attr, :format => :json
667 response.message.should match(/Unprocessable/)
673 describe '編集フォーム表示に於いて' do
676 Artist.stub(:edit).and_return(@artist)
678 context 'つつがなく終わるとき' do
679 it 'ステータスコード200 OKを返す' do
680 get :edit, :id => @artist.id
681 response.should be_success
683 it '絵師モデルに編集取得を問い合わせている' do
684 Artist.should_receive(:edit).exactly(1)
685 get :edit, :id => @artist.id
687 it '@artistにデータを用意している' do
688 get :edit, :id => @artist.id
689 assigns(:artist).should eq @artist
692 it 'editテンプレートを描画する' do
693 get :edit, :id => @artist.id
694 response.should render_template("edit")
698 it 'edit.jsテンプレートを描画する' do
699 get :edit, :id => @artist.id, :format => :js
700 response.should render_template("edit")
704 context 'ユーザ権限がないとき' do
709 it 'ステータスコード302 Foundを返す' do
710 get :edit, :id => @artist.id
711 response.status.should eq 302
713 it 'サインインページへ遷移する' do
714 get :edit, :id => @artist.id
715 response.body.should redirect_to '/users/sign_in'
719 it 'ステータスコード401 Unauthorizedを返す' do
720 get :edit, :id => @artist.id, :format => :js
721 response.status.should eq 401
723 it '応答メッセージにUnauthorizedを返す' do
724 get :edit, :id => @artist.id, :format => :js
725 response.message.should match(/Unauthorized/)
729 context 'ユーザ権限はないが管理者権限があるとき' do
735 it 'ステータスコード302 Foundを返す' do
736 get :edit, :id => @artist.id
737 response.status.should eq 302
739 it 'サインインページへ遷移する' do
740 get :edit, :id => @artist.id
741 response.body.should redirect_to '/users/sign_in'
745 context 'ユーザだが作家登録していないとき' do
750 it 'ステータスコード302 Foundを返す' do
751 get :edit, :id => @artist.id
752 response.status.should eq 302
755 get :edit, :id => @artist.id
756 response.body.should redirect_to new_author_path
764 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
767 context '事前チェックしておく' do
768 it '絵師モデルに編集取得を問い合わせている' do
769 Artist.stub(:edit).with(any_args()).and_return @artist
770 Artist.should_receive(:edit).exactly(1)
771 put :update, :id => @artist.id, :artist => @attr
773 it '絵師モデルにカラム値復元を依頼している' do
774 Artist.any_instance.should_receive(:attributes=).exactly(1)
775 put :update, :id => @artist.id, :artist => @attr
777 it '絵師モデルに上書き補充を依頼している' do
778 Artist.any_instance.should_receive(:overwrite).exactly(1)
779 put :update, :id => @artist.id, :artist => @attr
782 Artist.any_instance.stub(:save).with(any_args).and_return true
783 Artist.any_instance.should_receive(:save).exactly(1)
784 put :update, :id => @artist.id, :artist => @attr
786 it '@arにアレを取得している' do
787 put :update, :id => @artist.id, :artist => @attr
788 assigns(:ar).should eq @artist
791 context 'つつがなく終わるとき' do
793 put :update, :id => @artist.id, :artist => @attr
794 Artist.find(@artist.id).name.should eq 'ryu'
797 it 'ステータスコード302 Foundを返す' do
798 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
799 put :update, :id => @artist.id, :artist => @attr
800 response.status.should eq 302
803 put :update, :id => @artist.id, :artist => @attr
804 response.should redirect_to('/home/configure')
808 it 'ステータスコード200 OKを返す' do
809 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
810 put :update, :id => @artist.id, :artist => @attr, :format => :json
811 response.should be_success
814 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
815 put :update, :id => @artist.id, :artist => @attr, :format => :json
816 response.body.should match /./
820 context 'ユーザ権限がないとき' do
825 it 'ステータスコード302 Foundを返す' do
826 put :update, :id => @artist.id, :artist => @attr
827 response.status.should eq 302
829 it 'サインインページへ遷移する' do
830 put :update, :id => @artist.id, :artist => @attr
831 response.body.should redirect_to '/users/sign_in'
835 it '応答メッセージにUnauthorizedを返す' do
836 put :update, :id => @artist.id, :artist => @attr, :format => :json
837 response.message.should match(/Unauthorized/)
841 context 'ユーザ権限はないが管理者権限があるとき' do
847 it 'ステータスコード302 Foundを返す' do
848 put :update, :id => @artist.id, :artist => @attr
849 response.status.should eq 302
851 it 'サインインページへ遷移する' do
852 put :update, :id => @artist.id, :artist => @attr
853 response.body.should redirect_to '/users/sign_in'
857 context 'ユーザだが作家登録していないとき' do
862 it 'ステータスコード302 Foundを返す' do
863 put :update, :id => @artist.id, :artist => @attr
864 response.status.should eq 302
867 put :update, :id => @artist.id, :artist => @attr
868 response.body.should redirect_to new_author_path
872 context '検証、保存に失敗したとき' do
874 Artist.any_instance.stub(:save).and_return(false)
877 it 'ステータスコード200 Okを返す' do
878 put :update, :id => @artist.id, :artist => @attr
879 response.status.should eq 200
882 put :update, :id => @artist.id, :artist => @attr
883 response.should render_template("edit")
887 it 'ステータスコード422 unprocessable_entity を返す' do
888 Artist.any_instance.stub(:save).and_return(false)
889 put :update, :id => @artist.id, :artist => @attr, :format => :json
890 response.status.should eq 422
892 it '応答メッセージUnprocessable Entityを返す' do
893 put :update, :id => @artist.id, :artist => @attr, :format => :json
894 response.message.should match(/Unprocessable/)
901 describe '一覧表示に於いて' do
903 Artist.stub(:list).and_return([@artist, @artist, @artist])
906 context 'つつがなく終わるとき' do
907 it 'ステータスコード200 OKを返す' do
909 response.should be_success
912 it 'indexテンプレートを描画する' do
914 response.should render_template("index")
919 get :index, :format => :json
920 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
924 context 'ユーザ権限がないとき' do
928 it 'ステータスコード200 OKを返す' do
930 response.should be_success
933 it 'indexテンプレートを描画する' do
935 response.should render_template("index")
940 get :index, :format => :json
941 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
949 Artist.stub(:show).and_return(@artist)
952 context 'つつがなく終わるとき' do
953 it 'ステータスコード200 OKを返す' do
954 get :show, :id => @artist.id
955 response.should be_success
958 it 'showテンプレートを描画する' do
959 get :show, :id => @artist.id
960 response.should render_template("show")
965 get :show, :id => @artist.id, :format => :json
966 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
970 context 'ユーザ権限がないとき' do
974 it 'ステータスコード200 OKを返す' do
975 get :show, :id => @artist.id
976 response.should be_success
979 it 'showテンプレートを描画する' do
980 get :show, :id => @artist.id
981 response.should render_template("show")
986 get :show, :id => @artist.id, :format => :json
987 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
993 describe '対象絵師の素材一覧表示に於いて' do
995 @other_user = FactoryGirl.create( :user_yas)
996 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
997 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
998 @op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
999 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @other_artist.id
1000 @rp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
1001 ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp])
1004 context 'つつがなく終わるとき' do
1005 it 'ステータスコード200 OKを返す' do
1006 get :resource_pictures, :id => @other_artist.id
1007 response.should be_success
1010 it 'resource_pictureテンプレートを描画する' do
1011 get :resource_pictures, :id => @other_artist.id
1012 response.should render_template("resource_pictures")
1017 get :resource_pictures, :id => @other_artist.id, :format => :json
1018 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1022 context 'ユーザ権限がないとき' do
1026 it 'ステータスコード200 OKを返す' do
1027 get :resource_pictures, :id => @other_artist.id
1028 response.should be_success
1031 it 'resource_pictureテンプレートを描画する' do
1032 get :resource_pictures, :id => @other_artist.id
1033 response.should render_template("resource_pictures")
1038 get :resource_pictures, :id => @other_artist.id, :format => :json
1039 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1045 describe '絵師数取得に於いて' do
1047 Artist.should_receive(:visible_count).and_return(3)
1050 context 'つつがなく終わるとき' do
1051 it 'ステータスコード200 OKを返す' do
1052 get :count, :format => :json
1053 response.should be_success
1057 get :count, :format => :json
1058 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1064 describe '新規作成フォーム表示に於いて' do
1068 context 'つつがなく終わるとき' do
1069 it 'ステータスコード200 OKを返す' do
1071 response.should be_success
1074 it 'newテンプレートを描画する' do
1076 response.should render_template("new")
1080 it 'new.jsテンプレートを描画する' do
1081 get :new, :format => :js
1082 response.should render_template("new")
1087 get :new, :format => :json
1088 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1092 context 'ユーザ権限がないとき' do
1097 it 'ステータスコード302 Foundを返す' do
1099 response.status.should eq 302
1101 it 'サインインページへ遷移する' do
1103 response.body.should redirect_to '/users/sign_in'
1107 it 'ステータスコード401 Unauthorizedを返す' do
1108 get :new, :format => :js
1109 response.status.should eq 401
1111 it '応答メッセージにUnauthorizedを返す' do
1112 get :new, :format => :js
1113 response.message.should match(/Unauthorized/)
1117 it 'ステータスコード401 Unauthorizedを返す' do
1118 get :new, :format => :json
1119 response.status.should eq 401
1121 it '応答メッセージにUnauthorizedを返す' do
1122 get :new, :format => :json
1123 response.message.should match(/Unauthorized/)
1129 describe '新規作成に於いて' do
1132 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
1134 context 'つつがなく終わるとき' do
1136 it 'ステータスコード302 Foundを返す' do
1137 Artist.any_instance.stub(:save).and_return(true)
1138 post :create, :artist => @attr
1139 response.status.should eq 302
1142 # Artist.any_instance.stub(:save).and_return(true)
1143 post :create, :artist => @attr
1144 response.should redirect_to(root_path)
1148 it 'ステータスコード200 OKを返す' do
1149 # Artist.any_instance.stub(:save).and_return(true)
1150 post :create, :artist => @attr, :format => :json
1151 response.should be_success
1153 it '作成された絵師をjsonデータで返す' do
1154 post :create, :artist => @attr, :format => :json
1155 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1159 context 'ユーザ権限がないとき' do
1164 it 'ステータスコード302 Foundを返す' do
1165 post :create, :artist => @attr
1166 response.status.should eq 302
1168 it 'サインインページへ遷移する' do
1169 post :create, :artist => @attr
1170 response.body.should redirect_to '/users/sign_in'
1174 it 'ステータスコード401 Unauthorizedを返す' do
1175 post :create, :artist => @attr, :format => :json
1176 response.status.should eq 401
1178 it '応答メッセージにUnauthorizedを返す' do
1179 post :create, :artist => @attr, :format => :json
1180 response.message.should match(/Unauthorized/)
1186 describe '編集フォーム表示に於いて' do
1189 Artist.stub(:edit).and_return(@artist)
1191 context 'つつがなく終わるとき' do
1192 it 'ステータスコード200 OKを返す' do
1193 get :edit, :id => @artist.id
1194 response.should be_success
1197 it 'editテンプレートを描画する' do
1198 get :edit, :id => @artist.id
1199 response.should render_template("edit")
1203 it 'edit.jsテンプレートを描画する' do
1204 get :edit, :id => @artist.id, :format => :js
1205 response.should render_template("edit")
1209 context 'ユーザ権限がないとき' do
1214 it 'ステータスコード302 Foundを返す' do
1215 get :edit, :id => @artist.id
1216 response.status.should eq 302
1218 it 'サインインページへ遷移する' do
1219 get :edit, :id => @artist.id
1220 response.body.should redirect_to '/users/sign_in'
1224 it 'ステータスコード401 Unauthorizedを返す' do
1225 get :edit, :id => @artist.id, :format => :js
1226 response.status.should eq 401
1228 it '応答メッセージにUnauthorizedを返す' do
1229 get :edit, :id => @artist.id, :format => :js
1230 response.message.should match(/Unauthorized/)
1236 describe '更新に於いて' do
1238 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
1241 context 'つつがなく終わるとき' do
1243 it 'ステータスコード302 Foundを返す' do
1244 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
1245 put :update, :id => @artist.id, :artist => @attr
1246 response.status.should eq 302
1249 put :update, :id => @artist.id, :artist => @attr
1250 response.should redirect_to('/home/configure')
1254 it 'ステータスコード200 OKを返す' 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.should be_success
1259 it 'ページ本体は特に返さない' 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.body.should match /./
1266 context 'ユーザ権限がないとき' do
1270 it 'ステータスコード302 Foundを返す' do
1271 put :update, :id => @artist.id, :artist => @attr
1272 response.status.should eq 302
1275 it 'サインインページへ遷移する' do
1276 put :update, :id => @artist.id, :artist => @attr
1277 response.body.should redirect_to '/users/sign_in'
1281 it '応答メッセージにUnauthorizedを返す' do
1282 put :update, :id => @artist.id, :artist => @attr, :format => :json
1283 response.message.should match(/Unauthorized/)