1 # -*- encoding: utf-8 -*-
4 describe ScrollPanelsController 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
12 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
13 @panel = FactoryGirl.create :panel, :author_id => @author.id
16 if MagicNumber['run_mode'] == 1
17 describe '一覧表示に於いて' do
20 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
21 ScrollPanel.stub(:list).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
23 context 'パラメータpageについて' do
25 get :index, :page => 5
26 assigns(:page).should eq 5
28 it '省略されると@pageに1値が入る' do
30 assigns(:page).should eq 1
32 it '与えられたpage_sizeがセットされている' do
33 get :index, :page_size => 15
34 assigns(:page_size).should eq 15
36 it '省略されると@page_sizeにデフォルト値が入る' do
38 assigns(:page_size).should eq ScrollPanel.default_page_size
40 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
41 get :index, :page_size => 1500
42 assigns(:page_size).should eq ScrollPanel.max_page_size
44 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
45 get :index, :page_size => 0
46 assigns(:page_size).should eq ScrollPanel.default_page_size
49 context 'つつがなく終わるとき' do
50 it 'ステータスコード200 OKを返す' do
52 response.should be_success
54 it 'スクコマモデルに一覧を問い合わせている' do
55 ScrollPanel.should_receive(:list).exactly(1)
58 it '@scroll_panelsにリストを取得している' do
60 assigns(:scroll_panels).should have_at_least(3).items
63 it '@paginateにページ制御を取得している' do
65 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
67 it 'indexテンプレートを描画する' do
69 response.should render_template("index")
74 get :index, :format => :json
75 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
77 it 'スクコマモデルにjson一覧出力オプションを問い合わせている' do
78 ScrollPanel.should_receive(:list_json_opt).exactly(1)
79 get :index, :format => :json
81 it 'データがリスト構造になっている' do
82 get :index, :format => :json
83 json = JSON.parse response.body
84 json.should have_at_least(3).items
86 it 'リストの先頭くらいはスクコマっぽいものであって欲しい' do
87 get :index, :format => :json
88 json = JSON.parse response.body
89 json.first.has_key?("panel_id").should be_true
90 json.first.has_key?("scroll_id").should be_true
91 json.first.has_key?("t").should be_true
95 context 'ユーザ権限がないとき' do
100 it 'ステータスコード302 Foundを返す' do
102 response.status.should eq 302
104 it 'サインインページへ遷移する' do
106 response.should redirect_to '/users/sign_in'
110 it 'ステータスコード401 Unauthorizedを返す' do
111 get :index, :format => :json
112 response.status.should eq 401
114 it '応答メッセージにUnauthorizedを返す' do
115 get :index, :format => :json
116 response.message.should match(/Unauthorized/)
120 context 'ユーザ権限はないが管理者権限があるとき' do
125 it 'ステータスコード200 OKを返す' do
127 response.should be_success
130 context 'ユーザだが作家登録していないとき' do
134 it 'ステータスコード200 OKを返す' do
136 response.should be_success
141 describe '単体表示に於いて' do
144 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
145 Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
146 Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
147 ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [@user, nil]).and_return(@scroll_panel)
148 ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [nil, @admin]).and_return(@scroll_panel)
150 context 'つつがなく終わるとき' do
151 it 'スクコマモデルに単体取得を問い合わせている' do
152 ScrollPanel.should_receive(:show).with(@scroll_panel.id.to_s, [@user, nil]).exactly(1)
153 get :show, :id => @scroll_panel.id
155 it '@scroll_panelにアレを取得している' do
156 get :show, :id => @scroll_panel.id
157 assigns(:scroll_panel).should eq @scroll_panel
160 it 'ステータスコード200 OKを返す' do
161 get :show, :id => @scroll_panel.id
162 response.should be_success
164 it 'showテンプレートを描画する' do
165 get :show, :id => @scroll_panel.id
166 response.should render_template("show")
170 it 'ステータスコード200 OKを返す' do
171 get :show, :id => @scroll_panel.id, :format => :json
172 response.should be_success
175 get :show, :id => @scroll_panel.id, :format => :json
176 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
178 it 'スクコマモデルにスクコマjson出力を問い合わせている' do
179 ScrollPanel.any_instance.should_receive(:scroll_panel_as_json).exactly(1)
180 get :show, :id => @scroll_panel.id, :format => :json
183 get :show, :id => @scroll_panel.id, :format => :json
184 json = JSON.parse response.body
185 json.has_key?("panel_id").should be_true
186 json.has_key?("scroll_id").should be_true
187 json.has_key?("author_id").should be_true
191 context 'ユーザ権限がないとき' do
196 it 'ステータスコード302 Foundを返す' do
197 get :show, :id => @scroll_panel.id
198 response.status.should eq 302
200 it 'サインインページへ遷移する' do
201 get :show, :id => @scroll_panel.id
202 response.body.should redirect_to '/users/sign_in'
206 it 'ステータスコード401 Unauthorizedを返す' do
207 get :show, :id => @scroll_panel.id, :format => :json
208 response.status.should eq 401
210 it '応答メッセージにUnauthorizedを返す' do
211 get :show, :id => @scroll_panel.id, :format => :json
212 response.message.should match(/Unauthorized/)
216 context 'ユーザ権限はないが管理者権限があるとき' do
221 it 'ステータスコード200 OKを返す' do
222 get :show, :id => @scroll_panel.id
223 response.should be_success
226 context 'ユーザだが作家登録していないとき' do
230 it 'ステータスコード200 OKを返す' do
231 get :show, :id => @scroll_panel.id
232 response.should be_success
237 describe '新規作成フォーム表示に於いて' do
241 context 'つつがなく終わるとき' do
242 it '@scroll_panelに新規データを用意している' do
244 assigns(:scroll_panel).should be_a_new(ScrollPanel)
246 it 'モデルにデフォルト値補充を依頼している' do
247 ScrollPanel.any_instance.should_receive(:supply_default).exactly(1)
251 it 'ステータスコード200 OKを返す' do
253 response.should be_success
255 it 'newテンプレートを描画する' do
257 response.should render_template("new")
261 it 'ステータスコード200 OKを返す' do
262 get :new, :format => :js
263 response.should be_success
265 it 'new.jsテンプレートを描画する' do
266 get :new, :format => :js
267 response.should render_template("new")
271 it 'ステータスコード200 OKを返す' do
272 get :new, :format => :json
273 response.should be_success
276 get :new, :format => :json
277 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
279 it 'スクコマモデルのスクコマのjson出力を問い合わせている' do
280 ScrollPanel.any_instance.should_receive(:scroll_panel_as_json).exactly(1)
281 get :new, :format => :json
284 get :new, :format => :json
285 json = JSON.parse response.body
286 json.has_key?("panel_id").should be_true
287 json.has_key?("scroll_id").should be_true
288 json.has_key?("author_id").should be_true
292 context 'ユーザ権限がないとき' do
297 it 'ステータスコード302 Foundを返す' do
299 response.status.should eq 302
301 it 'サインインページへ遷移する' do
303 response.body.should redirect_to '/users/sign_in'
307 it 'ステータスコード401 Unauthorizedを返す' do
308 get :new, :format => :json
309 response.status.should eq 401
311 it '応答メッセージにUnauthorizedを返す' do
312 get :new, :format => :json
313 response.message.should match(/Unauthorized/)
317 context 'ユーザ権限はないが管理者権限があるとき' do
323 it 'ステータスコード302 Foundを返す' do
325 response.status.should eq 302
327 it 'サインインページへ遷移する' do
329 response.body.should redirect_to '/users/sign_in'
333 context 'ユーザだが作家登録していないとき' do
338 it 'ステータスコード302 Foundを返す' do
340 response.status.should eq 302
344 response.body.should redirect_to new_author_path
350 describe '新規作成に於いて' do
352 @attr = FactoryGirl.attributes_for(:scroll_panel, :t => nil, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id)
355 context 'つつがなく終わるとき' do
356 it 'デフォルト値補充を依頼する' do
357 ScrollPanel.any_instance.should_receive(:supply_default).exactly(1)
358 post :create, :scroll_panel => @attr
360 it 'POSTデータから、カラム値を復元している' do
361 ScrollPanel.any_instance.stub(:store).and_return(true)
362 post :create, :scroll_panel => @attr
363 assigns(:scroll_panel).scroll_id.should eq @scroll.id
364 assigns(:scroll_panel).panel_id.should eq @panel.id
367 ScrollPanel.any_instance.should_receive(:overwrite).exactly(1)
368 post :create, :scroll_panel => @attr
370 it 'スクロールモデルに編集取得を依頼している' do
371 Scroll.stub(:edit).and_return(@scroll)
372 Scroll.should_receive(:edit).with(@scroll.id, @author).exactly(1)
373 post :create, :scroll_panel => @attr
375 it 'コマモデルに単体取得を依頼している' do
376 Panel.should_receive(:show).with(@panel.id, @author).exactly(1)
377 post :create, :scroll_panel => @attr
380 ScrollPanel.any_instance.should_receive(:store).exactly(1)
381 post :create, :scroll_panel => @attr
383 it "@scroll_panelに作成されたコマを保持していて、それがDBにある" do
384 post :create, :scroll_panel => @attr
385 assigns(:scroll_panel).should be_a(ScrollPanel)
386 assigns(:scroll_panel).should be_persisted
389 it 'ステータスコード302 Foundを返す' do
390 ScrollPanel.any_instance.stub(:store).and_return(true)
391 post :create, :scroll_panel => @attr
392 response.status.should eq 302
394 it 'スクロールのスクコマ表示へ遷移する' do
395 # ScrollPanel.any_instance.stub(:store).and_return(true)
396 post :create, :scroll_panel => @attr
397 response.should redirect_to(play_scroll_path(@attr[:scroll_id]))
401 it 'ステータスコード200 OKを返す' do
402 # ScrollPanel.any_instance.stub(:store).and_return(true)
403 post :create, :scroll_panel => @attr, :format => :json
404 response.should be_success
406 it '作成されたコマをjsonデータで返す' do
407 post :create, :scroll_panel => @attr, :format => :json
408 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
410 it 'スクコマモデルのスクコマのjson出力を問い合わせている' do
411 ScrollPanel.any_instance.should_receive(:scroll_panel_as_json).exactly(1)
412 post :create, :scroll_panel => @attr, :format => :json
415 post :create, :scroll_panel => @attr, :format => :json
416 json = JSON.parse response.body
417 json["t"].should eq 0
421 context 'ユーザ権限がないとき' do
426 it 'ステータスコード302 Foundを返す' do
427 post :create, :scroll_panel => @attr
428 response.status.should eq 302
430 it 'サインインページへ遷移する' do
431 post :create, :scroll_panel => @attr
432 response.body.should redirect_to '/users/sign_in'
436 it 'ステータスコード401 Unauthorizedを返す' do
437 post :create, :scroll_panel => @attr, :format => :json
438 response.status.should eq 401
440 it '応答メッセージにUnauthorizedを返す' do
441 post :create, :scroll_panel => @attr, :format => :json
442 response.message.should match(/Unauthorized/)
446 context 'ユーザ権限はないが管理者権限があるとき' do
452 it 'ステータスコード302 Foundを返す' do
453 post :create, :scroll_panel => @attr
454 response.status.should eq 302
456 it 'サインインページへ遷移する' do
457 post :create, :scroll_panel => @attr
458 response.body.should redirect_to '/users/sign_in'
462 context 'ユーザだが作家登録していないとき' do
467 it 'ステータスコード302 Foundを返す' do
468 post :create, :scroll_panel => @attr
469 response.status.should eq 302
472 post :create, :scroll_panel => @attr
473 response.body.should redirect_to new_author_path
477 context '検証、保存に失敗した' do
479 ScrollPanel.any_instance.stub(:store).and_return(false)
481 it "未保存のコマを保持している" do
482 post :create, :scroll_panel => @attr
483 assigns(:scroll_panel).should be_a_new(ScrollPanel)
486 it 'ステータスコード200 OKを返す' do
487 post :create, :scroll_panel => @attr
488 response.status.should eq 200
491 post :create, :scroll_panel => @attr
492 response.should render_template("new")
496 it 'ステータスコード422 unprocessable_entity を返す' do
497 post :create, :scroll_panel => @attr, :format => :json
498 response.status.should eq 422
500 it '応答メッセージUnprocessable Entityを返す' do
501 post :create, :scroll_panel => @attr, :format => :json
502 response.message.should match(/Unprocessable/)
508 describe '編集フォーム表示に於いて' do
510 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id
512 ScrollPanel.stub(:show).and_return(@scroll_panel)
514 context 'つつがなく終わるとき' do
515 it 'スクコマモデルに編集取得を問い合わせている' do
516 ScrollPanel.should_receive(:edit).exactly(1)
517 get :edit, :id => @scroll_panel.id
519 it '@scroll_panelにデータを用意している' do
520 get :edit, :id => @scroll_panel.id
521 assigns(:scroll_panel).should eq @scroll_panel
524 it 'ステータスコード200 OKを返す' do
525 get :edit, :id => @scroll_panel.id
526 response.should be_success
528 it 'editテンプレートを描画する' do
529 get :edit, :id => @scroll_panel.id
530 response.should render_template("edit")
534 it 'ステータスコード200 OKを返す' do
535 get :edit, :id => @scroll_panel.id, :format => :js
536 response.should be_success
538 it 'edit.jsテンプレートを描画する' do
539 get :edit, :id => @scroll_panel.id, :format => :js
540 response.should render_template("edit")
544 context 'ユーザ権限がないとき' do
549 it 'ステータスコード302 Foundを返す' do
550 get :edit, :id => @scroll_panel.id
551 response.status.should eq 302
553 it 'サインインページへ遷移する' do
554 get :edit, :id => @scroll_panel.id
555 response.body.should redirect_to '/users/sign_in'
559 it 'ステータスコード401 Unauthorizedを返す' do
560 get :edit, :id => @scroll_panel.id, :format => :js
561 response.status.should eq 401
563 it '応答メッセージにUnauthorizedを返す' do
564 get :edit, :id => @scroll_panel.id, :format => :js
565 response.message.should match(/Unauthorized/)
569 context 'ユーザ権限はないが管理者権限があるとき' do
575 it 'ステータスコード302 Foundを返す' do
576 get :edit, :id => @scroll_panel.id
577 response.status.should eq 302
579 it 'サインインページへ遷移する' do
580 get :edit, :id => @scroll_panel.id
581 response.body.should redirect_to '/users/sign_in'
585 context 'ユーザだが作家登録していないとき' do
590 it 'ステータスコード302 Foundを返す' do
591 get :edit, :id => @scroll_panel.id
592 response.status.should eq 302
595 get :edit, :id => @scroll_panel.id
596 response.body.should redirect_to new_author_path
604 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @user.author.id
605 @attr = FactoryGirl.attributes_for(:scroll_panel, :author_id => @author.id)
608 context 'つつがなく終わるとき' do
610 ScrollPanel.stub(:edit).with(any_args).and_return(@scroll_panel)
611 ScrollPanel.should_receive(:edit).exactly(1)
612 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
614 it 'POSTデータから、カラム値を復元している' do
615 ScrollPanel.any_instance.stub(:store).and_return(true)
616 ScrollPanel.any_instance.should_receive(:attributes=).exactly(1)
617 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
620 ScrollPanel.any_instance.should_receive(:overwrite).exactly(1)
621 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
624 ScrollPanel.any_instance.should_receive(:store).exactly(1)
625 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
627 it "@scroll_panelに作成されたスクコマを保持していて、それがDBにある" do
628 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
629 assigns(:scroll_panel).should be_a(ScrollPanel)
630 assigns(:scroll_panel).should be_persisted
633 it 'ステータスコード302 Foundを返す' do
634 ScrollPanel.any_instance.stub(:store).and_return(true)
635 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
636 response.status.should eq 302
639 # ScrollPanel.any_instance.stub(:store).and_return(true)
640 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
641 response.should redirect_to(play_scroll_path(@attr[:scroll_id]))
645 it 'ステータスコード200 OKを返す' do
646 # ScrollPanel.any_instance.stub(:store).and_return(true)
647 put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
648 response.should be_success
652 context 'ユーザ権限がないとき' do
657 it 'ステータスコード302 Foundを返す' do
658 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
659 response.status.should eq 302
661 it 'サインインページへ遷移する' do
662 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
663 response.body.should redirect_to '/users/sign_in'
667 it 'ステータスコード401 Unauthorizedを返す' do
668 put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
669 response.status.should eq 401
671 it '応答メッセージにUnauthorizedを返す' do
672 put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
673 response.message.should match(/Unauthorized/)
677 context 'ユーザ権限はないが管理者権限があるとき' do
683 it 'ステータスコード302 Foundを返す' do
684 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
685 response.status.should eq 302
687 it 'サインインページへ遷移する' do
688 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
689 response.body.should redirect_to '/users/sign_in'
693 context 'ユーザだが作家登録していないとき' do
698 it 'ステータスコード302 Foundを返す' do
699 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
700 response.status.should eq 302
703 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
704 response.body.should redirect_to new_author_path
708 context '検証、保存に失敗した' do
710 ScrollPanel.any_instance.stub(:store).and_return(false)
713 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
714 assigns(:scroll_panel).should eq @scroll_panel
717 it 'ステータスコード200 OKを返す' do
718 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
719 response.status.should eq 200
722 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
723 response.should render_template("edit")
727 it 'ステータスコード422 unprocessable_entity を返す' do
728 put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
729 response.status.should eq 422
731 it '応答メッセージUnprocessable Entityを返す' do
732 put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
733 response.message.should match(/Unprocessable/)
741 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id
743 ScrollPanel.stub(:edit).and_return(@scroll_panel)
745 context '事前チェックしておく' do
747 ScrollPanel.stub(:edit).with(any_args()).and_return @scroll_panel
748 ScrollPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
750 it 'スクコマモデルに編集取得を問い合わせている' do
751 ScrollPanel.should_receive(:edit).exactly(1)
752 delete :destroy, :id => @scroll_panel.id
755 ScrollPanel.any_instance.should_receive(:destroy_and_shorten).exactly(1)
756 delete :destroy, :id => @scroll_panel.id
758 it '@scroll_panelにアレを取得している' do
759 delete :destroy, :id => @scroll_panel.id
760 assigns(:scroll_panel).id.should eq(@scroll_panel.id)
763 context 'つつがなく終わるとき' do
765 ScrollPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
768 it 'ステータスコード302 Foundを返す' do
769 delete :destroy, :id => @scroll_panel.id
770 response.status.should eq 302
773 delete :destroy, :id => @scroll_panel.id
774 response.should redirect_to(play_scroll_path(@scroll_panel.scroll_id) )
778 it 'ステータスコード200 OKを返す' do
779 delete :destroy, :id => @scroll_panel.id, :format => :json
780 response.should be_success
784 context 'ユーザ権限がないとき' do
789 it 'ステータスコード302 Foundを返す' do
790 delete :destroy, :id => @scroll_panel.id
791 response.status.should eq 302
793 it 'サインインページへ遷移する' do
794 delete :destroy, :id => @scroll_panel.id
795 response.body.should redirect_to '/users/sign_in'
799 it 'ステータスコード401 Unauthorizedを返す' do
800 delete :destroy, :id => @scroll_panel.id, :format => :json
801 response.status.should eq 401
803 it '応答メッセージにUnauthorizedを返す' do
804 delete :destroy, :id => @scroll_panel.id, :format => :json
805 response.message.should match(/Unauthorized/)
809 context 'ユーザ権限はないが管理者権限があるとき' do
815 it 'ステータスコード302 Foundを返す' do
816 delete :destroy, :id => @scroll_panel.id
817 response.status.should eq 302
819 it 'サインインページへ遷移する' do
820 delete :destroy, :id => @scroll_panel.id
821 response.body.should redirect_to '/users/sign_in'
825 context 'ユーザだが作家登録していないとき' do
830 it 'ステータスコード302 Foundを返す' do
831 delete :destroy, :id => @scroll_panel.id
832 response.status.should eq 302
835 delete :destroy, :id => @scroll_panel.id
836 response.body.should redirect_to new_author_path
840 context '削除に失敗したとき' do
842 ScrollPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(false)
845 it 'ステータスコード302 Foundを返す' do
846 delete :destroy, :id => @scroll_panel.id
847 response.status.should eq 302
849 it 'そのスクロールの詳細ページへ遷移する' do
850 delete :destroy, :id => @scroll_panel.id
851 response.should redirect_to(scroll_panel_path(@scroll_panel))
855 it 'ステータスコード422 unprocessable_entity を返す' do
856 delete :destroy, :id => @scroll_panel.id, :format => :json
857 response.status.should eq 422
859 it '応答メッセージUnprocessable Entityを返す' do
860 delete :destroy, :id => @scroll_panel.id, :format => :json
861 response.message.should match(/Unprocessable/)
866 context '対象スクコマがないとき' do
868 context '他人のスクコマだったとき' do
874 describe '一覧表示に於いて' do
877 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
878 ScrollPanel.stub(:list).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
880 context 'つつがなく終わるとき' do
881 it 'ステータスコード200 OKを返す' do
883 response.should be_success
886 it 'indexテンプレートを描画する' do
888 response.should render_template("index")
893 get :index, :format => :json
894 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
898 context 'ユーザ権限がないとき' do
902 it 'ステータスコード200 OKを返す' do
904 response.should be_success
907 it 'indexテンプレートを描画する' do
909 response.should render_template("index")
914 get :index, :format => :json
915 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
921 describe '単体表示に於いて' do
924 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
925 Scroll.stub(:show).with(@scroll.id.to_s, [nil, nil]).and_return(@scroll)
926 Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
927 Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
928 ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [nil, nil]).and_return(@scroll_panel)
929 ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [@user, nil]).and_return(@scroll_panel)
930 ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [nil, @admin]).and_return(@scroll_panel)
932 context 'つつがなく終わるとき' do
934 it 'ステータスコード200 OKを返す' do
935 get :show, :id => @scroll_panel.id
936 response.should be_success
938 it 'showテンプレートを描画する' do
939 get :show, :id => @scroll_panel.id
940 response.should render_template("show")
944 it 'ステータスコード200 OKを返す' do
945 get :show, :id => @scroll_panel.id, :format => :json
946 response.should be_success
949 get :show, :id => @scroll_panel.id, :format => :json
950 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
954 context 'ユーザ権限がないとき' do
959 it 'ステータスコード200 OKを返す' do
960 get :show, :id => @scroll_panel.id
961 response.should be_success
963 it 'showテンプレートを描画する' do
964 get :show, :id => @scroll_panel.id
965 response.should render_template("show")
969 it 'ステータスコード200 OKを返す' do
970 get :show, :id => @scroll_panel.id, :format => :json
971 response.should be_success
974 get :show, :id => @scroll_panel.id, :format => :json
975 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
983 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
984 Scroll.stub(:show).with(@scroll.id.to_s, [nil, nil]).and_return(@scroll)
985 Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
986 Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
987 ScrollPanel.stub(:count).and_return(10)
988 ScrollPanel.stub(:play_list).with(any_args).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
991 context 'つつがなく終わるとき' do
993 it 'ステータスコード200 OKを返す' do
994 get :scroll, :id => @scroll.id
995 response.should be_success
997 it 'scrollテンプレートを描画する' do
998 get :scroll, :id => @scroll.id
999 response.should render_template("scroll")
1003 it 'ステータスコード200 OKを返す' do
1004 get :scroll, :id => @scroll.id, :format => :json
1005 response.should be_success
1008 get :scroll, :id => @scroll.id, :format => :json
1009 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1013 context 'ユーザ権限がないとき' do
1018 it 'ステータスコード200 OKを返す' do
1019 get :scroll, :id => @scroll.id
1020 response.should be_success
1022 it 'scrollテンプレートを描画する' do
1023 get :scroll, :id => @scroll.id
1024 response.should render_template("scroll")
1028 it 'ステータスコード200 OKを返す' do
1029 get :scroll, :id => @scroll.id, :format => :json
1030 response.should be_success
1033 get :scroll, :id => @scroll.id, :format => :json
1034 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1040 describe '新規作成フォーム表示に於いて' do
1044 context 'つつがなく終わるとき' do
1046 it 'ステータスコード200 OKを返す' do
1048 response.should be_success
1050 it 'newテンプレートを描画する' do
1052 response.should render_template("new")
1056 it 'ステータスコード200 OKを返す' do
1057 get :new, :format => :js
1058 response.should be_success
1060 it 'new.jsテンプレートを描画する' do
1061 get :new, :format => :js
1062 response.should render_template("new")
1066 it 'ステータスコード200 OKを返す' do
1067 get :new, :format => :json
1068 response.should be_success
1071 get :new, :format => :json
1072 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1076 context 'ユーザ権限がないとき' do
1081 it 'ステータスコード302 Foundを返す' do
1083 response.status.should eq 302
1085 it 'サインインページへ遷移する' do
1087 response.body.should redirect_to '/users/sign_in'
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
1105 @attr = FactoryGirl.attributes_for(:scroll_panel, :t => nil, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id)
1108 context 'つつがなく終わるとき' do
1110 it 'ステータスコード302 Foundを返す' do
1111 ScrollPanel.any_instance.stub(:store).and_return(true)
1112 post :create, :scroll_panel => @attr
1113 response.status.should eq 302
1115 it 'スクロールのスクコマ表示へ遷移する' do
1116 # ScrollPanel.any_instance.stub(:store).and_return(true)
1117 post :create, :scroll_panel => @attr
1118 response.should redirect_to(:action => :scroll, :id => @attr[:scroll_id])
1122 it 'ステータスコード200 OKを返す' do
1123 # ScrollPanel.any_instance.stub(:store).and_return(true)
1124 post :create, :scroll_panel => @attr, :format => :json
1125 response.should be_success
1127 it '作成されたコマをjsonデータで返す' do
1128 post :create, :scroll_panel => @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_panel => @attr
1140 response.status.should eq 302
1142 it 'サインインページへ遷移する' do
1143 post :create, :scroll_panel => @attr
1144 response.body.should redirect_to '/users/sign_in'
1148 it 'ステータスコード401 Unauthorizedを返す' do
1149 post :create, :scroll_panel => @attr, :format => :json
1150 response.status.should eq 401
1152 it '応答メッセージにUnauthorizedを返す' do
1153 post :create, :scroll_panel => @attr, :format => :json
1154 response.message.should match(/Unauthorized/)
1160 describe '編集フォーム表示に於いて' do
1162 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id
1164 ScrollPanel.stub(:show).and_return(@scroll_panel)
1166 context 'つつがなく終わるとき' do
1168 it 'ステータスコード200 OKを返す' do
1169 get :edit, :id => @scroll_panel.id
1170 response.should be_success
1172 it 'editテンプレートを描画する' do
1173 get :edit, :id => @scroll_panel.id
1174 response.should render_template("edit")
1178 it 'ステータスコード200 OKを返す' do
1179 get :edit, :id => @scroll_panel.id, :format => :js
1180 response.should be_success
1182 it 'edit.jsテンプレートを描画する' do
1183 get :edit, :id => @scroll_panel.id, :format => :js
1184 response.should render_template("edit")
1188 context 'ユーザ権限がないとき' do
1193 it 'ステータスコード302 Foundを返す' do
1194 get :edit, :id => @scroll_panel.id
1195 response.status.should eq 302
1197 it 'サインインページへ遷移する' do
1198 get :edit, :id => @scroll_panel.id
1199 response.body.should redirect_to '/users/sign_in'
1203 it 'ステータスコード401 Unauthorizedを返す' do
1204 get :edit, :id => @scroll_panel.id, :format => :js
1205 response.status.should eq 401
1207 it '応答メッセージにUnauthorizedを返す' do
1208 get :edit, :id => @scroll_panel.id, :format => :js
1209 response.message.should match(/Unauthorized/)
1215 describe '更新に於いて' do
1217 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @user.author.id
1218 @attr = FactoryGirl.attributes_for(:scroll_panel, :author_id => @author.id)
1221 context 'つつがなく終わるとき' do
1223 it 'ステータスコード302 Foundを返す' do
1224 ScrollPanel.any_instance.stub(:store).and_return(true)
1225 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
1226 response.status.should eq 302
1229 # ScrollPanel.any_instance.stub(:store).and_return(true)
1230 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
1231 response.should redirect_to(:action => :scroll, :id => @attr[:scroll_id])
1235 it 'ステータスコード200 OKを返す' do
1236 # ScrollPanel.any_instance.stub(:store).and_return(true)
1237 put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
1238 response.should be_success
1242 context 'ユーザ権限がないとき' do
1247 it 'ステータスコード302 Foundを返す' do
1248 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
1249 response.status.should eq 302
1251 it 'サインインページへ遷移する' do
1252 put :update, :id => @scroll_panel.id, :scroll_panel => @attr
1253 response.body.should redirect_to '/users/sign_in'
1257 it 'ステータスコード401 Unauthorizedを返す' do
1258 put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
1259 response.status.should eq 401
1261 it '応答メッセージにUnauthorizedを返す' do
1262 put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
1263 response.message.should match(/Unauthorized/)
1269 describe '削除に於いて' do
1271 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id
1273 ScrollPanel.stub(:edit).and_return(@scroll_panel)
1275 context 'つつがなく終わるとき' do
1277 ScrollPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
1280 it 'ステータスコード302 Foundを返す' do
1281 delete :destroy, :id => @scroll_panel.id
1282 response.status.should eq 302
1285 delete :destroy, :id => @scroll_panel.id
1286 response.should redirect_to(:controller => 'scroll_panels', :action => :scroll, :id => @scroll_panel.scroll_id)
1290 it 'ステータスコード200 OKを返す' do
1291 delete :destroy, :id => @scroll_panel.id, :format => :json
1292 response.should be_success
1296 context 'ユーザ権限がないとき' do
1301 it 'ステータスコード302 Foundを返す' do
1302 delete :destroy, :id => @scroll_panel.id
1303 response.status.should eq 302
1305 it 'サインインページへ遷移する' do
1306 delete :destroy, :id => @scroll_panel.id
1307 response.body.should redirect_to '/users/sign_in'
1311 it 'ステータスコード401 Unauthorizedを返す' do
1312 delete :destroy, :id => @scroll_panel.id, :format => :json
1313 response.status.should eq 401
1315 it '応答メッセージにUnauthorizedを返す' do
1316 delete :destroy, :id => @scroll_panel.id, :format => :json
1317 response.message.should match(/Unauthorized/)