1 # -*- encoding: utf-8 -*-
4 describe ScrollsController do
6 @admin =FactoryGirl.create :admin
7 @sp = FactoryGirl.create :system_picture
8 @lg = FactoryGirl.create :license_group
9 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
10 @user = FactoryGirl.create :user_yas
11 @author = FactoryGirl.create :author, :user_id => @user.id
14 if MagicNumber['run_mode'] == 1
15 describe '一覧表示に於いて' do
17 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
18 Scroll.stub(:list).and_return([@scroll, @scroll, @scroll])
22 it '与えられたpageがセットされている' do
23 get :index, :page => 5
24 assigns(:page).should eq 5
26 it '省略されると@pageに1値が入る' do
28 assigns(:page).should eq 1
30 it '与えられたpage_sizeがセットされている' do
31 get :index, :page_size => 15
32 assigns(:page_size).should eq 15
34 it '省略されると@page_sizeにデフォルト値が入る' do
36 assigns(:page_size).should eq Scroll.default_page_size
38 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
39 get :index, :page_size => 1500
40 assigns(:page_size).should eq Scroll.max_page_size
42 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
43 get :index, :page_size => 0
44 assigns(:page_size).should eq Scroll.default_page_size
47 context 'つつがなく終わるとき' do
48 it 'ステータスコード200 OKを返す' do
50 response.should be_success
52 it 'コミックモデルに一覧を問い合わせている' do
53 Scroll.should_receive(:list).exactly(1)
56 it '@scrollsにリストを取得している' do
58 assigns(:scrolls).should have_at_least(3).items
61 it '@paginateにページ制御を取得している' do
63 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
65 it 'indexテンプレートを描画する' do
67 response.should render_template("index")
72 get :index, :format => :json
73 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
75 it 'コミックモデルにjson一覧出力オプションを問い合わせている' do
76 Scroll.should_receive(:list_json_opt).exactly(1)
77 get :index, :format => :json
79 it 'データがリスト構造になっている' do
80 get :index, :format => :json
81 json = JSON.parse response.body
82 json.should have_at_least(3).items
84 it 'リストの先頭くらいはコミックっぽいものであって欲しい' do
85 get :index, :format => :json
86 json = JSON.parse response.body
87 json.first.has_key?("title").should be_true
88 json.first.has_key?("visible").should be_true
92 context 'ユーザ権限がないとき' do
97 it 'ステータスコード302 Foundを返す' do
99 response.status.should eq 302
101 it 'サインインページへ遷移する' do
103 response.should redirect_to '/users/sign_in'
107 it 'ステータスコード401 Unauthorizedを返す' do
108 get :index, :format => :json
109 response.status.should eq 401
111 it '応答メッセージにUnauthorizedを返す' do
112 get :index, :format => :json
113 response.message.should match(/Unauthorized/)
117 context 'ユーザ権限はないが管理者権限があるとき' do
122 it 'ステータスコード200 OKを返す' do
124 response.should be_success
127 context 'ユーザだが作家登録していないとき' do
132 it 'ステータスコード200 OKを返す' do
134 response.should be_success
140 describe '単体表示に於いて' do
142 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id, :title => 'normal'
143 Scroll.stub(:show).and_return(@scroll)
146 context 'つつがなく終わるとき' do
147 it 'ステータスコード200 OKを返す' do
148 get :show, :id => @scroll.id
149 response.should be_success
151 it 'コミックモデルに単体取得を問い合わせている' do
152 Scroll.should_receive(:show).exactly(1)
155 it '@scrollにアレを取得している' do
156 get :show, :id => @scroll.id
157 assigns(:scroll).id.should eq(@scroll.id)
160 it 'showテンプレートを描画する' do
161 get :show, :id => @scroll.id
162 response.should render_template("show")
167 get :show, :id => @scroll.id, :format => :json
168 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
170 it 'コミックモデルにjson単体出力オプションを問い合わせている' do
171 Scroll.should_receive(:show_json_opt).exactly(1)
172 get :show, :id => @scroll.id, :format => :json
175 get :show, :id => @scroll.id, :format => :json
176 json = JSON.parse response.body
177 json["title"].should match(/normal/)
178 json["visible"].should_not be_nil
182 context 'ユーザ権限がないとき' do
187 it 'ステータスコード302 Foundを返す' do
188 get :show, :id => @scroll.id
189 response.status.should eq 302
191 it 'サインインページへ遷移する' do
192 get :show, :id => @scroll.id
193 response.body.should redirect_to '/users/sign_in'
197 it 'ステータスコード401 Unauthorizedを返す' do
198 get :show, :id => @scroll.id, :format => :json
199 response.status.should eq 401
201 it '応答メッセージにUnauthorizedを返す' do
202 get :show, :id => @scroll.id, :format => :json
203 response.message.should match(/Unauthorized/)
207 context 'ユーザ権限はないが管理者権限があるとき' do
212 it 'ステータスコード200 OKを返す' do
213 get :show, :id => @scroll.id
214 response.should be_success
217 context 'ユーザだが作家登録していないとき' do
222 it 'ステータスコード200 OKを返す' do
223 get :show, :id => @scroll.id
224 response.should be_success
229 context '対象コミックがないとき' do
231 it '例外404 not_foundを返す' do
234 }.should raise_error(ActiveRecord::RecordNotFound)
238 it '例外404 not_foundを返す' do
240 get :show, :id => 0, :format => :json
241 }.should raise_error(ActiveRecord::RecordNotFound)
245 context '非公開コミックを見ようとしたとき' do
247 it '例外403 forbiddenを返す' do
248 Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
249 hidden = FactoryGirl.create :hidden_scroll, :author_id => @author.id
251 get :show, :id => hidden
252 }.should raise_error(ActiveRecord::Forbidden)
256 it '例外403 forbiddenを返す' do
257 Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
258 hidden = FactoryGirl.create :hidden_scroll, :author_id => @author.id
260 get :show, :id => hidden, :format => :json
261 }.should raise_error(ActiveRecord::Forbidden)
267 describe 'コミック数取得に於いて' do
269 Scroll.should_receive(:visible_count).and_return(3)
272 context 'つつがなく終わるとき' do
273 it 'ステータスコード200 OKを返す' do
274 get :count, :format => :json
275 response.should be_success
279 get :count, :format => :json
280 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
282 it 'データがHash構造になっていてコミック数が1である' do
283 get :count, :format => :json
284 json = JSON.parse response.body
285 json["count"].should == 3
291 describe '新規作成フォーム表示に於いて' do
295 context 'つつがなく終わるとき' do
296 it 'ステータスコード200 OKを返す' do
298 response.should be_success
300 it '@scrollに新規データを用意している' do
302 assigns(:scroll).should be_a_new(Scroll)
304 it 'コミックモデルにデフォルト値補充を依頼している' do
305 Scroll.any_instance.should_receive(:supply_default).exactly(1)
309 it 'newテンプレートを描画する' do
311 response.should render_template("new")
315 it 'new.jsテンプレートを描画する' do
316 get :new, :format => :js
317 response.should render_template("new")
322 get :new, :format => :json
323 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
325 it 'コミックモデルにjson単体出力オプションを問い合わせている' do
326 Scroll.should_receive(:show_json_opt).exactly(1)
327 get :new, :format => :json
331 context 'ユーザ権限がないとき' do
336 it 'ステータスコード302 Foundを返す' do
338 response.status.should eq 302
340 it 'サインインページへ遷移する' do
342 response.body.should redirect_to '/users/sign_in'
346 it 'ステータスコード401 Unauthorizedを返す' do
347 get :new, :format => :js
348 response.status.should eq 401
350 it '応答メッセージにUnauthorizedを返す' do
351 get :new, :format => :js
352 response.message.should match(/Unauthorized/)
356 it 'ステータスコード401 Unauthorizedを返す' do
357 get :new, :format => :json
358 response.status.should eq 401
360 it '応答メッセージにUnauthorizedを返す' do
361 get :new, :format => :json
362 response.message.should match(/Unauthorized/)
366 context 'ユーザ権限はないが管理者権限があるとき' do
372 it 'ステータスコード302 Foundを返す' do
374 response.status.should eq 302
376 it 'サインインページへ遷移する' do
378 response.body.should redirect_to '/users/sign_in'
382 context 'ユーザだが作家登録していないとき' do
387 it 'ステータスコード302 Foundを返す' do
389 response.status.should eq 302
393 response.body.should redirect_to new_author_path
399 describe '新規作成に於いて' do
402 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
404 context '事前チェックしておく' do
405 it 'コミックモデルにデフォルト値補充を依頼している' do
406 Scroll.any_instance.should_receive(:supply_default).exactly(1)
407 post :create, :scroll => @attr
409 it 'コミックモデルにカラム値復元を依頼している' do
410 Scroll.any_instance.should_receive(:attributes=).exactly(1)
411 post :create, :scroll => @attr
413 it 'コミックモデルに上書き補充を依頼している' do
414 Scroll.any_instance.should_receive(:overwrite).exactly(1)
415 post :create, :scroll => @attr
418 Scroll.any_instance.should_receive(:save).exactly(1)
419 post :create, :scroll => @attr
422 context 'つつがなく終わるとき' do
423 it "@scrollに作成されたコミックを保持していて、それがDBにある" do
424 post :create, :scroll => @attr
425 assigns(:scroll).should be_a(Scroll)
426 assigns(:scroll).should be_persisted
429 it 'ステータスコード302 Foundを返す' do
430 Scroll.any_instance.stub(:save).and_return(true)
431 post :create, :scroll => @attr
432 response.status.should eq 302
434 it '作成されたコミックの表示ページへ遷移する' do
435 # Scroll.any_instance.stub(:save).and_return(true)
436 post :create, :scroll => @attr
437 response.should redirect_to(Scroll.last)
441 it 'ステータスコード200 OKを返す' do
442 # Scroll.any_instance.stub(:save).and_return(true)
443 post :create, :scroll => @attr, :format => :json
444 response.should be_success
446 it '作成されたコミックをjsonデータで返す' do
447 post :create, :scroll => @attr, :format => :json
448 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
451 post :create, :scroll => @attr, :format => :json
452 json = JSON.parse response.body
453 json["title"].should match(/normal/)
454 json["visible"].should_not be_nil
458 context 'ユーザ権限がないとき' do
463 it 'ステータスコード302 Foundを返す' do
464 post :create, :scroll => @attr
465 response.status.should eq 302
467 it 'サインインページへ遷移する' do
468 post :create, :scroll => @attr
469 response.body.should redirect_to '/users/sign_in'
473 it 'ステータスコード401 Unauthorizedを返す' do
474 post :create, :scroll => @attr, :format => :json
475 response.status.should eq 401
477 it '応答メッセージにUnauthorizedを返す' do
478 post :create, :scroll => @attr, :format => :json
479 response.message.should match(/Unauthorized/)
483 context 'ユーザ権限はないが管理者権限があるとき' do
489 it 'ステータスコード302 Foundを返す' do
490 post :create, :scroll => @attr
491 response.status.should eq 302
493 it 'サインインページへ遷移する' do
494 post :create, :scroll => @attr
495 response.body.should redirect_to '/users/sign_in'
499 context 'ユーザだが作家登録していないとき' do
504 it 'ステータスコード302 Foundを返す' do
505 post :create, :scroll => @attr
506 response.status.should eq 302
509 post :create, :scroll => @attr
510 response.body.should redirect_to new_author_path
514 context '検証、保存に失敗した' do
516 Scroll.any_instance.stub(:save).and_return(false)
518 it "未保存のコミックを保持している" do
519 post :create, :scroll => @attr
520 assigns(:scroll).should be_a_new(Scroll)
523 it 'ステータスコード200 OKを返す' do
524 post :create, :scroll => @attr
525 response.status.should eq 200
528 post :create, :scroll => @attr
529 response.should render_template("new")
533 it 'ステータスコード422 unprocessable_entity を返す' do
534 post :create, :scroll => @attr, :format => :json
535 response.status.should eq 422
537 it '応答メッセージUnprocessable Entityを返す' do
538 post :create, :scroll => @attr, :format => :json
539 response.message.should match(/Unprocessable/)
545 describe '編集フォーム表示に於いて' do
547 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
549 Scroll.stub(:edit).and_return(@scroll)
551 context 'つつがなく終わるとき' do
552 it 'ステータスコード200 OKを返す' do
553 get :edit, :id => @scroll.id
554 response.should be_success
556 it 'コミックモデルに編集取得を問い合わせている' do
557 Scroll.should_receive(:edit).exactly(1)
558 get :edit, :id => @scroll.id
560 it '@scrollにデータを用意している' do
561 get :edit, :id => @scroll.id
562 assigns(:scroll).should eq @scroll
565 it 'editテンプレートを描画する' do
566 get :edit, :id => @scroll.id
567 response.should render_template("edit")
571 it 'edit.jsテンプレートを描画する' do
572 get :edit, :id => @scroll.id, :format => :js
573 response.should render_template("edit")
577 context 'ユーザ権限がないとき' do
582 it 'ステータスコード302 Foundを返す' do
583 get :edit, :id => @scroll.id
584 response.status.should eq 302
586 it 'サインインページへ遷移する' do
587 get :edit, :id => @scroll.id
588 response.body.should redirect_to '/users/sign_in'
592 it 'ステータスコード401 Unauthorizedを返す' do
593 get :edit, :id => @scroll.id, :format => :js
594 response.status.should eq 401
596 it '応答メッセージにUnauthorizedを返す' do
597 get :edit, :id => @scroll.id, :format => :js
598 response.message.should match(/Unauthorized/)
602 context 'ユーザ権限はないが管理者権限があるとき' do
608 it 'ステータスコード302 Foundを返す' do
609 get :edit, :id => @scroll.id
610 response.status.should eq 302
612 it 'サインインページへ遷移する' do
613 get :edit, :id => @scroll.id
614 response.body.should redirect_to '/users/sign_in'
618 context 'ユーザだが作家登録していないとき' do
623 it 'ステータスコード302 Foundを返す' do
624 get :edit, :id => @scroll.id
625 response.status.should eq 302
628 get :edit, :id => @scroll.id
629 response.body.should redirect_to new_author_path
637 @scroll = FactoryGirl.create :scroll, :author => @author
638 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
641 context '事前チェックしておく' do
642 it 'コミックモデルに編集取得を問い合わせている' do
643 Scroll.stub(:edit).with(any_args()).and_return @scroll
644 Scroll.should_receive(:edit).exactly(1)
645 put :update, :id => @scroll.id, :scroll => @attr
647 it 'コミックモデルにカラム値復元を依頼している' do
648 Scroll.any_instance.should_receive(:attributes=).exactly(1)
649 put :update, :id => @scroll.id, :scroll => @attr
651 it 'コミックモデルに上書き補充を依頼している' do
652 Scroll.any_instance.should_receive(:overwrite).exactly(1)
653 put :update, :id => @scroll.id, :scroll => @attr
656 Scroll.any_instance.stub(:save).with(any_args).and_return true
657 Scroll.any_instance.should_receive(:save).exactly(1)
658 put :update, :id => @scroll.id, :scroll => @attr
660 it '@scrollにアレを取得している' do
661 put :update, :id => @scroll.id, :scroll => @attr
662 assigns(:scroll).id.should eq(@scroll.id)
665 context 'つつがなく終わるとき' do
667 put :update, :id => @scroll.id, :scroll => @attr
668 Scroll.find(@scroll.id).visible.should eq 0
671 it 'ステータスコード302 Foundを返す' do
672 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
673 put :update, :id => @scroll.id, :scroll => @attr
674 response.status.should eq 302
676 it '更新されたコミックの表示ページへ遷移する' do
677 put :update, :id => @scroll.id, :scroll => @attr
678 response.should redirect_to(@scroll)
682 it 'ステータスコード200 OKを返す' do
683 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
684 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
685 response.should be_success
688 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
689 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
690 response.body.should match /./
694 context 'ユーザ権限がないとき' do
699 it 'ステータスコード302 Foundを返す' do
700 put :update, :id => @scroll.id, :scroll => @attr
701 response.status.should eq 302
703 it 'サインインページへ遷移する' do
704 put :update, :id => @scroll.id, :scroll => @attr
705 response.body.should redirect_to '/users/sign_in'
709 it '応答メッセージにUnauthorizedを返す' do
710 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
711 response.message.should match(/Unauthorized/)
715 context 'ユーザ権限はないが管理者権限があるとき' do
721 it 'ステータスコード302 Foundを返す' do
722 put :update, :id => @scroll.id, :scroll => @attr
723 response.status.should eq 302
725 it 'サインインページへ遷移する' do
726 put :update, :id => @scroll.id, :scroll => @attr
727 response.body.should redirect_to '/users/sign_in'
731 context 'ユーザだが作家登録していないとき' do
736 it 'ステータスコード302 Foundを返す' do
737 put :update, :id => @scroll.id, :scroll => @attr
738 response.status.should eq 302
741 put :update, :id => @scroll.id, :scroll => @attr
742 response.body.should redirect_to new_author_path
746 context '検証、保存に失敗したとき' do
748 Scroll.any_instance.stub(:save).and_return(false)
751 it 'ステータスコード200 Okを返す' do
752 put :update, :id => @scroll.id, :scroll => @attr
753 response.status.should eq 200
756 put :update, :id => @scroll.id, :scroll => @attr
757 response.should render_template("edit")
761 it 'ステータスコード422 unprocessable_entity を返す' do
762 Scroll.any_instance.stub(:save).and_return(false)
763 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
764 response.status.should eq 422
766 it '応答メッセージUnprocessable Entityを返す' do
767 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
768 response.message.should match(/Unprocessable/)
776 @scroll = FactoryGirl.create :scroll, :author => @author
779 context '事前チェックしておく' do
781 Scroll.stub(:edit).with(any_args()).and_return @scroll
782 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
784 it 'コミックモデルに編集取得を問い合わせている' do
785 Scroll.should_receive(:edit).exactly(1)
786 delete :destroy, :id => @scroll.id
789 Scroll.any_instance.should_receive(:destroy_with_scroll_panel).exactly(1)
790 delete :destroy, :id => @scroll.id
792 it '@scrollにアレを取得している' do
793 delete :destroy, :id => @scroll.id
794 assigns(:scroll).id.should eq(@scroll.id)
797 context 'つつがなく終わるとき' do
800 delete :destroy, :id => @scroll.id
801 }.should change Scroll, :count
805 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
807 it 'ステータスコード302 Foundを返す' do
808 delete :destroy, :id => @scroll.id
809 response.status.should eq 302
811 it 'マイコミックの一覧ページへ遷移する' do
812 delete :destroy, :id => @scroll.id
813 response.should redirect_to('/home/scrolls')
818 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
820 it 'ステータスコード200 OKを返す' do
821 delete :destroy, :id => @scroll.id, :format => :json
822 response.should be_success
825 delete :destroy, :id => @scroll.id, :format => :json
826 response.body.should match /./
830 context 'ユーザ権限がないとき' do
835 it 'ステータスコード302 Foundを返す' do
836 delete :destroy, :id => @scroll.id
837 response.status.should eq 302
839 it 'サインインページへ遷移する' do
840 delete :destroy, :id => @scroll.id
841 response.body.should redirect_to '/users/sign_in'
845 it '応答メッセージにUnauthorizedを返す' do
846 delete :destroy, :id => @scroll.id, :format => :json
847 response.message.should match(/Unauthorized/)
851 context 'ユーザ権限はないが管理者権限があるとき' do
857 it 'ステータスコード302 Foundを返す' do
858 delete :destroy, :id => @scroll.id
859 response.status.should eq 302
861 it 'サインインページへ遷移する' do
862 delete :destroy, :id => @scroll.id
863 response.body.should redirect_to '/users/sign_in'
867 context 'ユーザだが作家登録していないとき' do
872 it 'ステータスコード302 Foundを返す' do
873 delete :destroy, :id => @scroll.id
874 response.status.should eq 302
877 delete :destroy, :id => @scroll.id
878 response.body.should redirect_to new_author_path
882 context '削除に失敗したとき' do
884 Scroll.any_instance.stub(:destroy_with_scroll_panel).and_return(false)
887 it 'ステータスコード302 Foundを返す' do
888 delete :destroy, :id => @scroll.id
889 response.status.should eq 302
891 it 'そのコミックの詳細ページへ遷移する' do
892 delete :destroy, :id => @scroll.id
893 response.should redirect_to(scroll_path(@scroll))
897 it 'ステータスコード422 unprocessable_entity を返す' do
898 delete :destroy, :id => @scroll.id, :format => :json
899 response.status.should eq 422
901 it '応答メッセージUnprocessable Entityを返す' do
902 delete :destroy, :id => @scroll.id, :format => :json
903 response.message.should match(/Unprocessable/)
910 describe '一覧表示に於いて' do
912 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
913 Scroll.stub(:list).and_return([@scroll, @scroll, @scroll])
916 context 'つつがなく終わるとき' do
917 it 'ステータスコード200 OKを返す' do
919 response.should be_success
922 it 'indexテンプレートを描画する' do
924 response.should render_template("index")
929 get :index, :format => :json
930 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
934 context 'ユーザ権限がないとき' do
938 it 'ステータスコード200 OKを返す' do
940 response.should be_success
943 it 'indexテンプレートを描画する' do
945 response.should render_template("index")
950 get :index, :format => :json
951 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
957 describe '単体表示に於いて' do
959 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id, :title => 'normal'
960 Scroll.stub(:show).and_return(@scroll)
963 context 'つつがなく終わるとき' do
964 it 'ステータスコード200 OKを返す' do
965 get :show, :id => @scroll.id
966 response.should be_success
969 it 'showテンプレートを描画する' do
970 get :show, :id => @scroll.id
971 response.should render_template("show")
976 get :show, :id => @scroll.id, :format => :json
977 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
981 context 'ユーザ権限がないとき' do
985 it 'ステータスコード200 OKを返す' do
986 get :show, :id => @scroll.id
987 response.should be_success
990 it 'showテンプレートを描画する' do
991 get :show, :id => @scroll.id
992 response.should render_template("show")
997 get :show, :id => @scroll.id, :format => :json
998 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1003 describe 'コミック数取得に於いて' do
1005 Scroll.should_receive(:visible_count).and_return(3)
1008 context 'つつがなく終わるとき' do
1009 it 'ステータスコード200 OKを返す' do
1010 get :count, :format => :json
1011 response.should be_success
1015 get :count, :format => :json
1016 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1022 describe '新規作成フォーム表示に於いて' do
1026 context 'つつがなく終わるとき' do
1027 it 'ステータスコード200 OKを返す' do
1029 response.should be_success
1032 it 'newテンプレートを描画する' do
1034 response.should render_template("new")
1038 it 'new.jsテンプレートを描画する' do
1039 get :new, :format => :js
1040 response.should render_template("new")
1045 get :new, :format => :json
1046 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1050 context 'ユーザ権限がないとき' do
1055 it 'ステータスコード302 Foundを返す' do
1057 response.status.should eq 302
1059 it 'サインインページへ遷移する' do
1061 response.body.should redirect_to '/users/sign_in'
1065 it 'ステータスコード401 Unauthorizedを返す' do
1066 get :new, :format => :js
1067 response.status.should eq 401
1069 it '応答メッセージにUnauthorizedを返す' do
1070 get :new, :format => :js
1071 response.message.should match(/Unauthorized/)
1075 it 'ステータスコード401 Unauthorizedを返す' do
1076 get :new, :format => :json
1077 response.status.should eq 401
1079 it '応答メッセージにUnauthorizedを返す' do
1080 get :new, :format => :json
1081 response.message.should match(/Unauthorized/)
1087 describe '新規作成に於いて' do
1090 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
1092 context 'つつがなく終わるとき' do
1094 it 'ステータスコード302 Foundを返す' do
1095 Scroll.any_instance.stub(:save).and_return(true)
1096 post :create, :scroll => @attr
1097 response.status.should eq 302
1099 it '作成されたコミックの表示ページへ遷移する' do
1100 # Scroll.any_instance.stub(:save).and_return(true)
1101 post :create, :scroll => @attr
1102 response.should redirect_to(Scroll.last)
1106 it 'ステータスコード200 OKを返す' do
1107 # Scroll.any_instance.stub(:save).and_return(true)
1108 post :create, :scroll => @attr, :format => :json
1109 response.should be_success
1111 it '作成されたコミックをjsonデータで返す' do
1112 post :create, :scroll => @attr, :format => :json
1113 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1117 context 'ユーザ権限がないとき' do
1122 it 'ステータスコード302 Foundを返す' do
1123 post :create, :scroll => @attr
1124 response.status.should eq 302
1126 it 'サインインページへ遷移する' do
1127 post :create, :scroll => @attr
1128 response.body.should redirect_to '/users/sign_in'
1132 it 'ステータスコード401 Unauthorizedを返す' do
1133 post :create, :scroll => @attr, :format => :json
1134 response.status.should eq 401
1136 it '応答メッセージにUnauthorizedを返す' do
1137 post :create, :scroll => @attr, :format => :json
1138 response.message.should match(/Unauthorized/)
1144 describe '編集フォーム表示に於いて' do
1146 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
1148 Scroll.stub(:edit).and_return(@scroll)
1150 context 'つつがなく終わるとき' do
1151 it 'ステータスコード200 OKを返す' do
1152 get :edit, :id => @scroll.id
1153 response.should be_success
1156 it 'editテンプレートを描画する' do
1157 get :edit, :id => @scroll.id
1158 response.should render_template("edit")
1162 it 'edit.jsテンプレートを描画する' do
1163 get :edit, :id => @scroll.id, :format => :js
1164 response.should render_template("edit")
1168 context 'ユーザ権限がないとき' do
1173 it 'ステータスコード302 Foundを返す' do
1174 get :edit, :id => @scroll.id
1175 response.status.should eq 302
1177 it 'サインインページへ遷移する' do
1178 get :edit, :id => @scroll.id
1179 response.body.should redirect_to '/users/sign_in'
1183 it 'ステータスコード401 Unauthorizedを返す' do
1184 get :edit, :id => @scroll.id, :format => :js
1185 response.status.should eq 401
1187 it '応答メッセージにUnauthorizedを返す' do
1188 get :edit, :id => @scroll.id, :format => :js
1189 response.message.should match(/Unauthorized/)
1195 describe '更新に於いて' do
1197 @scroll = FactoryGirl.create :scroll, :author => @author
1198 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
1201 context 'つつがなく終わるとき' do
1203 it 'ステータスコード302 Foundを返す' do
1204 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1205 put :update, :id => @scroll.id, :scroll => @attr
1206 response.status.should eq 302
1208 it '更新されたコミックの表示ページへ遷移する' do
1209 put :update, :id => @scroll.id, :scroll => @attr
1210 response.should redirect_to(@scroll)
1214 it 'ステータスコード200 OKを返す' do
1215 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1216 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
1217 response.should be_success
1219 it 'ページ本体は特に返さない' do
1220 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1221 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
1222 response.body.should match /./
1226 context 'ユーザ権限がないとき' do
1230 it 'ステータスコード302 Foundを返す' do
1231 put :update, :id => @scroll.id, :scroll => @attr
1232 response.status.should eq 302
1235 it 'サインインページへ遷移する' do
1236 put :update, :id => @scroll.id, :scroll => @attr
1237 response.body.should redirect_to '/users/sign_in'
1243 describe '削除に於いて' do
1245 @scroll = FactoryGirl.create :scroll, :author => @author
1248 context 'つつがなく終わるとき' do
1251 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
1253 it 'ステータスコード302 Foundを返す' do
1254 delete :destroy, :id => @scroll.id
1255 response.status.should eq 302
1257 it 'マイコミックの一覧ページへ遷移する' do
1258 delete :destroy, :id => @scroll.id
1259 response.should redirect_to('/home/scroll')
1264 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
1266 it 'ステータスコード200 OKを返す' do
1267 delete :destroy, :id => @scroll.id, :format => :json
1268 response.should be_success
1270 it 'ページ本体は特に返さない' do
1271 delete :destroy, :id => @scroll.id, :format => :json
1272 response.body.should match /./
1276 context 'ユーザ権限がないとき' do
1280 it 'ステータスコード302 Foundを返す' do
1281 delete :destroy, :id => @scroll.id
1282 response.status.should eq 302
1285 it 'サインインページへ遷移する' do
1286 delete :destroy, :id => @scroll.id
1287 response.body.should redirect_to '/users/sign_in'
1291 it '応答メッセージにUnauthorizedを返す' do
1292 delete :destroy, :id => @scroll.id, :format => :json
1293 response.message.should match(/Unauthorized/)