1 # -*- encoding: utf-8 -*-
4 describe SheetsController 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 @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
18 Sheet.stub(:list).and_return([@sheet, @sheet, @sheet])
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 Sheet.default_page_size
38 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
39 get :index, :page_size => 1500
40 assigns(:page_size).should eq Sheet.max_page_size
42 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
43 get :index, :page_size => 0
44 assigns(:page_size).should eq Sheet.default_page_size
47 context 'つつがなく終わるとき' do
48 it 'ステータスコード200 OKを返す' do
50 response.should be_success
52 it '用紙モデルに一覧を問い合わせている' do
53 Sheet.should_receive(:list).exactly(1)
56 it '@sheetsにリストを取得している' do
58 assigns(:sheets).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 Sheet.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?("caption").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 @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id, :caption => 'normal'
143 Sheet.stub(:show).and_return(@sheet)
146 context 'つつがなく終わるとき' do
147 it 'ステータスコード200 OKを返す' do
148 get :show, :id => @sheet.id
149 response.should be_success
151 it '用紙モデルに単体取得を問い合わせている' do
152 Sheet.should_receive(:show).exactly(1)
155 it '@sheetにアレを取得している' do
156 get :show, :id => @sheet.id
157 assigns(:sheet).id.should eq(@sheet.id)
160 it 'showテンプレートを描画する' do
161 get :show, :id => @sheet.id
162 response.should render_template("show")
167 get :show, :id => @sheet.id, :format => :json
168 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
170 it '用紙モデルにjson単体出力オプションを問い合わせている' do
171 Sheet.should_receive(:show_json_opt).exactly(1)
172 get :show, :id => @sheet.id, :format => :json
175 get :show, :id => @sheet.id, :format => :json
176 json = JSON.parse response.body
177 json["caption"].should match(/normal/)
178 json["visible"].should_not be_nil
182 context 'ユーザ権限がないとき' do
187 it 'ステータスコード302 Foundを返す' do
188 get :show, :id => @sheet.id
189 response.status.should eq 302
191 it 'サインインページへ遷移する' do
192 get :show, :id => @sheet.id
193 response.body.should redirect_to '/users/sign_in'
197 it 'ステータスコード401 Unauthorizedを返す' do
198 get :show, :id => @sheet.id, :format => :json
199 response.status.should eq 401
201 it '応答メッセージにUnauthorizedを返す' do
202 get :show, :id => @sheet.id, :format => :json
203 response.message.should match(/Unauthorized/)
207 context 'ユーザ権限はないが管理者権限があるとき' do
212 it 'ステータスコード200 OKを返す' do
213 get :show, :id => @sheet.id
214 response.should be_success
217 context 'ユーザだが作家登録していないとき' do
222 it 'ステータスコード200 OKを返す' do
223 get :show, :id => @sheet.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 Sheet.any_instance.stub(:visible?).with(any_args()).and_return(false)
249 hidden = FactoryGirl.create :hidden_sheet, :author_id => @author.id
251 get :show, :id => hidden
252 }.should raise_error(ActiveRecord::Forbidden)
256 it '例外403 forbiddenを返す' do
257 Sheet.any_instance.stub(:visible?).with(any_args()).and_return(false)
258 hidden = FactoryGirl.create :hidden_sheet, :author_id => @author.id
260 get :show, :id => hidden, :format => :json
261 }.should raise_error(ActiveRecord::Forbidden)
270 @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id, :caption => 'normal'
271 @panel = FactoryGirl.create :panel, :author_id => @author.id
272 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
273 Sheet.stub(:show).with(@sheet.id.to_s, [@user, nil]).and_return(@sheet)
274 Sheet.stub(:show).with(@sheet.id.to_s, [nil, @admin]).and_return(@sheet)
275 SheetPanel.stub(:count).and_return(10)
276 SheetPanel.stub(:play_list).with(any_args).and_return([@sheet_panel, @sheet_panel, @sheet_panel])
279 context '事前チェックする' do
280 it '用紙モデルに単体取得を問い合わせている' do
281 Sheet.should_receive(:show).with(@sheet.id.to_s, [@user, nil]).exactly(1)
282 get :play, :id => @sheet.id
285 context 'つつがなく終わるとき' do
287 it 'ステータスコード200 OKを返す' do
288 get :play, :id => @sheet.id
289 response.should be_success
291 it 'sheetテンプレートを描画する' do
292 get :play, :id => @sheet.id
293 response.should render_template("sheet")
297 it 'ステータスコード200 OKを返す' do
298 get :play, :id => @sheet.id, :format => :json
299 response.should be_success
302 get :play, :id => @sheet.id, :format => :json
303 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
305 it '用紙モデルにjson単体出力オプションを問い合わせている' do
306 Sheet.should_receive(:show_json_opt).exactly(1)
307 get :show, :id => @sheet.id, :format => :json
310 get :play, :id => @sheet.id, :format => :json
311 json = JSON.parse response.body
312 json["caption"].should match(/normal/)
313 json["visible"].should_not be_nil
317 context 'ユーザ権限がないとき' do
322 it 'ステータスコード302 Foundを返す' do
323 get :play, :id => @sheet.id
324 response.status.should eq 302
326 it 'サインインページへ遷移する' do
327 get :play, :id => @sheet.id
328 response.should redirect_to '/users/sign_in'
332 it 'ステータスコード401 Unauthorizedを返す' do
333 get :play, :id => @sheet.id, :format => :json
334 response.status.should eq 401
336 it '応答メッセージにUnauthorizedを返す' do
337 get :play, :id => @sheet.id, :format => :json
338 response.message.should match(/Unauthorized/)
342 context 'ユーザ権限はないが管理者権限があるとき' do
347 it 'ステータスコード200 OKを返す' do
348 get :play, :id => @sheet.id
349 response.should be_success
352 context 'ユーザだが作家登録していないとき' do
356 it 'ステータスコード200 OKを返す' do
357 get :play, :id => @sheet.id
358 response.should be_success
363 describe '用紙数取得に於いて' do
365 Sheet.should_receive(:visible_count).and_return(3)
368 context 'つつがなく終わるとき' do
369 it 'ステータスコード200 OKを返す' do
370 get :count, :format => :json
371 response.should be_success
375 get :count, :format => :json
376 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
378 it 'データがHash構造になっていて用紙数が1である' do
379 get :count, :format => :json
380 json = JSON.parse response.body
381 json["count"].should == 3
387 describe '新規作成フォーム表示に於いて' do
391 context 'つつがなく終わるとき' do
392 it 'ステータスコード200 OKを返す' do
394 response.should be_success
396 it '@sheetに新規データを用意している' do
398 assigns(:sheet).should be_a_new(Sheet)
400 it '用紙モデルにデフォルト値補充を依頼している' do
401 Sheet.any_instance.should_receive(:supply_default).exactly(1)
405 it 'newテンプレートを描画する' do
407 response.should render_template("new")
411 it 'new.jsテンプレートを描画する' do
412 get :new, :format => :js
413 response.should render_template("new")
418 get :new, :format => :json
419 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
421 it '用紙モデルにjson単体出力オプションを問い合わせている' do
422 Sheet.should_receive(:show_json_opt).exactly(1)
423 get :new, :format => :json
427 context 'ユーザ権限がないとき' do
432 it 'ステータスコード302 Foundを返す' do
434 response.status.should eq 302
436 it 'サインインページへ遷移する' do
438 response.body.should redirect_to '/users/sign_in'
442 it 'ステータスコード401 Unauthorizedを返す' do
443 get :new, :format => :js
444 response.status.should eq 401
446 it '応答メッセージにUnauthorizedを返す' do
447 get :new, :format => :js
448 response.message.should match(/Unauthorized/)
452 it 'ステータスコード401 Unauthorizedを返す' do
453 get :new, :format => :json
454 response.status.should eq 401
456 it '応答メッセージにUnauthorizedを返す' do
457 get :new, :format => :json
458 response.message.should match(/Unauthorized/)
462 context 'ユーザ権限はないが管理者権限があるとき' do
468 it 'ステータスコード302 Foundを返す' do
470 response.status.should eq 302
472 it 'サインインページへ遷移する' do
474 response.body.should redirect_to '/users/sign_in'
478 context 'ユーザだが作家登録していないとき' do
483 it 'ステータスコード302 Foundを返す' do
485 response.status.should eq 302
489 response.body.should redirect_to new_author_path
495 describe '新規作成に於いて' do
498 @attr = FactoryGirl.attributes_for(:sheet, :author_id => @author.id, :caption => 'normal')
500 context '事前チェックしておく' do
501 it 'sheetがパラメータにあれば、展開する' do
502 post :create, :sheet => @attr
503 assigns(:prm)['caption'].should eq 'normal'
505 it 'jsonがパラメータにあれば、展開する' do
506 post :create, :json => FactoryGirl.attributes_for(:sheet, :caption => 'json prm').to_json
507 assigns(:prm)['caption'].should eq 'json prm'
509 it 'sheet・json両パラメータがあれば、sheetを優先して展開する' do
511 :sheet => FactoryGirl.attributes_for(:sheet, :caption => 'normal'),
512 :json => FactoryGirl.attributes_for(:sheet, :caption => 'json prm').to_json
514 assigns(:prm)['caption'].should eq 'normal'
516 it '用紙モデルにデフォルト値補充を依頼している' do
517 Sheet.any_instance.should_receive(:supply_default).exactly(1)
518 post :create, :sheet => @attr
521 Sheet.any_instance.should_receive(:store).exactly(1)
522 post :create, :sheet => @attr
525 context 'つつがなく終わるとき' do
526 it "@sheetに作成された用紙を保持していて、それがDBにある" do
527 post :create, :sheet => @attr
528 assigns(:sheet).should be_a(Sheet)
529 assigns(:sheet).should be_persisted
532 it 'ステータスコード302 Foundを返す' do
533 Sheet.any_instance.stub(:store).and_return(true)
534 post :create, :sheet => @attr
535 response.status.should eq 302
537 it '作成された用紙の表示ページへ遷移する' do
538 # Sheet.any_instance.stub(:store).and_return(true)
539 post :create, :sheet => @attr
540 response.should redirect_to(Sheet.last)
544 it 'ステータスコード200 OKを返す' do
545 # Sheet.any_instance.stub(:store).and_return(true)
546 post :create, :sheet => @attr, :format => :json
547 response.should be_success
549 it '作成された用紙をjsonデータで返す' do
550 post :create, :sheet => @attr, :format => :json
551 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
554 post :create, :sheet => @attr, :format => :json
555 json = JSON.parse response.body
556 json["caption"].should match(/normal/)
557 json["visible"].should_not be_nil
561 context 'ユーザ権限がないとき' do
566 it 'ステータスコード302 Foundを返す' do
567 post :create, :sheet => @attr
568 response.status.should eq 302
570 it 'サインインページへ遷移する' do
571 post :create, :sheet => @attr
572 response.body.should redirect_to '/users/sign_in'
576 it 'ステータスコード401 Unauthorizedを返す' do
577 post :create, :sheet => @attr, :format => :json
578 response.status.should eq 401
580 it '応答メッセージにUnauthorizedを返す' do
581 post :create, :sheet => @attr, :format => :json
582 response.message.should match(/Unauthorized/)
586 context 'ユーザ権限はないが管理者権限があるとき' do
592 it 'ステータスコード302 Foundを返す' do
593 post :create, :sheet => @attr
594 response.status.should eq 302
596 it 'サインインページへ遷移する' do
597 post :create, :sheet => @attr
598 response.body.should redirect_to '/users/sign_in'
602 context 'ユーザだが作家登録していないとき' do
607 it 'ステータスコード302 Foundを返す' do
608 post :create, :sheet => @attr
609 response.status.should eq 302
612 post :create, :sheet => @attr
613 response.body.should redirect_to new_author_path
617 context '検証、保存に失敗した' do
619 Sheet.any_instance.stub(:save).and_return(false)
621 it "未保存の用紙を保持している" do
622 post :create, :sheet => @attr
623 assigns(:sheet).should be_a_new(Sheet)
626 it 'ステータスコード200 OKを返す' do
627 post :create, :sheet => @attr
628 response.status.should eq 200
631 post :create, :sheet => @attr
632 response.should render_template("new")
636 it 'ステータスコード422 unprocessable_entity を返す' do
637 post :create, :sheet => @attr, :format => :json
638 response.status.should eq 422
640 it '応答メッセージUnprocessable Entityを返す' do
641 post :create, :sheet => @attr, :format => :json
642 response.message.should match(/Unprocessable/)
648 describe '編集フォーム表示に於いて' do
650 @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
652 Sheet.stub(:edit).and_return(@sheet)
654 context 'つつがなく終わるとき' do
655 it 'ステータスコード200 OKを返す' do
656 get :edit, :id => @sheet.id
657 response.should be_success
659 it '用紙モデルに編集取得を問い合わせている' do
660 Sheet.should_receive(:edit).exactly(1)
661 get :edit, :id => @sheet.id
663 it '@sheetにデータを用意している' do
664 get :edit, :id => @sheet.id
665 assigns(:sheet).should eq @sheet
668 it 'editテンプレートを描画する' do
669 get :edit, :id => @sheet.id
670 response.should render_template("edit")
674 it 'edit.jsテンプレートを描画する' do
675 get :edit, :id => @sheet.id, :format => :js
676 response.should render_template("edit")
680 context 'ユーザ権限がないとき' do
685 it 'ステータスコード302 Foundを返す' do
686 get :edit, :id => @sheet.id
687 response.status.should eq 302
689 it 'サインインページへ遷移する' do
690 get :edit, :id => @sheet.id
691 response.body.should redirect_to '/users/sign_in'
695 it 'ステータスコード401 Unauthorizedを返す' do
696 get :edit, :id => @sheet.id, :format => :js
697 response.status.should eq 401
699 it '応答メッセージにUnauthorizedを返す' do
700 get :edit, :id => @sheet.id, :format => :js
701 response.message.should match(/Unauthorized/)
705 context 'ユーザ権限はないが管理者権限があるとき' do
711 it 'ステータスコード302 Foundを返す' do
712 get :edit, :id => @sheet.id
713 response.status.should eq 302
715 it 'サインインページへ遷移する' do
716 get :edit, :id => @sheet.id
717 response.body.should redirect_to '/users/sign_in'
721 context 'ユーザだが作家登録していないとき' do
726 it 'ステータスコード302 Foundを返す' do
727 get :edit, :id => @sheet.id
728 response.status.should eq 302
731 get :edit, :id => @sheet.id
732 response.body.should redirect_to new_author_path
740 @sheet = FactoryGirl.create :sheet, :author => @author
741 @attr = FactoryGirl.attributes_for(:sheet, :author_id => @author.id, :caption => 'updated caption', :visible => 0)
744 context '事前チェックしておく' do
745 it 'sheetがパラメータにあれば、展開する' do
746 put :update, :id => @sheet.id, :sheet => @attr
747 assigns(:prm)['caption'].should eq 'updated caption'
749 it 'jsonがパラメータにあれば、展開する' do
750 put :update, :id => @sheet.id, :json => FactoryGirl.attributes_for(:sheet, :caption => 'json caption').to_json
751 assigns(:prm)['caption'].should eq 'json caption'
753 it 'sheet・json両パラメータがあれば、sheetを優先して展開する' do
756 :sheet => FactoryGirl.attributes_for(:sheet, :caption => 'updated caption'),
757 :json => FactoryGirl.attributes_for(:sheet, :caption => 'json caption').to_json
759 assigns(:prm)['caption'].should eq 'updated caption'
762 context 'つつがなく終わるとき' do
763 it '用紙モデルに編集取得を問い合わせている' do
764 Sheet.stub(:edit).with(any_args()).and_return @sheet
765 Sheet.should_receive(:edit).exactly(1)
766 put :update, :id => @sheet.id, :sheet => @attr
769 Sheet.any_instance.stub(:store).with(any_args).and_return true
770 Sheet.any_instance.should_receive(:store).exactly(1)
771 put :update, :id => @sheet.id, :sheet => @attr
773 it '@sheetにアレを取得している' do
774 put :update, :id => @sheet.id, :sheet => @attr
775 assigns(:sheet).id.should eq(@sheet.id)
778 put :update, :id => @sheet.id, :sheet => @attr
779 Sheet.find(@sheet.id).visible.should eq 0
782 it 'ステータスコード302 Foundを返す' do
783 Sheet.any_instance.stub(:store).with(any_args()).and_return(true)
784 put :update, :id => @sheet.id, :sheet => @attr
785 response.status.should eq 302
787 it '更新された用紙の表示ページへ遷移する' do
788 put :update, :id => @sheet.id, :sheet => @attr
789 response.should redirect_to(@sheet)
793 it 'ステータスコード200 OKを返す' do
794 Sheet.any_instance.stub(:store).with(any_args()).and_return(true)
795 put :update, :id => @sheet.id, :sheet => @attr, :format => :json
796 response.should be_success
799 Sheet.any_instance.stub(:store).with(any_args()).and_return(true)
800 put :update, :id => @sheet.id, :sheet => @attr, :format => :json
801 response.body.should match /./
805 context 'ユーザ権限がないとき' do
810 it 'ステータスコード302 Foundを返す' do
811 put :update, :id => @sheet.id, :sheet => @attr
812 response.status.should eq 302
814 it 'サインインページへ遷移する' do
815 put :update, :id => @sheet.id, :sheet => @attr
816 response.body.should redirect_to '/users/sign_in'
820 it '応答メッセージにUnauthorizedを返す' do
821 put :update, :id => @sheet.id, :sheet => @attr, :format => :json
822 response.message.should match(/Unauthorized/)
826 context 'ユーザ権限はないが管理者権限があるとき' do
832 it 'ステータスコード302 Foundを返す' do
833 put :update, :id => @sheet.id, :sheet => @attr
834 response.status.should eq 302
836 it 'サインインページへ遷移する' do
837 put :update, :id => @sheet.id, :sheet => @attr
838 response.body.should redirect_to '/users/sign_in'
842 context 'ユーザだが作家登録していないとき' do
847 it 'ステータスコード302 Foundを返す' do
848 put :update, :id => @sheet.id, :sheet => @attr
849 response.status.should eq 302
852 put :update, :id => @sheet.id, :sheet => @attr
853 response.body.should redirect_to new_author_path
857 context '検証、保存に失敗したとき' do
859 Sheet.any_instance.stub(:save).and_return(false)
862 it 'ステータスコード200 Okを返す' do
863 put :update, :id => @sheet.id, :sheet => @attr
864 response.status.should eq 200
867 put :update, :id => @sheet.id, :sheet => @attr
868 response.should render_template("edit")
872 it 'ステータスコード422 unprocessable_entity を返す' do
873 Sheet.any_instance.stub(:save).and_return(false)
874 put :update, :id => @sheet.id, :sheet => @attr, :format => :json
875 response.status.should eq 422
877 it '応答メッセージUnprocessable Entityを返す' do
878 put :update, :id => @sheet.id, :sheet => @attr, :format => :json
879 response.message.should match(/Unprocessable/)
887 @sheet = FactoryGirl.create :sheet, :author => @author
890 context '事前チェックしておく' do
892 Sheet.stub(:edit).with(any_args()).and_return @sheet
893 Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
895 it '用紙モデルに編集取得を問い合わせている' do
896 Sheet.should_receive(:edit).exactly(1)
897 delete :destroy, :id => @sheet.id
900 Sheet.any_instance.should_receive(:destroy_with_sheet_panel).exactly(1)
901 delete :destroy, :id => @sheet.id
903 it '@sheetにアレを取得している' do
904 delete :destroy, :id => @sheet.id
905 assigns(:sheet).id.should eq(@sheet.id)
908 context 'つつがなく終わるとき' do
911 delete :destroy, :id => @sheet.id
912 }.should change Sheet, :count
916 Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
918 it 'ステータスコード302 Foundを返す' do
919 delete :destroy, :id => @sheet.id
920 response.status.should eq 302
922 it 'マイ用紙の一覧ページへ遷移する' do
923 delete :destroy, :id => @sheet.id
924 response.should redirect_to('/home/sheets')
929 Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
931 it 'ステータスコード200 OKを返す' do
932 delete :destroy, :id => @sheet.id, :format => :json
933 response.should be_success
936 delete :destroy, :id => @sheet.id, :format => :json
937 response.body.should match /./
941 context 'ユーザ権限がないとき' do
946 it 'ステータスコード302 Foundを返す' do
947 delete :destroy, :id => @sheet.id
948 response.status.should eq 302
950 it 'サインインページへ遷移する' do
951 delete :destroy, :id => @sheet.id
952 response.body.should redirect_to '/users/sign_in'
956 it '応答メッセージにUnauthorizedを返す' do
957 delete :destroy, :id => @sheet.id, :format => :json
958 response.message.should match(/Unauthorized/)
962 context 'ユーザ権限はないが管理者権限があるとき' do
968 it 'ステータスコード302 Foundを返す' do
969 delete :destroy, :id => @sheet.id
970 response.status.should eq 302
972 it 'サインインページへ遷移する' do
973 delete :destroy, :id => @sheet.id
974 response.body.should redirect_to '/users/sign_in'
978 context 'ユーザだが作家登録していないとき' do
983 it 'ステータスコード302 Foundを返す' do
984 delete :destroy, :id => @sheet.id
985 response.status.should eq 302
988 delete :destroy, :id => @sheet.id
989 response.body.should redirect_to new_author_path
993 context '削除に失敗したとき' do
995 Sheet.any_instance.stub(:destroy_with_sheet_panel).and_return(false)
998 it 'ステータスコード302 Foundを返す' do
999 delete :destroy, :id => @sheet.id
1000 response.status.should eq 302
1002 it 'その用紙の詳細ページへ遷移する' do
1003 delete :destroy, :id => @sheet.id
1004 response.should redirect_to(sheet_path(@sheet))
1008 it 'ステータスコード422 unprocessable_entity を返す' do
1009 delete :destroy, :id => @sheet.id, :format => :json
1010 response.status.should eq 422
1012 it '応答メッセージUnprocessable Entityを返す' do
1013 delete :destroy, :id => @sheet.id, :format => :json
1014 response.message.should match(/Unprocessable/)
1021 describe '一覧表示に於いて' do
1023 @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
1024 Sheet.stub(:list).and_return([@sheet, @sheet, @sheet])
1027 context 'つつがなく終わるとき' do
1028 it 'ステータスコード200 OKを返す' do
1030 response.should be_success
1033 it 'indexテンプレートを描画する' do
1035 response.should render_template("index")
1040 get :index, :format => :json
1041 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1045 context 'ユーザ権限がないとき' do
1049 it 'ステータスコード200 OKを返す' do
1051 response.should be_success
1054 it 'indexテンプレートを描画する' do
1056 response.should render_template("index")
1061 get :index, :format => :json
1062 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1068 describe '単体表示に於いて' do
1070 @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id, :caption => 'normal'
1071 Sheet.stub(:show).and_return(@sheet)
1074 context 'つつがなく終わるとき' do
1075 it 'ステータスコード200 OKを返す' do
1076 get :show, :id => @sheet.id
1077 response.should be_success
1080 it 'showテンプレートを描画する' do
1081 get :show, :id => @sheet.id
1082 response.should render_template("show")
1087 get :show, :id => @sheet.id, :format => :json
1088 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1092 context 'ユーザ権限がないとき' do
1096 it 'ステータスコード200 OKを返す' do
1097 get :show, :id => @sheet.id
1098 response.should be_success
1101 it 'showテンプレートを描画する' do
1102 get :show, :id => @sheet.id
1103 response.should render_template("show")
1108 get :show, :id => @sheet.id, :format => :json
1109 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1114 describe '用紙数取得に於いて' do
1116 Sheet.should_receive(:visible_count).and_return(3)
1119 context 'つつがなく終わるとき' do
1120 it 'ステータスコード200 OKを返す' do
1121 get :count, :format => :json
1122 response.should be_success
1126 get :count, :format => :json
1127 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1133 describe '新規作成フォーム表示に於いて' do
1137 context 'つつがなく終わるとき' do
1138 it 'ステータスコード200 OKを返す' do
1140 response.should be_success
1143 it 'newテンプレートを描画する' do
1145 response.should render_template("new")
1149 it 'new.jsテンプレートを描画する' do
1150 get :new, :format => :js
1151 response.should render_template("new")
1156 get :new, :format => :json
1157 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1161 context 'ユーザ権限がないとき' do
1166 it 'ステータスコード302 Foundを返す' do
1168 response.status.should eq 302
1170 it 'サインインページへ遷移する' do
1172 response.body.should redirect_to '/users/sign_in'
1176 it 'ステータスコード401 Unauthorizedを返す' do
1177 get :new, :format => :js
1178 response.status.should eq 401
1180 it '応答メッセージにUnauthorizedを返す' do
1181 get :new, :format => :js
1182 response.message.should match(/Unauthorized/)
1186 it 'ステータスコード401 Unauthorizedを返す' do
1187 get :new, :format => :json
1188 response.status.should eq 401
1190 it '応答メッセージにUnauthorizedを返す' do
1191 get :new, :format => :json
1192 response.message.should match(/Unauthorized/)
1198 describe '新規作成に於いて' do
1201 @attr = FactoryGirl.attributes_for(:sheet, :author_id => @author.id, :caption => 'normal')
1203 context 'つつがなく終わるとき' do
1205 it 'ステータスコード302 Foundを返す' do
1206 Sheet.any_instance.stub(:save).and_return(true)
1207 post :create, :sheet => @attr
1208 response.status.should eq 302
1210 it '作成された用紙の表示ページへ遷移する' do
1211 # Sheet.any_instance.stub(:save).and_return(true)
1212 post :create, :sheet => @attr
1213 response.should redirect_to(Sheet.last)
1217 it 'ステータスコード200 OKを返す' do
1218 # Sheet.any_instance.stub(:save).and_return(true)
1219 post :create, :sheet => @attr, :format => :json
1220 response.should be_success
1222 it '作成された用紙をjsonデータで返す' do
1223 post :create, :sheet => @attr, :format => :json
1224 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1228 context 'ユーザ権限がないとき' do
1233 it 'ステータスコード302 Foundを返す' do
1234 post :create, :sheet => @attr
1235 response.status.should eq 302
1237 it 'サインインページへ遷移する' do
1238 post :create, :sheet => @attr
1239 response.body.should redirect_to '/users/sign_in'
1243 it 'ステータスコード401 Unauthorizedを返す' do
1244 post :create, :sheet => @attr, :format => :json
1245 response.status.should eq 401
1247 it '応答メッセージにUnauthorizedを返す' do
1248 post :create, :sheet => @attr, :format => :json
1249 response.message.should match(/Unauthorized/)
1255 describe '編集フォーム表示に於いて' do
1257 @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
1259 Sheet.stub(:edit).and_return(@sheet)
1261 context 'つつがなく終わるとき' do
1262 it 'ステータスコード200 OKを返す' do
1263 get :edit, :id => @sheet.id
1264 response.should be_success
1267 it 'editテンプレートを描画する' do
1268 get :edit, :id => @sheet.id
1269 response.should render_template("edit")
1273 it 'edit.jsテンプレートを描画する' do
1274 get :edit, :id => @sheet.id, :format => :js
1275 response.should render_template("edit")
1279 context 'ユーザ権限がないとき' do
1284 it 'ステータスコード302 Foundを返す' do
1285 get :edit, :id => @sheet.id
1286 response.status.should eq 302
1288 it 'サインインページへ遷移する' do
1289 get :edit, :id => @sheet.id
1290 response.body.should redirect_to '/users/sign_in'
1294 it 'ステータスコード401 Unauthorizedを返す' do
1295 get :edit, :id => @sheet.id, :format => :js
1296 response.status.should eq 401
1298 it '応答メッセージにUnauthorizedを返す' do
1299 get :edit, :id => @sheet.id, :format => :js
1300 response.message.should match(/Unauthorized/)
1306 describe '更新に於いて' do
1308 @sheet = FactoryGirl.create :sheet, :author => @author
1309 @attr = FactoryGirl.attributes_for(:sheet, :author_id => @author.id, :caption => 'updated caption', :visible => 0)
1312 context 'つつがなく終わるとき' do
1314 it 'ステータスコード302 Foundを返す' do
1315 Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
1316 put :update, :id => @sheet.id, :sheet => @attr
1317 response.status.should eq 302
1319 it '更新された用紙の表示ページへ遷移する' do
1320 put :update, :id => @sheet.id, :sheet => @attr
1321 response.should redirect_to(@sheet)
1325 it 'ステータスコード200 OKを返す' do
1326 Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
1327 put :update, :id => @sheet.id, :sheet => @attr, :format => :json
1328 response.should be_success
1330 it 'ページ本体は特に返さない' do
1331 Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
1332 put :update, :id => @sheet.id, :sheet => @attr, :format => :json
1333 response.body.should match /./
1337 context 'ユーザ権限がないとき' do
1341 it 'ステータスコード302 Foundを返す' do
1342 put :update, :id => @sheet.id, :sheet => @attr
1343 response.status.should eq 302
1346 it 'サインインページへ遷移する' do
1347 put :update, :id => @sheet.id, :sheet => @attr
1348 response.body.should redirect_to '/users/sign_in'
1354 describe '削除に於いて' do
1356 @sheet = FactoryGirl.create :sheet, :author => @author
1359 context 'つつがなく終わるとき' do
1362 Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
1364 it 'ステータスコード302 Foundを返す' do
1365 delete :destroy, :id => @sheet.id
1366 response.status.should eq 302
1368 it 'マイ用紙の一覧ページへ遷移する' do
1369 delete :destroy, :id => @sheet.id
1370 response.should redirect_to('/home/sheet')
1375 Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
1377 it 'ステータスコード200 OKを返す' do
1378 delete :destroy, :id => @sheet.id, :format => :json
1379 response.should be_success
1381 it 'ページ本体は特に返さない' do
1382 delete :destroy, :id => @sheet.id, :format => :json
1383 response.body.should match /./
1387 context 'ユーザ権限がないとき' do
1391 it 'ステータスコード302 Foundを返す' do
1392 delete :destroy, :id => @sheet.id
1393 response.status.should eq 302
1396 it 'サインインページへ遷移する' do
1397 delete :destroy, :id => @sheet.id
1398 response.body.should redirect_to '/users/sign_in'
1402 it '応答メッセージにUnauthorizedを返す' do
1403 delete :destroy, :id => @sheet.id, :format => :json
1404 response.message.should match(/Unauthorized/)