1 # -*- encoding: utf-8 -*-
4 describe StorySheetsController 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 @comic = FactoryGirl.create :comic, :author_id => @user.author.id
13 @story = FactoryGirl.create :story, :comic_id => @comic.id
14 @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
17 if MagicNumber['run_mode'] == 1
18 describe '一覧表示に於いて' do
21 @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
22 StorySheet.stub(:list).and_return([@story_sheet, @story_sheet, @story_sheet])
24 context 'パラメータpageについて' do
26 get :index, :page => 5
27 assigns(:page).should eq 5
29 it '省略されると@pageに1値が入る' do
31 assigns(:page).should eq 1
33 it '与えられたpage_sizeがセットされている' do
34 get :index, :page_size => 15
35 assigns(:page_size).should eq 15
37 it '省略されると@page_sizeにデフォルト値が入る' do
39 assigns(:page_size).should eq StorySheet.default_page_size
41 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
42 get :index, :page_size => 1500
43 assigns(:page_size).should eq StorySheet.max_page_size
45 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
46 get :index, :page_size => 0
47 assigns(:page_size).should eq StorySheet.default_page_size
50 context 'つつがなく終わるとき' do
51 it 'ステータスコード200 OKを返す' do
53 response.should be_success
55 it 'スト紙モデルに一覧を問い合わせている' do
56 StorySheet.should_receive(:list).exactly(1)
59 it '@story_sheetsにリストを取得している' do
61 assigns(:story_sheets).should have_at_least(3).items
64 it '@paginateにページ制御を取得している' do
66 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
68 it 'indexテンプレートを描画する' do
70 response.should render_template("index")
75 get :index, :format => :json
76 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
78 it 'スト紙モデルにjson一覧出力オプションを問い合わせている' do
79 StorySheet.should_receive(:list_json_opt).exactly(1)
80 get :index, :format => :json
82 it 'データがリスト構造になっている' do
83 get :index, :format => :json
84 json = JSON.parse response.body
85 json.should have_at_least(3).items
87 it 'リストの先頭くらいはスト紙っぽいものであって欲しい' do
88 get :index, :format => :json
89 json = JSON.parse response.body
90 json.first.has_key?("story_id").should be_true
91 json.first.has_key?("sheet_id").should be_true
92 json.first.has_key?("t").should be_true
96 context 'ユーザ権限がないとき' do
101 it 'ステータスコード302 Foundを返す' do
103 response.status.should eq 302
105 it 'サインインページへ遷移する' do
107 response.should redirect_to '/users/sign_in'
111 it 'ステータスコード401 Unauthorizedを返す' do
112 get :index, :format => :json
113 response.status.should eq 401
115 it '応答メッセージにUnauthorizedを返す' do
116 get :index, :format => :json
117 response.message.should match(/Unauthorized/)
121 context 'ユーザ権限はないが管理者権限があるとき' do
126 it 'ステータスコード200 OKを返す' do
128 response.should be_success
131 context 'ユーザだが作家登録していないとき' do
135 it 'ステータスコード200 OKを返す' do
137 response.should be_success
142 describe '単体表示に於いて' do
145 @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
146 Sheet.stub(:show).with(@sheet.id.to_s, [@user, nil]).and_return(@sheet)
147 Sheet.stub(:show).with(@sheet.id.to_s, [nil, @admin]).and_return(@sheet)
148 StorySheet.stub(:show).with(@story_sheet.id.to_s, [@user, nil]).and_return(@story_sheet)
149 StorySheet.stub(:show).with(@story_sheet.id.to_s, [nil, @admin]).and_return(@story_sheet)
151 context 'つつがなく終わるとき' do
152 it 'スト紙モデルに単体取得を問い合わせている' do
153 StorySheet.should_receive(:show).with(@story_sheet.id.to_s, [@user, nil]).exactly(1)
154 get :show, :id => @story_sheet.id
156 it '@story_sheetにアレを取得している' do
157 get :show, :id => @story_sheet.id
158 assigns(:story_sheet).should eq @story_sheet
161 it 'ステータスコード200 OKを返す' do
162 get :show, :id => @story_sheet.id
163 response.should be_success
165 it 'showテンプレートを描画する' do
166 get :show, :id => @story_sheet.id
167 response.should render_template("show")
171 it 'ステータスコード200 OKを返す' do
172 get :show, :id => @story_sheet.id, :format => :json
173 response.should be_success
176 get :show, :id => @story_sheet.id, :format => :json
177 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
179 it 'スト紙モデルにjson単体出力オプションを問い合わせている' do
180 StorySheet.should_receive(:show_json_opt).exactly(1)
181 get :show, :id => @story_sheet.id, :format => :json
184 get :show, :id => @story_sheet.id, :format => :json
185 json = JSON.parse response.body
186 json.has_key?("story_id").should be_true
187 json.has_key?("sheet_id").should be_true
188 json.has_key?("author_id").should be_true
192 context 'ユーザ権限がないとき' do
197 it 'ステータスコード302 Foundを返す' do
198 get :show, :id => @story_sheet.id
199 response.status.should eq 302
201 it 'サインインページへ遷移する' do
202 get :show, :id => @story_sheet.id
203 response.body.should redirect_to '/users/sign_in'
207 it 'ステータスコード401 Unauthorizedを返す' do
208 get :show, :id => @story_sheet.id, :format => :json
209 response.status.should eq 401
211 it '応答メッセージにUnauthorizedを返す' do
212 get :show, :id => @story_sheet.id, :format => :json
213 response.message.should match(/Unauthorized/)
217 context 'ユーザ権限はないが管理者権限があるとき' do
222 it 'ステータスコード200 OKを返す' do
223 get :show, :id => @story_sheet.id
224 response.should be_success
227 context 'ユーザだが作家登録していないとき' do
231 it 'ステータスコード200 OKを返す' do
232 get :show, :id => @story_sheet.id
233 response.should be_success
238 describe '新規作成フォーム表示に於いて' do
242 context 'つつがなく終わるとき' do
243 it '@story_sheetに新規データを用意している' do
245 assigns(:story_sheet).should be_a_new(StorySheet)
247 it 'モデルにデフォルト値補充を依頼している' do
248 StorySheet.any_instance.should_receive(:supply_default).exactly(1)
252 it 'ステータスコード200 OKを返す' do
254 response.should be_success
256 it 'newテンプレートを描画する' do
258 response.should render_template("new")
262 it 'ステータスコード200 OKを返す' do
263 get :new, :format => :js
264 response.should be_success
266 it 'new.jsテンプレートを描画する' do
267 get :new, :format => :js
268 response.should render_template("new")
272 it 'ステータスコード200 OKを返す' do
273 get :new, :format => :json
274 response.should be_success
277 get :new, :format => :json
278 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
280 it 'スト紙モデルにjson単体出力オプションを問い合わせている' do
281 StorySheet.should_receive(:show_json_opt).exactly(1)
282 get :new, :format => :json
285 get :new, :format => :json
286 json = JSON.parse response.body
287 json.has_key?("story_id").should be_true
288 json.has_key?("sheet_id").should be_true
289 json.has_key?("author_id").should be_true
293 context 'ユーザ権限がないとき' do
298 it 'ステータスコード302 Foundを返す' do
300 response.status.should eq 302
302 it 'サインインページへ遷移する' do
304 response.body.should redirect_to '/users/sign_in'
308 it 'ステータスコード401 Unauthorizedを返す' do
309 get :new, :format => :json
310 response.status.should eq 401
312 it '応答メッセージにUnauthorizedを返す' do
313 get :new, :format => :json
314 response.message.should match(/Unauthorized/)
318 context 'ユーザ権限はないが管理者権限があるとき' do
324 it 'ステータスコード302 Foundを返す' do
326 response.status.should eq 302
328 it 'サインインページへ遷移する' do
330 response.body.should redirect_to '/users/sign_in'
334 context 'ユーザだが作家登録していないとき' do
339 it 'ステータスコード302 Foundを返す' do
341 response.status.should eq 302
345 response.body.should redirect_to new_author_path
351 describe '新規作成に於いて' do
353 @attr = FactoryGirl.attributes_for(:story_sheet, :t => nil, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id)
356 context 'つつがなく終わるとき' do
357 it 'デフォルト値補充を依頼する' do
358 StorySheet.any_instance.should_receive(:supply_default).exactly(1)
359 post :create, :story_sheet => @attr
361 it 'POSTデータから、カラム値を復元している' do
362 StorySheet.any_instance.stub(:store).and_return(true)
363 post :create, :story_sheet => @attr
364 assigns(:story_sheet).story_id.should eq @story.id
365 assigns(:story_sheet).sheet_id.should eq @sheet.id
368 StorySheet.any_instance.should_receive(:overwrite).exactly(1)
369 post :create, :story_sheet => @attr
371 it 'ストーリーモデルに編集取得を依頼している' do
372 Story.stub(:edit).and_return(@story)
373 Story.should_receive(:edit).with(@story.id, @author).exactly(1)
374 post :create, :story_sheet => @attr
376 it '用紙モデルに単体取得を依頼している' do
377 Sheet.should_receive(:show).with(@sheet.id, @author).exactly(1)
378 post :create, :story_sheet => @attr
381 StorySheet.any_instance.should_receive(:store).exactly(1)
382 post :create, :story_sheet => @attr
384 it "@story_sheetに作成されたストーリーを保持していて、それがDBにある" do
385 post :create, :story_sheet => @attr
386 assigns(:story_sheet).should be_a(StorySheet)
387 assigns(:story_sheet).should be_persisted
390 it 'ステータスコード302 Foundを返す' do
391 StorySheet.any_instance.stub(:store).and_return(true)
392 post :create, :story_sheet => @attr
393 response.status.should eq 302
395 it 'ストーリーのスト紙表示へ遷移する' do
396 # StorySheet.any_instance.stub(:store).and_return(true)
397 post :create, :story_sheet => @attr
398 response.should redirect_to(play_story_path(@attr[:story_id]))
402 it 'ステータスコード200 OKを返す' do
403 # StorySheet.any_instance.stub(:store).and_return(true)
404 post :create, :story_sheet => @attr, :format => :json
405 response.should be_success
407 it '作成されたストーリーをjsonデータで返す' do
408 post :create, :story_sheet => @attr, :format => :json
409 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
411 it 'スト紙モデルにjson単体出力オプションを問い合わせている' do
412 StorySheet.should_receive(:show_json_opt).exactly(1)
413 post :create, :story_sheet => @attr, :format => :json
416 post :create, :story_sheet => @attr, :format => :json
417 json = JSON.parse response.body
418 json["t"].should eq 0
422 context 'ユーザ権限がないとき' do
427 it 'ステータスコード302 Foundを返す' do
428 post :create, :story_sheet => @attr
429 response.status.should eq 302
431 it 'サインインページへ遷移する' do
432 post :create, :story_sheet => @attr
433 response.body.should redirect_to '/users/sign_in'
437 it 'ステータスコード401 Unauthorizedを返す' do
438 post :create, :story_sheet => @attr, :format => :json
439 response.status.should eq 401
441 it '応答メッセージにUnauthorizedを返す' do
442 post :create, :story_sheet => @attr, :format => :json
443 response.message.should match(/Unauthorized/)
447 context 'ユーザ権限はないが管理者権限があるとき' do
453 it 'ステータスコード302 Foundを返す' do
454 post :create, :story_sheet => @attr
455 response.status.should eq 302
457 it 'サインインページへ遷移する' do
458 post :create, :story_sheet => @attr
459 response.body.should redirect_to '/users/sign_in'
463 context 'ユーザだが作家登録していないとき' do
468 it 'ステータスコード302 Foundを返す' do
469 post :create, :story_sheet => @attr
470 response.status.should eq 302
473 post :create, :story_sheet => @attr
474 response.body.should redirect_to new_author_path
478 context '検証、保存に失敗した' do
480 StorySheet.any_instance.stub(:store).and_return(false)
482 it "未保存のストーリーを保持している" do
483 post :create, :story_sheet => @attr
484 assigns(:story_sheet).should be_a_new(StorySheet)
487 it 'ステータスコード200 OKを返す' do
488 post :create, :story_sheet => @attr
489 response.status.should eq 200
492 post :create, :story_sheet => @attr
493 response.should render_template("new")
497 it 'ステータスコード422 unprocessable_entity を返す' do
498 post :create, :story_sheet => @attr, :format => :json
499 response.status.should eq 422
501 it '応答メッセージUnprocessable Entityを返す' do
502 post :create, :story_sheet => @attr, :format => :json
503 response.message.should match(/Unprocessable/)
509 describe '編集フォーム表示に於いて' do
511 @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id
513 StorySheet.stub(:show).and_return(@story_sheet)
515 context 'つつがなく終わるとき' do
516 it 'スト紙モデルに編集取得を問い合わせている' do
517 StorySheet.should_receive(:edit).exactly(1)
518 get :edit, :id => @story_sheet.id
520 it '@story_sheetにデータを用意している' do
521 get :edit, :id => @story_sheet.id
522 assigns(:story_sheet).should eq @story_sheet
525 it 'ステータスコード200 OKを返す' do
526 get :edit, :id => @story_sheet.id
527 response.should be_success
529 it 'editテンプレートを描画する' do
530 get :edit, :id => @story_sheet.id
531 response.should render_template("edit")
535 it 'ステータスコード200 OKを返す' do
536 get :edit, :id => @story_sheet.id, :format => :js
537 response.should be_success
539 it 'edit.jsテンプレートを描画する' do
540 get :edit, :id => @story_sheet.id, :format => :js
541 response.should render_template("edit")
545 context 'ユーザ権限がないとき' do
550 it 'ステータスコード302 Foundを返す' do
551 get :edit, :id => @story_sheet.id
552 response.status.should eq 302
554 it 'サインインページへ遷移する' do
555 get :edit, :id => @story_sheet.id
556 response.body.should redirect_to '/users/sign_in'
560 it 'ステータスコード401 Unauthorizedを返す' do
561 get :edit, :id => @story_sheet.id, :format => :js
562 response.status.should eq 401
564 it '応答メッセージにUnauthorizedを返す' do
565 get :edit, :id => @story_sheet.id, :format => :js
566 response.message.should match(/Unauthorized/)
570 context 'ユーザ権限はないが管理者権限があるとき' do
576 it 'ステータスコード302 Foundを返す' do
577 get :edit, :id => @story_sheet.id
578 response.status.should eq 302
580 it 'サインインページへ遷移する' do
581 get :edit, :id => @story_sheet.id
582 response.body.should redirect_to '/users/sign_in'
586 context 'ユーザだが作家登録していないとき' do
591 it 'ステータスコード302 Foundを返す' do
592 get :edit, :id => @story_sheet.id
593 response.status.should eq 302
596 get :edit, :id => @story_sheet.id
597 response.body.should redirect_to new_author_path
605 @story_sheet = FactoryGirl.create :story_sheet, :author_id => @user.author.id
606 @attr = FactoryGirl.attributes_for(:story_sheet, :author_id => @author.id)
609 context 'つつがなく終わるとき' do
611 StorySheet.stub(:edit).with(any_args).and_return(@story_sheet)
612 StorySheet.should_receive(:edit).exactly(1)
613 put :update, :id => @story_sheet.id, :story_sheet => @attr
615 it 'POSTデータから、カラム値を復元している' do
616 StorySheet.any_instance.stub(:store).and_return(true)
617 StorySheet.any_instance.should_receive(:attributes=).exactly(1)
618 put :update, :id => @story_sheet.id, :story_sheet => @attr
621 StorySheet.any_instance.should_receive(:overwrite).exactly(1)
622 put :update, :id => @story_sheet.id, :story_sheet => @attr
625 StorySheet.any_instance.should_receive(:store).exactly(1)
626 put :update, :id => @story_sheet.id, :story_sheet => @attr
628 it "@story_sheetに作成されたスト紙を保持していて、それがDBにある" do
629 put :update, :id => @story_sheet.id, :story_sheet => @attr
630 assigns(:story_sheet).should be_a(StorySheet)
631 assigns(:story_sheet).should be_persisted
634 it 'ステータスコード302 Foundを返す' do
635 StorySheet.any_instance.stub(:store).and_return(true)
636 put :update, :id => @story_sheet.id, :story_sheet => @attr
637 response.status.should eq 302
640 # StorySheet.any_instance.stub(:store).and_return(true)
641 put :update, :id => @story_sheet.id, :story_sheet => @attr
642 response.should redirect_to(play_story_path(@attr[:story_id]))
646 it 'ステータスコード200 OKを返す' do
647 # StorySheet.any_instance.stub(:store).and_return(true)
648 put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
649 response.should be_success
653 context 'ユーザ権限がないとき' do
658 it 'ステータスコード302 Foundを返す' do
659 put :update, :id => @story_sheet.id, :story_sheet => @attr
660 response.status.should eq 302
662 it 'サインインページへ遷移する' do
663 put :update, :id => @story_sheet.id, :story_sheet => @attr
664 response.body.should redirect_to '/users/sign_in'
668 it 'ステータスコード401 Unauthorizedを返す' do
669 put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
670 response.status.should eq 401
672 it '応答メッセージにUnauthorizedを返す' do
673 put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
674 response.message.should match(/Unauthorized/)
678 context 'ユーザ権限はないが管理者権限があるとき' do
684 it 'ステータスコード302 Foundを返す' do
685 put :update, :id => @story_sheet.id, :story_sheet => @attr
686 response.status.should eq 302
688 it 'サインインページへ遷移する' do
689 put :update, :id => @story_sheet.id, :story_sheet => @attr
690 response.body.should redirect_to '/users/sign_in'
694 context 'ユーザだが作家登録していないとき' do
699 it 'ステータスコード302 Foundを返す' do
700 put :update, :id => @story_sheet.id, :story_sheet => @attr
701 response.status.should eq 302
704 put :update, :id => @story_sheet.id, :story_sheet => @attr
705 response.body.should redirect_to new_author_path
709 context '検証、保存に失敗した' do
711 StorySheet.any_instance.stub(:store).and_return(false)
713 it "指定のスト紙を保持している" do
714 put :update, :id => @story_sheet.id, :story_sheet => @attr
715 assigns(:story_sheet).should eq @story_sheet
718 it 'ステータスコード200 OKを返す' do
719 put :update, :id => @story_sheet.id, :story_sheet => @attr
720 response.status.should eq 200
723 put :update, :id => @story_sheet.id, :story_sheet => @attr
724 response.should render_template("edit")
728 it 'ステータスコード422 unprocessable_entity を返す' do
729 put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
730 response.status.should eq 422
732 it '応答メッセージUnprocessable Entityを返す' do
733 put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
734 response.message.should match(/Unprocessable/)
742 @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id
744 StorySheet.stub(:edit).and_return(@story_sheet)
746 context '事前チェックしておく' do
748 StorySheet.stub(:edit).with(any_args()).and_return @story_sheet
749 StorySheet.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
751 it 'スト紙モデルに編集取得を問い合わせている' do
752 StorySheet.should_receive(:edit).exactly(1)
753 delete :destroy, :id => @story_sheet.id
756 StorySheet.any_instance.should_receive(:destroy_and_shorten).exactly(1)
757 delete :destroy, :id => @story_sheet.id
759 it '@story_sheetにアレを取得している' do
760 delete :destroy, :id => @story_sheet.id
761 assigns(:story_sheet).id.should eq(@story_sheet.id)
764 context 'つつがなく終わるとき' do
766 StorySheet.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
769 it 'ステータスコード302 Foundを返す' do
770 delete :destroy, :id => @story_sheet.id
771 response.status.should eq 302
774 delete :destroy, :id => @story_sheet.id
775 response.should redirect_to(play_story_path(@story_sheet.story_id))
779 it 'ステータスコード200 OKを返す' do
780 delete :destroy, :id => @story_sheet.id, :format => :json
781 response.should be_success
785 context 'ユーザ権限がないとき' do
790 it 'ステータスコード302 Foundを返す' do
791 delete :destroy, :id => @story_sheet.id
792 response.status.should eq 302
794 it 'サインインページへ遷移する' do
795 delete :destroy, :id => @story_sheet.id
796 response.body.should redirect_to '/users/sign_in'
800 it 'ステータスコード401 Unauthorizedを返す' do
801 delete :destroy, :id => @story_sheet.id, :format => :json
802 response.status.should eq 401
804 it '応答メッセージにUnauthorizedを返す' do
805 delete :destroy, :id => @story_sheet.id, :format => :json
806 response.message.should match(/Unauthorized/)
810 context 'ユーザ権限はないが管理者権限があるとき' do
816 it 'ステータスコード302 Foundを返す' do
817 delete :destroy, :id => @story_sheet.id
818 response.status.should eq 302
820 it 'サインインページへ遷移する' do
821 delete :destroy, :id => @story_sheet.id
822 response.body.should redirect_to '/users/sign_in'
826 context 'ユーザだが作家登録していないとき' do
831 it 'ステータスコード302 Foundを返す' do
832 delete :destroy, :id => @story_sheet.id
833 response.status.should eq 302
836 delete :destroy, :id => @story_sheet.id
837 response.body.should redirect_to new_author_path
841 context '削除に失敗したとき' do
843 StorySheet.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(false)
846 it 'ステータスコード302 Foundを返す' do
847 delete :destroy, :id => @story_sheet.id
848 response.status.should eq 302
850 it 'その用紙の詳細ページへ遷移する' do
851 delete :destroy, :id => @story_sheet.id
852 response.should redirect_to(story_sheet_path(@story_sheet))
856 it 'ステータスコード422 unprocessable_entity を返す' do
857 delete :destroy, :id => @story_sheet.id, :format => :json
858 response.status.should eq 422
860 it '応答メッセージUnprocessable Entityを返す' do
861 delete :destroy, :id => @story_sheet.id, :format => :json
862 response.message.should match(/Unprocessable/)
867 context '対象スト紙がないとき' do
869 context '他人のスト紙だったとき' do
875 describe '一覧表示に於いて' do
878 @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :sheet_id => @sheet.id, :story_id => @story.id, :author_id => @author.id
879 StorySheet.stub(:list).and_return([@story_sheet, @story_sheet, @story_sheet])
881 context 'つつがなく終わるとき' do
882 it 'ステータスコード200 OKを返す' do
884 response.should be_success
887 it 'indexテンプレートを描画する' do
889 response.should render_template("index")
894 get :index, :format => :json
895 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
899 context 'ユーザ権限がないとき' do
903 it 'ステータスコード200 OKを返す' do
905 response.should be_success
908 it 'indexテンプレートを描画する' do
910 response.should render_template("index")
915 get :index, :format => :json
916 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
922 describe '単体表示に於いて' do
925 @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :sheet_id => @sheet.id, :story_id => @story.id, :author_id => @author.id
926 Sheet.stub(:show).with(@sheet.id.to_s, [nil, nil]).and_return(@sheet)
927 Sheet.stub(:show).with(@sheet.id.to_s, [@user, nil]).and_return(@sheet)
928 Sheet.stub(:show).with(@sheet.id.to_s, [nil, @admin]).and_return(@sheet)
929 StorySheet.stub(:show).with(@story_sheet.id.to_s, [nil, nil]).and_return(@story_sheet)
930 StorySheet.stub(:show).with(@story_sheet.id.to_s, [@user, nil]).and_return(@story_sheet)
931 StorySheet.stub(:show).with(@story_sheet.id.to_s, [nil, @admin]).and_return(@story_sheet)
933 context 'つつがなく終わるとき' do
935 it 'ステータスコード200 OKを返す' do
936 get :show, :id => @story_sheet.id
937 response.should be_success
939 it 'showテンプレートを描画する' do
940 get :show, :id => @story_sheet.id
941 response.should render_template("show")
945 it 'ステータスコード200 OKを返す' do
946 get :show, :id => @story_sheet.id, :format => :json
947 response.should be_success
950 get :show, :id => @story_sheet.id, :format => :json
951 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
955 context 'ユーザ権限がないとき' do
960 it 'ステータスコード200 OKを返す' do
961 get :show, :id => @story_sheet.id
962 response.should be_success
964 it 'showテンプレートを描画する' do
965 get :show, :id => @story_sheet.id
966 response.should render_template("show")
970 it 'ステータスコード200 OKを返す' do
971 get :show, :id => @story_sheet.id, :format => :json
972 response.should be_success
975 get :show, :id => @story_sheet.id, :format => :json
976 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
984 @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :sheet_id => @sheet.id, :story_id => @story.id, :author_id => @author.id
985 Sheet.stub(:show).with(@sheet.id.to_s, [nil, nil]).and_return(@sheet)
986 Sheet.stub(:show).with(@sheet.id.to_s, [@user, nil]).and_return(@sheet)
987 Sheet.stub(:show).with(@sheet.id.to_s, [nil, @admin]).and_return(@sheet)
988 StorySheet.stub(:count).and_return(10)
989 StorySheet.stub(:play_list).with(any_args).and_return([@story_sheet, @story_sheet, @story_sheet])
992 context 'つつがなく終わるとき' do
994 it 'ステータスコード200 OKを返す' do
995 get :sheet, :id => @sheet.id
996 response.should be_success
998 it 'sheetテンプレートを描画する' do
999 get :sheet, :id => @sheet.id
1000 response.should render_template("sheet")
1004 it 'ステータスコード200 OKを返す' do
1005 get :sheet, :id => @sheet.id, :format => :json
1006 response.should be_success
1009 get :sheet, :id => @sheet.id, :format => :json
1010 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1014 context 'ユーザ権限がないとき' do
1019 it 'ステータスコード200 OKを返す' do
1020 get :sheet, :id => @sheet.id
1021 response.should be_success
1023 it 'sheetテンプレートを描画する' do
1024 get :sheet, :id => @sheet.id
1025 response.should render_template("sheet")
1029 it 'ステータスコード200 OKを返す' do
1030 get :sheet, :id => @sheet.id, :format => :json
1031 response.should be_success
1034 get :sheet, :id => @sheet.id, :format => :json
1035 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1041 describe '新規作成フォーム表示に於いて' do
1045 context 'つつがなく終わるとき' do
1047 it 'ステータスコード200 OKを返す' do
1049 response.should be_success
1051 it 'newテンプレートを描画する' do
1053 response.should render_template("new")
1057 it 'ステータスコード200 OKを返す' do
1058 get :new, :format => :js
1059 response.should be_success
1061 it 'new.jsテンプレートを描画する' do
1062 get :new, :format => :js
1063 response.should render_template("new")
1067 it 'ステータスコード200 OKを返す' do
1068 get :new, :format => :json
1069 response.should be_success
1072 get :new, :format => :json
1073 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1077 context 'ユーザ権限がないとき' do
1082 it 'ステータスコード302 Foundを返す' do
1084 response.status.should eq 302
1086 it 'サインインページへ遷移する' do
1088 response.body.should redirect_to '/users/sign_in'
1092 it 'ステータスコード401 Unauthorizedを返す' do
1093 get :new, :format => :json
1094 response.status.should eq 401
1096 it '応答メッセージにUnauthorizedを返す' do
1097 get :new, :format => :json
1098 response.message.should match(/Unauthorized/)
1104 describe '新規作成に於いて' do
1106 @attr = FactoryGirl.attributes_for(:story_sheet, :t => nil, :sheet_id => @sheet.id, :story_id => @story.id, :author_id => @author.id)
1109 context 'つつがなく終わるとき' do
1111 it 'ステータスコード302 Foundを返す' do
1112 StorySheet.any_instance.stub(:store).and_return(true)
1113 post :create, :story_sheet => @attr
1114 response.status.should eq 302
1116 it '用紙のスト紙表示へ遷移する' do
1117 # StorySheet.any_instance.stub(:store).and_return(true)
1118 post :create, :story_sheet => @attr
1119 response.should redirect_to(:action => :sheet, :id => @attr[:sheet_id])
1123 it 'ステータスコード200 OKを返す' do
1124 # StorySheet.any_instance.stub(:store).and_return(true)
1125 post :create, :story_sheet => @attr, :format => :json
1126 response.should be_success
1128 it '作成されたストーリーをjsonデータで返す' do
1129 post :create, :story_sheet => @attr, :format => :json
1130 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1134 context 'ユーザ権限がないとき' do
1139 it 'ステータスコード302 Foundを返す' do
1140 post :create, :story_sheet => @attr
1141 response.status.should eq 302
1143 it 'サインインページへ遷移する' do
1144 post :create, :story_sheet => @attr
1145 response.body.should redirect_to '/users/sign_in'
1149 it 'ステータスコード401 Unauthorizedを返す' do
1150 post :create, :story_sheet => @attr, :format => :json
1151 response.status.should eq 401
1153 it '応答メッセージにUnauthorizedを返す' do
1154 post :create, :story_sheet => @attr, :format => :json
1155 response.message.should match(/Unauthorized/)
1161 describe '編集フォーム表示に於いて' do
1163 @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id
1165 StorySheet.stub(:show).and_return(@story_sheet)
1167 context 'つつがなく終わるとき' do
1169 it 'ステータスコード200 OKを返す' do
1170 get :edit, :id => @story_sheet.id
1171 response.should be_success
1173 it 'editテンプレートを描画する' do
1174 get :edit, :id => @story_sheet.id
1175 response.should render_template("edit")
1179 it 'ステータスコード200 OKを返す' do
1180 get :edit, :id => @story_sheet.id, :format => :js
1181 response.should be_success
1183 it 'edit.jsテンプレートを描画する' do
1184 get :edit, :id => @story_sheet.id, :format => :js
1185 response.should render_template("edit")
1189 context 'ユーザ権限がないとき' do
1194 it 'ステータスコード302 Foundを返す' do
1195 get :edit, :id => @story_sheet.id
1196 response.status.should eq 302
1198 it 'サインインページへ遷移する' do
1199 get :edit, :id => @story_sheet.id
1200 response.body.should redirect_to '/users/sign_in'
1204 it 'ステータスコード401 Unauthorizedを返す' do
1205 get :edit, :id => @story_sheet.id, :format => :js
1206 response.status.should eq 401
1208 it '応答メッセージにUnauthorizedを返す' do
1209 get :edit, :id => @story_sheet.id, :format => :js
1210 response.message.should match(/Unauthorized/)
1216 describe '更新に於いて' do
1218 @story_sheet = FactoryGirl.create :story_sheet, :author_id => @user.author.id
1219 @attr = FactoryGirl.attributes_for(:story_sheet, :author_id => @author.id)
1222 context 'つつがなく終わるとき' do
1224 it 'ステータスコード302 Foundを返す' do
1225 StorySheet.any_instance.stub(:store).and_return(true)
1226 put :update, :id => @story_sheet.id, :story_sheet => @attr
1227 response.status.should eq 302
1230 # StorySheet.any_instance.stub(:store).and_return(true)
1231 put :update, :id => @story_sheet.id, :story_sheet => @attr
1232 response.should redirect_to(:action => :sheet, :id => @attr[:sheet_id])
1236 it 'ステータスコード200 OKを返す' do
1237 # StorySheet.any_instance.stub(:store).and_return(true)
1238 put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
1239 response.should be_success
1243 context 'ユーザ権限がないとき' do
1248 it 'ステータスコード302 Foundを返す' do
1249 put :update, :id => @story_sheet.id, :story_sheet => @attr
1250 response.status.should eq 302
1252 it 'サインインページへ遷移する' do
1253 put :update, :id => @story_sheet.id, :story_sheet => @attr
1254 response.body.should redirect_to '/users/sign_in'
1258 it 'ステータスコード401 Unauthorizedを返す' do
1259 put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
1260 response.status.should eq 401
1262 it '応答メッセージにUnauthorizedを返す' do
1263 put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
1264 response.message.should match(/Unauthorized/)
1270 describe '削除に於いて' do
1272 @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id
1274 StorySheet.stub(:edit).and_return(@story_sheet)
1276 context 'つつがなく終わるとき' do
1278 StorySheet.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
1281 it 'ステータスコード302 Foundを返す' do
1282 delete :destroy, :id => @story_sheet.id
1283 response.status.should eq 302
1286 delete :destroy, :id => @story_sheet.id
1287 response.should redirect_to(:controller => 'story_sheets', :action => :sheet, :id => @story_sheet.sheet_id)
1291 it 'ステータスコード200 OKを返す' do
1292 delete :destroy, :id => @story_sheet.id, :format => :json
1293 response.should be_success
1297 context 'ユーザ権限がないとき' do
1302 it 'ステータスコード302 Foundを返す' do
1303 delete :destroy, :id => @story_sheet.id
1304 response.status.should eq 302
1306 it 'サインインページへ遷移する' do
1307 delete :destroy, :id => @story_sheet.id
1308 response.body.should redirect_to '/users/sign_in'
1312 it 'ステータスコード401 Unauthorizedを返す' do
1313 delete :destroy, :id => @story_sheet.id, :format => :json
1314 response.status.should eq 401
1316 it '応答メッセージにUnauthorizedを返す' do
1317 delete :destroy, :id => @story_sheet.id, :format => :json
1318 response.message.should match(/Unauthorized/)