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 Manifest.manifest.magic_numbers['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])
21 context 'つつがなく終わるとき' do
22 it 'ステータスコード200 OKを返す' do
24 response.should be_success
26 it '@scrollsにリストを取得している' do
28 assigns(:scrolls).should have_at_least(3).items
31 it 'indexテンプレートを描画する' do
33 response.should render_template("index")
38 get :index, :format => :json
39 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
43 context 'ユーザ権限がないとき' do
48 it 'ステータスコード302 Foundを返す' do
50 response.status.should eq 302
54 response.should redirect_to '/users/sign_in'
58 it 'ステータスコード401 Unauthorizedを返す' do
59 get :index, :format => :json
60 response.status.should eq 401
62 it '応答メッセージにUnauthorizedを返す' do
63 get :index, :format => :json
64 response.message.should match(/Unauthorized/)
68 context 'ユーザ権限はないが管理者権限があるとき' do
73 it 'ステータスコード200 OKを返す' do
75 response.should be_success
78 context 'ユーザだが作家登録していないとき' do
83 it 'ステータスコード200 OKを返す' do
85 response.should be_success
91 describe '単体表示に於いて' do
93 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id, :title => 'normal'
94 Scroll.stub(:show).and_return(@scroll)
97 context 'つつがなく終わるとき' do
98 it 'ステータスコード200 OKを返す' do
99 get :show, :id => @scroll.id
100 response.should be_success
102 it 'スクロールモデルに単体取得を問い合わせている' do
103 Scroll.should_receive(:show).exactly(1)
106 it '@scrollにアレを取得している' do
107 get :show, :id => @scroll.id
108 assigns(:scroll).id.should eq(@scroll.id)
111 it 'showテンプレートを描画する' do
112 get :show, :id => @scroll.id
113 response.should render_template("show")
118 get :show, :id => @scroll.id, :format => :json
119 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
121 it 'スクロールモデルにjson単体出力オプションを問い合わせている' do
122 Scroll.should_receive(:show_json_opt).exactly(1)
123 get :show, :id => @scroll.id, :format => :json
126 get :show, :id => @scroll.id, :format => :json
127 json = JSON.parse response.body
128 json["title"].should match(/normal/)
129 json["visible"].should_not be_nil
133 context 'ユーザ権限がないとき' do
138 it 'ステータスコード302 Foundを返す' do
139 get :show, :id => @scroll.id
140 response.status.should eq 302
142 it 'サインインページへ遷移する' do
143 get :show, :id => @scroll.id
144 response.body.should redirect_to '/users/sign_in'
148 it 'ステータスコード401 Unauthorizedを返す' do
149 get :show, :id => @scroll.id, :format => :json
150 response.status.should eq 401
152 it '応答メッセージにUnauthorizedを返す' do
153 get :show, :id => @scroll.id, :format => :json
154 response.message.should match(/Unauthorized/)
158 context 'ユーザ権限はないが管理者権限があるとき' do
163 it 'ステータスコード200 OKを返す' do
164 get :show, :id => @scroll.id
165 response.should be_success
168 context 'ユーザだが作家登録していないとき' do
173 it 'ステータスコード200 OKを返す' do
174 get :show, :id => @scroll.id
175 response.should be_success
180 context '対象スクロールがないとき' do
182 it '例外404 not_foundを返す' do
185 }.should raise_error(ActiveRecord::RecordNotFound)
189 it '例外404 not_foundを返す' do
191 get :show, :id => 0, :format => :json
192 }.should raise_error(ActiveRecord::RecordNotFound)
196 context '非公開スクロールを見ようとしたとき' do
198 it '例外403 forbiddenを返す' do
199 Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
200 hidden = FactoryGirl.create :hidden_scroll, :author_id => @author.id
202 get :show, :id => hidden
203 }.should raise_error(ActiveRecord::Forbidden)
207 it '例外403 forbiddenを返す' do
208 Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
209 hidden = FactoryGirl.create :hidden_scroll, :author_id => @author.id
211 get :show, :id => hidden, :format => :json
212 }.should raise_error(ActiveRecord::Forbidden)
221 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
222 @panel = FactoryGirl.create :panel, :author_id => @author.id
223 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
224 Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
225 Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
226 ScrollPanel.stub(:count).and_return(10)
227 ScrollPanel.stub(:play_list).with(any_args).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
230 context 'パラメータチェックする' do
231 it '与えられたoffsetがセットされている' do
232 get :play, :id => @scroll.id, :offset => 5
233 assigns(:offset).should eq 5
235 it '省略されると@offsetに0値が入る' do
236 get :play, :id => @scroll.id
237 assigns(:offset).should eq 0
239 it '与えられたcountがセットされている' do
240 get :play, :id => @scroll.id, :count => 4
241 assigns(:panel_count).should eq 4
243 it '省略されると@panel_countにデフォルト値が入る' do
244 get :play, :id => @scroll.id
245 assigns(:panel_count).should eq ScrollPanel.default_panel_size
247 it '最大を超えると@panel_countにデフォルト最大値が入る' do
248 get :play, :id => @scroll.id, :count => 1500
249 assigns(:panel_count).should eq ScrollPanel.max_panel_size
251 it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
252 get :play, :id => @scroll.id, :count => -1
253 assigns(:panel_count).should eq ScrollPanel.default_panel_size
256 context '事前チェックする' do
257 it 'スクロールモデルに単体取得を問い合わせている' do
258 Scroll.should_receive(:show).with(@scroll.id.to_s, [@user, nil]).exactly(1)
259 get :play, :id => @scroll.id
261 it 'スクコマモデルにプレイリスト取得を問い合わせている' do
262 ScrollPanel.should_receive(:play_list).with(@scroll, @author, 0, 30).exactly(1)
263 get :play, :id => @scroll.id
266 context 'つつがなく終わるとき' do
267 it '@scroll_panelsにリストを取得している' do
268 get :play, :id => @scroll.id
269 assigns(:scroll_panels).should have_at_least(3).items
272 it 'ステータスコード200 OKを返す' do
273 get :play, :id => @scroll.id
274 response.should be_success
276 it 'scrollテンプレートを描画する' do
277 get :play, :id => @scroll.id
278 response.should render_template("scroll")
282 it 'ステータスコード200 OKを返す' do
283 get :play, :id => @scroll.id, :format => :json
284 response.should be_success
287 get :play, :id => @scroll.id, :format => :json
288 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
290 it 'スクコマモデルにスクコマリストのjson出力を問い合わせている' do
291 ScrollPanel.should_receive(:list_as_json_text).exactly(1)
292 get :play, :id => @scroll.id, :format => :json
294 it 'データがリスト構造になっている' do
295 get :play, :id => @scroll.id, :format => :json
296 json = JSON.parse response.body
297 json.should have_at_least(3).items
299 it 'リストの先頭くらいはスクコマっぽいものであって欲しい' do
300 get :play, :id => @scroll.id, :format => :json
301 json = JSON.parse response.body
302 json.first.has_key?("panel_id").should be_true
303 json.first.has_key?("scroll_id").should be_true
304 json.first.has_key?("author_id").should be_true
308 context 'ユーザ権限がないとき' do
313 it 'ステータスコード302 Foundを返す' do
314 get :play, :id => @scroll.id
315 response.status.should eq 302
317 it 'サインインページへ遷移する' do
318 get :play, :id => @scroll.id
319 response.should redirect_to '/users/sign_in'
323 it 'ステータスコード401 Unauthorizedを返す' do
324 get :play, :id => @scroll.id, :format => :json
325 response.status.should eq 401
327 it '応答メッセージにUnauthorizedを返す' do
328 get :play, :id => @scroll.id, :format => :json
329 response.message.should match(/Unauthorized/)
333 context 'ユーザ権限はないが管理者権限があるとき' do
338 it 'ステータスコード200 OKを返す' do
339 get :play, :id => @scroll.id
340 response.should be_success
343 context 'ユーザだが作家登録していないとき' do
347 it 'ステータスコード200 OKを返す' do
348 get :play, :id => @scroll.id
349 response.should be_success
354 describe 'スクロール数取得に於いて' do
356 Scroll.should_receive(:visible_count).and_return(3)
359 context 'つつがなく終わるとき' do
360 it 'ステータスコード200 OKを返す' do
361 get :count, :format => :json
362 response.should be_success
366 get :count, :format => :json
367 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
369 it 'データがHash構造になっていてスクロール数が1である' do
370 get :count, :format => :json
371 json = JSON.parse response.body
372 json["count"].should == 3
378 describe '新規作成フォーム表示に於いて' do
382 context 'つつがなく終わるとき' do
383 it 'ステータスコード200 OKを返す' do
385 response.should be_success
387 it '@scrollに新規データを用意している' do
389 assigns(:scroll).should be_a_new(Scroll)
391 it 'スクロールモデルにデフォルト値補充を依頼している' do
392 Scroll.any_instance.should_receive(:supply_default).exactly(1)
396 it 'newテンプレートを描画する' do
398 response.should render_template("new")
402 it 'new.jsテンプレートを描画する' do
403 get :new, :format => :js
404 response.should render_template("new")
409 get :new, :format => :json
410 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
412 it 'スクロールモデルにjson単体出力オプションを問い合わせている' do
413 Scroll.should_receive(:show_json_opt).exactly(1)
414 get :new, :format => :json
418 context 'ユーザ権限がないとき' do
423 it 'ステータスコード302 Foundを返す' do
425 response.status.should eq 302
427 it 'サインインページへ遷移する' do
429 response.body.should redirect_to '/users/sign_in'
433 it 'ステータスコード401 Unauthorizedを返す' do
434 get :new, :format => :js
435 response.status.should eq 401
437 it '応答メッセージにUnauthorizedを返す' do
438 get :new, :format => :js
439 response.message.should match(/Unauthorized/)
443 it 'ステータスコード401 Unauthorizedを返す' do
444 get :new, :format => :json
445 response.status.should eq 401
447 it '応答メッセージにUnauthorizedを返す' do
448 get :new, :format => :json
449 response.message.should match(/Unauthorized/)
453 context 'ユーザ権限はないが管理者権限があるとき' do
459 it 'ステータスコード302 Foundを返す' do
461 response.status.should eq 302
463 it 'サインインページへ遷移する' do
465 response.body.should redirect_to '/users/sign_in'
469 context 'ユーザだが作家登録していないとき' do
474 it 'ステータスコード302 Foundを返す' do
476 response.status.should eq 302
480 response.body.should redirect_to new_author_path
486 describe '新規作成に於いて' do
489 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
491 context '事前チェックしておく' do
492 it 'スクロールモデルにデフォルト値補充を依頼している' do
493 Scroll.any_instance.should_receive(:supply_default).exactly(1)
494 post :create, :scroll => @attr
496 it 'スクロールモデルにカラム値復元を依頼している' do
497 Scroll.any_instance.should_receive(:attributes=).exactly(1)
498 post :create, :scroll => @attr
500 it 'スクロールモデルに上書き補充を依頼している' do
501 Scroll.any_instance.should_receive(:overwrite).exactly(1)
502 post :create, :scroll => @attr
505 Scroll.any_instance.should_receive(:save).exactly(1)
506 post :create, :scroll => @attr
509 context 'つつがなく終わるとき' do
510 it "@scrollに作成されたスクロールを保持していて、それがDBにある" do
511 post :create, :scroll => @attr
512 assigns(:scroll).should be_a(Scroll)
513 assigns(:scroll).should be_persisted
516 it 'ステータスコード302 Foundを返す' do
517 Scroll.any_instance.stub(:save).and_return(true)
518 post :create, :scroll => @attr
519 response.status.should eq 302
521 it '作成されたスクロールの表示ページへ遷移する' do
522 # Scroll.any_instance.stub(:save).and_return(true)
523 post :create, :scroll => @attr
524 response.should redirect_to(Scroll.last)
528 it 'ステータスコード200 OKを返す' do
529 # Scroll.any_instance.stub(:save).and_return(true)
530 post :create, :scroll => @attr, :format => :json
531 response.should be_success
533 it '作成されたスクロールをjsonデータで返す' do
534 post :create, :scroll => @attr, :format => :json
535 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
538 post :create, :scroll => @attr, :format => :json
539 json = JSON.parse response.body
540 json["title"].should match(/normal/)
541 json["visible"].should_not be_nil
545 context 'ユーザ権限がないとき' do
550 it 'ステータスコード302 Foundを返す' do
551 post :create, :scroll => @attr
552 response.status.should eq 302
554 it 'サインインページへ遷移する' do
555 post :create, :scroll => @attr
556 response.body.should redirect_to '/users/sign_in'
560 it 'ステータスコード401 Unauthorizedを返す' do
561 post :create, :scroll => @attr, :format => :json
562 response.status.should eq 401
564 it '応答メッセージにUnauthorizedを返す' do
565 post :create, :scroll => @attr, :format => :json
566 response.message.should match(/Unauthorized/)
570 context 'ユーザ権限はないが管理者権限があるとき' do
576 it 'ステータスコード302 Foundを返す' do
577 post :create, :scroll => @attr
578 response.status.should eq 302
580 it 'サインインページへ遷移する' do
581 post :create, :scroll => @attr
582 response.body.should redirect_to '/users/sign_in'
586 context 'ユーザだが作家登録していないとき' do
591 it 'ステータスコード302 Foundを返す' do
592 post :create, :scroll => @attr
593 response.status.should eq 302
596 post :create, :scroll => @attr
597 response.body.should redirect_to new_author_path
601 context '検証、保存に失敗した' do
603 Scroll.any_instance.stub(:save).and_return(false)
605 it "未保存のスクロールを保持している" do
606 post :create, :scroll => @attr
607 assigns(:scroll).should be_a_new(Scroll)
610 it 'ステータスコード200 OKを返す' do
611 post :create, :scroll => @attr
612 response.status.should eq 200
615 post :create, :scroll => @attr
616 response.should render_template("new")
620 it 'ステータスコード422 unprocessable_entity を返す' do
621 post :create, :scroll => @attr, :format => :json
622 response.status.should eq 422
624 it '応答メッセージUnprocessable Entityを返す' do
625 post :create, :scroll => @attr, :format => :json
626 response.message.should match(/Unprocessable/)
632 describe '編集フォーム表示に於いて' do
634 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
636 Scroll.stub(:edit).and_return(@scroll)
638 context 'つつがなく終わるとき' do
639 it 'ステータスコード200 OKを返す' do
640 get :edit, :id => @scroll.id
641 response.should be_success
643 it 'スクロールモデルに編集取得を問い合わせている' do
644 Scroll.should_receive(:edit).exactly(1)
645 get :edit, :id => @scroll.id
647 it '@scrollにデータを用意している' do
648 get :edit, :id => @scroll.id
649 assigns(:scroll).should eq @scroll
652 it 'editテンプレートを描画する' do
653 get :edit, :id => @scroll.id
654 response.should render_template("edit")
658 it 'edit.jsテンプレートを描画する' do
659 get :edit, :id => @scroll.id, :format => :js
660 response.should render_template("edit")
664 context 'ユーザ権限がないとき' do
669 it 'ステータスコード302 Foundを返す' do
670 get :edit, :id => @scroll.id
671 response.status.should eq 302
673 it 'サインインページへ遷移する' do
674 get :edit, :id => @scroll.id
675 response.body.should redirect_to '/users/sign_in'
679 it 'ステータスコード401 Unauthorizedを返す' do
680 get :edit, :id => @scroll.id, :format => :js
681 response.status.should eq 401
683 it '応答メッセージにUnauthorizedを返す' do
684 get :edit, :id => @scroll.id, :format => :js
685 response.message.should match(/Unauthorized/)
689 context 'ユーザ権限はないが管理者権限があるとき' do
695 it 'ステータスコード302 Foundを返す' do
696 get :edit, :id => @scroll.id
697 response.status.should eq 302
699 it 'サインインページへ遷移する' do
700 get :edit, :id => @scroll.id
701 response.body.should redirect_to '/users/sign_in'
705 context 'ユーザだが作家登録していないとき' do
710 it 'ステータスコード302 Foundを返す' do
711 get :edit, :id => @scroll.id
712 response.status.should eq 302
715 get :edit, :id => @scroll.id
716 response.body.should redirect_to new_author_path
724 @scroll = FactoryGirl.create :scroll, :author => @author
725 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
728 context '事前チェックしておく' do
729 it 'スクロールモデルに編集取得を問い合わせている' do
730 Scroll.stub(:edit).with(any_args()).and_return @scroll
731 Scroll.should_receive(:edit).exactly(1)
732 put :update, :id => @scroll.id, :scroll => @attr
734 it 'スクロールモデルにカラム値復元を依頼している' do
735 Scroll.any_instance.should_receive(:attributes=).exactly(1)
736 put :update, :id => @scroll.id, :scroll => @attr
738 it 'スクロールモデルに上書き補充を依頼している' do
739 Scroll.any_instance.should_receive(:overwrite).exactly(1)
740 put :update, :id => @scroll.id, :scroll => @attr
743 Scroll.any_instance.stub(:save).with(any_args).and_return true
744 Scroll.any_instance.should_receive(:save).exactly(1)
745 put :update, :id => @scroll.id, :scroll => @attr
747 it '@scrollにアレを取得している' do
748 put :update, :id => @scroll.id, :scroll => @attr
749 assigns(:scroll).id.should eq(@scroll.id)
752 context 'つつがなく終わるとき' do
754 put :update, :id => @scroll.id, :scroll => @attr
755 Scroll.find(@scroll.id).visible.should eq 0
758 it 'ステータスコード302 Foundを返す' do
759 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
760 put :update, :id => @scroll.id, :scroll => @attr
761 response.status.should eq 302
763 it '更新されたスクロールの表示ページへ遷移する' do
764 put :update, :id => @scroll.id, :scroll => @attr
765 response.should redirect_to(@scroll)
769 it 'ステータスコード200 OKを返す' do
770 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
771 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
772 response.should be_success
775 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
776 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
777 response.body.should match /./
781 context 'ユーザ権限がないとき' do
786 it 'ステータスコード302 Foundを返す' do
787 put :update, :id => @scroll.id, :scroll => @attr
788 response.status.should eq 302
790 it 'サインインページへ遷移する' do
791 put :update, :id => @scroll.id, :scroll => @attr
792 response.body.should redirect_to '/users/sign_in'
796 it '応答メッセージにUnauthorizedを返す' do
797 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
798 response.message.should match(/Unauthorized/)
802 context 'ユーザ権限はないが管理者権限があるとき' do
808 it 'ステータスコード302 Foundを返す' do
809 put :update, :id => @scroll.id, :scroll => @attr
810 response.status.should eq 302
812 it 'サインインページへ遷移する' do
813 put :update, :id => @scroll.id, :scroll => @attr
814 response.body.should redirect_to '/users/sign_in'
818 context 'ユーザだが作家登録していないとき' do
823 it 'ステータスコード302 Foundを返す' do
824 put :update, :id => @scroll.id, :scroll => @attr
825 response.status.should eq 302
828 put :update, :id => @scroll.id, :scroll => @attr
829 response.body.should redirect_to new_author_path
833 context '検証、保存に失敗したとき' do
835 Scroll.any_instance.stub(:save).and_return(false)
838 it 'ステータスコード200 Okを返す' do
839 put :update, :id => @scroll.id, :scroll => @attr
840 response.status.should eq 200
843 put :update, :id => @scroll.id, :scroll => @attr
844 response.should render_template("edit")
848 it 'ステータスコード422 unprocessable_entity を返す' do
849 Scroll.any_instance.stub(:save).and_return(false)
850 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
851 response.status.should eq 422
853 it '応答メッセージUnprocessable Entityを返す' do
854 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
855 response.message.should match(/Unprocessable/)
863 @scroll = FactoryGirl.create :scroll, :author => @author
866 context '事前チェックしておく' do
868 Scroll.stub(:edit).with(any_args()).and_return @scroll
869 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
871 it 'スクロールモデルに編集取得を問い合わせている' do
872 Scroll.should_receive(:edit).exactly(1)
873 delete :destroy, :id => @scroll.id
876 Scroll.any_instance.should_receive(:destroy_with_scroll_panel).exactly(1)
877 delete :destroy, :id => @scroll.id
879 it '@scrollにアレを取得している' do
880 delete :destroy, :id => @scroll.id
881 assigns(:scroll).id.should eq(@scroll.id)
884 context 'つつがなく終わるとき' do
887 delete :destroy, :id => @scroll.id
888 }.should change Scroll, :count
892 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
894 it 'ステータスコード302 Foundを返す' do
895 delete :destroy, :id => @scroll.id
896 response.status.should eq 302
898 it 'マイスクロールの一覧ページへ遷移する' do
899 delete :destroy, :id => @scroll.id
900 response.should redirect_to('/home/scrolls')
905 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
907 it 'ステータスコード200 OKを返す' do
908 delete :destroy, :id => @scroll.id, :format => :json
909 response.should be_success
912 delete :destroy, :id => @scroll.id, :format => :json
913 response.body.should match /./
917 context 'ユーザ権限がないとき' do
922 it 'ステータスコード302 Foundを返す' do
923 delete :destroy, :id => @scroll.id
924 response.status.should eq 302
926 it 'サインインページへ遷移する' do
927 delete :destroy, :id => @scroll.id
928 response.body.should redirect_to '/users/sign_in'
932 it '応答メッセージにUnauthorizedを返す' do
933 delete :destroy, :id => @scroll.id, :format => :json
934 response.message.should match(/Unauthorized/)
938 context 'ユーザ権限はないが管理者権限があるとき' do
944 it 'ステータスコード302 Foundを返す' do
945 delete :destroy, :id => @scroll.id
946 response.status.should eq 302
948 it 'サインインページへ遷移する' do
949 delete :destroy, :id => @scroll.id
950 response.body.should redirect_to '/users/sign_in'
954 context 'ユーザだが作家登録していないとき' do
959 it 'ステータスコード302 Foundを返す' do
960 delete :destroy, :id => @scroll.id
961 response.status.should eq 302
964 delete :destroy, :id => @scroll.id
965 response.body.should redirect_to new_author_path
969 context '削除に失敗したとき' do
971 Scroll.any_instance.stub(:destroy_with_scroll_panel).and_return(false)
974 it 'ステータスコード302 Foundを返す' do
975 delete :destroy, :id => @scroll.id
976 response.status.should eq 302
978 it 'そのスクロールの詳細ページへ遷移する' do
979 delete :destroy, :id => @scroll.id
980 response.should redirect_to(scroll_path(@scroll))
984 it 'ステータスコード422 unprocessable_entity を返す' do
985 delete :destroy, :id => @scroll.id, :format => :json
986 response.status.should eq 422
988 it '応答メッセージUnprocessable Entityを返す' do
989 delete :destroy, :id => @scroll.id, :format => :json
990 response.message.should match(/Unprocessable/)
997 describe '一覧表示に於いて' do
999 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
1000 Scroll.stub(:list).and_return([@scroll, @scroll, @scroll])
1003 context 'つつがなく終わるとき' do
1004 it 'ステータスコード200 OKを返す' do
1006 response.should be_success
1009 it 'indexテンプレートを描画する' do
1011 response.should render_template("index")
1016 get :index, :format => :json
1017 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1021 context 'ユーザ権限がないとき' do
1025 it 'ステータスコード200 OKを返す' do
1027 response.should be_success
1030 it 'indexテンプレートを描画する' do
1032 response.should render_template("index")
1037 get :index, :format => :json
1038 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1044 describe '単体表示に於いて' do
1046 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id, :title => 'normal'
1047 Scroll.stub(:show).and_return(@scroll)
1050 context 'つつがなく終わるとき' do
1051 it 'ステータスコード200 OKを返す' do
1052 get :show, :id => @scroll.id
1053 response.should be_success
1056 it 'showテンプレートを描画する' do
1057 get :show, :id => @scroll.id
1058 response.should render_template("show")
1063 get :show, :id => @scroll.id, :format => :json
1064 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1068 context 'ユーザ権限がないとき' do
1072 it 'ステータスコード200 OKを返す' do
1073 get :show, :id => @scroll.id
1074 response.should be_success
1077 it 'showテンプレートを描画する' do
1078 get :show, :id => @scroll.id
1079 response.should render_template("show")
1084 get :show, :id => @scroll.id, :format => :json
1085 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1090 describe 'スクロール数取得に於いて' do
1092 Scroll.should_receive(:visible_count).and_return(3)
1095 context 'つつがなく終わるとき' do
1096 it 'ステータスコード200 OKを返す' do
1097 get :count, :format => :json
1098 response.should be_success
1102 get :count, :format => :json
1103 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1109 describe '新規作成フォーム表示に於いて' do
1113 context 'つつがなく終わるとき' do
1114 it 'ステータスコード200 OKを返す' do
1116 response.should be_success
1119 it 'newテンプレートを描画する' do
1121 response.should render_template("new")
1125 it 'new.jsテンプレートを描画する' do
1126 get :new, :format => :js
1127 response.should render_template("new")
1132 get :new, :format => :json
1133 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1137 context 'ユーザ権限がないとき' do
1142 it 'ステータスコード302 Foundを返す' do
1144 response.status.should eq 302
1146 it 'サインインページへ遷移する' do
1148 response.body.should redirect_to '/users/sign_in'
1152 it 'ステータスコード401 Unauthorizedを返す' do
1153 get :new, :format => :js
1154 response.status.should eq 401
1156 it '応答メッセージにUnauthorizedを返す' do
1157 get :new, :format => :js
1158 response.message.should match(/Unauthorized/)
1162 it 'ステータスコード401 Unauthorizedを返す' do
1163 get :new, :format => :json
1164 response.status.should eq 401
1166 it '応答メッセージにUnauthorizedを返す' do
1167 get :new, :format => :json
1168 response.message.should match(/Unauthorized/)
1174 describe '新規作成に於いて' do
1177 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
1179 context 'つつがなく終わるとき' do
1181 it 'ステータスコード302 Foundを返す' do
1182 Scroll.any_instance.stub(:save).and_return(true)
1183 post :create, :scroll => @attr
1184 response.status.should eq 302
1186 it '作成されたスクロールの表示ページへ遷移する' do
1187 # Scroll.any_instance.stub(:save).and_return(true)
1188 post :create, :scroll => @attr
1189 response.should redirect_to(Scroll.last)
1193 it 'ステータスコード200 OKを返す' do
1194 # Scroll.any_instance.stub(:save).and_return(true)
1195 post :create, :scroll => @attr, :format => :json
1196 response.should be_success
1198 it '作成されたスクロールをjsonデータで返す' do
1199 post :create, :scroll => @attr, :format => :json
1200 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1204 context 'ユーザ権限がないとき' do
1209 it 'ステータスコード302 Foundを返す' do
1210 post :create, :scroll => @attr
1211 response.status.should eq 302
1213 it 'サインインページへ遷移する' do
1214 post :create, :scroll => @attr
1215 response.body.should redirect_to '/users/sign_in'
1219 it 'ステータスコード401 Unauthorizedを返す' do
1220 post :create, :scroll => @attr, :format => :json
1221 response.status.should eq 401
1223 it '応答メッセージにUnauthorizedを返す' do
1224 post :create, :scroll => @attr, :format => :json
1225 response.message.should match(/Unauthorized/)
1231 describe '編集フォーム表示に於いて' do
1233 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
1235 Scroll.stub(:edit).and_return(@scroll)
1237 context 'つつがなく終わるとき' do
1238 it 'ステータスコード200 OKを返す' do
1239 get :edit, :id => @scroll.id
1240 response.should be_success
1243 it 'editテンプレートを描画する' do
1244 get :edit, :id => @scroll.id
1245 response.should render_template("edit")
1249 it 'edit.jsテンプレートを描画する' do
1250 get :edit, :id => @scroll.id, :format => :js
1251 response.should render_template("edit")
1255 context 'ユーザ権限がないとき' do
1260 it 'ステータスコード302 Foundを返す' do
1261 get :edit, :id => @scroll.id
1262 response.status.should eq 302
1264 it 'サインインページへ遷移する' do
1265 get :edit, :id => @scroll.id
1266 response.body.should redirect_to '/users/sign_in'
1270 it 'ステータスコード401 Unauthorizedを返す' do
1271 get :edit, :id => @scroll.id, :format => :js
1272 response.status.should eq 401
1274 it '応答メッセージにUnauthorizedを返す' do
1275 get :edit, :id => @scroll.id, :format => :js
1276 response.message.should match(/Unauthorized/)
1282 describe '更新に於いて' do
1284 @scroll = FactoryGirl.create :scroll, :author => @author
1285 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
1288 context 'つつがなく終わるとき' do
1290 it 'ステータスコード302 Foundを返す' do
1291 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1292 put :update, :id => @scroll.id, :scroll => @attr
1293 response.status.should eq 302
1295 it '更新されたスクロールの表示ページへ遷移する' do
1296 put :update, :id => @scroll.id, :scroll => @attr
1297 response.should redirect_to(@scroll)
1301 it 'ステータスコード200 OKを返す' do
1302 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1303 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
1304 response.should be_success
1306 it 'ページ本体は特に返さない' do
1307 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1308 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
1309 response.body.should match /./
1313 context 'ユーザ権限がないとき' do
1317 it 'ステータスコード302 Foundを返す' do
1318 put :update, :id => @scroll.id, :scroll => @attr
1319 response.status.should eq 302
1322 it 'サインインページへ遷移する' do
1323 put :update, :id => @scroll.id, :scroll => @attr
1324 response.body.should redirect_to '/users/sign_in'
1330 describe '削除に於いて' do
1332 @scroll = FactoryGirl.create :scroll, :author => @author
1335 context 'つつがなく終わるとき' do
1338 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
1340 it 'ステータスコード302 Foundを返す' do
1341 delete :destroy, :id => @scroll.id
1342 response.status.should eq 302
1344 it 'マイスクロールの一覧ページへ遷移する' do
1345 delete :destroy, :id => @scroll.id
1346 response.should redirect_to('/home/scroll')
1351 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
1353 it 'ステータスコード200 OKを返す' do
1354 delete :destroy, :id => @scroll.id, :format => :json
1355 response.should be_success
1357 it 'ページ本体は特に返さない' do
1358 delete :destroy, :id => @scroll.id, :format => :json
1359 response.body.should match /./
1363 context 'ユーザ権限がないとき' do
1367 it 'ステータスコード302 Foundを返す' do
1368 delete :destroy, :id => @scroll.id
1369 response.status.should eq 302
1372 it 'サインインページへ遷移する' do
1373 delete :destroy, :id => @scroll.id
1374 response.body.should redirect_to '/users/sign_in'
1378 it '応答メッセージにUnauthorizedを返す' do
1379 delete :destroy, :id => @scroll.id, :format => :json
1380 response.message.should match(/Unauthorized/)