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)
270 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
271 @panel = FactoryGirl.create :panel, :author_id => @author.id
272 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
273 Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
274 Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
275 ScrollPanel.stub(:count).and_return(10)
276 ScrollPanel.stub(:play_list).with(any_args).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
279 context 'パラメータチェックする' do
280 it '与えられたoffsetがセットされている' do
281 get :play, :id => @scroll.id, :offset => 5
282 assigns(:offset).should eq 5
284 it '省略されると@offsetに0値が入る' do
285 get :play, :id => @scroll.id
286 assigns(:offset).should eq 0
288 it '与えられたcountがセットされている' do
289 get :play, :id => @scroll.id, :count => 4
290 assigns(:panel_count).should eq 4
292 it '省略されると@panel_countにデフォルト値が入る' do
293 get :play, :id => @scroll.id
294 assigns(:panel_count).should eq ScrollPanel.default_panel_size
296 it '最大を超えると@panel_countにデフォルト最大値が入る' do
297 get :play, :id => @scroll.id, :count => 1500
298 assigns(:panel_count).should eq ScrollPanel.max_panel_size
300 it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
301 get :play, :id => @scroll.id, :count => -1
302 assigns(:panel_count).should eq ScrollPanel.default_panel_size
305 context '事前チェックする' do
306 it 'スクロールモデルに単体取得を問い合わせている' do
307 Scroll.should_receive(:show).with(@scroll.id.to_s, [@user, nil]).exactly(1)
308 get :play, :id => @scroll.id
310 it 'スクコマモデルにプレイリスト取得を問い合わせている' do
311 ScrollPanel.should_receive(:play_list).with(@scroll, @author, 0, 30).exactly(1)
312 get :play, :id => @scroll.id
315 context 'つつがなく終わるとき' do
316 it '@scroll_panelsにリストを取得している' do
317 get :play, :id => @scroll.id
318 assigns(:scroll_panels).should have_at_least(3).items
321 it 'ステータスコード200 OKを返す' do
322 get :play, :id => @scroll.id
323 response.should be_success
325 it 'scrollテンプレートを描画する' do
326 get :play, :id => @scroll.id
327 response.should render_template("scroll")
331 it 'ステータスコード200 OKを返す' do
332 get :play, :id => @scroll.id, :format => :json
333 response.should be_success
336 get :play, :id => @scroll.id, :format => :json
337 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
339 it 'スクコマモデルにスクコマリストのjson出力を問い合わせている' do
340 ScrollPanel.should_receive(:list_as_json_text).exactly(1)
341 get :play, :id => @scroll.id, :format => :json
343 it 'データがリスト構造になっている' do
344 get :play, :id => @scroll.id, :format => :json
345 json = JSON.parse response.body
346 json.should have_at_least(3).items
348 it 'リストの先頭くらいはスクコマっぽいものであって欲しい' do
349 get :play, :id => @scroll.id, :format => :json
350 json = JSON.parse response.body
351 json.first.has_key?("panel_id").should be_true
352 json.first.has_key?("scroll_id").should be_true
353 json.first.has_key?("author_id").should be_true
357 context 'ユーザ権限がないとき' do
362 it 'ステータスコード302 Foundを返す' do
363 get :play, :id => @scroll.id
364 response.status.should eq 302
366 it 'サインインページへ遷移する' do
367 get :play, :id => @scroll.id
368 response.should redirect_to '/users/sign_in'
372 it 'ステータスコード401 Unauthorizedを返す' do
373 get :play, :id => @scroll.id, :format => :json
374 response.status.should eq 401
376 it '応答メッセージにUnauthorizedを返す' do
377 get :play, :id => @scroll.id, :format => :json
378 response.message.should match(/Unauthorized/)
382 context 'ユーザ権限はないが管理者権限があるとき' do
387 it 'ステータスコード200 OKを返す' do
388 get :play, :id => @scroll.id
389 response.should be_success
392 context 'ユーザだが作家登録していないとき' do
396 it 'ステータスコード200 OKを返す' do
397 get :play, :id => @scroll.id
398 response.should be_success
403 describe 'スクロール数取得に於いて' do
405 Scroll.should_receive(:visible_count).and_return(3)
408 context 'つつがなく終わるとき' do
409 it 'ステータスコード200 OKを返す' do
410 get :count, :format => :json
411 response.should be_success
415 get :count, :format => :json
416 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
418 it 'データがHash構造になっていてスクロール数が1である' do
419 get :count, :format => :json
420 json = JSON.parse response.body
421 json["count"].should == 3
427 describe '新規作成フォーム表示に於いて' do
431 context 'つつがなく終わるとき' do
432 it 'ステータスコード200 OKを返す' do
434 response.should be_success
436 it '@scrollに新規データを用意している' do
438 assigns(:scroll).should be_a_new(Scroll)
440 it 'スクロールモデルにデフォルト値補充を依頼している' do
441 Scroll.any_instance.should_receive(:supply_default).exactly(1)
445 it 'newテンプレートを描画する' do
447 response.should render_template("new")
451 it 'new.jsテンプレートを描画する' do
452 get :new, :format => :js
453 response.should render_template("new")
458 get :new, :format => :json
459 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
461 it 'スクロールモデルにjson単体出力オプションを問い合わせている' do
462 Scroll.should_receive(:show_json_opt).exactly(1)
463 get :new, :format => :json
467 context 'ユーザ権限がないとき' do
472 it 'ステータスコード302 Foundを返す' do
474 response.status.should eq 302
476 it 'サインインページへ遷移する' do
478 response.body.should redirect_to '/users/sign_in'
482 it 'ステータスコード401 Unauthorizedを返す' do
483 get :new, :format => :js
484 response.status.should eq 401
486 it '応答メッセージにUnauthorizedを返す' do
487 get :new, :format => :js
488 response.message.should match(/Unauthorized/)
492 it 'ステータスコード401 Unauthorizedを返す' do
493 get :new, :format => :json
494 response.status.should eq 401
496 it '応答メッセージにUnauthorizedを返す' do
497 get :new, :format => :json
498 response.message.should match(/Unauthorized/)
502 context 'ユーザ権限はないが管理者権限があるとき' do
508 it 'ステータスコード302 Foundを返す' do
510 response.status.should eq 302
512 it 'サインインページへ遷移する' do
514 response.body.should redirect_to '/users/sign_in'
518 context 'ユーザだが作家登録していないとき' do
523 it 'ステータスコード302 Foundを返す' do
525 response.status.should eq 302
529 response.body.should redirect_to new_author_path
535 describe '新規作成に於いて' do
538 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
540 context '事前チェックしておく' do
541 it 'スクロールモデルにデフォルト値補充を依頼している' do
542 Scroll.any_instance.should_receive(:supply_default).exactly(1)
543 post :create, :scroll => @attr
545 it 'スクロールモデルにカラム値復元を依頼している' do
546 Scroll.any_instance.should_receive(:attributes=).exactly(1)
547 post :create, :scroll => @attr
549 it 'スクロールモデルに上書き補充を依頼している' do
550 Scroll.any_instance.should_receive(:overwrite).exactly(1)
551 post :create, :scroll => @attr
554 Scroll.any_instance.should_receive(:save).exactly(1)
555 post :create, :scroll => @attr
558 context 'つつがなく終わるとき' do
559 it "@scrollに作成されたスクロールを保持していて、それがDBにある" do
560 post :create, :scroll => @attr
561 assigns(:scroll).should be_a(Scroll)
562 assigns(:scroll).should be_persisted
565 it 'ステータスコード302 Foundを返す' do
566 Scroll.any_instance.stub(:save).and_return(true)
567 post :create, :scroll => @attr
568 response.status.should eq 302
570 it '作成されたスクロールの表示ページへ遷移する' do
571 # Scroll.any_instance.stub(:save).and_return(true)
572 post :create, :scroll => @attr
573 response.should redirect_to(Scroll.last)
577 it 'ステータスコード200 OKを返す' do
578 # Scroll.any_instance.stub(:save).and_return(true)
579 post :create, :scroll => @attr, :format => :json
580 response.should be_success
582 it '作成されたスクロールをjsonデータで返す' do
583 post :create, :scroll => @attr, :format => :json
584 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
587 post :create, :scroll => @attr, :format => :json
588 json = JSON.parse response.body
589 json["title"].should match(/normal/)
590 json["visible"].should_not be_nil
594 context 'ユーザ権限がないとき' do
599 it 'ステータスコード302 Foundを返す' do
600 post :create, :scroll => @attr
601 response.status.should eq 302
603 it 'サインインページへ遷移する' do
604 post :create, :scroll => @attr
605 response.body.should redirect_to '/users/sign_in'
609 it 'ステータスコード401 Unauthorizedを返す' do
610 post :create, :scroll => @attr, :format => :json
611 response.status.should eq 401
613 it '応答メッセージにUnauthorizedを返す' do
614 post :create, :scroll => @attr, :format => :json
615 response.message.should match(/Unauthorized/)
619 context 'ユーザ権限はないが管理者権限があるとき' do
625 it 'ステータスコード302 Foundを返す' do
626 post :create, :scroll => @attr
627 response.status.should eq 302
629 it 'サインインページへ遷移する' do
630 post :create, :scroll => @attr
631 response.body.should redirect_to '/users/sign_in'
635 context 'ユーザだが作家登録していないとき' do
640 it 'ステータスコード302 Foundを返す' do
641 post :create, :scroll => @attr
642 response.status.should eq 302
645 post :create, :scroll => @attr
646 response.body.should redirect_to new_author_path
650 context '検証、保存に失敗した' do
652 Scroll.any_instance.stub(:save).and_return(false)
654 it "未保存のスクロールを保持している" do
655 post :create, :scroll => @attr
656 assigns(:scroll).should be_a_new(Scroll)
659 it 'ステータスコード200 OKを返す' do
660 post :create, :scroll => @attr
661 response.status.should eq 200
664 post :create, :scroll => @attr
665 response.should render_template("new")
669 it 'ステータスコード422 unprocessable_entity を返す' do
670 post :create, :scroll => @attr, :format => :json
671 response.status.should eq 422
673 it '応答メッセージUnprocessable Entityを返す' do
674 post :create, :scroll => @attr, :format => :json
675 response.message.should match(/Unprocessable/)
681 describe '編集フォーム表示に於いて' do
683 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
685 Scroll.stub(:edit).and_return(@scroll)
687 context 'つつがなく終わるとき' do
688 it 'ステータスコード200 OKを返す' do
689 get :edit, :id => @scroll.id
690 response.should be_success
692 it 'スクロールモデルに編集取得を問い合わせている' do
693 Scroll.should_receive(:edit).exactly(1)
694 get :edit, :id => @scroll.id
696 it '@scrollにデータを用意している' do
697 get :edit, :id => @scroll.id
698 assigns(:scroll).should eq @scroll
701 it 'editテンプレートを描画する' do
702 get :edit, :id => @scroll.id
703 response.should render_template("edit")
707 it 'edit.jsテンプレートを描画する' do
708 get :edit, :id => @scroll.id, :format => :js
709 response.should render_template("edit")
713 context 'ユーザ権限がないとき' do
718 it 'ステータスコード302 Foundを返す' do
719 get :edit, :id => @scroll.id
720 response.status.should eq 302
722 it 'サインインページへ遷移する' do
723 get :edit, :id => @scroll.id
724 response.body.should redirect_to '/users/sign_in'
728 it 'ステータスコード401 Unauthorizedを返す' do
729 get :edit, :id => @scroll.id, :format => :js
730 response.status.should eq 401
732 it '応答メッセージにUnauthorizedを返す' do
733 get :edit, :id => @scroll.id, :format => :js
734 response.message.should match(/Unauthorized/)
738 context 'ユーザ権限はないが管理者権限があるとき' do
744 it 'ステータスコード302 Foundを返す' do
745 get :edit, :id => @scroll.id
746 response.status.should eq 302
748 it 'サインインページへ遷移する' do
749 get :edit, :id => @scroll.id
750 response.body.should redirect_to '/users/sign_in'
754 context 'ユーザだが作家登録していないとき' do
759 it 'ステータスコード302 Foundを返す' do
760 get :edit, :id => @scroll.id
761 response.status.should eq 302
764 get :edit, :id => @scroll.id
765 response.body.should redirect_to new_author_path
773 @scroll = FactoryGirl.create :scroll, :author => @author
774 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
777 context '事前チェックしておく' do
778 it 'スクロールモデルに編集取得を問い合わせている' do
779 Scroll.stub(:edit).with(any_args()).and_return @scroll
780 Scroll.should_receive(:edit).exactly(1)
781 put :update, :id => @scroll.id, :scroll => @attr
783 it 'スクロールモデルにカラム値復元を依頼している' do
784 Scroll.any_instance.should_receive(:attributes=).exactly(1)
785 put :update, :id => @scroll.id, :scroll => @attr
787 it 'スクロールモデルに上書き補充を依頼している' do
788 Scroll.any_instance.should_receive(:overwrite).exactly(1)
789 put :update, :id => @scroll.id, :scroll => @attr
792 Scroll.any_instance.stub(:save).with(any_args).and_return true
793 Scroll.any_instance.should_receive(:save).exactly(1)
794 put :update, :id => @scroll.id, :scroll => @attr
796 it '@scrollにアレを取得している' do
797 put :update, :id => @scroll.id, :scroll => @attr
798 assigns(:scroll).id.should eq(@scroll.id)
801 context 'つつがなく終わるとき' do
803 put :update, :id => @scroll.id, :scroll => @attr
804 Scroll.find(@scroll.id).visible.should eq 0
807 it 'ステータスコード302 Foundを返す' do
808 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
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.should redirect_to(@scroll)
818 it 'ステータスコード200 OKを返す' do
819 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
820 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
821 response.should be_success
824 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
825 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
826 response.body.should match /./
830 context 'ユーザ権限がないとき' do
835 it 'ステータスコード302 Foundを返す' do
836 put :update, :id => @scroll.id, :scroll => @attr
837 response.status.should eq 302
839 it 'サインインページへ遷移する' do
840 put :update, :id => @scroll.id, :scroll => @attr
841 response.body.should redirect_to '/users/sign_in'
845 it '応答メッセージにUnauthorizedを返す' do
846 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
847 response.message.should match(/Unauthorized/)
851 context 'ユーザ権限はないが管理者権限があるとき' do
857 it 'ステータスコード302 Foundを返す' do
858 put :update, :id => @scroll.id, :scroll => @attr
859 response.status.should eq 302
861 it 'サインインページへ遷移する' do
862 put :update, :id => @scroll.id, :scroll => @attr
863 response.body.should redirect_to '/users/sign_in'
867 context 'ユーザだが作家登録していないとき' do
872 it 'ステータスコード302 Foundを返す' do
873 put :update, :id => @scroll.id, :scroll => @attr
874 response.status.should eq 302
877 put :update, :id => @scroll.id, :scroll => @attr
878 response.body.should redirect_to new_author_path
882 context '検証、保存に失敗したとき' do
884 Scroll.any_instance.stub(:save).and_return(false)
887 it 'ステータスコード200 Okを返す' do
888 put :update, :id => @scroll.id, :scroll => @attr
889 response.status.should eq 200
892 put :update, :id => @scroll.id, :scroll => @attr
893 response.should render_template("edit")
897 it 'ステータスコード422 unprocessable_entity を返す' do
898 Scroll.any_instance.stub(:save).and_return(false)
899 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
900 response.status.should eq 422
902 it '応答メッセージUnprocessable Entityを返す' do
903 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
904 response.message.should match(/Unprocessable/)
912 @scroll = FactoryGirl.create :scroll, :author => @author
915 context '事前チェックしておく' do
917 Scroll.stub(:edit).with(any_args()).and_return @scroll
918 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
920 it 'スクロールモデルに編集取得を問い合わせている' do
921 Scroll.should_receive(:edit).exactly(1)
922 delete :destroy, :id => @scroll.id
925 Scroll.any_instance.should_receive(:destroy_with_scroll_panel).exactly(1)
926 delete :destroy, :id => @scroll.id
928 it '@scrollにアレを取得している' do
929 delete :destroy, :id => @scroll.id
930 assigns(:scroll).id.should eq(@scroll.id)
933 context 'つつがなく終わるとき' do
936 delete :destroy, :id => @scroll.id
937 }.should change Scroll, :count
941 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
943 it 'ステータスコード302 Foundを返す' do
944 delete :destroy, :id => @scroll.id
945 response.status.should eq 302
947 it 'マイスクロールの一覧ページへ遷移する' do
948 delete :destroy, :id => @scroll.id
949 response.should redirect_to('/home/scrolls')
954 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
956 it 'ステータスコード200 OKを返す' do
957 delete :destroy, :id => @scroll.id, :format => :json
958 response.should be_success
961 delete :destroy, :id => @scroll.id, :format => :json
962 response.body.should match /./
966 context 'ユーザ権限がないとき' do
971 it 'ステータスコード302 Foundを返す' do
972 delete :destroy, :id => @scroll.id
973 response.status.should eq 302
975 it 'サインインページへ遷移する' do
976 delete :destroy, :id => @scroll.id
977 response.body.should redirect_to '/users/sign_in'
981 it '応答メッセージにUnauthorizedを返す' do
982 delete :destroy, :id => @scroll.id, :format => :json
983 response.message.should match(/Unauthorized/)
987 context 'ユーザ権限はないが管理者権限があるとき' do
993 it 'ステータスコード302 Foundを返す' do
994 delete :destroy, :id => @scroll.id
995 response.status.should eq 302
997 it 'サインインページへ遷移する' do
998 delete :destroy, :id => @scroll.id
999 response.body.should redirect_to '/users/sign_in'
1003 context 'ユーザだが作家登録していないとき' do
1008 it 'ステータスコード302 Foundを返す' do
1009 delete :destroy, :id => @scroll.id
1010 response.status.should eq 302
1012 it '作家登録ページへ遷移する' do
1013 delete :destroy, :id => @scroll.id
1014 response.body.should redirect_to new_author_path
1018 context '削除に失敗したとき' do
1020 Scroll.any_instance.stub(:destroy_with_scroll_panel).and_return(false)
1023 it 'ステータスコード302 Foundを返す' do
1024 delete :destroy, :id => @scroll.id
1025 response.status.should eq 302
1027 it 'そのスクロールの詳細ページへ遷移する' do
1028 delete :destroy, :id => @scroll.id
1029 response.should redirect_to(scroll_path(@scroll))
1033 it 'ステータスコード422 unprocessable_entity を返す' do
1034 delete :destroy, :id => @scroll.id, :format => :json
1035 response.status.should eq 422
1037 it '応答メッセージUnprocessable Entityを返す' do
1038 delete :destroy, :id => @scroll.id, :format => :json
1039 response.message.should match(/Unprocessable/)
1046 describe '一覧表示に於いて' do
1048 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
1049 Scroll.stub(:list).and_return([@scroll, @scroll, @scroll])
1052 context 'つつがなく終わるとき' do
1053 it 'ステータスコード200 OKを返す' do
1055 response.should be_success
1058 it 'indexテンプレートを描画する' do
1060 response.should render_template("index")
1065 get :index, :format => :json
1066 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1070 context 'ユーザ権限がないとき' do
1074 it 'ステータスコード200 OKを返す' do
1076 response.should be_success
1079 it 'indexテンプレートを描画する' do
1081 response.should render_template("index")
1086 get :index, :format => :json
1087 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1093 describe '単体表示に於いて' do
1095 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id, :title => 'normal'
1096 Scroll.stub(:show).and_return(@scroll)
1099 context 'つつがなく終わるとき' do
1100 it 'ステータスコード200 OKを返す' do
1101 get :show, :id => @scroll.id
1102 response.should be_success
1105 it 'showテンプレートを描画する' do
1106 get :show, :id => @scroll.id
1107 response.should render_template("show")
1112 get :show, :id => @scroll.id, :format => :json
1113 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1117 context 'ユーザ権限がないとき' do
1121 it 'ステータスコード200 OKを返す' do
1122 get :show, :id => @scroll.id
1123 response.should be_success
1126 it 'showテンプレートを描画する' do
1127 get :show, :id => @scroll.id
1128 response.should render_template("show")
1133 get :show, :id => @scroll.id, :format => :json
1134 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1139 describe 'スクロール数取得に於いて' do
1141 Scroll.should_receive(:visible_count).and_return(3)
1144 context 'つつがなく終わるとき' do
1145 it 'ステータスコード200 OKを返す' do
1146 get :count, :format => :json
1147 response.should be_success
1151 get :count, :format => :json
1152 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1158 describe '新規作成フォーム表示に於いて' do
1162 context 'つつがなく終わるとき' do
1163 it 'ステータスコード200 OKを返す' do
1165 response.should be_success
1168 it 'newテンプレートを描画する' do
1170 response.should render_template("new")
1174 it 'new.jsテンプレートを描画する' do
1175 get :new, :format => :js
1176 response.should render_template("new")
1181 get :new, :format => :json
1182 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1186 context 'ユーザ権限がないとき' do
1191 it 'ステータスコード302 Foundを返す' do
1193 response.status.should eq 302
1195 it 'サインインページへ遷移する' do
1197 response.body.should redirect_to '/users/sign_in'
1201 it 'ステータスコード401 Unauthorizedを返す' do
1202 get :new, :format => :js
1203 response.status.should eq 401
1205 it '応答メッセージにUnauthorizedを返す' do
1206 get :new, :format => :js
1207 response.message.should match(/Unauthorized/)
1211 it 'ステータスコード401 Unauthorizedを返す' do
1212 get :new, :format => :json
1213 response.status.should eq 401
1215 it '応答メッセージにUnauthorizedを返す' do
1216 get :new, :format => :json
1217 response.message.should match(/Unauthorized/)
1223 describe '新規作成に於いて' do
1226 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
1228 context 'つつがなく終わるとき' do
1230 it 'ステータスコード302 Foundを返す' do
1231 Scroll.any_instance.stub(:save).and_return(true)
1232 post :create, :scroll => @attr
1233 response.status.should eq 302
1235 it '作成されたスクロールの表示ページへ遷移する' do
1236 # Scroll.any_instance.stub(:save).and_return(true)
1237 post :create, :scroll => @attr
1238 response.should redirect_to(Scroll.last)
1242 it 'ステータスコード200 OKを返す' do
1243 # Scroll.any_instance.stub(:save).and_return(true)
1244 post :create, :scroll => @attr, :format => :json
1245 response.should be_success
1247 it '作成されたスクロールをjsonデータで返す' do
1248 post :create, :scroll => @attr, :format => :json
1249 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1253 context 'ユーザ権限がないとき' do
1258 it 'ステータスコード302 Foundを返す' do
1259 post :create, :scroll => @attr
1260 response.status.should eq 302
1262 it 'サインインページへ遷移する' do
1263 post :create, :scroll => @attr
1264 response.body.should redirect_to '/users/sign_in'
1268 it 'ステータスコード401 Unauthorizedを返す' do
1269 post :create, :scroll => @attr, :format => :json
1270 response.status.should eq 401
1272 it '応答メッセージにUnauthorizedを返す' do
1273 post :create, :scroll => @attr, :format => :json
1274 response.message.should match(/Unauthorized/)
1280 describe '編集フォーム表示に於いて' do
1282 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
1284 Scroll.stub(:edit).and_return(@scroll)
1286 context 'つつがなく終わるとき' do
1287 it 'ステータスコード200 OKを返す' do
1288 get :edit, :id => @scroll.id
1289 response.should be_success
1292 it 'editテンプレートを描画する' do
1293 get :edit, :id => @scroll.id
1294 response.should render_template("edit")
1298 it 'edit.jsテンプレートを描画する' do
1299 get :edit, :id => @scroll.id, :format => :js
1300 response.should render_template("edit")
1304 context 'ユーザ権限がないとき' do
1309 it 'ステータスコード302 Foundを返す' do
1310 get :edit, :id => @scroll.id
1311 response.status.should eq 302
1313 it 'サインインページへ遷移する' do
1314 get :edit, :id => @scroll.id
1315 response.body.should redirect_to '/users/sign_in'
1319 it 'ステータスコード401 Unauthorizedを返す' do
1320 get :edit, :id => @scroll.id, :format => :js
1321 response.status.should eq 401
1323 it '応答メッセージにUnauthorizedを返す' do
1324 get :edit, :id => @scroll.id, :format => :js
1325 response.message.should match(/Unauthorized/)
1331 describe '更新に於いて' do
1333 @scroll = FactoryGirl.create :scroll, :author => @author
1334 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
1337 context 'つつがなく終わるとき' do
1339 it 'ステータスコード302 Foundを返す' do
1340 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1341 put :update, :id => @scroll.id, :scroll => @attr
1342 response.status.should eq 302
1344 it '更新されたスクロールの表示ページへ遷移する' do
1345 put :update, :id => @scroll.id, :scroll => @attr
1346 response.should redirect_to(@scroll)
1350 it 'ステータスコード200 OKを返す' do
1351 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1352 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
1353 response.should be_success
1355 it 'ページ本体は特に返さない' do
1356 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1357 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
1358 response.body.should match /./
1362 context 'ユーザ権限がないとき' do
1366 it 'ステータスコード302 Foundを返す' do
1367 put :update, :id => @scroll.id, :scroll => @attr
1368 response.status.should eq 302
1371 it 'サインインページへ遷移する' do
1372 put :update, :id => @scroll.id, :scroll => @attr
1373 response.body.should redirect_to '/users/sign_in'
1379 describe '削除に於いて' do
1381 @scroll = FactoryGirl.create :scroll, :author => @author
1384 context 'つつがなく終わるとき' do
1387 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
1389 it 'ステータスコード302 Foundを返す' do
1390 delete :destroy, :id => @scroll.id
1391 response.status.should eq 302
1393 it 'マイスクロールの一覧ページへ遷移する' do
1394 delete :destroy, :id => @scroll.id
1395 response.should redirect_to('/home/scroll')
1400 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
1402 it 'ステータスコード200 OKを返す' do
1403 delete :destroy, :id => @scroll.id, :format => :json
1404 response.should be_success
1406 it 'ページ本体は特に返さない' do
1407 delete :destroy, :id => @scroll.id, :format => :json
1408 response.body.should match /./
1412 context 'ユーザ権限がないとき' do
1416 it 'ステータスコード302 Foundを返す' do
1417 delete :destroy, :id => @scroll.id
1418 response.status.should eq 302
1421 it 'サインインページへ遷移する' do
1422 delete :destroy, :id => @scroll.id
1423 response.body.should redirect_to '/users/sign_in'
1427 it '応答メッセージにUnauthorizedを返す' do
1428 delete :destroy, :id => @scroll.id, :format => :json
1429 response.message.should match(/Unauthorized/)