1 # -*- encoding: utf-8 -*-
4 describe ScrollsController do
6 @admin =FactoryGirl.create :admin
7 @author_yas = FactoryGirl.create :yas_with_scrolls
8 @user_yas = @author_yas.user
9 @user_rom = FactoryGirl.create :user_rom
12 if Manifest.manifest.magic_numbers['run_mode'] == 1
13 describe '一覧表示に於いて' do
21 it 'ステータス OKを返して、ファイラーまたはjsonデータを返す。' do
22 list_should_return_filer_or_json :index
24 it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
26 expect(assigns(:my_model_class)).to be Scroll
28 it 'リストグループのマニフェストから新着リストの取得処理を@listに取得している' do
30 expect(assigns(:list).item_name).to eq('scroll')
31 expect(assigns(:list).list_name).to eq('public')
33 it '@itemsにリストを取得している' do
35 expect(assigns(:items).size).to be >= 3
38 it '@filerにファイラーを取得している' do
40 expect(assigns(:filer).class).to be Locmare::Filer
44 it '@filerにファイラーをセットしていない' do
45 get :index, format: :json
46 expect(assigns(:filer)).to be nil
55 return_ok_at_get :count, format: :json
59 get :count, format: :json
60 expect {JSON.parse(response.body)}.not_to raise_error
64 context 'サインインの状態が例外的なとき' do
65 it 'ユーザではなく管理者でも通常通り応答する' do
67 return_ok_at_get :index
68 return_ok_at_get :index, format: :json
70 it '創作活動してないROM専の読者にも通常通り応答する' do
72 return_ok_at_get :index
73 return_ok_at_get :index, format: :json
75 it 'ゲスト(サインインしていない)はサインインページに遷移する' do
76 announce_sign_in_at_get :index
80 describe '作家フィルタ一覧及びカウント' do
87 it '@itemsにリストを取得している' do
89 expect(assigns(:items).size).to be >= 3
91 it 'ステータスコード200 OKを返す' do
92 list_should_return_filer_or_json :by_author, id: @author_yas.id
96 it 'ユーザ権限はないが管理者権限があるとき 200 OKを返す' do
98 return_ok_at_get :by_author, id: @author_yas.id
99 return_ok_at_get :by_author, id: @author_yas.id, format: :json
101 it 'ユーザだが作家登録していないとき 200 OKを返す' do
103 return_ok_at_get :by_author, id: @author_yas.id
104 return_ok_at_get :by_author, id: @author_yas.id, format: :json
107 announce_sign_in_at_get :by_author, id: @author_yas.id
112 describe '単体表示に於いて' do
114 @item = @author_yas.scrolls.first
117 context '正常系の共通処理' do
121 it '[html, json, prof]でステータスコード200 OKを返す' do
122 return_ok_at_get :show, id: @item_id
123 return_ok_at_get :show, id: @item_id, format: :json
124 return_ok_at_get :show, id: @item_id, format: :prof
126 it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
127 get :show, id: @item_id
128 expect(assigns(:my_model_class)).to be Scroll
130 it '@itemにリクエストしたアイテムを取得している' do
131 get :show, id: @item_id
132 expect(assigns(:item)).to eq(@item)
135 it 'showテンプレートを描画する' do
136 get :show, id: @item_id
137 expect(response).to render_template("show")
142 get :show, id: @item_id, format: :json
143 expect {JSON.parse(response.body)}.not_to raise_error
145 it 'プロファイラーは必要ないので@profilerに用意していない' do
146 get :show, id: @item_id, format: :json
147 expect(assigns(:profiler)).to be nil
151 it 'プロファイラーテンプレートを描画する' do
152 get :show, id: @item_id, format: :prof
153 expect(response).to render_template("templates/r/profiler/profiler")
157 context 'サインインの状態が例外的なとき' do
158 it 'ユーザではなく管理者でも通常通り応答する' do
160 return_ok_at_get :show, id: @item_id
161 return_ok_at_get :show, id: @item_id, format: :json
163 it '創作活動してないROM専の読者にも通常通り応答する' do
165 return_ok_at_get :show, id: @item_id
166 return_ok_at_get :show, id: @item_id, format: :json
168 it 'ゲスト(サインインしていない)はサインインページに遷移する' do
169 announce_sign_in_at_get :show, id: @item_id
174 describe 'プレイリストに於いて' do
176 @item = @author_yas.scrolls.first
179 context '正常系の共通処理' do
183 it '[html, json]でステータス OKを返す' do
184 return_ok_at_get :play, id: @item_id
185 return_ok_at_get :play, id: @item_id, format: :json
187 it 'コントローラのマニフェストからScrollPanelモデルを@my_model_classに取得している' do
188 # リクエストの対象はスクロールであるが、返されるのはスクコマのリストである。
190 get :play, :id => @item_id
191 expect(assigns(:my_model_class)).to be ScrollPanel
193 it '@itemにリクエストしたスクロールを取得している' do
194 get :play, :id => @item_id
195 expect(assigns(:item)).to eq(@item)
197 it 'リストグループのマニフェストからプレイリストの取得処理を@listに取得している' do
198 get :play, :id => @item_id
199 expect(assigns(:list).item_name).to eq('scroll_panel')
200 expect(assigns(:list).list_name).to eq('play')
202 it '@itemsにプレイリストを取得している' do
203 get :play, :id => @item_id
204 expect(assigns(:items).size).to be >= 3
205 expect(assigns(:count)).to be >= 3
206 expect(assigns(:pager)).to be nil
209 it 'playテンプレートを描画する' do
210 get :play, :id => @item_id
211 expect(response).to render_template("play")
216 get :play, :id => @item_id, :format => :json
217 expect {JSON.parse(response.body)}.not_to raise_error
221 context 'サインインの状態が例外的なとき' do
222 it 'ユーザではなく管理者でも通常通り応答する' do
224 return_ok_at_get :play, id: @item_id
225 return_ok_at_get :play, id: @item_id, format: :json
227 it '創作活動してないROM専の読者にも通常通り応答する' do
229 return_ok_at_get :play, id: @item_id
230 return_ok_at_get :play, id: @item_id, format: :json
232 it 'ゲスト(サインインしていない)はサインインページに遷移する' do
233 announce_sign_in_at_get :play, id: @item_id
238 describe '新規作成フォーム表示に於いて' do
240 @item = @author_yas.scrolls.first
243 context '正常系の共通処理' do
247 it '[html, json]でステータス OKを返す' do
248 return_ok_at_get :new
249 return_ok_at_get :new, format: :json
251 it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
253 expect(assigns(:my_model_class)).to be Scroll
255 it '@itemに新規データを用意している' do
257 expect(assigns(:item)).to eq(@item)
259 it '@formに入力フォーム(Bucket)を取得している' do
261 expect(assigns(:form).item).to eq(@item)
262 expect(assigns(:form).mounted).to eq(true)
263 expect(assigns(:form).submit).to eq(true)
265 it 'スクロールモデルにデフォルト値補充とブーストを依頼している' do
266 expect_any_instance_of(Scroll).to receive(:supply_default)
267 expect_any_instance_of(Scroll).to receive(:boosts)
271 it 'formテンプレートを描画する' do
273 expect(response).to render_template("templates/r/form/form")
278 get :new, format: :json
279 expect {JSON.parse(response.body)}.not_to raise_error
283 context 'サインインの状態が例外的なとき' do
287 it '創作活動してないROM専の読者には作家登録ページへ遷移する' do
289 expect(response.status).to eq(302)
290 expect(response).to redirect_to new_author_path
291 return_ok_at_get :play, id: @item_id, format: :json
293 it 'ゲスト(サインインしていない)はサインインページに遷移する' do
294 announce_sign_in_at_get :new, id: @item_id
296 it 'ユーザではなく管理者でもサインインページに遷移する' do
298 announce_sign_in_at_get :new, id: @item_id
301 context 'ユーザだが作家登録していないとき' do
306 it 'ステータスコード302 Foundを返す' do
308 response.status.should eq 302
312 response.body.should redirect_to new_author_path
318 describe '新規作成に於いて' do
321 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
323 context '事前チェックしておく' do
324 it 'スクロールモデルにデフォルト値補充を依頼している' do
325 Scroll.any_instance.should_receive(:supply_default).exactly(1)
326 post :create, :scroll => @attr
328 it 'スクロールモデルにカラム値復元を依頼している' do
329 Scroll.any_instance.should_receive(:attributes=).exactly(1)
330 post :create, :scroll => @attr
332 it 'スクロールモデルに上書き補充を依頼している' do
333 Scroll.any_instance.should_receive(:overwrite).exactly(1)
334 post :create, :scroll => @attr
337 Scroll.any_instance.should_receive(:save).exactly(1)
338 post :create, :scroll => @attr
341 context '正常系の共通処理' do
342 it "@scrollに作成されたスクロールを保持していて、それがDBにある" do
343 post :create, :scroll => @attr
344 assigns(:scroll).should be_a(Scroll)
345 assigns(:scroll).should be_persisted
348 it 'ステータスコード302 Foundを返す' do
349 Scroll.any_instance.stub(:save).and_return(true)
350 post :create, :scroll => @attr
351 response.status.should eq 302
353 it '作成されたスクロールの表示ページへ遷移する' do
354 # Scroll.any_instance.stub(:save).and_return(true)
355 post :create, :scroll => @attr
356 response.should redirect_to(Scroll.last)
360 it 'ステータスコード200 OKを返す' do
361 # Scroll.any_instance.stub(:save).and_return(true)
362 post :create, :scroll => @attr, :format => :json
363 response.should be_success
365 it '作成されたスクロールをjsonデータで返す' do
366 post :create, :scroll => @attr, :format => :json
367 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
370 post :create, :scroll => @attr, :format => :json
371 json = JSON.parse response.body
372 json["title"].should match(/normal/)
373 json["visible"].should_not be_nil
377 context 'ユーザ権限がないとき' do
382 it 'ステータスコード302 Foundを返す' do
383 post :create, :scroll => @attr
384 response.status.should eq 302
386 it 'サインインページへ遷移する' do
387 post :create, :scroll => @attr
388 response.body.should redirect_to '/users/sign_in'
392 it 'ステータスコード401 Unauthorizedを返す' do
393 post :create, :scroll => @attr, :format => :json
394 response.status.should eq 401
396 it '応答メッセージにUnauthorizedを返す' do
397 post :create, :scroll => @attr, :format => :json
398 response.message.should match(/Unauthorized/)
402 context 'ユーザ権限はないが管理者権限があるとき' do
408 it 'ステータスコード302 Foundを返す' do
409 post :create, :scroll => @attr
410 response.status.should eq 302
412 it 'サインインページへ遷移する' do
413 post :create, :scroll => @attr
414 response.body.should redirect_to '/users/sign_in'
418 context 'ユーザだが作家登録していないとき' do
423 it 'ステータスコード302 Foundを返す' do
424 post :create, :scroll => @attr
425 response.status.should eq 302
428 post :create, :scroll => @attr
429 response.body.should redirect_to new_author_path
433 context '検証、保存に失敗した' do
435 Scroll.any_instance.stub(:save).and_return(false)
437 it "未保存のスクロールを保持している" do
438 post :create, :scroll => @attr
439 assigns(:scroll).should be_a_new(Scroll)
442 it 'ステータスコード200 OKを返す' do
443 post :create, :scroll => @attr
444 response.status.should eq 200
447 post :create, :scroll => @attr
448 response.should render_template("new")
452 it 'ステータスコード422 unprocessable_entity を返す' do
453 post :create, :scroll => @attr, :format => :json
454 response.status.should eq 422
456 it '応答メッセージUnprocessable Entityを返す' do
457 post :create, :scroll => @attr, :format => :json
458 response.message.should match(/Unprocessable/)
464 describe '編集フォーム表示に於いて' do
466 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
468 Scroll.stub(:edit).and_return(@scroll)
470 context '正常系の共通処理' do
471 it 'ステータスコード200 OKを返す' do
472 get :edit, :id => @scroll.id
473 response.should be_success
475 it 'スクロールモデルに編集取得を問い合わせている' do
476 Scroll.should_receive(:edit).exactly(1)
477 get :edit, :id => @scroll.id
479 it '@scrollにデータを用意している' do
480 get :edit, :id => @scroll.id
481 assigns(:scroll).should eq @scroll
484 it 'editテンプレートを描画する' do
485 get :edit, :id => @scroll.id
486 response.should render_template("edit")
490 it 'edit.jsテンプレートを描画する' do
491 get :edit, :id => @scroll.id, :format => :js
492 response.should render_template("edit")
496 context 'ユーザ権限がないとき' do
501 it 'ステータスコード302 Foundを返す' do
502 get :edit, :id => @scroll.id
503 response.status.should eq 302
505 it 'サインインページへ遷移する' do
506 get :edit, :id => @scroll.id
507 response.body.should redirect_to '/users/sign_in'
511 it 'ステータスコード401 Unauthorizedを返す' do
512 get :edit, :id => @scroll.id, :format => :js
513 response.status.should eq 401
515 it '応答メッセージにUnauthorizedを返す' do
516 get :edit, :id => @scroll.id, :format => :js
517 response.message.should match(/Unauthorized/)
521 context 'ユーザ権限はないが管理者権限があるとき' do
527 it 'ステータスコード302 Foundを返す' do
528 get :edit, :id => @scroll.id
529 response.status.should eq 302
531 it 'サインインページへ遷移する' do
532 get :edit, :id => @scroll.id
533 response.body.should redirect_to '/users/sign_in'
537 context 'ユーザだが作家登録していないとき' do
542 it 'ステータスコード302 Foundを返す' do
543 get :edit, :id => @scroll.id
544 response.status.should eq 302
547 get :edit, :id => @scroll.id
548 response.body.should redirect_to new_author_path
556 @scroll = FactoryGirl.create :scroll, :author => @author
557 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
560 context '事前チェックしておく' do
561 it 'スクロールモデルに編集取得を問い合わせている' do
562 Scroll.stub(:edit).with(any_args()).and_return @scroll
563 Scroll.should_receive(:edit).exactly(1)
564 put :update, :id => @scroll.id, :scroll => @attr
566 it 'スクロールモデルにカラム値復元を依頼している' do
567 Scroll.any_instance.should_receive(:attributes=).exactly(1)
568 put :update, :id => @scroll.id, :scroll => @attr
570 it 'スクロールモデルに上書き補充を依頼している' do
571 Scroll.any_instance.should_receive(:overwrite).exactly(1)
572 put :update, :id => @scroll.id, :scroll => @attr
575 Scroll.any_instance.stub(:save).with(any_args).and_return true
576 Scroll.any_instance.should_receive(:save).exactly(1)
577 put :update, :id => @scroll.id, :scroll => @attr
579 it '@scrollにアレを取得している' do
580 put :update, :id => @scroll.id, :scroll => @attr
581 assigns(:scroll).id.should eq(@scroll.id)
584 context '正常系の共通処理' do
586 put :update, :id => @scroll.id, :scroll => @attr
587 Scroll.find(@scroll.id).visible.should eq 0
590 it 'ステータスコード302 Foundを返す' do
591 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
592 put :update, :id => @scroll.id, :scroll => @attr
593 response.status.should eq 302
595 it '更新されたスクロールの表示ページへ遷移する' do
596 put :update, :id => @scroll.id, :scroll => @attr
597 response.should redirect_to(@scroll)
601 it 'ステータスコード200 OKを返す' do
602 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
603 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
604 response.should be_success
607 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
608 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
609 response.body.should match /./
613 context 'ユーザ権限がないとき' do
618 it 'ステータスコード302 Foundを返す' do
619 put :update, :id => @scroll.id, :scroll => @attr
620 response.status.should eq 302
622 it 'サインインページへ遷移する' do
623 put :update, :id => @scroll.id, :scroll => @attr
624 response.body.should redirect_to '/users/sign_in'
628 it '応答メッセージにUnauthorizedを返す' do
629 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
630 response.message.should match(/Unauthorized/)
634 context 'ユーザ権限はないが管理者権限があるとき' do
640 it 'ステータスコード302 Foundを返す' do
641 put :update, :id => @scroll.id, :scroll => @attr
642 response.status.should eq 302
644 it 'サインインページへ遷移する' do
645 put :update, :id => @scroll.id, :scroll => @attr
646 response.body.should redirect_to '/users/sign_in'
650 context 'ユーザだが作家登録していないとき' do
655 it 'ステータスコード302 Foundを返す' do
656 put :update, :id => @scroll.id, :scroll => @attr
657 response.status.should eq 302
660 put :update, :id => @scroll.id, :scroll => @attr
661 response.body.should redirect_to new_author_path
665 context '検証、保存に失敗したとき' do
667 Scroll.any_instance.stub(:save).and_return(false)
670 it 'ステータスコード200 Okを返す' do
671 put :update, :id => @scroll.id, :scroll => @attr
672 response.status.should eq 200
675 put :update, :id => @scroll.id, :scroll => @attr
676 response.should render_template("edit")
680 it 'ステータスコード422 unprocessable_entity を返す' do
681 Scroll.any_instance.stub(:save).and_return(false)
682 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
683 response.status.should eq 422
685 it '応答メッセージUnprocessable Entityを返す' do
686 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
687 response.message.should match(/Unprocessable/)
695 @scroll = FactoryGirl.create :scroll, :author => @author
698 context '事前チェックしておく' do
700 Scroll.stub(:edit).with(any_args()).and_return @scroll
701 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
703 it 'スクロールモデルに編集取得を問い合わせている' do
704 Scroll.should_receive(:edit).exactly(1)
705 delete :destroy, :id => @scroll.id
708 Scroll.any_instance.should_receive(:destroy_with_scroll_panel).exactly(1)
709 delete :destroy, :id => @scroll.id
711 it '@scrollにアレを取得している' do
712 delete :destroy, :id => @scroll.id
713 assigns(:scroll).id.should eq(@scroll.id)
716 context '正常系の共通処理' do
719 delete :destroy, :id => @scroll.id
720 }.should change Scroll, :count
724 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
726 it 'ステータスコード302 Foundを返す' do
727 delete :destroy, :id => @scroll.id
728 response.status.should eq 302
730 it 'マイスクロールの一覧ページへ遷移する' do
731 delete :destroy, :id => @scroll.id
732 response.should redirect_to('/home/scrolls')
737 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
739 it 'ステータスコード200 OKを返す' do
740 delete :destroy, :id => @scroll.id, :format => :json
741 response.should be_success
744 delete :destroy, :id => @scroll.id, :format => :json
745 response.body.should match /./
749 context 'ユーザ権限がないとき' do
754 it 'ステータスコード302 Foundを返す' do
755 delete :destroy, :id => @scroll.id
756 response.status.should eq 302
758 it 'サインインページへ遷移する' do
759 delete :destroy, :id => @scroll.id
760 response.body.should redirect_to '/users/sign_in'
764 it '応答メッセージにUnauthorizedを返す' do
765 delete :destroy, :id => @scroll.id, :format => :json
766 response.message.should match(/Unauthorized/)
770 context 'ユーザ権限はないが管理者権限があるとき' do
776 it 'ステータスコード302 Foundを返す' do
777 delete :destroy, :id => @scroll.id
778 response.status.should eq 302
780 it 'サインインページへ遷移する' do
781 delete :destroy, :id => @scroll.id
782 response.body.should redirect_to '/users/sign_in'
786 context 'ユーザだが作家登録していないとき' do
791 it 'ステータスコード302 Foundを返す' do
792 delete :destroy, :id => @scroll.id
793 response.status.should eq 302
796 delete :destroy, :id => @scroll.id
797 response.body.should redirect_to new_author_path
801 context '削除に失敗したとき' do
803 Scroll.any_instance.stub(:destroy_with_scroll_panel).and_return(false)
806 it 'ステータスコード302 Foundを返す' do
807 delete :destroy, :id => @scroll.id
808 response.status.should eq 302
810 it 'そのスクロールの詳細ページへ遷移する' do
811 delete :destroy, :id => @scroll.id
812 response.should redirect_to(scroll_path(@scroll))
816 it 'ステータスコード422 unprocessable_entity を返す' do
817 delete :destroy, :id => @scroll.id, :format => :json
818 response.status.should eq 422
820 it '応答メッセージUnprocessable Entityを返す' do
821 delete :destroy, :id => @scroll.id, :format => :json
822 response.message.should match(/Unprocessable/)
829 describe '一覧表示に於いて' do
831 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
832 Scroll.stub(:list).and_return([@scroll, @scroll, @scroll])
835 context '正常系の共通処理' do
836 it 'ステータスコード200 OKを返す' do
838 response.should be_success
841 it 'indexテンプレートを描画する' do
843 response.should render_template("index")
848 get :index, :format => :json
849 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
853 context 'ユーザ権限がないとき' do
857 it 'ステータスコード200 OKを返す' do
859 response.should be_success
862 it 'indexテンプレートを描画する' do
864 response.should render_template("index")
869 get :index, :format => :json
870 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
876 describe '単体表示に於いて' do
878 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id, :title => 'normal'
879 Scroll.stub(:show).and_return(@scroll)
882 context '正常系の共通処理' do
883 it 'ステータスコード200 OKを返す' do
884 get :show, :id => @scroll.id
885 response.should be_success
888 it 'showテンプレートを描画する' do
889 get :show, :id => @scroll.id
890 response.should render_template("show")
895 get :show, :id => @scroll.id, :format => :json
896 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
900 context 'ユーザ権限がないとき' do
904 it 'ステータスコード200 OKを返す' do
905 get :show, :id => @scroll.id
906 response.should be_success
909 it 'showテンプレートを描画する' do
910 get :show, :id => @scroll.id
911 response.should render_template("show")
916 get :show, :id => @scroll.id, :format => :json
917 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
922 describe 'スクロール数取得に於いて' do
924 Scroll.should_receive(:visible_count).and_return(3)
927 context '正常系の共通処理' do
928 it 'ステータスコード200 OKを返す' do
929 get :count, :format => :json
930 response.should be_success
934 get :count, :format => :json
935 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
941 describe '新規作成フォーム表示に於いて' do
945 context '正常系の共通処理' do
946 it 'ステータスコード200 OKを返す' do
948 response.should be_success
951 it 'newテンプレートを描画する' do
953 response.should render_template("new")
957 it 'new.jsテンプレートを描画する' do
958 get :new, :format => :js
959 response.should render_template("new")
964 get :new, :format => :json
965 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
969 context 'ユーザ権限がないとき' do
974 it 'ステータスコード302 Foundを返す' do
976 response.status.should eq 302
978 it 'サインインページへ遷移する' do
980 response.body.should redirect_to '/users/sign_in'
984 it 'ステータスコード401 Unauthorizedを返す' do
985 get :new, :format => :js
986 response.status.should eq 401
988 it '応答メッセージにUnauthorizedを返す' do
989 get :new, :format => :js
990 response.message.should match(/Unauthorized/)
994 it 'ステータスコード401 Unauthorizedを返す' do
995 get :new, :format => :json
996 response.status.should eq 401
998 it '応答メッセージにUnauthorizedを返す' do
999 get :new, :format => :json
1000 response.message.should match(/Unauthorized/)
1006 describe '新規作成に於いて' do
1009 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
1011 context '正常系の共通処理' do
1013 it 'ステータスコード302 Foundを返す' do
1014 Scroll.any_instance.stub(:save).and_return(true)
1015 post :create, :scroll => @attr
1016 response.status.should eq 302
1018 it '作成されたスクロールの表示ページへ遷移する' do
1019 # Scroll.any_instance.stub(:save).and_return(true)
1020 post :create, :scroll => @attr
1021 response.should redirect_to(Scroll.last)
1025 it 'ステータスコード200 OKを返す' do
1026 # Scroll.any_instance.stub(:save).and_return(true)
1027 post :create, :scroll => @attr, :format => :json
1028 response.should be_success
1030 it '作成されたスクロールをjsonデータで返す' do
1031 post :create, :scroll => @attr, :format => :json
1032 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1036 context 'ユーザ権限がないとき' do
1041 it 'ステータスコード302 Foundを返す' do
1042 post :create, :scroll => @attr
1043 response.status.should eq 302
1045 it 'サインインページへ遷移する' do
1046 post :create, :scroll => @attr
1047 response.body.should redirect_to '/users/sign_in'
1051 it 'ステータスコード401 Unauthorizedを返す' do
1052 post :create, :scroll => @attr, :format => :json
1053 response.status.should eq 401
1055 it '応答メッセージにUnauthorizedを返す' do
1056 post :create, :scroll => @attr, :format => :json
1057 response.message.should match(/Unauthorized/)
1063 describe '編集フォーム表示に於いて' do
1065 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
1067 Scroll.stub(:edit).and_return(@scroll)
1069 context '正常系の共通処理' do
1070 it 'ステータスコード200 OKを返す' do
1071 get :edit, :id => @scroll.id
1072 response.should be_success
1075 it 'editテンプレートを描画する' do
1076 get :edit, :id => @scroll.id
1077 response.should render_template("edit")
1081 it 'edit.jsテンプレートを描画する' do
1082 get :edit, :id => @scroll.id, :format => :js
1083 response.should render_template("edit")
1087 context 'ユーザ権限がないとき' do
1092 it 'ステータスコード302 Foundを返す' do
1093 get :edit, :id => @scroll.id
1094 response.status.should eq 302
1096 it 'サインインページへ遷移する' do
1097 get :edit, :id => @scroll.id
1098 response.body.should redirect_to '/users/sign_in'
1102 it 'ステータスコード401 Unauthorizedを返す' do
1103 get :edit, :id => @scroll.id, :format => :js
1104 response.status.should eq 401
1106 it '応答メッセージにUnauthorizedを返す' do
1107 get :edit, :id => @scroll.id, :format => :js
1108 response.message.should match(/Unauthorized/)
1114 describe '更新に於いて' do
1116 @scroll = FactoryGirl.create :scroll, :author => @author
1117 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
1120 context '正常系の共通処理' do
1122 it 'ステータスコード302 Foundを返す' do
1123 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1124 put :update, :id => @scroll.id, :scroll => @attr
1125 response.status.should eq 302
1127 it '更新されたスクロールの表示ページへ遷移する' do
1128 put :update, :id => @scroll.id, :scroll => @attr
1129 response.should redirect_to(@scroll)
1133 it 'ステータスコード200 OKを返す' do
1134 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1135 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
1136 response.should be_success
1138 it 'ページ本体は特に返さない' do
1139 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1140 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
1141 response.body.should match /./
1145 context 'ユーザ権限がないとき' do
1149 it 'ステータスコード302 Foundを返す' do
1150 put :update, :id => @scroll.id, :scroll => @attr
1151 response.status.should eq 302
1154 it 'サインインページへ遷移する' do
1155 put :update, :id => @scroll.id, :scroll => @attr
1156 response.body.should redirect_to '/users/sign_in'
1162 describe '削除に於いて' do
1164 @scroll = FactoryGirl.create :scroll, :author => @author
1167 context '正常系の共通処理' do
1170 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
1172 it 'ステータスコード302 Foundを返す' do
1173 delete :destroy, :id => @scroll.id
1174 response.status.should eq 302
1176 it 'マイスクロールの一覧ページへ遷移する' do
1177 delete :destroy, :id => @scroll.id
1178 response.should redirect_to('/home/scroll')
1183 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
1185 it 'ステータスコード200 OKを返す' do
1186 delete :destroy, :id => @scroll.id, :format => :json
1187 response.should be_success
1189 it 'ページ本体は特に返さない' do
1190 delete :destroy, :id => @scroll.id, :format => :json
1191 response.body.should match /./
1195 context 'ユーザ権限がないとき' do
1199 it 'ステータスコード302 Foundを返す' do
1200 delete :destroy, :id => @scroll.id
1201 response.status.should eq 302
1204 it 'サインインページへ遷移する' do
1205 delete :destroy, :id => @scroll.id
1206 response.body.should redirect_to '/users/sign_in'
1210 it '応答メッセージにUnauthorizedを返す' do
1211 delete :destroy, :id => @scroll.id, :format => :json
1212 response.message.should match(/Unauthorized/)