1 # -*- encoding: utf-8 -*-
5 describe AuthorsController do
7 @admin =FactoryGirl.create :admin
8 @sp = FactoryGirl.create :system_picture
9 @lg = FactoryGirl.create :license_group
10 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
11 @user = FactoryGirl.create( :user_yas)
12 @author = FactoryGirl.create :author, :user_id => @user.id
13 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
16 if MagicNumber['run_mode'] == 1
17 describe '一覧表示に於いて' do
19 Author.stub(:list).and_return([@author, @author, @author])
23 it '与えられたpageがセットされている' do
24 get :index, :page => 5
25 assigns(:page).should eq 5
27 it '省略されると@pageに1値が入る' do
29 assigns(:page).should eq 1
31 it '与えられたpage_sizeがセットされている' do
32 get :index, :page_size => 15
33 assigns(:page_size).should eq 15
35 it '省略されると@page_sizeにデフォルト値が入る' do
37 assigns(:page_size).should eq Author.default_page_size
39 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
40 get :index, :page_size => 1500
41 assigns(:page_size).should eq Author.max_page_size
43 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
44 get :index, :page_size => 0
45 assigns(:page_size).should eq Author.default_page_size
48 context 'つつがなく終わるとき' do
49 it 'ステータスコード200 OKを返す' do
51 response.should be_success
53 it '作家モデルに一覧を問い合わせている' do
54 Author.should_receive(:list).exactly(1)
57 it '@authorsにリストを取得している' do
59 assigns(:authors).should have_at_least(3).items
62 it 'indexテンプレートを描画する' do
64 response.should render_template("index")
69 get :index, :format => :json
70 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
72 it '作家モデルにjson一覧出力オプションを問い合わせている' do
73 Author.should_receive(:list_json_opt).exactly(1)
74 get :index, :format => :json
76 it 'データがリスト構造になっている' do
77 get :index, :format => :json
78 json = JSON.parse response.body
79 json.should have_at_least(3).items
81 it 'リストの先頭くらいは作家っぽいものであって欲しい' do
82 get :index, :format => :json
83 json = JSON.parse response.body
84 json.first.has_key?("name").should be_true
85 json.first.has_key?("user_id").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
128 it 'ステータスコード200 OKを返す' do
130 response.should be_success
137 Author.stub(:show).and_return(@author)
140 context 'つつがなく終わるとき' do
141 it 'ステータスコード200 OKを返す' do
142 get :show, :id => @author.id
143 response.should be_success
145 it '作家モデルに単体取得を問い合わせている' do
146 Author.should_receive(:show).exactly(1)
149 #@authorだとログイン中のアカウントと干渉してしまう。
150 it '@auにアレを取得している' do
151 get :show, :id => @author.id
152 assigns(:au).should eq(@author)
155 it 'showテンプレートを描画する' do
156 get :show, :id => @author.id
157 response.should render_template("show")
162 get :show, :id => @author.id, :format => :json
163 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
165 it '作家モデルにjson単体出力オプションを問い合わせている' do
166 Author.should_receive(:show_json_opt).exactly(1)
167 get :show, :id => @author.id, :format => :json
170 get :show, :id => @author.id, :format => :json
171 json = JSON.parse response.body
172 json["name"].should match(/test/)
173 json["user_id"].should eq @author.user_id
177 context 'ユーザ権限がないとき' do
182 it 'ステータスコード302 Foundを返す' do
183 get :show, :id => @author.id
184 response.status.should eq 302
186 it 'サインインページへ遷移する' do
187 get :show, :id => @author.id
188 response.body.should redirect_to '/users/sign_in'
192 it 'ステータスコード401 Unauthorizedを返す' do
193 get :show, :id => @author.id, :format => :json
194 response.status.should eq 401
196 it '応答メッセージにUnauthorizedを返す' do
197 get :show, :id => @author.id, :format => :json
198 response.message.should match(/Unauthorized/)
202 context 'ユーザ権限はないが管理者権限があるとき' do
207 it 'ステータスコード200 OKを返す' do
208 get :show, :id => @author.id
209 response.should be_success
212 context 'ユーザだが作家登録していないとき' do
216 it 'ステータスコード200 OKを返す' do
217 get :show, :id => @author.id
218 response.should be_success
222 context '対象作家がないとき' do
224 it '例外404 not_foundを返す' do
227 }.should raise_error(ActiveRecord::RecordNotFound)
231 it '例外404 not_foundを返す' do
233 get :show, :id => 0, :format => :json
234 }.should raise_error(ActiveRecord::RecordNotFound)
241 describe '対象作家のコミック一覧表示に於いて' do
243 @other_user = FactoryGirl.create( :user_yas)
244 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
245 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
246 @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id
247 Comic.stub(:mylist).and_return([@comic, @comic, @comic])
250 context 'パラメータpageについて' do
252 get :comics, :id => @other_author.id, :page => 5
253 assigns(:page).should eq 5
255 it '省略されると@pageに1値が入る' do
256 get :comics, :id => @other_author.id
257 assigns(:page).should eq 1
259 it '与えられたpage_sizeがセットされている' do
260 get :comics, :id => @other_author.id, :page_size => 15
261 assigns(:page_size).should eq 15
263 it '省略されると@page_sizeにデフォルト値が入る' do
264 get :comics, :id => @other_author.id
265 assigns(:page_size).should eq Author.default_comic_page_size
267 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
268 get :comics, :id => @other_author.id, :page_size => 1500
269 assigns(:page_size).should eq Author.comic_max_page_size
271 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
272 get :comics, :id => @other_author.id, :page_size => 0
273 assigns(:page_size).should eq Author.default_comic_page_size
276 context 'つつがなく終わるとき' do
277 it 'ステータスコード200 OKを返す' do
278 get :comics, :id => @other_author.id
279 response.should be_success
281 it '作家モデルに単体取得を問い合わせている' do
282 Author.should_receive(:show).exactly(1)
283 get :comics, :id => @other_author.id
285 it 'コミックモデルに一覧を問い合わせている' do
286 Comic.should_receive(:mylist).exactly(1)
287 get :comics, :id => @other_author.id
289 it '@comicsにリストを取得している' do
290 get :comics, :id => @other_author.id
291 assigns(:comics).should have_at_least(3).items
294 it 'comicテンプレートを描画する' do
295 get :comics, :id => @other_author.id
296 response.should render_template("comic")
301 get :comics, :id => @other_author.id, :format => :json
302 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
304 it 'コミックモデルにjson一覧出力オプションを問い合わせている' do
305 Comic.should_receive(:list_json_opt).exactly(1)
306 get :comics, :id => @other_author.id, :format => :json
308 it 'データがリスト構造になっている' do
309 get :comics, :id => @other_author.id, :format => :json
310 json = JSON.parse response.body
311 json.should have_at_least(3).items
313 it 'リストの先頭くらいはコミックっぽいものであって欲しい' do
314 get :comics, :id => @other_author.id, :format => :json
315 json = JSON.parse response.body
316 json.first.has_key?("title").should be_true
317 json.first.has_key?("visible").should be_true
321 context 'ユーザ権限がないとき' do
326 it 'ステータスコード302 Foundを返す' do
327 get :comics, :id => @other_author.id
328 response.status.should eq 302
330 it 'サインインページへ遷移する' do
331 get :comics, :id => @other_author.id
332 response.should redirect_to '/users/sign_in'
336 it 'ステータスコード401 Unauthorizedを返す' do
337 get :comics, :id => @other_author.id, :format => :json
338 response.status.should eq 401
340 it '応答メッセージにUnauthorizedを返す' do
341 get :comics, :id => @other_author.id, :format => :json
342 response.message.should match(/Unauthorized/)
346 context 'ユーザ権限はないが管理者権限があるとき' do
351 it 'ステータスコード200 OKを返す' do
352 get :comics, :id => @other_author.id
353 response.should be_success
356 context 'ユーザだが作家登録していないとき' do
360 it 'ステータスコード200 OKを返す' do
361 get :comics, :id => @other_author.id
362 response.should be_success
367 describe '対象作家のコマ一覧表示に於いて' do
369 @other_user = FactoryGirl.create( :user_yas)
370 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
371 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
372 @panel = FactoryGirl.create :panel, :author_id => @other_author.id
373 Panel.stub(:mylist).and_return([@panel, @panel, @panel])
376 context 'パラメータpageについて' do
378 get :panels, :id => @other_author.id, :page => 5
379 assigns(:page).should eq 5
381 it '省略されると@pageに1値が入る' do
382 get :panels, :id => @other_author.id
383 assigns(:page).should eq 1
385 it '与えられたpage_sizeがセットされている' do
386 get :panels, :id => @other_author.id, :page_size => 15
387 assigns(:page_size).should eq 15
389 it '省略されると@page_sizeにデフォルト値が入る' do
390 get :panels, :id => @other_author.id
391 assigns(:page_size).should eq Author.default_panel_page_size
393 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
394 get :panels, :id => @other_author.id, :page_size => 1500
395 assigns(:page_size).should eq Author.panel_max_page_size
397 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
398 get :panels, :id => @other_author.id, :page_size => 0
399 assigns(:page_size).should eq Author.default_panel_page_size
402 context 'つつがなく終わるとき' do
403 it 'ステータスコード200 OKを返す' do
404 get :panels, :id => @other_author.id
405 response.should be_success
407 it '作家モデルに単体取得を問い合わせている' do
408 Author.should_receive(:show).exactly(1)
409 get :panels, :id => @other_author.id
411 it 'コマモデルに一覧を問い合わせている' do
412 Panel.should_receive(:mylist).exactly(1)
413 get :panels, :id => @other_author.id
415 it '@panelsにリストを取得している' do
416 get :panels, :id => @other_author.id
417 assigns(:panels).should have_at_least(3).items
420 it 'comicテンプレートを描画する' do
421 get :panels, :id => @other_author.id
422 response.should render_template("panels")
427 get :panels, :id => @other_author.id, :format => :json
428 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
430 it 'コマモデルにコマリストのjson出力を問い合わせている' do
431 Panel.should_receive(:list_as_json_text).exactly(1)
432 get :panels, :id => @other_author.id, :format => :json
434 it 'データがリスト構造になっている' do
435 get :panels, :id => @other_author.id, :format => :json
436 json = JSON.parse response.body
437 json.should have_at_least(3).items
439 it 'リストの先頭くらいはコマっぽいものであって欲しい' do
440 get :panels, :id => @other_author.id, :format => :json
441 json = JSON.parse response.body
442 json.first.has_key?("z").should be_true
446 context 'ユーザ権限がないとき' do
451 it 'ステータスコード302 Foundを返す' do
452 get :panels, :id => @other_author.id
453 response.status.should eq 302
455 it 'サインインページへ遷移する' do
456 get :panels, :id => @other_author.id
457 response.should redirect_to '/users/sign_in'
461 it 'ステータスコード401 Unauthorizedを返す' do
462 get :panels, :id => @other_author.id, :format => :json
463 response.status.should eq 401
465 it '応答メッセージにUnauthorizedを返す' do
466 get :panels, :id => @other_author.id, :format => :json
467 response.message.should match(/Unauthorized/)
471 context 'ユーザ権限はないが管理者権限があるとき' do
476 it 'ステータスコード200 OKを返す' do
477 get :panels, :id => @other_author.id
478 response.should be_success
481 context 'ユーザだが作家登録していないとき' do
485 it 'ステータスコード200 OKを返す' do
486 get :panels, :id => @other_author.id
487 response.should be_success
492 describe '作家数取得に於いて' do
494 Author.should_receive(:visible_count).and_return(3)
497 context 'つつがなく終わるとき' do
498 it 'ステータスコード200 OKを返す' do
499 get :count, :format => :json
500 response.should be_success
504 get :count, :format => :json
505 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
507 it 'データがHash構造になっていて作家数が3である' do
508 get :count, :format => :json
509 json = JSON.parse response.body
510 json["count"].should == 3
516 describe '新規作成フォーム表示に於いて' do
518 @new_user = FactoryGirl.create( :user_yas)
521 context 'つつがなく終わるとき' do
522 it 'ステータスコード200 OKを返す' do
524 response.should be_success
526 it '@auに新規データを用意している' do
528 assigns(:au).should be_a_new(Author)
530 it '作家モデルにデフォルト値補充を依頼している' do
531 Author.any_instance.should_receive(:supply_default).exactly(1)
535 it 'newテンプレートを描画する' do
537 response.should render_template("new")
541 it 'new.jsテンプレートを描画する' do
542 get :new, :format => :js
543 response.should render_template("new")
548 get :new, :format => :json
549 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
551 it '作家モデルにjson単体出力オプションを問い合わせている' do
552 Author.should_receive(:show_json_opt).exactly(1)
553 get :new, :format => :json
557 context 'ユーザ権限がないとき' do
562 it 'ステータスコード302 Foundを返す' do
564 response.status.should eq 302
566 it 'サインインページへ遷移する' do
568 response.body.should redirect_to '/users/sign_in'
572 it 'ステータスコード401 Unauthorizedを返す' do
573 get :new, :format => :js
574 response.status.should eq 401
576 it '応答メッセージにUnauthorizedを返す' do
577 get :new, :format => :js
578 response.message.should match(/Unauthorized/)
582 it 'ステータスコード401 Unauthorizedを返す' do
583 get :new, :format => :json
584 response.status.should eq 401
586 it '応答メッセージにUnauthorizedを返す' do
587 get :new, :format => :json
588 response.message.should match(/Unauthorized/)
592 context 'ユーザ権限はないが管理者権限があるとき' do
598 it 'ステータスコード302 Foundを返す' do
600 response.status.should eq 302
602 it 'サインインページへ遷移する' do
604 response.body.should redirect_to '/users/sign_in'
608 context 'ユーザだが作家登録していないとき' do
612 it 'ステータスコード200 OKを返す' do
614 response.should be_success
619 describe '新規作成に於いて' do
621 @new_user = FactoryGirl.create( :user_yas)
623 @attr = FactoryGirl.attributes_for(:author, :user_id => @new_user.id, :name => 'ken')
625 context '事前チェックしておく' do
626 it '作家モデルにデフォルト値補充を依頼している' do
627 Author.any_instance.should_receive(:supply_default).exactly(1)
628 post :create, :author => @attr
630 it '作家モデルにカラム値復元を依頼している' do
631 Author.any_instance.should_receive(:attributes=).exactly(1)
632 post :create, :author => @attr
634 it '作家モデルに上書き補充を依頼している' do
635 Author.any_instance.should_receive(:overwrite).exactly(1)
636 post :create, :author => @attr
639 Author.any_instance.should_receive(:save).exactly(1)
640 post :create, :author => @attr
643 context 'つつがなく終わるとき' do
644 it "@auに作成された作家を保持していて、それがDBにある" do
645 post :create, :author => @attr
646 assigns(:au).should be_a(Author)
647 assigns(:au).should be_persisted
650 it 'ステータスコード302 Foundを返す' do
651 Author.any_instance.stub(:save).and_return(true)
652 post :create, :author => @attr
653 response.status.should eq 302
656 # Author.any_instance.stub(:save).and_return(true)
657 post :create, :author => @attr
658 response.should redirect_to(root_path)
662 it 'ステータスコード200 OKを返す' do
663 # Author.any_instance.stub(:save).and_return(true)
664 post :create, :author => @attr, :format => :json
665 response.should be_success
667 it '作成された作家をjsonデータで返す' do
668 post :create, :author => @attr, :format => :json
669 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
671 it '作家モデルにjson単体出力オプションを問い合わせている' do
672 Author.should_receive(:show_json_opt).exactly(1)
673 post :create, :author => @attr, :format => :json
676 post :create, :author => @attr, :format => :json
677 json = JSON.parse response.body
678 json["name"].should match(/ken/)
682 context 'ユーザ権限がないとき' do
687 it 'ステータスコード302 Foundを返す' do
688 post :create, :author => @attr
689 response.status.should eq 302
691 it 'サインインページへ遷移する' do
692 post :create, :author => @attr
693 response.body.should redirect_to '/users/sign_in'
697 it 'ステータスコード401 Unauthorizedを返す' do
698 post :create, :author => @attr, :format => :json
699 response.status.should eq 401
701 it '応答メッセージにUnauthorizedを返す' do
702 post :create, :author => @attr, :format => :json
703 response.message.should match(/Unauthorized/)
707 context 'ユーザ権限はないが管理者権限があるとき' do
713 it 'ステータスコード302 Foundを返す' do
714 post :create, :author => @attr
715 response.status.should eq 302
717 it 'サインインページへ遷移する' do
718 post :create, :author => @attr
719 response.body.should redirect_to '/users/sign_in'
723 context '検証、保存に失敗した' do
725 Author.any_instance.stub(:save).and_return(false)
727 it "未保存の作家を保持している" do
728 post :create, :author => @attr
729 assigns(:au).should be_a_new(Author)
732 it 'ステータスコード200 OKを返す' do
733 post :create, :author => @attr
734 response.status.should eq 200
737 post :create, :author => @attr
738 response.should render_template("new")
742 it 'ステータスコード422 unprocessable_entity を返す' do
743 post :create, :author => @attr, :format => :json
744 response.status.should eq 422
746 it '応答メッセージUnprocessable Entityを返す' do
747 post :create, :author => @attr, :format => :json
748 response.message.should match(/Unprocessable/)
754 describe '編集フォーム表示に於いて' do
757 Author.stub(:edit).and_return(@author)
759 context 'つつがなく終わるとき' do
760 it 'ステータスコード200 OKを返す' do
761 get :edit, :id => @author.id
762 response.should be_success
764 it '作家モデルに編集取得を問い合わせている' do
765 Author.should_receive(:edit).exactly(1)
766 get :edit, :id => @author.id
768 #@authorだとログイン中のアカウントと干渉してしまう。
769 it '@auにデータを用意している' do
770 get :edit, :id => @author.id
771 assigns(:au).should eq @author
774 it 'editテンプレートを描画する' do
775 get :edit, :id => @author.id
776 response.should render_template("edit")
780 it 'edit.jsテンプレートを描画する' do
781 get :edit, :id => @author.id, :format => :js
782 response.should render_template("edit")
786 context 'ユーザ権限がないとき' do
791 it 'ステータスコード302 Foundを返す' do
792 get :edit, :id => @author.id
793 response.status.should eq 302
795 it 'サインインページへ遷移する' do
796 get :edit, :id => @author.id
797 response.body.should redirect_to '/users/sign_in'
801 it 'ステータスコード401 Unauthorizedを返す' do
802 get :edit, :id => @author.id, :format => :js
803 response.status.should eq 401
805 it '応答メッセージにUnauthorizedを返す' do
806 get :edit, :id => @author.id, :format => :js
807 response.message.should match(/Unauthorized/)
811 context 'ユーザ権限はないが管理者権限があるとき' do
817 it 'ステータスコード302 Foundを返す' do
818 get :edit, :id => @author.id
819 response.status.should eq 302
821 it 'サインインページへ遷移する' do
822 get :edit, :id => @author.id
823 response.body.should redirect_to '/users/sign_in'
827 context 'ユーザだが作家登録していないとき' do
829 @other_user = FactoryGirl.create( :user_yas)
830 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
834 it 'ステータスコード302 Foundを返す' do
835 get :edit, :id => @other_author.id
836 response.status.should eq 302
839 get :edit, :id => @other_author.id
840 response.body.should redirect_to new_author_path
848 @attr = @author.attributes
849 @attr['name'] = 'ryu'
852 context '事前チェックしておく' do
853 it '作家モデルに編集取得を問い合わせている' do
854 Author.stub(:edit).with(any_args()).and_return @author
855 Author.should_receive(:edit).exactly(1)
856 put :update, :id => @author.id, :author => @attr
858 it 'モデルにpostデータ転送を依頼する' do
859 Author.any_instance.stub(:attributes=).with(any_args)
860 Author.any_instance.should_receive(:attributes=).exactly(1)
861 put :update, :id => @author.id, :author => @attr
863 it 'モデルに上書き補充を依頼する' do
864 Author.any_instance.stub(:overwrite).with(any_args)
865 Author.any_instance.should_receive(:overwrite).exactly(1)
866 put :update, :id => @author.id, :author => @attr
869 Author.any_instance.stub(:save).with(any_args).and_return true
870 Author.any_instance.should_receive(:save).exactly(1)
871 put :update, :id => @author.id, :author => @attr
873 it '@auにアレを取得している' do
874 put :update, :id => @author.id, :author => @attr
875 assigns(:au).should eq @author
878 context 'つつがなく終わるとき' do
880 put :update, :id => @author.id, :author => @attr
881 Author.find(@author.id).name.should eq 'ryu'
884 it 'ステータスコード302 Foundを返す' do
885 Author.any_instance.stub(:save).with(any_args()).and_return(true)
886 put :update, :id => @author.id, :author => @attr
887 response.status.should eq 302
890 put :update, :id => @author.id, :author => @attr
891 response.should redirect_to('/home/configure')
895 it 'ステータスコード200 OKを返す' do
896 Author.any_instance.stub(:save).with(any_args()).and_return(true)
897 put :update, :id => @author.id, :author => @attr, :format => :json
898 response.should be_success
901 Author.any_instance.stub(:save).with(any_args()).and_return(true)
902 put :update, :id => @author.id, :author => @attr, :format => :json
903 response.body.should match /./
907 context 'ユーザ権限がないとき' do
912 it 'ステータスコード302 Foundを返す' do
913 put :update, :id => @author.id, :author => @attr
914 response.status.should eq 302
916 it 'サインインページへ遷移する' do
917 put :update, :id => @author.id, :author => @attr
918 response.body.should redirect_to '/users/sign_in'
922 it '応答メッセージにUnauthorizedを返す' do
923 put :update, :id => @author.id, :author => @attr, :format => :json
924 response.message.should match(/Unauthorized/)
928 context 'ユーザ権限はないが管理者権限があるとき' do
934 it 'ステータスコード302 Foundを返す' do
935 put :update, :id => @author.id, :author => @attr
936 response.status.should eq 302
938 it 'サインインページへ遷移する' do
939 put :update, :id => @author.id, :author => @attr
940 response.body.should redirect_to '/users/sign_in'
944 context 'ユーザだが作家登録していないとき' do
946 @other_user = FactoryGirl.create( :user_yas)
947 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
951 it 'ステータスコード302 Foundを返す' do
952 get :update, :id => @other_author.id
953 response.status.should eq 302
956 get :update, :id => @other_author.id
957 response.body.should redirect_to new_author_path
961 context '検証、保存に失敗したとき' do
963 Author.any_instance.stub(:save).and_return(false)
966 it 'ステータスコード200 Okを返す' do
967 put :update, :id => @author.id, :author => @attr
968 response.status.should eq 200
971 put :update, :id => @author.id, :author => @attr
972 response.should render_template("edit")
976 it 'ステータスコード422 unprocessable_entity を返す' do
977 Author.any_instance.stub(:save).and_return(false)
978 put :update, :id => @author.id, :author => @attr, :format => :json
979 response.status.should eq 422
981 it '応答メッセージUnprocessable Entityを返す' do
982 put :update, :id => @author.id, :author => @attr, :format => :json
983 response.message.should match(/Unprocessable/)
990 describe '一覧表示に於いて' do
992 Author.stub(:list).and_return([@author, @author, @author])
995 context 'つつがなく終わるとき' do
996 it 'ステータスコード200 OKを返す' do
998 response.should be_success
1001 it 'indexテンプレートを描画する' do
1003 response.should render_template("index")
1008 get :index, :format => :json
1009 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1013 context 'ユーザ権限がないとき' do
1017 it 'ステータスコード200 OKを返す' do
1019 response.should be_success
1022 it 'indexテンプレートを描画する' do
1024 response.should render_template("index")
1029 get :index, :format => :json
1030 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1036 describe '閲覧に於いて' do
1038 Author.stub(:show).and_return(@author)
1041 context 'つつがなく終わるとき' do
1042 it 'ステータスコード200 OKを返す' do
1043 get :show, :id => @author.id
1044 response.should be_success
1047 it 'showテンプレートを描画する' do
1048 get :show, :id => @author.id
1049 response.should render_template("show")
1054 get :show, :id => @author.id, :format => :json
1055 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1059 context 'ユーザ権限がないとき' do
1063 it 'ステータスコード200 OKを返す' do
1064 get :show, :id => @author.id
1065 response.should be_success
1068 it 'showテンプレートを描画する' do
1069 get :show, :id => @author.id
1070 response.should render_template("show")
1075 get :show, :id => @author.id, :format => :json
1076 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1082 describe '対象作家のコミック一覧表示に於いて' do
1084 @other_user = FactoryGirl.create( :user_yas)
1085 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1086 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1087 @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id
1088 Comic.stub(:mylist).and_return([@comic, @comic, @comic])
1091 context 'つつがなく終わるとき' do
1092 it 'ステータスコード200 OKを返す' do
1093 get :comics, :id => @other_author.id
1094 response.should be_success
1097 it 'comicテンプレートを描画する' do
1098 get :comics, :id => @other_author.id
1099 response.should render_template("comic")
1104 get :comics, :id => @other_author.id, :format => :json
1105 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1109 context 'ユーザ権限がないとき' do
1113 it 'ステータスコード200 OKを返す' do
1114 get :comics, :id => @other_author.id
1115 response.should be_success
1118 it 'comicテンプレートを描画する' do
1119 get :comics, :id => @other_author.id
1120 response.should render_template("comic")
1125 get :comics, :id => @other_author.id, :format => :json
1126 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1132 describe '対象作家のコマ一覧表示に於いて' do
1134 @other_user = FactoryGirl.create( :user_yas)
1135 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1136 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1137 @panel = FactoryGirl.create :panel, :author_id => @other_author.id
1138 Panel.stub(:mylist).and_return([@panel, @panel, @panel])
1141 context 'つつがなく終わるとき' do
1142 it 'ステータスコード200 OKを返す' do
1143 get :panels, :id => @other_author.id
1144 response.should be_success
1147 it 'comicテンプレートを描画する' do
1148 get :panels, :id => @other_author.id
1149 response.should render_template("panels")
1154 get :panels, :id => @other_author.id, :format => :json
1155 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1159 context 'ユーザ権限がないとき' do
1163 it 'ステータスコード200 OKを返す' do
1164 get :panels, :id => @other_author.id
1165 response.should be_success
1168 it 'comicテンプレートを描画する' do
1169 get :panels, :id => @other_author.id
1170 response.should render_template("panels")
1175 get :panels, :id => @other_author.id, :format => :json
1176 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1182 describe '作家数取得に於いて' do
1184 Author.should_receive(:visible_count).and_return(3)
1187 context 'つつがなく終わるとき' do
1188 it 'ステータスコード200 OKを返す' do
1189 get :count, :format => :json
1190 response.should be_success
1194 get :count, :format => :json
1195 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1201 describe '新規作成フォーム表示に於いて' do
1203 @new_user = FactoryGirl.create( :user_yas)
1206 context 'つつがなく終わるとき' do
1207 it 'ステータスコード200 OKを返す' do
1209 response.should be_success
1212 it 'newテンプレートを描画する' do
1214 response.should render_template("new")
1218 it 'new.jsテンプレートを描画する' do
1219 get :new, :format => :js
1220 response.should render_template("new")
1225 get :new, :format => :json
1226 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1230 context 'ユーザ権限がないとき' do
1235 it 'ステータスコード302 Foundを返す' do
1237 response.status.should eq 302
1239 it 'サインインページへ遷移する' do
1241 response.body.should redirect_to '/users/sign_in'
1245 it 'ステータスコード401 Unauthorizedを返す' do
1246 get :new, :format => :js
1247 response.status.should eq 401
1249 it '応答メッセージにUnauthorizedを返す' do
1250 get :new, :format => :js
1251 response.message.should match(/Unauthorized/)
1255 it 'ステータスコード401 Unauthorizedを返す' do
1256 get :new, :format => :json
1257 response.status.should eq 401
1259 it '応答メッセージにUnauthorizedを返す' do
1260 get :new, :format => :json
1261 response.message.should match(/Unauthorized/)
1267 describe '新規作成に於いて' do
1269 @new_user = FactoryGirl.create( :user_yas)
1271 @attr = FactoryGirl.attributes_for(:author, :user_id => @new_user.id, :name => 'ken')
1273 context 'つつがなく終わるとき' do
1275 it 'ステータスコード302 Foundを返す' do
1276 Author.any_instance.stub(:save).and_return(true)
1277 post :create, :author => @attr
1278 response.status.should eq 302
1281 # Author.any_instance.stub(:save).and_return(true)
1282 post :create, :author => @attr
1283 response.should redirect_to(root_path)
1287 it 'ステータスコード200 OKを返す' do
1288 # Author.any_instance.stub(:save).and_return(true)
1289 post :create, :author => @attr, :format => :json
1290 response.should be_success
1294 context 'ユーザ権限がないとき' do
1299 it 'ステータスコード302 Foundを返す' do
1300 post :create, :author => @attr
1301 response.status.should eq 302
1303 it 'サインインページへ遷移する' do
1304 post :create, :author => @attr
1305 response.body.should redirect_to '/users/sign_in'
1309 it 'ステータスコード401 Unauthorizedを返す' do
1310 post :create, :author => @attr, :format => :json
1311 response.status.should eq 401
1313 it '応答メッセージにUnauthorizedを返す' do
1314 post :create, :author => @attr, :format => :json
1315 response.message.should match(/Unauthorized/)
1321 describe '編集フォーム表示に於いて' do
1324 Author.stub(:edit).and_return(@author)
1326 context 'つつがなく終わるとき' do
1327 it 'ステータスコード200 OKを返す' do
1328 get :edit, :id => @author.id
1329 response.should be_success
1332 it 'editテンプレートを描画する' do
1333 get :edit, :id => @author.id
1334 response.should render_template("edit")
1338 it 'edit.jsテンプレートを描画する' do
1339 get :edit, :id => @author.id, :format => :js
1340 response.should render_template("edit")
1344 context 'ユーザ権限がないとき' do
1349 it 'ステータスコード302 Foundを返す' do
1350 get :edit, :id => @author.id
1351 response.status.should eq 302
1353 it 'サインインページへ遷移する' do
1354 get :edit, :id => @author.id
1355 response.body.should redirect_to '/users/sign_in'
1359 it 'ステータスコード401 Unauthorizedを返す' do
1360 get :edit, :id => @author.id, :format => :js
1361 response.status.should eq 401
1363 it '応答メッセージにUnauthorizedを返す' do
1364 get :edit, :id => @author.id, :format => :js
1365 response.message.should match(/Unauthorized/)
1371 describe '更新に於いて' do
1373 @attr = @author.attributes
1374 @attr['name'] = 'ryu'
1377 context 'つつがなく終わるとき' do
1379 put :update, :id => @author.id, :author => @attr
1380 Author.find(@author.id).name.should eq 'ryu'
1383 it 'ステータスコード302 Foundを返す' do
1384 Author.any_instance.stub(:save).with(any_args()).and_return(true)
1385 put :update, :id => @author.id, :author => @attr
1386 response.status.should eq 302
1389 put :update, :id => @author.id, :author => @attr
1390 response.should redirect_to('/home/configure')
1394 it 'ステータスコード200 OKを返す' do
1395 Author.any_instance.stub(:save).with(any_args()).and_return(true)
1396 put :update, :id => @author.id, :author => @attr, :format => :json
1397 response.should be_success
1399 it 'ページ本体は特に返さない' do
1400 Author.any_instance.stub(:save).with(any_args()).and_return(true)
1401 put :update, :id => @author.id, :author => @attr, :format => :json
1402 response.body.should match /./
1406 context 'ユーザ権限がないとき' do
1410 it 'ステータスコード302 Foundを返す' do
1411 put :update, :id => @author.id, :author => @attr
1412 response.status.should eq 302
1415 it 'サインインページへ遷移する' do
1416 put :update, :id => @author.id, :author => @attr
1417 response.body.should redirect_to '/users/sign_in'
1421 it '応答メッセージにUnauthorizedを返す' do
1422 put :update, :id => @author.id, :author => @attr, :format => :json
1423 response.message.should match(/Unauthorized/)