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 #@scroll = FactoryGirl.create :scroll_hello
13 #@author_yas = @scroll.author
14 @author_yas = FactoryGirl.create :yas_with_scrolls
15 @user_yas = @author_yas.user
18 context 'つつがなく終わるとき' do
19 it 'ステータスコード200 OKを返す' do
21 response.should be_success
23 it '@scrollsにリストを取得している' do
25 assigns(:scrolls).should have_at_least(3).items
28 it 'indexテンプレートを描画する' do
30 response.should render_template("index")
35 get :index, :format => :json
36 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
40 context 'ユーザ権限がないとき' do
45 it 'ステータスコード302 Foundを返す' do
47 response.status.should eq 302
51 response.should redirect_to '/users/sign_in'
55 it 'ステータスコード401 Unauthorizedを返す' do
56 get :index, :format => :json
57 response.status.should eq 401
59 it '応答メッセージにUnauthorizedを返す' do
60 get :index, :format => :json
61 response.message.should match(/Unauthorized/)
65 context 'ユーザ権限はないが管理者権限があるとき' do
70 it 'ステータスコード200 OKを返す' do
72 response.should be_success
75 context 'ユーザだが作家登録していないとき' do
78 @user_ghost = FactoryGirl.create :user_ghost
82 it 'ステータスコード200 OKを返す' do
84 response.should be_success
90 describe '単体表示に於いて' do
92 @scroll = FactoryGirl.create :scroll_hello
93 @author_yas = @scroll.author
94 @user_yas = @author_yas.user
95 Scroll.stub(:show).and_return(@scroll)
98 context 'つつがなく終わるとき' do
99 it 'ステータスコード200 OKを返す' do
100 get :show, :id => @scroll.id
101 response.should be_success
103 it '@scrollにアレを取得している' do
104 get :show, :id => @scroll.id
105 assigns(:scroll).id.should eq(@scroll.id)
108 it 'showテンプレートを描画する' do
109 get :show, :id => @scroll.id
110 response.should render_template("show")
115 get :show, :id => @scroll.id, :format => :json
116 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
120 context 'ユーザ権限がないとき' do
125 it 'ステータスコード302 Foundを返す' do
126 get :show, :id => @scroll.id
127 response.status.should eq 302
129 it 'サインインページへ遷移する' do
130 get :show, :id => @scroll.id
131 response.body.should redirect_to '/users/sign_in'
135 it 'ステータスコード401 Unauthorizedを返す' do
136 get :show, :id => @scroll.id, :format => :json
137 response.status.should eq 401
139 it '応答メッセージにUnauthorizedを返す' do
140 get :show, :id => @scroll.id, :format => :json
141 response.message.should match(/Unauthorized/)
145 context 'ユーザ権限はないが管理者権限があるとき' do
150 it 'ステータスコード200 OKを返す' do
151 get :show, :id => @scroll.id
152 response.should be_success
155 context 'ユーザだが作家登録していないとき' do
158 @user_ghost = FactoryGirl.create :user_ghost
162 it 'ステータスコード200 OKを返す' do
163 get :show, :id => @scroll.id
164 response.should be_success
169 context '対象スクロールがないとき' do
171 it '例外404 not_foundを返す' do
174 }.should raise_error(ActiveRecord::RecordNotFound)
178 it '例外404 not_foundを返す' do
180 get :show, :id => 0, :format => :json
181 }.should raise_error(ActiveRecord::RecordNotFound)
185 context '非公開スクロールを見ようとしたとき' do
187 it '例外403 forbiddenを返す' do
188 Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
189 hidden = FactoryGirl.create :hidden_scroll, :author_id => @author.id
191 get :show, :id => hidden
192 }.should raise_error(ActiveRecord::Forbidden)
196 it '例外403 forbiddenを返す' do
197 Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
198 hidden = FactoryGirl.create :hidden_scroll, :author_id => @author.id
200 get :show, :id => hidden, :format => :json
201 }.should raise_error(ActiveRecord::Forbidden)
210 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
211 @panel = FactoryGirl.create :panel, :author_id => @author.id
212 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
213 Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
214 Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
215 ScrollPanel.stub(:count).and_return(10)
216 ScrollPanel.stub(:play_list).with(any_args).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
219 context 'パラメータチェックする' do
220 it '与えられたoffsetがセットされている' do
221 get :play, :id => @scroll.id, :offset => 5
222 assigns(:offset).should eq 5
224 it '省略されると@offsetに0値が入る' do
225 get :play, :id => @scroll.id
226 assigns(:offset).should eq 0
228 it '与えられたcountがセットされている' do
229 get :play, :id => @scroll.id, :count => 4
230 assigns(:panel_count).should eq 4
232 it '省略されると@panel_countにデフォルト値が入る' do
233 get :play, :id => @scroll.id
234 assigns(:panel_count).should eq ScrollPanel.default_panel_size
236 it '最大を超えると@panel_countにデフォルト最大値が入る' do
237 get :play, :id => @scroll.id, :count => 1500
238 assigns(:panel_count).should eq ScrollPanel.max_panel_size
240 it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
241 get :play, :id => @scroll.id, :count => -1
242 assigns(:panel_count).should eq ScrollPanel.default_panel_size
245 context '事前チェックする' do
246 it 'スクロールモデルに単体取得を問い合わせている' do
247 Scroll.should_receive(:show).with(@scroll.id.to_s, [@user, nil]).exactly(1)
248 get :play, :id => @scroll.id
250 it 'スクコマモデルにプレイリスト取得を問い合わせている' do
251 ScrollPanel.should_receive(:play_list).with(@scroll, @author, 0, 30).exactly(1)
252 get :play, :id => @scroll.id
255 context 'つつがなく終わるとき' do
256 it '@scroll_panelsにリストを取得している' do
257 get :play, :id => @scroll.id
258 assigns(:scroll_panels).should have_at_least(3).items
261 it 'ステータスコード200 OKを返す' do
262 get :play, :id => @scroll.id
263 response.should be_success
265 it 'scrollテンプレートを描画する' do
266 get :play, :id => @scroll.id
267 response.should render_template("scroll")
271 it 'ステータスコード200 OKを返す' do
272 get :play, :id => @scroll.id, :format => :json
273 response.should be_success
276 get :play, :id => @scroll.id, :format => :json
277 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
279 it 'スクコマモデルにスクコマリストのjson出力を問い合わせている' do
280 ScrollPanel.should_receive(:list_as_json_text).exactly(1)
281 get :play, :id => @scroll.id, :format => :json
283 it 'データがリスト構造になっている' do
284 get :play, :id => @scroll.id, :format => :json
285 json = JSON.parse response.body
286 json.should have_at_least(3).items
288 it 'リストの先頭くらいはスクコマっぽいものであって欲しい' do
289 get :play, :id => @scroll.id, :format => :json
290 json = JSON.parse response.body
291 json.first.has_key?("panel_id").should be_true
292 json.first.has_key?("scroll_id").should be_true
293 json.first.has_key?("author_id").should be_true
297 context 'ユーザ権限がないとき' do
302 it 'ステータスコード302 Foundを返す' do
303 get :play, :id => @scroll.id
304 response.status.should eq 302
306 it 'サインインページへ遷移する' do
307 get :play, :id => @scroll.id
308 response.should redirect_to '/users/sign_in'
312 it 'ステータスコード401 Unauthorizedを返す' do
313 get :play, :id => @scroll.id, :format => :json
314 response.status.should eq 401
316 it '応答メッセージにUnauthorizedを返す' do
317 get :play, :id => @scroll.id, :format => :json
318 response.message.should match(/Unauthorized/)
322 context 'ユーザ権限はないが管理者権限があるとき' do
327 it 'ステータスコード200 OKを返す' do
328 get :play, :id => @scroll.id
329 response.should be_success
332 context 'ユーザだが作家登録していないとき' do
336 it 'ステータスコード200 OKを返す' do
337 get :play, :id => @scroll.id
338 response.should be_success
343 describe 'スクロール数取得に於いて' do
345 Scroll.should_receive(:visible_count).and_return(3)
348 context 'つつがなく終わるとき' do
349 it 'ステータスコード200 OKを返す' do
350 get :count, :format => :json
351 response.should be_success
355 get :count, :format => :json
356 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
358 it 'データがHash構造になっていてスクロール数が1である' do
359 get :count, :format => :json
360 json = JSON.parse response.body
361 json["count"].should == 3
367 describe '新規作成フォーム表示に於いて' do
371 context 'つつがなく終わるとき' do
372 it 'ステータスコード200 OKを返す' do
374 response.should be_success
376 it '@scrollに新規データを用意している' do
378 assigns(:scroll).should be_a_new(Scroll)
380 it 'スクロールモデルにデフォルト値補充を依頼している' do
381 Scroll.any_instance.should_receive(:supply_default).exactly(1)
385 it 'newテンプレートを描画する' do
387 response.should render_template("new")
391 it 'new.jsテンプレートを描画する' do
392 get :new, :format => :js
393 response.should render_template("new")
398 get :new, :format => :json
399 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
401 it 'スクロールモデルにjson単体出力オプションを問い合わせている' do
402 Scroll.should_receive(:show_json_opt).exactly(1)
403 get :new, :format => :json
407 context 'ユーザ権限がないとき' do
412 it 'ステータスコード302 Foundを返す' do
414 response.status.should eq 302
416 it 'サインインページへ遷移する' do
418 response.body.should redirect_to '/users/sign_in'
422 it 'ステータスコード401 Unauthorizedを返す' do
423 get :new, :format => :js
424 response.status.should eq 401
426 it '応答メッセージにUnauthorizedを返す' do
427 get :new, :format => :js
428 response.message.should match(/Unauthorized/)
432 it 'ステータスコード401 Unauthorizedを返す' do
433 get :new, :format => :json
434 response.status.should eq 401
436 it '応答メッセージにUnauthorizedを返す' do
437 get :new, :format => :json
438 response.message.should match(/Unauthorized/)
442 context 'ユーザ権限はないが管理者権限があるとき' do
448 it 'ステータスコード302 Foundを返す' do
450 response.status.should eq 302
452 it 'サインインページへ遷移する' do
454 response.body.should redirect_to '/users/sign_in'
458 context 'ユーザだが作家登録していないとき' do
463 it 'ステータスコード302 Foundを返す' do
465 response.status.should eq 302
469 response.body.should redirect_to new_author_path
475 describe '新規作成に於いて' do
478 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
480 context '事前チェックしておく' do
481 it 'スクロールモデルにデフォルト値補充を依頼している' do
482 Scroll.any_instance.should_receive(:supply_default).exactly(1)
483 post :create, :scroll => @attr
485 it 'スクロールモデルにカラム値復元を依頼している' do
486 Scroll.any_instance.should_receive(:attributes=).exactly(1)
487 post :create, :scroll => @attr
489 it 'スクロールモデルに上書き補充を依頼している' do
490 Scroll.any_instance.should_receive(:overwrite).exactly(1)
491 post :create, :scroll => @attr
494 Scroll.any_instance.should_receive(:save).exactly(1)
495 post :create, :scroll => @attr
498 context 'つつがなく終わるとき' do
499 it "@scrollに作成されたスクロールを保持していて、それがDBにある" do
500 post :create, :scroll => @attr
501 assigns(:scroll).should be_a(Scroll)
502 assigns(:scroll).should be_persisted
505 it 'ステータスコード302 Foundを返す' do
506 Scroll.any_instance.stub(:save).and_return(true)
507 post :create, :scroll => @attr
508 response.status.should eq 302
510 it '作成されたスクロールの表示ページへ遷移する' do
511 # Scroll.any_instance.stub(:save).and_return(true)
512 post :create, :scroll => @attr
513 response.should redirect_to(Scroll.last)
517 it 'ステータスコード200 OKを返す' do
518 # Scroll.any_instance.stub(:save).and_return(true)
519 post :create, :scroll => @attr, :format => :json
520 response.should be_success
522 it '作成されたスクロールをjsonデータで返す' do
523 post :create, :scroll => @attr, :format => :json
524 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
527 post :create, :scroll => @attr, :format => :json
528 json = JSON.parse response.body
529 json["title"].should match(/normal/)
530 json["visible"].should_not be_nil
534 context 'ユーザ権限がないとき' do
539 it 'ステータスコード302 Foundを返す' do
540 post :create, :scroll => @attr
541 response.status.should eq 302
543 it 'サインインページへ遷移する' do
544 post :create, :scroll => @attr
545 response.body.should redirect_to '/users/sign_in'
549 it 'ステータスコード401 Unauthorizedを返す' do
550 post :create, :scroll => @attr, :format => :json
551 response.status.should eq 401
553 it '応答メッセージにUnauthorizedを返す' do
554 post :create, :scroll => @attr, :format => :json
555 response.message.should match(/Unauthorized/)
559 context 'ユーザ権限はないが管理者権限があるとき' do
565 it 'ステータスコード302 Foundを返す' do
566 post :create, :scroll => @attr
567 response.status.should eq 302
569 it 'サインインページへ遷移する' do
570 post :create, :scroll => @attr
571 response.body.should redirect_to '/users/sign_in'
575 context 'ユーザだが作家登録していないとき' do
580 it 'ステータスコード302 Foundを返す' do
581 post :create, :scroll => @attr
582 response.status.should eq 302
585 post :create, :scroll => @attr
586 response.body.should redirect_to new_author_path
590 context '検証、保存に失敗した' do
592 Scroll.any_instance.stub(:save).and_return(false)
594 it "未保存のスクロールを保持している" do
595 post :create, :scroll => @attr
596 assigns(:scroll).should be_a_new(Scroll)
599 it 'ステータスコード200 OKを返す' do
600 post :create, :scroll => @attr
601 response.status.should eq 200
604 post :create, :scroll => @attr
605 response.should render_template("new")
609 it 'ステータスコード422 unprocessable_entity を返す' do
610 post :create, :scroll => @attr, :format => :json
611 response.status.should eq 422
613 it '応答メッセージUnprocessable Entityを返す' do
614 post :create, :scroll => @attr, :format => :json
615 response.message.should match(/Unprocessable/)
621 describe '編集フォーム表示に於いて' do
623 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
625 Scroll.stub(:edit).and_return(@scroll)
627 context 'つつがなく終わるとき' do
628 it 'ステータスコード200 OKを返す' do
629 get :edit, :id => @scroll.id
630 response.should be_success
632 it 'スクロールモデルに編集取得を問い合わせている' do
633 Scroll.should_receive(:edit).exactly(1)
634 get :edit, :id => @scroll.id
636 it '@scrollにデータを用意している' do
637 get :edit, :id => @scroll.id
638 assigns(:scroll).should eq @scroll
641 it 'editテンプレートを描画する' do
642 get :edit, :id => @scroll.id
643 response.should render_template("edit")
647 it 'edit.jsテンプレートを描画する' do
648 get :edit, :id => @scroll.id, :format => :js
649 response.should render_template("edit")
653 context 'ユーザ権限がないとき' do
658 it 'ステータスコード302 Foundを返す' do
659 get :edit, :id => @scroll.id
660 response.status.should eq 302
662 it 'サインインページへ遷移する' do
663 get :edit, :id => @scroll.id
664 response.body.should redirect_to '/users/sign_in'
668 it 'ステータスコード401 Unauthorizedを返す' do
669 get :edit, :id => @scroll.id, :format => :js
670 response.status.should eq 401
672 it '応答メッセージにUnauthorizedを返す' do
673 get :edit, :id => @scroll.id, :format => :js
674 response.message.should match(/Unauthorized/)
678 context 'ユーザ権限はないが管理者権限があるとき' do
684 it 'ステータスコード302 Foundを返す' do
685 get :edit, :id => @scroll.id
686 response.status.should eq 302
688 it 'サインインページへ遷移する' do
689 get :edit, :id => @scroll.id
690 response.body.should redirect_to '/users/sign_in'
694 context 'ユーザだが作家登録していないとき' do
699 it 'ステータスコード302 Foundを返す' do
700 get :edit, :id => @scroll.id
701 response.status.should eq 302
704 get :edit, :id => @scroll.id
705 response.body.should redirect_to new_author_path
713 @scroll = FactoryGirl.create :scroll, :author => @author
714 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
717 context '事前チェックしておく' do
718 it 'スクロールモデルに編集取得を問い合わせている' do
719 Scroll.stub(:edit).with(any_args()).and_return @scroll
720 Scroll.should_receive(:edit).exactly(1)
721 put :update, :id => @scroll.id, :scroll => @attr
723 it 'スクロールモデルにカラム値復元を依頼している' do
724 Scroll.any_instance.should_receive(:attributes=).exactly(1)
725 put :update, :id => @scroll.id, :scroll => @attr
727 it 'スクロールモデルに上書き補充を依頼している' do
728 Scroll.any_instance.should_receive(:overwrite).exactly(1)
729 put :update, :id => @scroll.id, :scroll => @attr
732 Scroll.any_instance.stub(:save).with(any_args).and_return true
733 Scroll.any_instance.should_receive(:save).exactly(1)
734 put :update, :id => @scroll.id, :scroll => @attr
736 it '@scrollにアレを取得している' do
737 put :update, :id => @scroll.id, :scroll => @attr
738 assigns(:scroll).id.should eq(@scroll.id)
741 context 'つつがなく終わるとき' do
743 put :update, :id => @scroll.id, :scroll => @attr
744 Scroll.find(@scroll.id).visible.should eq 0
747 it 'ステータスコード302 Foundを返す' do
748 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
749 put :update, :id => @scroll.id, :scroll => @attr
750 response.status.should eq 302
752 it '更新されたスクロールの表示ページへ遷移する' do
753 put :update, :id => @scroll.id, :scroll => @attr
754 response.should redirect_to(@scroll)
758 it 'ステータスコード200 OKを返す' do
759 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
760 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
761 response.should be_success
764 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
765 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
766 response.body.should match /./
770 context 'ユーザ権限がないとき' do
775 it 'ステータスコード302 Foundを返す' do
776 put :update, :id => @scroll.id, :scroll => @attr
777 response.status.should eq 302
779 it 'サインインページへ遷移する' do
780 put :update, :id => @scroll.id, :scroll => @attr
781 response.body.should redirect_to '/users/sign_in'
785 it '応答メッセージにUnauthorizedを返す' do
786 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
787 response.message.should match(/Unauthorized/)
791 context 'ユーザ権限はないが管理者権限があるとき' do
797 it 'ステータスコード302 Foundを返す' do
798 put :update, :id => @scroll.id, :scroll => @attr
799 response.status.should eq 302
801 it 'サインインページへ遷移する' do
802 put :update, :id => @scroll.id, :scroll => @attr
803 response.body.should redirect_to '/users/sign_in'
807 context 'ユーザだが作家登録していないとき' do
812 it 'ステータスコード302 Foundを返す' do
813 put :update, :id => @scroll.id, :scroll => @attr
814 response.status.should eq 302
817 put :update, :id => @scroll.id, :scroll => @attr
818 response.body.should redirect_to new_author_path
822 context '検証、保存に失敗したとき' do
824 Scroll.any_instance.stub(:save).and_return(false)
827 it 'ステータスコード200 Okを返す' do
828 put :update, :id => @scroll.id, :scroll => @attr
829 response.status.should eq 200
832 put :update, :id => @scroll.id, :scroll => @attr
833 response.should render_template("edit")
837 it 'ステータスコード422 unprocessable_entity を返す' do
838 Scroll.any_instance.stub(:save).and_return(false)
839 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
840 response.status.should eq 422
842 it '応答メッセージUnprocessable Entityを返す' do
843 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
844 response.message.should match(/Unprocessable/)
852 @scroll = FactoryGirl.create :scroll, :author => @author
855 context '事前チェックしておく' do
857 Scroll.stub(:edit).with(any_args()).and_return @scroll
858 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
860 it 'スクロールモデルに編集取得を問い合わせている' do
861 Scroll.should_receive(:edit).exactly(1)
862 delete :destroy, :id => @scroll.id
865 Scroll.any_instance.should_receive(:destroy_with_scroll_panel).exactly(1)
866 delete :destroy, :id => @scroll.id
868 it '@scrollにアレを取得している' do
869 delete :destroy, :id => @scroll.id
870 assigns(:scroll).id.should eq(@scroll.id)
873 context 'つつがなく終わるとき' do
876 delete :destroy, :id => @scroll.id
877 }.should change Scroll, :count
881 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
883 it 'ステータスコード302 Foundを返す' do
884 delete :destroy, :id => @scroll.id
885 response.status.should eq 302
887 it 'マイスクロールの一覧ページへ遷移する' do
888 delete :destroy, :id => @scroll.id
889 response.should redirect_to('/home/scrolls')
894 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
896 it 'ステータスコード200 OKを返す' do
897 delete :destroy, :id => @scroll.id, :format => :json
898 response.should be_success
901 delete :destroy, :id => @scroll.id, :format => :json
902 response.body.should match /./
906 context 'ユーザ権限がないとき' do
911 it 'ステータスコード302 Foundを返す' do
912 delete :destroy, :id => @scroll.id
913 response.status.should eq 302
915 it 'サインインページへ遷移する' do
916 delete :destroy, :id => @scroll.id
917 response.body.should redirect_to '/users/sign_in'
921 it '応答メッセージにUnauthorizedを返す' do
922 delete :destroy, :id => @scroll.id, :format => :json
923 response.message.should match(/Unauthorized/)
927 context 'ユーザ権限はないが管理者権限があるとき' do
933 it 'ステータスコード302 Foundを返す' do
934 delete :destroy, :id => @scroll.id
935 response.status.should eq 302
937 it 'サインインページへ遷移する' do
938 delete :destroy, :id => @scroll.id
939 response.body.should redirect_to '/users/sign_in'
943 context 'ユーザだが作家登録していないとき' do
948 it 'ステータスコード302 Foundを返す' do
949 delete :destroy, :id => @scroll.id
950 response.status.should eq 302
953 delete :destroy, :id => @scroll.id
954 response.body.should redirect_to new_author_path
958 context '削除に失敗したとき' do
960 Scroll.any_instance.stub(:destroy_with_scroll_panel).and_return(false)
963 it 'ステータスコード302 Foundを返す' do
964 delete :destroy, :id => @scroll.id
965 response.status.should eq 302
967 it 'そのスクロールの詳細ページへ遷移する' do
968 delete :destroy, :id => @scroll.id
969 response.should redirect_to(scroll_path(@scroll))
973 it 'ステータスコード422 unprocessable_entity を返す' do
974 delete :destroy, :id => @scroll.id, :format => :json
975 response.status.should eq 422
977 it '応答メッセージUnprocessable Entityを返す' do
978 delete :destroy, :id => @scroll.id, :format => :json
979 response.message.should match(/Unprocessable/)
986 describe '一覧表示に於いて' do
988 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
989 Scroll.stub(:list).and_return([@scroll, @scroll, @scroll])
992 context 'つつがなく終わるとき' do
993 it 'ステータスコード200 OKを返す' do
995 response.should be_success
998 it 'indexテンプレートを描画する' do
1000 response.should render_template("index")
1005 get :index, :format => :json
1006 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1010 context 'ユーザ権限がないとき' do
1014 it 'ステータスコード200 OKを返す' do
1016 response.should be_success
1019 it 'indexテンプレートを描画する' do
1021 response.should render_template("index")
1026 get :index, :format => :json
1027 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1033 describe '単体表示に於いて' do
1035 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id, :title => 'normal'
1036 Scroll.stub(:show).and_return(@scroll)
1039 context 'つつがなく終わるとき' do
1040 it 'ステータスコード200 OKを返す' do
1041 get :show, :id => @scroll.id
1042 response.should be_success
1045 it 'showテンプレートを描画する' do
1046 get :show, :id => @scroll.id
1047 response.should render_template("show")
1052 get :show, :id => @scroll.id, :format => :json
1053 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1057 context 'ユーザ権限がないとき' do
1061 it 'ステータスコード200 OKを返す' do
1062 get :show, :id => @scroll.id
1063 response.should be_success
1066 it 'showテンプレートを描画する' do
1067 get :show, :id => @scroll.id
1068 response.should render_template("show")
1073 get :show, :id => @scroll.id, :format => :json
1074 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1079 describe 'スクロール数取得に於いて' do
1081 Scroll.should_receive(:visible_count).and_return(3)
1084 context 'つつがなく終わるとき' do
1085 it 'ステータスコード200 OKを返す' do
1086 get :count, :format => :json
1087 response.should be_success
1091 get :count, :format => :json
1092 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1098 describe '新規作成フォーム表示に於いて' do
1102 context 'つつがなく終わるとき' do
1103 it 'ステータスコード200 OKを返す' do
1105 response.should be_success
1108 it 'newテンプレートを描画する' do
1110 response.should render_template("new")
1114 it 'new.jsテンプレートを描画する' do
1115 get :new, :format => :js
1116 response.should render_template("new")
1121 get :new, :format => :json
1122 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1126 context 'ユーザ権限がないとき' do
1131 it 'ステータスコード302 Foundを返す' do
1133 response.status.should eq 302
1135 it 'サインインページへ遷移する' do
1137 response.body.should redirect_to '/users/sign_in'
1141 it 'ステータスコード401 Unauthorizedを返す' do
1142 get :new, :format => :js
1143 response.status.should eq 401
1145 it '応答メッセージにUnauthorizedを返す' do
1146 get :new, :format => :js
1147 response.message.should match(/Unauthorized/)
1151 it 'ステータスコード401 Unauthorizedを返す' do
1152 get :new, :format => :json
1153 response.status.should eq 401
1155 it '応答メッセージにUnauthorizedを返す' do
1156 get :new, :format => :json
1157 response.message.should match(/Unauthorized/)
1163 describe '新規作成に於いて' do
1166 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
1168 context 'つつがなく終わるとき' do
1170 it 'ステータスコード302 Foundを返す' do
1171 Scroll.any_instance.stub(:save).and_return(true)
1172 post :create, :scroll => @attr
1173 response.status.should eq 302
1175 it '作成されたスクロールの表示ページへ遷移する' do
1176 # Scroll.any_instance.stub(:save).and_return(true)
1177 post :create, :scroll => @attr
1178 response.should redirect_to(Scroll.last)
1182 it 'ステータスコード200 OKを返す' do
1183 # Scroll.any_instance.stub(:save).and_return(true)
1184 post :create, :scroll => @attr, :format => :json
1185 response.should be_success
1187 it '作成されたスクロールをjsonデータで返す' do
1188 post :create, :scroll => @attr, :format => :json
1189 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1193 context 'ユーザ権限がないとき' do
1198 it 'ステータスコード302 Foundを返す' do
1199 post :create, :scroll => @attr
1200 response.status.should eq 302
1202 it 'サインインページへ遷移する' do
1203 post :create, :scroll => @attr
1204 response.body.should redirect_to '/users/sign_in'
1208 it 'ステータスコード401 Unauthorizedを返す' do
1209 post :create, :scroll => @attr, :format => :json
1210 response.status.should eq 401
1212 it '応答メッセージにUnauthorizedを返す' do
1213 post :create, :scroll => @attr, :format => :json
1214 response.message.should match(/Unauthorized/)
1220 describe '編集フォーム表示に於いて' do
1222 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
1224 Scroll.stub(:edit).and_return(@scroll)
1226 context 'つつがなく終わるとき' do
1227 it 'ステータスコード200 OKを返す' do
1228 get :edit, :id => @scroll.id
1229 response.should be_success
1232 it 'editテンプレートを描画する' do
1233 get :edit, :id => @scroll.id
1234 response.should render_template("edit")
1238 it 'edit.jsテンプレートを描画する' do
1239 get :edit, :id => @scroll.id, :format => :js
1240 response.should render_template("edit")
1244 context 'ユーザ権限がないとき' do
1249 it 'ステータスコード302 Foundを返す' do
1250 get :edit, :id => @scroll.id
1251 response.status.should eq 302
1253 it 'サインインページへ遷移する' do
1254 get :edit, :id => @scroll.id
1255 response.body.should redirect_to '/users/sign_in'
1259 it 'ステータスコード401 Unauthorizedを返す' do
1260 get :edit, :id => @scroll.id, :format => :js
1261 response.status.should eq 401
1263 it '応答メッセージにUnauthorizedを返す' do
1264 get :edit, :id => @scroll.id, :format => :js
1265 response.message.should match(/Unauthorized/)
1271 describe '更新に於いて' do
1273 @scroll = FactoryGirl.create :scroll, :author => @author
1274 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
1277 context 'つつがなく終わるとき' do
1279 it 'ステータスコード302 Foundを返す' do
1280 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1281 put :update, :id => @scroll.id, :scroll => @attr
1282 response.status.should eq 302
1284 it '更新されたスクロールの表示ページへ遷移する' do
1285 put :update, :id => @scroll.id, :scroll => @attr
1286 response.should redirect_to(@scroll)
1290 it 'ステータスコード200 OKを返す' do
1291 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1292 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
1293 response.should be_success
1295 it 'ページ本体は特に返さない' do
1296 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1297 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
1298 response.body.should match /./
1302 context 'ユーザ権限がないとき' do
1306 it 'ステータスコード302 Foundを返す' do
1307 put :update, :id => @scroll.id, :scroll => @attr
1308 response.status.should eq 302
1311 it 'サインインページへ遷移する' do
1312 put :update, :id => @scroll.id, :scroll => @attr
1313 response.body.should redirect_to '/users/sign_in'
1319 describe '削除に於いて' do
1321 @scroll = FactoryGirl.create :scroll, :author => @author
1324 context 'つつがなく終わるとき' do
1327 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
1329 it 'ステータスコード302 Foundを返す' do
1330 delete :destroy, :id => @scroll.id
1331 response.status.should eq 302
1333 it 'マイスクロールの一覧ページへ遷移する' do
1334 delete :destroy, :id => @scroll.id
1335 response.should redirect_to('/home/scroll')
1340 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
1342 it 'ステータスコード200 OKを返す' do
1343 delete :destroy, :id => @scroll.id, :format => :json
1344 response.should be_success
1346 it 'ページ本体は特に返さない' do
1347 delete :destroy, :id => @scroll.id, :format => :json
1348 response.body.should match /./
1352 context 'ユーザ権限がないとき' do
1356 it 'ステータスコード302 Foundを返す' do
1357 delete :destroy, :id => @scroll.id
1358 response.status.should eq 302
1361 it 'サインインページへ遷移する' do
1362 delete :destroy, :id => @scroll.id
1363 response.body.should redirect_to '/users/sign_in'
1367 it '応答メッセージにUnauthorizedを返す' do
1368 delete :destroy, :id => @scroll.id, :format => :json
1369 response.message.should match(/Unauthorized/)