1 # -*- encoding: utf-8 -*-
4 describe ScrollsController do
6 @admin =FactoryGirl.create :admin
9 if Manifest.manifest.magic_numbers['run_mode'] == 1
10 describe '一覧表示に於いて' do
12 @author_yas = FactoryGirl.create :yas_with_scrolls
13 @user_yas = @author_yas.user
16 context 'つつがなく終わるとき' do
20 it '@itemsにリストを取得している' do
22 except(assigns(:items).size).to be >= 3
24 it 'ステータスコード200 OKを返す' do
25 list_should_return_filer_or_json :index
29 it 'ユーザ権限はないが管理者権限があるとき 200 OKを返す' do
31 return_ok_at_get :index
33 it 'ユーザだが作家登録していないとき 200 OKを返す' do
34 @user_rom = FactoryGirl.create :user_rom
36 return_ok_at_get :index
39 announce_sign_in_at_get :index
43 describe '作家フィルタ一覧及びカウント' do
45 @author_yas = FactoryGirl.create :yas_with_scrolls
46 @user_yas = @author_yas.user
47 @scroll = @author_yas.scrolls.first
49 context 'つつがなく終わるとき' do
53 it '@itemsにリストを取得している' do
55 except(assigns(:items).size).to be >= 3
57 it 'ステータスコード200 OKを返す' do
58 list_should_return_filer_or_json :by_author, id: @author_yas.id
62 it 'ユーザ権限はないが管理者権限があるとき 200 OKを返す' do
64 return_ok_at_get :by_author
66 it 'ユーザだが作家登録していないとき 200 OKを返す' do
67 @user_rom = FactoryGirl.create :user_rom, id: @author_yas.id
69 return_ok_at_get :by_author
72 announce_sign_in_at_get :by_author, id: @author_yas.id
77 describe '単体表示に於いて' do
79 @author_yas = FactoryGirl.create :yas_with_scrolls
80 @user_yas = @author_yas.user
82 @scroll = @author_yas.scrolls.first
84 context 'つつがなく終わるとき' do
85 it 'ステータスコード200 OKを返す' do
86 get :show, :id => @scroll.id
87 response.should be_success
89 it '@itemにアレを取得している' do
90 get :show, :id => @scroll.id
91 assigns(:item).id.should eq(@scroll.id)
94 it 'showテンプレートを描画する' do
95 get :show, :id => @scroll.id
96 response.should render_template("show")
101 get :show, :id => @scroll.id, :format => :json
102 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
106 it 'profilerを描画する' do
107 get :show, :id => @scroll.id, :format => :prof
108 response.should render_template("templates/r/profiler/profiler")
112 context 'ユーザ権限がないとき' do
117 it 'ステータスコード302 Foundを返す' do
118 get :show, :id => @scroll.id
119 response.status.should eq 302
121 it 'サインインページへ遷移する' do
122 get :show, :id => @scroll.id
123 response.body.should redirect_to '/users/sign_in'
127 it 'ステータスコード401 Unauthorizedを返す' do
128 get :show, :id => @scroll.id, :format => :json
129 response.status.should eq 401
131 it '応答メッセージにUnauthorizedを返す' do
132 get :show, :id => @scroll.id, :format => :json
133 response.message.should match(/Unauthorized/)
137 context 'ユーザ権限はないが管理者権限があるとき' do
142 it 'ステータスコード200 OKを返す' do
143 get :show, :id => @scroll.id
144 response.should be_success
147 context 'ユーザだが作家登録していないとき' do
150 @user_ghost = FactoryGirl.create :user_ghost
154 it 'ステータスコード200 OKを返す' do
155 get :show, :id => @scroll.id
156 response.should be_success
161 context '対象スクロールがないとき' do
163 it '例外404 not_foundを返す' do
166 }.should raise_error(ActiveRecord::RecordNotFound)
170 it '例外404 not_foundを返す' do
172 get :show, :id => 0, :format => :json
173 }.should raise_error(ActiveRecord::RecordNotFound)
177 context '非公開スクロールを見ようとしたとき' do
179 it '例外403 forbiddenを返す' do
180 Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
181 hidden = FactoryGirl.create :hidden_scroll, :author_id => @author.id
183 get :show, :id => hidden
184 }.should raise_error(ActiveRecord::Forbidden)
188 it '例外403 forbiddenを返す' do
189 Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
190 hidden = FactoryGirl.create :hidden_scroll, :author_id => @author.id
192 get :show, :id => hidden, :format => :json
193 }.should raise_error(ActiveRecord::Forbidden)
202 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
203 @panel = FactoryGirl.create :panel, :author_id => @author.id
204 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
205 Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
206 Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
207 ScrollPanel.stub(:count).and_return(10)
208 ScrollPanel.stub(:play_list).with(any_args).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
211 context 'つつがなく終わるとき' do
212 it '@scroll_panelsにリストを取得している' do
213 get :play, :id => @scroll.id
214 assigns(:scroll_panels).should have_at_least(3).items
217 it 'ステータスコード200 OKを返す' do
218 get :play, :id => @scroll.id
219 response.should be_success
221 it 'scrollテンプレートを描画する' do
222 get :play, :id => @scroll.id
223 response.should render_template("scroll")
227 it 'ステータスコード200 OKを返す' do
228 get :play, :id => @scroll.id, :format => :json
229 response.should be_success
232 get :play, :id => @scroll.id, :format => :json
233 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
237 context 'ユーザ権限がないとき' do
242 it 'ステータスコード302 Foundを返す' do
243 get :play, :id => @scroll.id
244 response.status.should eq 302
246 it 'サインインページへ遷移する' do
247 get :play, :id => @scroll.id
248 response.should redirect_to '/users/sign_in'
252 it 'ステータスコード401 Unauthorizedを返す' do
253 get :play, :id => @scroll.id, :format => :json
254 response.status.should eq 401
256 it '応答メッセージにUnauthorizedを返す' do
257 get :play, :id => @scroll.id, :format => :json
258 response.message.should match(/Unauthorized/)
262 context 'ユーザ権限はないが管理者権限があるとき' do
267 it 'ステータスコード200 OKを返す' do
268 get :play, :id => @scroll.id
269 response.should be_success
272 context 'ユーザだが作家登録していないとき' do
276 it 'ステータスコード200 OKを返す' do
277 get :play, :id => @scroll.id
278 response.should be_success
283 describe 'スクロール数取得に於いて' do
285 Scroll.should_receive(:visible_count).and_return(3)
288 context 'つつがなく終わるとき' do
289 it 'ステータスコード200 OKを返す' do
290 get :count, :format => :json
291 response.should be_success
295 get :count, :format => :json
296 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
298 it 'データがHash構造になっていてスクロール数が1である' do
299 get :count, :format => :json
300 json = JSON.parse response.body
301 json["count"].should == 3
307 describe '新規作成フォーム表示に於いて' do
311 context 'つつがなく終わるとき' do
312 it 'ステータスコード200 OKを返す' do
314 response.should be_success
316 it '@scrollに新規データを用意している' do
318 assigns(:scroll).should be_a_new(Scroll)
320 it 'スクロールモデルにデフォルト値補充を依頼している' do
321 Scroll.any_instance.should_receive(:supply_default).exactly(1)
325 it 'newテンプレートを描画する' do
327 response.should render_template("new")
331 it 'new.jsテンプレートを描画する' do
332 get :new, :format => :js
333 response.should render_template("new")
338 get :new, :format => :json
339 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
341 it 'スクロールモデルにjson単体出力オプションを問い合わせている' do
342 Scroll.should_receive(:show_json_opt).exactly(1)
343 get :new, :format => :json
347 context 'ユーザ権限がないとき' do
352 it 'ステータスコード302 Foundを返す' do
354 response.status.should eq 302
356 it 'サインインページへ遷移する' do
358 response.body.should redirect_to '/users/sign_in'
362 it 'ステータスコード401 Unauthorizedを返す' do
363 get :new, :format => :js
364 response.status.should eq 401
366 it '応答メッセージにUnauthorizedを返す' do
367 get :new, :format => :js
368 response.message.should match(/Unauthorized/)
372 it 'ステータスコード401 Unauthorizedを返す' do
373 get :new, :format => :json
374 response.status.should eq 401
376 it '応答メッセージにUnauthorizedを返す' do
377 get :new, :format => :json
378 response.message.should match(/Unauthorized/)
382 context 'ユーザ権限はないが管理者権限があるとき' do
388 it 'ステータスコード302 Foundを返す' do
390 response.status.should eq 302
392 it 'サインインページへ遷移する' do
394 response.body.should redirect_to '/users/sign_in'
398 context 'ユーザだが作家登録していないとき' do
403 it 'ステータスコード302 Foundを返す' do
405 response.status.should eq 302
409 response.body.should redirect_to new_author_path
415 describe '新規作成に於いて' do
418 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
420 context '事前チェックしておく' do
421 it 'スクロールモデルにデフォルト値補充を依頼している' do
422 Scroll.any_instance.should_receive(:supply_default).exactly(1)
423 post :create, :scroll => @attr
425 it 'スクロールモデルにカラム値復元を依頼している' do
426 Scroll.any_instance.should_receive(:attributes=).exactly(1)
427 post :create, :scroll => @attr
429 it 'スクロールモデルに上書き補充を依頼している' do
430 Scroll.any_instance.should_receive(:overwrite).exactly(1)
431 post :create, :scroll => @attr
434 Scroll.any_instance.should_receive(:save).exactly(1)
435 post :create, :scroll => @attr
438 context 'つつがなく終わるとき' do
439 it "@scrollに作成されたスクロールを保持していて、それがDBにある" do
440 post :create, :scroll => @attr
441 assigns(:scroll).should be_a(Scroll)
442 assigns(:scroll).should be_persisted
445 it 'ステータスコード302 Foundを返す' do
446 Scroll.any_instance.stub(:save).and_return(true)
447 post :create, :scroll => @attr
448 response.status.should eq 302
450 it '作成されたスクロールの表示ページへ遷移する' do
451 # Scroll.any_instance.stub(:save).and_return(true)
452 post :create, :scroll => @attr
453 response.should redirect_to(Scroll.last)
457 it 'ステータスコード200 OKを返す' do
458 # Scroll.any_instance.stub(:save).and_return(true)
459 post :create, :scroll => @attr, :format => :json
460 response.should be_success
462 it '作成されたスクロールをjsonデータで返す' do
463 post :create, :scroll => @attr, :format => :json
464 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
467 post :create, :scroll => @attr, :format => :json
468 json = JSON.parse response.body
469 json["title"].should match(/normal/)
470 json["visible"].should_not be_nil
474 context 'ユーザ権限がないとき' do
479 it 'ステータスコード302 Foundを返す' do
480 post :create, :scroll => @attr
481 response.status.should eq 302
483 it 'サインインページへ遷移する' do
484 post :create, :scroll => @attr
485 response.body.should redirect_to '/users/sign_in'
489 it 'ステータスコード401 Unauthorizedを返す' do
490 post :create, :scroll => @attr, :format => :json
491 response.status.should eq 401
493 it '応答メッセージにUnauthorizedを返す' do
494 post :create, :scroll => @attr, :format => :json
495 response.message.should match(/Unauthorized/)
499 context 'ユーザ権限はないが管理者権限があるとき' do
505 it 'ステータスコード302 Foundを返す' do
506 post :create, :scroll => @attr
507 response.status.should eq 302
509 it 'サインインページへ遷移する' do
510 post :create, :scroll => @attr
511 response.body.should redirect_to '/users/sign_in'
515 context 'ユーザだが作家登録していないとき' do
520 it 'ステータスコード302 Foundを返す' do
521 post :create, :scroll => @attr
522 response.status.should eq 302
525 post :create, :scroll => @attr
526 response.body.should redirect_to new_author_path
530 context '検証、保存に失敗した' do
532 Scroll.any_instance.stub(:save).and_return(false)
534 it "未保存のスクロールを保持している" do
535 post :create, :scroll => @attr
536 assigns(:scroll).should be_a_new(Scroll)
539 it 'ステータスコード200 OKを返す' do
540 post :create, :scroll => @attr
541 response.status.should eq 200
544 post :create, :scroll => @attr
545 response.should render_template("new")
549 it 'ステータスコード422 unprocessable_entity を返す' do
550 post :create, :scroll => @attr, :format => :json
551 response.status.should eq 422
553 it '応答メッセージUnprocessable Entityを返す' do
554 post :create, :scroll => @attr, :format => :json
555 response.message.should match(/Unprocessable/)
561 describe '編集フォーム表示に於いて' do
563 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
565 Scroll.stub(:edit).and_return(@scroll)
567 context 'つつがなく終わるとき' do
568 it 'ステータスコード200 OKを返す' do
569 get :edit, :id => @scroll.id
570 response.should be_success
572 it 'スクロールモデルに編集取得を問い合わせている' do
573 Scroll.should_receive(:edit).exactly(1)
574 get :edit, :id => @scroll.id
576 it '@scrollにデータを用意している' do
577 get :edit, :id => @scroll.id
578 assigns(:scroll).should eq @scroll
581 it 'editテンプレートを描画する' do
582 get :edit, :id => @scroll.id
583 response.should render_template("edit")
587 it 'edit.jsテンプレートを描画する' do
588 get :edit, :id => @scroll.id, :format => :js
589 response.should render_template("edit")
593 context 'ユーザ権限がないとき' do
598 it 'ステータスコード302 Foundを返す' do
599 get :edit, :id => @scroll.id
600 response.status.should eq 302
602 it 'サインインページへ遷移する' do
603 get :edit, :id => @scroll.id
604 response.body.should redirect_to '/users/sign_in'
608 it 'ステータスコード401 Unauthorizedを返す' do
609 get :edit, :id => @scroll.id, :format => :js
610 response.status.should eq 401
612 it '応答メッセージにUnauthorizedを返す' do
613 get :edit, :id => @scroll.id, :format => :js
614 response.message.should match(/Unauthorized/)
618 context 'ユーザ権限はないが管理者権限があるとき' do
624 it 'ステータスコード302 Foundを返す' do
625 get :edit, :id => @scroll.id
626 response.status.should eq 302
628 it 'サインインページへ遷移する' do
629 get :edit, :id => @scroll.id
630 response.body.should redirect_to '/users/sign_in'
634 context 'ユーザだが作家登録していないとき' do
639 it 'ステータスコード302 Foundを返す' do
640 get :edit, :id => @scroll.id
641 response.status.should eq 302
644 get :edit, :id => @scroll.id
645 response.body.should redirect_to new_author_path
653 @scroll = FactoryGirl.create :scroll, :author => @author
654 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
657 context '事前チェックしておく' do
658 it 'スクロールモデルに編集取得を問い合わせている' do
659 Scroll.stub(:edit).with(any_args()).and_return @scroll
660 Scroll.should_receive(:edit).exactly(1)
661 put :update, :id => @scroll.id, :scroll => @attr
663 it 'スクロールモデルにカラム値復元を依頼している' do
664 Scroll.any_instance.should_receive(:attributes=).exactly(1)
665 put :update, :id => @scroll.id, :scroll => @attr
667 it 'スクロールモデルに上書き補充を依頼している' do
668 Scroll.any_instance.should_receive(:overwrite).exactly(1)
669 put :update, :id => @scroll.id, :scroll => @attr
672 Scroll.any_instance.stub(:save).with(any_args).and_return true
673 Scroll.any_instance.should_receive(:save).exactly(1)
674 put :update, :id => @scroll.id, :scroll => @attr
676 it '@scrollにアレを取得している' do
677 put :update, :id => @scroll.id, :scroll => @attr
678 assigns(:scroll).id.should eq(@scroll.id)
681 context 'つつがなく終わるとき' do
683 put :update, :id => @scroll.id, :scroll => @attr
684 Scroll.find(@scroll.id).visible.should eq 0
687 it 'ステータスコード302 Foundを返す' do
688 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
689 put :update, :id => @scroll.id, :scroll => @attr
690 response.status.should eq 302
692 it '更新されたスクロールの表示ページへ遷移する' do
693 put :update, :id => @scroll.id, :scroll => @attr
694 response.should redirect_to(@scroll)
698 it 'ステータスコード200 OKを返す' do
699 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
700 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
701 response.should be_success
704 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
705 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
706 response.body.should match /./
710 context 'ユーザ権限がないとき' do
715 it 'ステータスコード302 Foundを返す' do
716 put :update, :id => @scroll.id, :scroll => @attr
717 response.status.should eq 302
719 it 'サインインページへ遷移する' do
720 put :update, :id => @scroll.id, :scroll => @attr
721 response.body.should redirect_to '/users/sign_in'
725 it '応答メッセージにUnauthorizedを返す' do
726 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
727 response.message.should match(/Unauthorized/)
731 context 'ユーザ権限はないが管理者権限があるとき' do
737 it 'ステータスコード302 Foundを返す' do
738 put :update, :id => @scroll.id, :scroll => @attr
739 response.status.should eq 302
741 it 'サインインページへ遷移する' do
742 put :update, :id => @scroll.id, :scroll => @attr
743 response.body.should redirect_to '/users/sign_in'
747 context 'ユーザだが作家登録していないとき' do
752 it 'ステータスコード302 Foundを返す' do
753 put :update, :id => @scroll.id, :scroll => @attr
754 response.status.should eq 302
757 put :update, :id => @scroll.id, :scroll => @attr
758 response.body.should redirect_to new_author_path
762 context '検証、保存に失敗したとき' do
764 Scroll.any_instance.stub(:save).and_return(false)
767 it 'ステータスコード200 Okを返す' do
768 put :update, :id => @scroll.id, :scroll => @attr
769 response.status.should eq 200
772 put :update, :id => @scroll.id, :scroll => @attr
773 response.should render_template("edit")
777 it 'ステータスコード422 unprocessable_entity を返す' do
778 Scroll.any_instance.stub(:save).and_return(false)
779 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
780 response.status.should eq 422
782 it '応答メッセージUnprocessable Entityを返す' do
783 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
784 response.message.should match(/Unprocessable/)
792 @scroll = FactoryGirl.create :scroll, :author => @author
795 context '事前チェックしておく' do
797 Scroll.stub(:edit).with(any_args()).and_return @scroll
798 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
800 it 'スクロールモデルに編集取得を問い合わせている' do
801 Scroll.should_receive(:edit).exactly(1)
802 delete :destroy, :id => @scroll.id
805 Scroll.any_instance.should_receive(:destroy_with_scroll_panel).exactly(1)
806 delete :destroy, :id => @scroll.id
808 it '@scrollにアレを取得している' do
809 delete :destroy, :id => @scroll.id
810 assigns(:scroll).id.should eq(@scroll.id)
813 context 'つつがなく終わるとき' do
816 delete :destroy, :id => @scroll.id
817 }.should change Scroll, :count
821 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
823 it 'ステータスコード302 Foundを返す' do
824 delete :destroy, :id => @scroll.id
825 response.status.should eq 302
827 it 'マイスクロールの一覧ページへ遷移する' do
828 delete :destroy, :id => @scroll.id
829 response.should redirect_to('/home/scrolls')
834 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
836 it 'ステータスコード200 OKを返す' do
837 delete :destroy, :id => @scroll.id, :format => :json
838 response.should be_success
841 delete :destroy, :id => @scroll.id, :format => :json
842 response.body.should match /./
846 context 'ユーザ権限がないとき' do
851 it 'ステータスコード302 Foundを返す' do
852 delete :destroy, :id => @scroll.id
853 response.status.should eq 302
855 it 'サインインページへ遷移する' do
856 delete :destroy, :id => @scroll.id
857 response.body.should redirect_to '/users/sign_in'
861 it '応答メッセージにUnauthorizedを返す' do
862 delete :destroy, :id => @scroll.id, :format => :json
863 response.message.should match(/Unauthorized/)
867 context 'ユーザ権限はないが管理者権限があるとき' do
873 it 'ステータスコード302 Foundを返す' do
874 delete :destroy, :id => @scroll.id
875 response.status.should eq 302
877 it 'サインインページへ遷移する' do
878 delete :destroy, :id => @scroll.id
879 response.body.should redirect_to '/users/sign_in'
883 context 'ユーザだが作家登録していないとき' do
888 it 'ステータスコード302 Foundを返す' do
889 delete :destroy, :id => @scroll.id
890 response.status.should eq 302
893 delete :destroy, :id => @scroll.id
894 response.body.should redirect_to new_author_path
898 context '削除に失敗したとき' do
900 Scroll.any_instance.stub(:destroy_with_scroll_panel).and_return(false)
903 it 'ステータスコード302 Foundを返す' do
904 delete :destroy, :id => @scroll.id
905 response.status.should eq 302
907 it 'そのスクロールの詳細ページへ遷移する' do
908 delete :destroy, :id => @scroll.id
909 response.should redirect_to(scroll_path(@scroll))
913 it 'ステータスコード422 unprocessable_entity を返す' do
914 delete :destroy, :id => @scroll.id, :format => :json
915 response.status.should eq 422
917 it '応答メッセージUnprocessable Entityを返す' do
918 delete :destroy, :id => @scroll.id, :format => :json
919 response.message.should match(/Unprocessable/)
926 describe '一覧表示に於いて' do
928 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
929 Scroll.stub(:list).and_return([@scroll, @scroll, @scroll])
932 context 'つつがなく終わるとき' do
933 it 'ステータスコード200 OKを返す' do
935 response.should be_success
938 it 'indexテンプレートを描画する' do
940 response.should render_template("index")
945 get :index, :format => :json
946 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
950 context 'ユーザ権限がないとき' do
954 it 'ステータスコード200 OKを返す' do
956 response.should be_success
959 it 'indexテンプレートを描画する' do
961 response.should render_template("index")
966 get :index, :format => :json
967 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
973 describe '単体表示に於いて' do
975 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id, :title => 'normal'
976 Scroll.stub(:show).and_return(@scroll)
979 context 'つつがなく終わるとき' do
980 it 'ステータスコード200 OKを返す' do
981 get :show, :id => @scroll.id
982 response.should be_success
985 it 'showテンプレートを描画する' do
986 get :show, :id => @scroll.id
987 response.should render_template("show")
992 get :show, :id => @scroll.id, :format => :json
993 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
997 context 'ユーザ権限がないとき' do
1001 it 'ステータスコード200 OKを返す' do
1002 get :show, :id => @scroll.id
1003 response.should be_success
1006 it 'showテンプレートを描画する' do
1007 get :show, :id => @scroll.id
1008 response.should render_template("show")
1013 get :show, :id => @scroll.id, :format => :json
1014 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1019 describe 'スクロール数取得に於いて' do
1021 Scroll.should_receive(:visible_count).and_return(3)
1024 context 'つつがなく終わるとき' do
1025 it 'ステータスコード200 OKを返す' do
1026 get :count, :format => :json
1027 response.should be_success
1031 get :count, :format => :json
1032 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1038 describe '新規作成フォーム表示に於いて' do
1042 context 'つつがなく終わるとき' do
1043 it 'ステータスコード200 OKを返す' do
1045 response.should be_success
1048 it 'newテンプレートを描画する' do
1050 response.should render_template("new")
1054 it 'new.jsテンプレートを描画する' do
1055 get :new, :format => :js
1056 response.should render_template("new")
1061 get :new, :format => :json
1062 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1066 context 'ユーザ権限がないとき' do
1071 it 'ステータスコード302 Foundを返す' do
1073 response.status.should eq 302
1075 it 'サインインページへ遷移する' do
1077 response.body.should redirect_to '/users/sign_in'
1081 it 'ステータスコード401 Unauthorizedを返す' do
1082 get :new, :format => :js
1083 response.status.should eq 401
1085 it '応答メッセージにUnauthorizedを返す' do
1086 get :new, :format => :js
1087 response.message.should match(/Unauthorized/)
1091 it 'ステータスコード401 Unauthorizedを返す' do
1092 get :new, :format => :json
1093 response.status.should eq 401
1095 it '応答メッセージにUnauthorizedを返す' do
1096 get :new, :format => :json
1097 response.message.should match(/Unauthorized/)
1103 describe '新規作成に於いて' do
1106 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
1108 context 'つつがなく終わるとき' do
1110 it 'ステータスコード302 Foundを返す' do
1111 Scroll.any_instance.stub(:save).and_return(true)
1112 post :create, :scroll => @attr
1113 response.status.should eq 302
1115 it '作成されたスクロールの表示ページへ遷移する' do
1116 # Scroll.any_instance.stub(:save).and_return(true)
1117 post :create, :scroll => @attr
1118 response.should redirect_to(Scroll.last)
1122 it 'ステータスコード200 OKを返す' do
1123 # Scroll.any_instance.stub(:save).and_return(true)
1124 post :create, :scroll => @attr, :format => :json
1125 response.should be_success
1127 it '作成されたスクロールをjsonデータで返す' do
1128 post :create, :scroll => @attr, :format => :json
1129 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1133 context 'ユーザ権限がないとき' do
1138 it 'ステータスコード302 Foundを返す' do
1139 post :create, :scroll => @attr
1140 response.status.should eq 302
1142 it 'サインインページへ遷移する' do
1143 post :create, :scroll => @attr
1144 response.body.should redirect_to '/users/sign_in'
1148 it 'ステータスコード401 Unauthorizedを返す' do
1149 post :create, :scroll => @attr, :format => :json
1150 response.status.should eq 401
1152 it '応答メッセージにUnauthorizedを返す' do
1153 post :create, :scroll => @attr, :format => :json
1154 response.message.should match(/Unauthorized/)
1160 describe '編集フォーム表示に於いて' do
1162 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
1164 Scroll.stub(:edit).and_return(@scroll)
1166 context 'つつがなく終わるとき' do
1167 it 'ステータスコード200 OKを返す' do
1168 get :edit, :id => @scroll.id
1169 response.should be_success
1172 it 'editテンプレートを描画する' do
1173 get :edit, :id => @scroll.id
1174 response.should render_template("edit")
1178 it 'edit.jsテンプレートを描画する' do
1179 get :edit, :id => @scroll.id, :format => :js
1180 response.should render_template("edit")
1184 context 'ユーザ権限がないとき' do
1189 it 'ステータスコード302 Foundを返す' do
1190 get :edit, :id => @scroll.id
1191 response.status.should eq 302
1193 it 'サインインページへ遷移する' do
1194 get :edit, :id => @scroll.id
1195 response.body.should redirect_to '/users/sign_in'
1199 it 'ステータスコード401 Unauthorizedを返す' do
1200 get :edit, :id => @scroll.id, :format => :js
1201 response.status.should eq 401
1203 it '応答メッセージにUnauthorizedを返す' do
1204 get :edit, :id => @scroll.id, :format => :js
1205 response.message.should match(/Unauthorized/)
1211 describe '更新に於いて' do
1213 @scroll = FactoryGirl.create :scroll, :author => @author
1214 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
1217 context 'つつがなく終わるとき' do
1219 it 'ステータスコード302 Foundを返す' do
1220 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1221 put :update, :id => @scroll.id, :scroll => @attr
1222 response.status.should eq 302
1224 it '更新されたスクロールの表示ページへ遷移する' do
1225 put :update, :id => @scroll.id, :scroll => @attr
1226 response.should redirect_to(@scroll)
1230 it 'ステータスコード200 OKを返す' do
1231 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1232 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
1233 response.should be_success
1235 it 'ページ本体は特に返さない' do
1236 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1237 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
1238 response.body.should match /./
1242 context 'ユーザ権限がないとき' do
1246 it 'ステータスコード302 Foundを返す' do
1247 put :update, :id => @scroll.id, :scroll => @attr
1248 response.status.should eq 302
1251 it 'サインインページへ遷移する' do
1252 put :update, :id => @scroll.id, :scroll => @attr
1253 response.body.should redirect_to '/users/sign_in'
1259 describe '削除に於いて' do
1261 @scroll = FactoryGirl.create :scroll, :author => @author
1264 context 'つつがなく終わるとき' do
1267 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
1269 it 'ステータスコード302 Foundを返す' do
1270 delete :destroy, :id => @scroll.id
1271 response.status.should eq 302
1273 it 'マイスクロールの一覧ページへ遷移する' do
1274 delete :destroy, :id => @scroll.id
1275 response.should redirect_to('/home/scroll')
1280 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
1282 it 'ステータスコード200 OKを返す' do
1283 delete :destroy, :id => @scroll.id, :format => :json
1284 response.should be_success
1286 it 'ページ本体は特に返さない' do
1287 delete :destroy, :id => @scroll.id, :format => :json
1288 response.body.should match /./
1292 context 'ユーザ権限がないとき' do
1296 it 'ステータスコード302 Foundを返す' do
1297 delete :destroy, :id => @scroll.id
1298 response.status.should eq 302
1301 it 'サインインページへ遷移する' do
1302 delete :destroy, :id => @scroll.id
1303 response.body.should redirect_to '/users/sign_in'
1307 it '応答メッセージにUnauthorizedを返す' do
1308 delete :destroy, :id => @scroll.id, :format => :json
1309 response.message.should match(/Unauthorized/)