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 '@paginateにページ制御を取得している' do
65 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
67 it 'indexテンプレートを描画する' do
69 response.should render_template("index")
74 get :index, :format => :json
75 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
77 it '絵師モデルにjson一覧出力オプションを問い合わせている' do
78 Artist.should_receive(:list_json_opt).exactly(1)
79 get :index, :format => :json
81 it 'データがリスト構造になっている' do
82 get :index, :format => :json
83 json = JSON.parse response.body
84 json.should have_at_least(3).items
86 it 'リストの先頭くらいは絵師っぽいものであって欲しい' do
87 get :index, :format => :json
88 json = JSON.parse response.body
89 json.first.has_key?("name").should be_true
93 context 'ユーザ権限がないとき' do
98 it 'ステータスコード302 Foundを返す' do
100 response.status.should eq 302
102 it 'サインインページへ遷移する' do
104 response.should redirect_to '/users/sign_in'
108 it 'ステータスコード401 Unauthorizedを返す' do
109 get :index, :format => :json
110 response.status.should eq 401
112 it '応答メッセージにUnauthorizedを返す' do
113 get :index, :format => :json
114 response.message.should match(/Unauthorized/)
118 context 'ユーザ権限はないが管理者権限があるとき' do
123 it 'ステータスコード200 OKを返す' do
125 response.should be_success
128 context 'ユーザ権限はないが借手権限があるとき' do
133 it 'ステータスコード200 OKを返す' do
135 response.should be_success
138 context 'ユーザだが作家登録していないとき' do
142 it 'ステータスコード200 OKを返す' do
144 response.should be_success
151 Artist.stub(:show).and_return(@artist)
154 context 'つつがなく終わるとき' do
155 it 'ステータスコード200 OKを返す' do
156 get :show, :id => @artist.id
157 response.should be_success
159 it '絵師モデルに単体取得を問い合わせている' do
160 Artist.should_receive(:show).exactly(1)
163 it '@arにアレを取得している' do
164 get :show, :id => @artist.id
165 assigns(:ar).should eq(@artist)
168 it 'showテンプレートを描画する' do
169 get :show, :id => @artist.id
170 response.should render_template("show")
175 get :show, :id => @artist.id, :format => :json
176 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
178 it '絵師モデルにjson単体出力オプションを問い合わせている' do
179 Artist.should_receive(:show_json_opt).exactly(1)
180 get :show, :id => @artist.id, :format => :json
183 get :show, :id => @artist.id, :format => :json
184 json = JSON.parse response.body
185 json["name"].should match(/yas/)
189 context 'ユーザ権限がないとき' do
194 it 'ステータスコード302 Foundを返す' do
195 get :show, :id => @artist.id
196 response.status.should eq 302
198 it 'サインインページへ遷移する' do
199 get :show, :id => @artist.id
200 response.body.should redirect_to '/users/sign_in'
204 it 'ステータスコード401 Unauthorizedを返す' do
205 get :show, :id => @artist.id, :format => :json
206 response.status.should eq 401
208 it '応答メッセージにUnauthorizedを返す' do
209 get :show, :id => @artist.id, :format => :json
210 response.message.should match(/Unauthorized/)
214 context 'ユーザ権限はないが管理者権限があるとき' do
219 it 'ステータスコード200 OKを返す' do
220 get :show, :id => @artist.id
221 response.should be_success
224 context 'ユーザ権限はないが借手権限があるとき' do
229 it 'ステータスコード200 OKを返す' do
230 get :show, :id => @artist.id
231 response.should be_success
234 context 'ユーザだが作家登録していないとき' do
238 it 'ステータスコード200 OKを返す' do
239 get :show, :id => @artist.id
240 response.should be_success
244 context '対象作家がないとき' do
246 it '例外404 not_foundを返す' do
249 }.should raise_error(ActiveRecord::RecordNotFound)
253 it '例外404 not_foundを返す' do
255 get :show, :id => 0, :format => :json
256 }.should raise_error(ActiveRecord::RecordNotFound)
263 describe '対象絵師の素材一覧表示に於いて' do
265 @other_user = FactoryGirl.create( :user_yas)
266 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
267 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
268 @op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
269 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @other_artist.id
270 @rp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
271 Artist.stub(:show).and_return(@artist)
272 ResourcePicture.stub(:himlist).and_return([@rp, @rp, @rp], [nil, nil, nil])
275 context 'パラメータpageについて' do
277 get :resource_pictures, :id => @other_artist.id, :page => 5
278 assigns(:page).should eq 5
280 it '省略されると@pageに1値が入る' do
281 get :resource_pictures, :id => @other_artist.id
282 assigns(:page).should eq 1
284 it '与えられたpage_sizeがセットされている' do
285 get :resource_pictures, :id => @other_artist.id, :page_size => 15
286 assigns(:page_size).should eq 15
288 it '省略されると@page_sizeにデフォルト値が入る' do
289 get :resource_pictures, :id => @other_artist.id
290 assigns(:page_size).should eq Author.default_resource_picture_page_size
292 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
293 get :resource_pictures, :id => @other_artist.id, :page_size => 1500
294 assigns(:page_size).should eq Author.resource_picture_max_page_size
296 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
297 get :resource_pictures, :id => @other_artist.id, :page_size => 0
298 assigns(:page_size).should eq Author.default_resource_picture_page_size
301 context 'つつがなく終わるとき' do
302 it 'ステータスコード200 OKを返す' do
303 get :resource_pictures, :id => @other_artist.id
304 response.should be_success
306 it '絵師モデルに単体取得を問い合わせている' do
307 Artist.should_receive(:show).exactly(1)
308 get :resource_pictures, :id => @other_artist.id
310 it '素材モデルに一覧を問い合わせている' do
311 ResourcePicture.should_receive(:himlist).exactly(1)
312 get :resource_pictures, :id => @other_artist.id
314 it '@resource_picturesにリストを取得している' do
315 get :resource_pictures, :id => @other_artist.id
316 assigns(:resource_pictures).should have_at_least(3).items
319 it '@paginateにページ制御を取得している' do
320 get :resource_pictures, :id => @other_artist.id
321 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
323 it 'resource_pictureテンプレートを描画する' do
324 get :resource_pictures, :id => @other_artist.id
325 response.should render_template("resource_pictures")
330 get :resource_pictures, :id => @other_artist.id, :format => :json
331 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
333 it '素材モデルにコマリストのjson出力を問い合わせている' do
334 ResourcePicture.should_receive(:list_json_opt).exactly(1)
335 get :resource_pictures, :id => @other_artist.id, :format => :json
337 it 'データがリスト構造になっている' do
338 get :resource_pictures, :id => @other_artist.id, :format => :json
339 json = JSON.parse response.body
340 json.should have_at_least(3).items
342 it 'リストの先頭くらいは素材っぽいものであって欲しい' do
343 get :resource_pictures, :id => @other_artist.id, :format => :json
344 json = JSON.parse response.body
345 json.first.has_key?("original_picture_id").should be_true
346 json.first.has_key?("license_id").should be_true
350 context 'ユーザ権限がないとき' do
355 it 'ステータスコード302 Foundを返す' do
356 get :resource_pictures, :id => @other_artist.id
357 response.status.should eq 302
359 it 'サインインページへ遷移する' do
360 get :resource_pictures, :id => @other_artist.id
361 response.should redirect_to '/users/sign_in'
365 it 'ステータスコード401 Unauthorizedを返す' do
366 get :resource_pictures, :id => @other_artist.id, :format => :json
367 response.status.should eq 401
369 it '応答メッセージにUnauthorizedを返す' do
370 get :resource_pictures, :id => @other_artist.id, :format => :json
371 response.message.should match(/Unauthorized/)
375 context 'ユーザ権限はないが管理者権限があるとき' do
380 it 'ステータスコード200 OKを返す' do
381 get :resource_pictures, :id => @other_artist.id
382 response.should be_success
385 context 'ユーザだが作家登録していないとき' do
389 it 'ステータスコード200 OKを返す' do
390 get :resource_pictures, :id => @other_artist.id
391 response.should be_success
396 describe '絵師数取得に於いて' do
398 Artist.should_receive(:visible_count).and_return(3)
401 context 'つつがなく終わるとき' do
402 it 'ステータスコード200 OKを返す' do
403 get :count, :format => :json
404 response.should be_success
408 get :count, :format => :json
409 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
411 it 'データがHash構造になっていて絵師数が3である' do
412 get :count, :format => :json
413 json = JSON.parse response.body
414 json["count"].should == 3
420 describe '新規作成フォーム表示に於いて' do
424 context 'つつがなく終わるとき' do
425 it 'ステータスコード200 OKを返す' do
427 response.should be_success
429 it '@artistに新規データを用意している' do
431 assigns(:ar).should be_a_new(Artist)
433 it '絵師モデルにデフォルト値補充を依頼している' do
434 Artist.any_instance.should_receive(:supply_default).exactly(1)
438 it 'newテンプレートを描画する' do
440 response.should render_template("new")
444 it 'new.jsテンプレートを描画する' do
445 get :new, :format => :js
446 response.should render_template("new")
451 get :new, :format => :json
452 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
454 it '絵師モデルにjson単体出力オプションを問い合わせている' do
455 Artist.should_receive(:show_json_opt).exactly(1)
456 get :new, :format => :json
460 context 'ユーザ権限がないとき' do
465 it 'ステータスコード302 Foundを返す' do
467 response.status.should eq 302
469 it 'サインインページへ遷移する' do
471 response.body.should redirect_to '/users/sign_in'
475 it 'ステータスコード401 Unauthorizedを返す' do
476 get :new, :format => :js
477 response.status.should eq 401
479 it '応答メッセージにUnauthorizedを返す' do
480 get :new, :format => :js
481 response.message.should match(/Unauthorized/)
485 it 'ステータスコード401 Unauthorizedを返す' do
486 get :new, :format => :json
487 response.status.should eq 401
489 it '応答メッセージにUnauthorizedを返す' do
490 get :new, :format => :json
491 response.message.should match(/Unauthorized/)
495 context 'ユーザ権限はないが管理者権限があるとき' do
501 it 'ステータスコード302 Foundを返す' do
503 response.status.should eq 302
505 it 'サインインページへ遷移する' do
507 response.body.should redirect_to '/users/sign_in'
511 context 'ユーザだが作家登録していないとき' do
516 it 'ステータスコード302 Foundを返す' do
518 response.status.should eq 302
522 response.body.should redirect_to new_author_path
528 describe '新規作成に於いて' do
531 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
533 context '事前チェックしておく' do
534 it '絵師モデルにデフォルト値補充を依頼している' do
535 Artist.any_instance.should_receive(:supply_default).exactly(1)
536 post :create, :artist => @attr
538 it '絵師モデルにカラム値復元を依頼している' do
539 Artist.any_instance.should_receive(:attributes=).exactly(1)
540 post :create, :artist => @attr
542 it '絵師モデルに上書き補充を依頼している' do
543 Artist.any_instance.should_receive(:overwrite).exactly(1)
544 post :create, :artist => @attr
547 Artist.any_instance.should_receive(:save).exactly(1)
548 post :create, :artist => @attr
551 context 'つつがなく終わるとき' do
552 it "@arに作成された絵師を保持していて、それがDBにある" do
553 post :create, :artist => @attr
554 assigns(:ar).should be_a(Artist)
555 assigns(:ar).should be_persisted
558 it 'ステータスコード302 Foundを返す' do
559 Artist.any_instance.stub(:save).and_return(true)
560 post :create, :artist => @attr
561 response.status.should eq 302
564 # Artist.any_instance.stub(:save).and_return(true)
565 post :create, :artist => @attr
566 response.should redirect_to(root_path)
570 it 'ステータスコード200 OKを返す' do
571 # Artist.any_instance.stub(:save).and_return(true)
572 post :create, :artist => @attr, :format => :json
573 response.should be_success
575 it '作成された絵師をjsonデータで返す' do
576 post :create, :artist => @attr, :format => :json
577 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
579 it '絵師モデルにjson単体出力オプションを問い合わせている' do
580 Artist.should_receive(:show_json_opt).exactly(1)
581 post :create, :artist => @attr, :format => :json
584 post :create, :artist => @attr, :format => :json
585 json = JSON.parse response.body
586 json["name"].should match(/ken/)
590 context 'ユーザ権限がないとき' do
595 it 'ステータスコード302 Foundを返す' do
596 post :create, :artist => @attr
597 response.status.should eq 302
599 it 'サインインページへ遷移する' do
600 post :create, :artist => @attr
601 response.body.should redirect_to '/users/sign_in'
605 it 'ステータスコード401 Unauthorizedを返す' do
606 post :create, :artist => @attr, :format => :json
607 response.status.should eq 401
609 it '応答メッセージにUnauthorizedを返す' do
610 post :create, :artist => @attr, :format => :json
611 response.message.should match(/Unauthorized/)
615 context 'ユーザ権限はないが管理者権限があるとき' do
621 it 'ステータスコード302 Foundを返す' do
622 post :create, :artist => @attr
623 response.status.should eq 302
625 it 'サインインページへ遷移する' do
626 post :create, :artist => @attr
627 response.body.should redirect_to '/users/sign_in'
631 context 'ユーザだが作家登録していないとき' do
636 it 'ステータスコード302 Foundを返す' do
637 post :create, :artist => @attr
638 response.status.should eq 302
641 post :create, :artist => @attr
642 response.body.should redirect_to new_author_path
646 context '検証、保存に失敗した' do
648 Artist.any_instance.stub(:save).and_return(false)
650 it "未保存の絵師を保持している" do
651 post :create, :artist => @attr
652 assigns(:ar).should be_a_new(Artist)
655 it 'ステータスコード200 OKを返す' do
656 post :create, :artist => @attr
657 response.status.should eq 200
660 post :create, :artist => @attr
661 response.should render_template("new")
665 it 'ステータスコード422 unprocessable_entity を返す' do
666 post :create, :artist => @attr, :format => :json
667 response.status.should eq 422
669 it '応答メッセージUnprocessable Entityを返す' do
670 post :create, :artist => @attr, :format => :json
671 response.message.should match(/Unprocessable/)
677 describe '編集フォーム表示に於いて' do
680 Artist.stub(:edit).and_return(@artist)
682 context 'つつがなく終わるとき' do
683 it 'ステータスコード200 OKを返す' do
684 get :edit, :id => @artist.id
685 response.should be_success
687 it '絵師モデルに編集取得を問い合わせている' do
688 Artist.should_receive(:edit).exactly(1)
689 get :edit, :id => @artist.id
691 it '@artistにデータを用意している' do
692 get :edit, :id => @artist.id
693 assigns(:artist).should eq @artist
696 it 'editテンプレートを描画する' do
697 get :edit, :id => @artist.id
698 response.should render_template("edit")
702 it 'edit.jsテンプレートを描画する' do
703 get :edit, :id => @artist.id, :format => :js
704 response.should render_template("edit")
708 context 'ユーザ権限がないとき' do
713 it 'ステータスコード302 Foundを返す' do
714 get :edit, :id => @artist.id
715 response.status.should eq 302
717 it 'サインインページへ遷移する' do
718 get :edit, :id => @artist.id
719 response.body.should redirect_to '/users/sign_in'
723 it 'ステータスコード401 Unauthorizedを返す' do
724 get :edit, :id => @artist.id, :format => :js
725 response.status.should eq 401
727 it '応答メッセージにUnauthorizedを返す' do
728 get :edit, :id => @artist.id, :format => :js
729 response.message.should match(/Unauthorized/)
733 context 'ユーザ権限はないが管理者権限があるとき' do
739 it 'ステータスコード302 Foundを返す' do
740 get :edit, :id => @artist.id
741 response.status.should eq 302
743 it 'サインインページへ遷移する' do
744 get :edit, :id => @artist.id
745 response.body.should redirect_to '/users/sign_in'
749 context 'ユーザだが作家登録していないとき' do
754 it 'ステータスコード302 Foundを返す' do
755 get :edit, :id => @artist.id
756 response.status.should eq 302
759 get :edit, :id => @artist.id
760 response.body.should redirect_to new_author_path
768 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
771 context '事前チェックしておく' do
772 it '絵師モデルに編集取得を問い合わせている' do
773 Artist.stub(:edit).with(any_args()).and_return @artist
774 Artist.should_receive(:edit).exactly(1)
775 put :update, :id => @artist.id, :artist => @attr
777 it '絵師モデルにカラム値復元を依頼している' do
778 Artist.any_instance.should_receive(:attributes=).exactly(1)
779 put :update, :id => @artist.id, :artist => @attr
781 it '絵師モデルに上書き補充を依頼している' do
782 Artist.any_instance.should_receive(:overwrite).exactly(1)
783 put :update, :id => @artist.id, :artist => @attr
786 Artist.any_instance.stub(:save).with(any_args).and_return true
787 Artist.any_instance.should_receive(:save).exactly(1)
788 put :update, :id => @artist.id, :artist => @attr
790 it '@arにアレを取得している' do
791 put :update, :id => @artist.id, :artist => @attr
792 assigns(:ar).should eq @artist
795 context 'つつがなく終わるとき' do
797 put :update, :id => @artist.id, :artist => @attr
798 Artist.find(@artist.id).name.should eq 'ryu'
801 it 'ステータスコード302 Foundを返す' do
802 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
803 put :update, :id => @artist.id, :artist => @attr
804 response.status.should eq 302
807 put :update, :id => @artist.id, :artist => @attr
808 response.should redirect_to('/home/configure')
812 it 'ステータスコード200 OKを返す' do
813 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
814 put :update, :id => @artist.id, :artist => @attr, :format => :json
815 response.should be_success
818 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
819 put :update, :id => @artist.id, :artist => @attr, :format => :json
820 response.body.should match /./
824 context 'ユーザ権限がないとき' do
829 it 'ステータスコード302 Foundを返す' do
830 put :update, :id => @artist.id, :artist => @attr
831 response.status.should eq 302
833 it 'サインインページへ遷移する' do
834 put :update, :id => @artist.id, :artist => @attr
835 response.body.should redirect_to '/users/sign_in'
839 it '応答メッセージにUnauthorizedを返す' do
840 put :update, :id => @artist.id, :artist => @attr, :format => :json
841 response.message.should match(/Unauthorized/)
845 context 'ユーザ権限はないが管理者権限があるとき' do
851 it 'ステータスコード302 Foundを返す' do
852 put :update, :id => @artist.id, :artist => @attr
853 response.status.should eq 302
855 it 'サインインページへ遷移する' do
856 put :update, :id => @artist.id, :artist => @attr
857 response.body.should redirect_to '/users/sign_in'
861 context 'ユーザだが作家登録していないとき' do
866 it 'ステータスコード302 Foundを返す' do
867 put :update, :id => @artist.id, :artist => @attr
868 response.status.should eq 302
871 put :update, :id => @artist.id, :artist => @attr
872 response.body.should redirect_to new_author_path
876 context '検証、保存に失敗したとき' do
878 Artist.any_instance.stub(:save).and_return(false)
881 it 'ステータスコード200 Okを返す' do
882 put :update, :id => @artist.id, :artist => @attr
883 response.status.should eq 200
886 put :update, :id => @artist.id, :artist => @attr
887 response.should render_template("edit")
891 it 'ステータスコード422 unprocessable_entity を返す' do
892 Artist.any_instance.stub(:save).and_return(false)
893 put :update, :id => @artist.id, :artist => @attr, :format => :json
894 response.status.should eq 422
896 it '応答メッセージUnprocessable Entityを返す' do
897 put :update, :id => @artist.id, :artist => @attr, :format => :json
898 response.message.should match(/Unprocessable/)
905 describe '一覧表示に於いて' do
907 Artist.stub(:list).and_return([@artist, @artist, @artist])
910 context 'つつがなく終わるとき' do
911 it 'ステータスコード200 OKを返す' do
913 response.should be_success
916 it 'indexテンプレートを描画する' do
918 response.should render_template("index")
923 get :index, :format => :json
924 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
928 context 'ユーザ権限がないとき' do
932 it 'ステータスコード200 OKを返す' do
934 response.should be_success
937 it 'indexテンプレートを描画する' do
939 response.should render_template("index")
944 get :index, :format => :json
945 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
953 Artist.stub(:show).and_return(@artist)
956 context 'つつがなく終わるとき' do
957 it 'ステータスコード200 OKを返す' do
958 get :show, :id => @artist.id
959 response.should be_success
962 it 'showテンプレートを描画する' do
963 get :show, :id => @artist.id
964 response.should render_template("show")
969 get :show, :id => @artist.id, :format => :json
970 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
974 context 'ユーザ権限がないとき' do
978 it 'ステータスコード200 OKを返す' do
979 get :show, :id => @artist.id
980 response.should be_success
983 it 'showテンプレートを描画する' do
984 get :show, :id => @artist.id
985 response.should render_template("show")
990 get :show, :id => @artist.id, :format => :json
991 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
997 describe '対象絵師の素材一覧表示に於いて' do
999 @other_user = FactoryGirl.create( :user_yas)
1000 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1001 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1002 @op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
1003 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @other_artist.id
1004 @rp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
1005 ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp])
1008 context 'つつがなく終わるとき' do
1009 it 'ステータスコード200 OKを返す' do
1010 get :resource_pictures, :id => @other_artist.id
1011 response.should be_success
1014 it 'resource_pictureテンプレートを描画する' do
1015 get :resource_pictures, :id => @other_artist.id
1016 response.should render_template("resource_pictures")
1021 get :resource_pictures, :id => @other_artist.id, :format => :json
1022 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1026 context 'ユーザ権限がないとき' do
1030 it 'ステータスコード200 OKを返す' do
1031 get :resource_pictures, :id => @other_artist.id
1032 response.should be_success
1035 it 'resource_pictureテンプレートを描画する' do
1036 get :resource_pictures, :id => @other_artist.id
1037 response.should render_template("resource_pictures")
1042 get :resource_pictures, :id => @other_artist.id, :format => :json
1043 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1049 describe '絵師数取得に於いて' do
1051 Artist.should_receive(:visible_count).and_return(3)
1054 context 'つつがなく終わるとき' do
1055 it 'ステータスコード200 OKを返す' do
1056 get :count, :format => :json
1057 response.should be_success
1061 get :count, :format => :json
1062 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1068 describe '新規作成フォーム表示に於いて' do
1072 context 'つつがなく終わるとき' do
1073 it 'ステータスコード200 OKを返す' do
1075 response.should be_success
1078 it 'newテンプレートを描画する' do
1080 response.should render_template("new")
1084 it 'new.jsテンプレートを描画する' do
1085 get :new, :format => :js
1086 response.should render_template("new")
1091 get :new, :format => :json
1092 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1096 context 'ユーザ権限がないとき' do
1101 it 'ステータスコード302 Foundを返す' do
1103 response.status.should eq 302
1105 it 'サインインページへ遷移する' do
1107 response.body.should redirect_to '/users/sign_in'
1111 it 'ステータスコード401 Unauthorizedを返す' do
1112 get :new, :format => :js
1113 response.status.should eq 401
1115 it '応答メッセージにUnauthorizedを返す' do
1116 get :new, :format => :js
1117 response.message.should match(/Unauthorized/)
1121 it 'ステータスコード401 Unauthorizedを返す' do
1122 get :new, :format => :json
1123 response.status.should eq 401
1125 it '応答メッセージにUnauthorizedを返す' do
1126 get :new, :format => :json
1127 response.message.should match(/Unauthorized/)
1133 describe '新規作成に於いて' do
1136 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
1138 context 'つつがなく終わるとき' do
1140 it 'ステータスコード302 Foundを返す' do
1141 Artist.any_instance.stub(:save).and_return(true)
1142 post :create, :artist => @attr
1143 response.status.should eq 302
1146 # Artist.any_instance.stub(:save).and_return(true)
1147 post :create, :artist => @attr
1148 response.should redirect_to(root_path)
1152 it 'ステータスコード200 OKを返す' do
1153 # Artist.any_instance.stub(:save).and_return(true)
1154 post :create, :artist => @attr, :format => :json
1155 response.should be_success
1157 it '作成された絵師をjsonデータで返す' do
1158 post :create, :artist => @attr, :format => :json
1159 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1163 context 'ユーザ権限がないとき' do
1168 it 'ステータスコード302 Foundを返す' do
1169 post :create, :artist => @attr
1170 response.status.should eq 302
1172 it 'サインインページへ遷移する' do
1173 post :create, :artist => @attr
1174 response.body.should redirect_to '/users/sign_in'
1178 it 'ステータスコード401 Unauthorizedを返す' do
1179 post :create, :artist => @attr, :format => :json
1180 response.status.should eq 401
1182 it '応答メッセージにUnauthorizedを返す' do
1183 post :create, :artist => @attr, :format => :json
1184 response.message.should match(/Unauthorized/)
1190 describe '編集フォーム表示に於いて' do
1193 Artist.stub(:edit).and_return(@artist)
1195 context 'つつがなく終わるとき' do
1196 it 'ステータスコード200 OKを返す' do
1197 get :edit, :id => @artist.id
1198 response.should be_success
1201 it 'editテンプレートを描画する' do
1202 get :edit, :id => @artist.id
1203 response.should render_template("edit")
1207 it 'edit.jsテンプレートを描画する' do
1208 get :edit, :id => @artist.id, :format => :js
1209 response.should render_template("edit")
1213 context 'ユーザ権限がないとき' do
1218 it 'ステータスコード302 Foundを返す' do
1219 get :edit, :id => @artist.id
1220 response.status.should eq 302
1222 it 'サインインページへ遷移する' do
1223 get :edit, :id => @artist.id
1224 response.body.should redirect_to '/users/sign_in'
1228 it 'ステータスコード401 Unauthorizedを返す' do
1229 get :edit, :id => @artist.id, :format => :js
1230 response.status.should eq 401
1232 it '応答メッセージにUnauthorizedを返す' do
1233 get :edit, :id => @artist.id, :format => :js
1234 response.message.should match(/Unauthorized/)
1240 describe '更新に於いて' do
1242 @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
1245 context 'つつがなく終わるとき' do
1247 it 'ステータスコード302 Foundを返す' do
1248 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
1249 put :update, :id => @artist.id, :artist => @attr
1250 response.status.should eq 302
1253 put :update, :id => @artist.id, :artist => @attr
1254 response.should redirect_to('/home/configure')
1258 it 'ステータスコード200 OKを返す' do
1259 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
1260 put :update, :id => @artist.id, :artist => @attr, :format => :json
1261 response.should be_success
1263 it 'ページ本体は特に返さない' do
1264 Artist.any_instance.stub(:save).with(any_args()).and_return(true)
1265 put :update, :id => @artist.id, :artist => @attr, :format => :json
1266 response.body.should match /./
1270 context 'ユーザ権限がないとき' do
1274 it 'ステータスコード302 Foundを返す' do
1275 put :update, :id => @artist.id, :artist => @attr
1276 response.status.should eq 302
1279 it 'サインインページへ遷移する' do
1280 put :update, :id => @artist.id, :artist => @attr
1281 response.body.should redirect_to '/users/sign_in'
1285 it '応答メッセージにUnauthorizedを返す' do
1286 put :update, :id => @artist.id, :artist => @attr, :format => :json
1287 response.message.should match(/Unauthorized/)