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
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
284 it '紙コマモデルにプレイリスト取得を問い合わせている' do
285 SheetPanel.should_receive(:play_list).with(@sheet, @author).exactly(1)
286 get :play, :id => @sheet.id
289 context 'つつがなく終わるとき' do
290 it '@sheet_panelsにリストを取得している' do
291 get :play, :id => @sheet.id
292 assigns(:sheet_panels).should have_at_least(3).items
295 it 'ステータスコード200 OKを返す' do
296 get :play, :id => @sheet.id
297 response.should be_success
299 it 'sheetテンプレートを描画する' do
300 get :play, :id => @sheet.id
301 response.should render_template("sheet")
305 it 'ステータスコード200 OKを返す' do
306 get :play, :id => @sheet.id, :format => :json
307 response.should be_success
310 get :play, :id => @sheet.id, :format => :json
311 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
313 it '紙コマモデルに紙コマリストのjson出力を問い合わせている' do
314 SheetPanel.should_receive(:list_as_json_text).exactly(1)
315 get :play, :id => @sheet.id, :format => :json
317 it 'データがリスト構造になっている' do
318 get :play, :id => @sheet.id, :format => :json
319 json = JSON.parse response.body
320 json.should have_at_least(3).items
322 it 'リストの先頭くらいは紙コマっぽいものであって欲しい' do
323 get :play, :id => @sheet.id, :format => :json
324 json = JSON.parse response.body
325 json.first.has_key?("panel_id").should be_true
326 json.first.has_key?("sheet_id").should be_true
327 json.first.has_key?("author_id").should be_true
331 context 'ユーザ権限がないとき' do
336 it 'ステータスコード302 Foundを返す' do
337 get :play, :id => @sheet.id
338 response.status.should eq 302
340 it 'サインインページへ遷移する' do
341 get :play, :id => @sheet.id
342 response.should redirect_to '/users/sign_in'
346 it 'ステータスコード401 Unauthorizedを返す' do
347 get :play, :id => @sheet.id, :format => :json
348 response.status.should eq 401
350 it '応答メッセージにUnauthorizedを返す' do
351 get :play, :id => @sheet.id, :format => :json
352 response.message.should match(/Unauthorized/)
356 context 'ユーザ権限はないが管理者権限があるとき' do
361 it 'ステータスコード200 OKを返す' do
362 get :play, :id => @sheet.id
363 response.should be_success
366 context 'ユーザだが作家登録していないとき' do
370 it 'ステータスコード200 OKを返す' do
371 get :play, :id => @sheet.id
372 response.should be_success
377 describe '用紙数取得に於いて' do
379 Sheet.should_receive(:visible_count).and_return(3)
382 context 'つつがなく終わるとき' do
383 it 'ステータスコード200 OKを返す' do
384 get :count, :format => :json
385 response.should be_success
389 get :count, :format => :json
390 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
392 it 'データがHash構造になっていて用紙数が1である' do
393 get :count, :format => :json
394 json = JSON.parse response.body
395 json["count"].should == 3
401 describe '新規作成フォーム表示に於いて' do
405 context 'つつがなく終わるとき' do
406 it 'ステータスコード200 OKを返す' do
408 response.should be_success
410 it '@sheetに新規データを用意している' do
412 assigns(:sheet).should be_a_new(Sheet)
414 it '用紙モデルにデフォルト値補充を依頼している' do
415 Sheet.any_instance.should_receive(:supply_default).exactly(1)
419 it 'newテンプレートを描画する' do
421 response.should render_template("new")
425 it 'new.jsテンプレートを描画する' do
426 get :new, :format => :js
427 response.should render_template("new")
432 get :new, :format => :json
433 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
435 it '用紙モデルにjson単体出力オプションを問い合わせている' do
436 Sheet.should_receive(:show_json_opt).exactly(1)
437 get :new, :format => :json
441 context 'ユーザ権限がないとき' do
446 it 'ステータスコード302 Foundを返す' do
448 response.status.should eq 302
450 it 'サインインページへ遷移する' do
452 response.body.should redirect_to '/users/sign_in'
456 it 'ステータスコード401 Unauthorizedを返す' do
457 get :new, :format => :js
458 response.status.should eq 401
460 it '応答メッセージにUnauthorizedを返す' do
461 get :new, :format => :js
462 response.message.should match(/Unauthorized/)
466 it 'ステータスコード401 Unauthorizedを返す' do
467 get :new, :format => :json
468 response.status.should eq 401
470 it '応答メッセージにUnauthorizedを返す' do
471 get :new, :format => :json
472 response.message.should match(/Unauthorized/)
476 context 'ユーザ権限はないが管理者権限があるとき' do
482 it 'ステータスコード302 Foundを返す' do
484 response.status.should eq 302
486 it 'サインインページへ遷移する' do
488 response.body.should redirect_to '/users/sign_in'
492 context 'ユーザだが作家登録していないとき' do
497 it 'ステータスコード302 Foundを返す' do
499 response.status.should eq 302
503 response.body.should redirect_to new_author_path
509 describe '新規作成に於いて' do
512 @attr = FactoryGirl.attributes_for(:sheet, :author_id => @author.id, :caption => 'normal')
514 context '事前チェックしておく' do
515 it '用紙モデルにデフォルト値補充を依頼している' do
516 Sheet.any_instance.should_receive(:supply_default).exactly(1)
517 post :create, :sheet => @attr
519 it '用紙モデルにカラム値復元を依頼している' do
520 Sheet.any_instance.should_receive(:attributes=).exactly(1)
521 post :create, :sheet => @attr
523 it '用紙モデルに上書き補充を依頼している' do
524 Sheet.any_instance.should_receive(:overwrite).exactly(1)
525 post :create, :sheet => @attr
528 Sheet.any_instance.should_receive(:save).exactly(1)
529 post :create, :sheet => @attr
532 context 'つつがなく終わるとき' do
533 it "@sheetに作成された用紙を保持していて、それがDBにある" do
534 post :create, :sheet => @attr
535 assigns(:sheet).should be_a(Sheet)
536 assigns(:sheet).should be_persisted
539 it 'ステータスコード302 Foundを返す' do
540 Sheet.any_instance.stub(:save).and_return(true)
541 post :create, :sheet => @attr
542 response.status.should eq 302
544 it '作成された用紙の表示ページへ遷移する' do
545 # Sheet.any_instance.stub(:save).and_return(true)
546 post :create, :sheet => @attr
547 response.should redirect_to(Sheet.last)
551 it 'ステータスコード200 OKを返す' do
552 # Sheet.any_instance.stub(:save).and_return(true)
553 post :create, :sheet => @attr, :format => :json
554 response.should be_success
556 it '作成された用紙をjsonデータで返す' do
557 post :create, :sheet => @attr, :format => :json
558 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
561 post :create, :sheet => @attr, :format => :json
562 json = JSON.parse response.body
563 json["caption"].should match(/normal/)
564 json["visible"].should_not be_nil
568 context 'ユーザ権限がないとき' do
573 it 'ステータスコード302 Foundを返す' do
574 post :create, :sheet => @attr
575 response.status.should eq 302
577 it 'サインインページへ遷移する' do
578 post :create, :sheet => @attr
579 response.body.should redirect_to '/users/sign_in'
583 it 'ステータスコード401 Unauthorizedを返す' do
584 post :create, :sheet => @attr, :format => :json
585 response.status.should eq 401
587 it '応答メッセージにUnauthorizedを返す' do
588 post :create, :sheet => @attr, :format => :json
589 response.message.should match(/Unauthorized/)
593 context 'ユーザ権限はないが管理者権限があるとき' do
599 it 'ステータスコード302 Foundを返す' do
600 post :create, :sheet => @attr
601 response.status.should eq 302
603 it 'サインインページへ遷移する' do
604 post :create, :sheet => @attr
605 response.body.should redirect_to '/users/sign_in'
609 context 'ユーザだが作家登録していないとき' do
614 it 'ステータスコード302 Foundを返す' do
615 post :create, :sheet => @attr
616 response.status.should eq 302
619 post :create, :sheet => @attr
620 response.body.should redirect_to new_author_path
624 context '検証、保存に失敗した' do
626 Sheet.any_instance.stub(:save).and_return(false)
628 it "未保存の用紙を保持している" do
629 post :create, :sheet => @attr
630 assigns(:sheet).should be_a_new(Sheet)
633 it 'ステータスコード200 OKを返す' do
634 post :create, :sheet => @attr
635 response.status.should eq 200
638 post :create, :sheet => @attr
639 response.should render_template("new")
643 it 'ステータスコード422 unprocessable_entity を返す' do
644 post :create, :sheet => @attr, :format => :json
645 response.status.should eq 422
647 it '応答メッセージUnprocessable Entityを返す' do
648 post :create, :sheet => @attr, :format => :json
649 response.message.should match(/Unprocessable/)
655 describe '編集フォーム表示に於いて' do
657 @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
659 Sheet.stub(:edit).and_return(@sheet)
661 context 'つつがなく終わるとき' do
662 it 'ステータスコード200 OKを返す' do
663 get :edit, :id => @sheet.id
664 response.should be_success
666 it '用紙モデルに編集取得を問い合わせている' do
667 Sheet.should_receive(:edit).exactly(1)
668 get :edit, :id => @sheet.id
670 it '@sheetにデータを用意している' do
671 get :edit, :id => @sheet.id
672 assigns(:sheet).should eq @sheet
675 it 'editテンプレートを描画する' do
676 get :edit, :id => @sheet.id
677 response.should render_template("edit")
681 it 'edit.jsテンプレートを描画する' do
682 get :edit, :id => @sheet.id, :format => :js
683 response.should render_template("edit")
687 context 'ユーザ権限がないとき' do
692 it 'ステータスコード302 Foundを返す' do
693 get :edit, :id => @sheet.id
694 response.status.should eq 302
696 it 'サインインページへ遷移する' do
697 get :edit, :id => @sheet.id
698 response.body.should redirect_to '/users/sign_in'
702 it 'ステータスコード401 Unauthorizedを返す' do
703 get :edit, :id => @sheet.id, :format => :js
704 response.status.should eq 401
706 it '応答メッセージにUnauthorizedを返す' do
707 get :edit, :id => @sheet.id, :format => :js
708 response.message.should match(/Unauthorized/)
712 context 'ユーザ権限はないが管理者権限があるとき' do
718 it 'ステータスコード302 Foundを返す' do
719 get :edit, :id => @sheet.id
720 response.status.should eq 302
722 it 'サインインページへ遷移する' do
723 get :edit, :id => @sheet.id
724 response.body.should redirect_to '/users/sign_in'
728 context 'ユーザだが作家登録していないとき' do
733 it 'ステータスコード302 Foundを返す' do
734 get :edit, :id => @sheet.id
735 response.status.should eq 302
738 get :edit, :id => @sheet.id
739 response.body.should redirect_to new_author_path
747 @sheet = FactoryGirl.create :sheet, :author => @author
748 @attr = FactoryGirl.attributes_for(:sheet, :author_id => @author.id, :caption => 'updated caption', :visible => 0)
751 context '事前チェックしておく' do
752 it '用紙モデルに編集取得を問い合わせている' do
753 Sheet.stub(:edit).with(any_args()).and_return @sheet
754 Sheet.should_receive(:edit).exactly(1)
755 put :update, :id => @sheet.id, :sheet => @attr
757 it '用紙モデルにカラム値復元を依頼している' do
758 Sheet.any_instance.should_receive(:attributes=).exactly(1)
759 put :update, :id => @sheet.id, :sheet => @attr
761 it '用紙モデルに上書き補充を依頼している' do
762 Sheet.any_instance.should_receive(:overwrite).exactly(1)
763 put :update, :id => @sheet.id, :sheet => @attr
766 Sheet.any_instance.stub(:save).with(any_args).and_return true
767 Sheet.any_instance.should_receive(:save).exactly(1)
768 put :update, :id => @sheet.id, :sheet => @attr
770 it '@sheetにアレを取得している' do
771 put :update, :id => @sheet.id, :sheet => @attr
772 assigns(:sheet).id.should eq(@sheet.id)
775 context 'つつがなく終わるとき' do
777 put :update, :id => @sheet.id, :sheet => @attr
778 Sheet.find(@sheet.id).visible.should eq 0
781 it 'ステータスコード302 Foundを返す' do
782 Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
783 put :update, :id => @sheet.id, :sheet => @attr
784 response.status.should eq 302
786 it '更新された用紙の表示ページへ遷移する' do
787 put :update, :id => @sheet.id, :sheet => @attr
788 response.should redirect_to(@sheet)
792 it 'ステータスコード200 OKを返す' do
793 Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
794 put :update, :id => @sheet.id, :sheet => @attr, :format => :json
795 response.should be_success
798 Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
799 put :update, :id => @sheet.id, :sheet => @attr, :format => :json
800 response.body.should match /./
804 context 'ユーザ権限がないとき' do
809 it 'ステータスコード302 Foundを返す' do
810 put :update, :id => @sheet.id, :sheet => @attr
811 response.status.should eq 302
813 it 'サインインページへ遷移する' do
814 put :update, :id => @sheet.id, :sheet => @attr
815 response.body.should redirect_to '/users/sign_in'
819 it '応答メッセージにUnauthorizedを返す' do
820 put :update, :id => @sheet.id, :sheet => @attr, :format => :json
821 response.message.should match(/Unauthorized/)
825 context 'ユーザ権限はないが管理者権限があるとき' do
831 it 'ステータスコード302 Foundを返す' do
832 put :update, :id => @sheet.id, :sheet => @attr
833 response.status.should eq 302
835 it 'サインインページへ遷移する' do
836 put :update, :id => @sheet.id, :sheet => @attr
837 response.body.should redirect_to '/users/sign_in'
841 context 'ユーザだが作家登録していないとき' do
846 it 'ステータスコード302 Foundを返す' do
847 put :update, :id => @sheet.id, :sheet => @attr
848 response.status.should eq 302
851 put :update, :id => @sheet.id, :sheet => @attr
852 response.body.should redirect_to new_author_path
856 context '検証、保存に失敗したとき' do
858 Sheet.any_instance.stub(:save).and_return(false)
861 it 'ステータスコード200 Okを返す' do
862 put :update, :id => @sheet.id, :sheet => @attr
863 response.status.should eq 200
866 put :update, :id => @sheet.id, :sheet => @attr
867 response.should render_template("edit")
871 it 'ステータスコード422 unprocessable_entity を返す' do
872 Sheet.any_instance.stub(:save).and_return(false)
873 put :update, :id => @sheet.id, :sheet => @attr, :format => :json
874 response.status.should eq 422
876 it '応答メッセージUnprocessable Entityを返す' do
877 put :update, :id => @sheet.id, :sheet => @attr, :format => :json
878 response.message.should match(/Unprocessable/)
886 @sheet = FactoryGirl.create :sheet, :author => @author
889 context '事前チェックしておく' do
891 Sheet.stub(:edit).with(any_args()).and_return @sheet
892 Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
894 it '用紙モデルに編集取得を問い合わせている' do
895 Sheet.should_receive(:edit).exactly(1)
896 delete :destroy, :id => @sheet.id
899 Sheet.any_instance.should_receive(:destroy_with_sheet_panel).exactly(1)
900 delete :destroy, :id => @sheet.id
902 it '@sheetにアレを取得している' do
903 delete :destroy, :id => @sheet.id
904 assigns(:sheet).id.should eq(@sheet.id)
907 context 'つつがなく終わるとき' do
910 delete :destroy, :id => @sheet.id
911 }.should change Sheet, :count
915 Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
917 it 'ステータスコード302 Foundを返す' do
918 delete :destroy, :id => @sheet.id
919 response.status.should eq 302
921 it 'マイ用紙の一覧ページへ遷移する' do
922 delete :destroy, :id => @sheet.id
923 response.should redirect_to('/home/sheets')
928 Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
930 it 'ステータスコード200 OKを返す' do
931 delete :destroy, :id => @sheet.id, :format => :json
932 response.should be_success
935 delete :destroy, :id => @sheet.id, :format => :json
936 response.body.should match /./
940 context 'ユーザ権限がないとき' do
945 it 'ステータスコード302 Foundを返す' do
946 delete :destroy, :id => @sheet.id
947 response.status.should eq 302
949 it 'サインインページへ遷移する' do
950 delete :destroy, :id => @sheet.id
951 response.body.should redirect_to '/users/sign_in'
955 it '応答メッセージにUnauthorizedを返す' do
956 delete :destroy, :id => @sheet.id, :format => :json
957 response.message.should match(/Unauthorized/)
961 context 'ユーザ権限はないが管理者権限があるとき' do
967 it 'ステータスコード302 Foundを返す' do
968 delete :destroy, :id => @sheet.id
969 response.status.should eq 302
971 it 'サインインページへ遷移する' do
972 delete :destroy, :id => @sheet.id
973 response.body.should redirect_to '/users/sign_in'
977 context 'ユーザだが作家登録していないとき' do
982 it 'ステータスコード302 Foundを返す' do
983 delete :destroy, :id => @sheet.id
984 response.status.should eq 302
987 delete :destroy, :id => @sheet.id
988 response.body.should redirect_to new_author_path
992 context '削除に失敗したとき' do
994 Sheet.any_instance.stub(:destroy_with_sheet_panel).and_return(false)
997 it 'ステータスコード302 Foundを返す' do
998 delete :destroy, :id => @sheet.id
999 response.status.should eq 302
1001 it 'その用紙の詳細ページへ遷移する' do
1002 delete :destroy, :id => @sheet.id
1003 response.should redirect_to(sheet_path(@sheet))
1007 it 'ステータスコード422 unprocessable_entity を返す' do
1008 delete :destroy, :id => @sheet.id, :format => :json
1009 response.status.should eq 422
1011 it '応答メッセージUnprocessable Entityを返す' do
1012 delete :destroy, :id => @sheet.id, :format => :json
1013 response.message.should match(/Unprocessable/)
1020 describe '一覧表示に於いて' do
1022 @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
1023 Sheet.stub(:list).and_return([@sheet, @sheet, @sheet])
1026 context 'つつがなく終わるとき' do
1027 it 'ステータスコード200 OKを返す' do
1029 response.should be_success
1032 it 'indexテンプレートを描画する' do
1034 response.should render_template("index")
1039 get :index, :format => :json
1040 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1044 context 'ユーザ権限がないとき' do
1048 it 'ステータスコード200 OKを返す' do
1050 response.should be_success
1053 it 'indexテンプレートを描画する' do
1055 response.should render_template("index")
1060 get :index, :format => :json
1061 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1067 describe '単体表示に於いて' do
1069 @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id, :caption => 'normal'
1070 Sheet.stub(:show).and_return(@sheet)
1073 context 'つつがなく終わるとき' do
1074 it 'ステータスコード200 OKを返す' do
1075 get :show, :id => @sheet.id
1076 response.should be_success
1079 it 'showテンプレートを描画する' do
1080 get :show, :id => @sheet.id
1081 response.should render_template("show")
1086 get :show, :id => @sheet.id, :format => :json
1087 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1091 context 'ユーザ権限がないとき' do
1095 it 'ステータスコード200 OKを返す' do
1096 get :show, :id => @sheet.id
1097 response.should be_success
1100 it 'showテンプレートを描画する' do
1101 get :show, :id => @sheet.id
1102 response.should render_template("show")
1107 get :show, :id => @sheet.id, :format => :json
1108 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1113 describe '用紙数取得に於いて' do
1115 Sheet.should_receive(:visible_count).and_return(3)
1118 context 'つつがなく終わるとき' do
1119 it 'ステータスコード200 OKを返す' do
1120 get :count, :format => :json
1121 response.should be_success
1125 get :count, :format => :json
1126 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1132 describe '新規作成フォーム表示に於いて' do
1136 context 'つつがなく終わるとき' do
1137 it 'ステータスコード200 OKを返す' do
1139 response.should be_success
1142 it 'newテンプレートを描画する' do
1144 response.should render_template("new")
1148 it 'new.jsテンプレートを描画する' do
1149 get :new, :format => :js
1150 response.should render_template("new")
1155 get :new, :format => :json
1156 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1160 context 'ユーザ権限がないとき' do
1165 it 'ステータスコード302 Foundを返す' do
1167 response.status.should eq 302
1169 it 'サインインページへ遷移する' do
1171 response.body.should redirect_to '/users/sign_in'
1175 it 'ステータスコード401 Unauthorizedを返す' do
1176 get :new, :format => :js
1177 response.status.should eq 401
1179 it '応答メッセージにUnauthorizedを返す' do
1180 get :new, :format => :js
1181 response.message.should match(/Unauthorized/)
1185 it 'ステータスコード401 Unauthorizedを返す' do
1186 get :new, :format => :json
1187 response.status.should eq 401
1189 it '応答メッセージにUnauthorizedを返す' do
1190 get :new, :format => :json
1191 response.message.should match(/Unauthorized/)
1197 describe '新規作成に於いて' do
1200 @attr = FactoryGirl.attributes_for(:sheet, :author_id => @author.id, :caption => 'normal')
1202 context 'つつがなく終わるとき' do
1204 it 'ステータスコード302 Foundを返す' do
1205 Sheet.any_instance.stub(:save).and_return(true)
1206 post :create, :sheet => @attr
1207 response.status.should eq 302
1209 it '作成された用紙の表示ページへ遷移する' do
1210 # Sheet.any_instance.stub(:save).and_return(true)
1211 post :create, :sheet => @attr
1212 response.should redirect_to(Sheet.last)
1216 it 'ステータスコード200 OKを返す' do
1217 # Sheet.any_instance.stub(:save).and_return(true)
1218 post :create, :sheet => @attr, :format => :json
1219 response.should be_success
1221 it '作成された用紙をjsonデータで返す' do
1222 post :create, :sheet => @attr, :format => :json
1223 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1227 context 'ユーザ権限がないとき' do
1232 it 'ステータスコード302 Foundを返す' do
1233 post :create, :sheet => @attr
1234 response.status.should eq 302
1236 it 'サインインページへ遷移する' do
1237 post :create, :sheet => @attr
1238 response.body.should redirect_to '/users/sign_in'
1242 it 'ステータスコード401 Unauthorizedを返す' do
1243 post :create, :sheet => @attr, :format => :json
1244 response.status.should eq 401
1246 it '応答メッセージにUnauthorizedを返す' do
1247 post :create, :sheet => @attr, :format => :json
1248 response.message.should match(/Unauthorized/)
1254 describe '編集フォーム表示に於いて' do
1256 @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
1258 Sheet.stub(:edit).and_return(@sheet)
1260 context 'つつがなく終わるとき' do
1261 it 'ステータスコード200 OKを返す' do
1262 get :edit, :id => @sheet.id
1263 response.should be_success
1266 it 'editテンプレートを描画する' do
1267 get :edit, :id => @sheet.id
1268 response.should render_template("edit")
1272 it 'edit.jsテンプレートを描画する' do
1273 get :edit, :id => @sheet.id, :format => :js
1274 response.should render_template("edit")
1278 context 'ユーザ権限がないとき' do
1283 it 'ステータスコード302 Foundを返す' do
1284 get :edit, :id => @sheet.id
1285 response.status.should eq 302
1287 it 'サインインページへ遷移する' do
1288 get :edit, :id => @sheet.id
1289 response.body.should redirect_to '/users/sign_in'
1293 it 'ステータスコード401 Unauthorizedを返す' do
1294 get :edit, :id => @sheet.id, :format => :js
1295 response.status.should eq 401
1297 it '応答メッセージにUnauthorizedを返す' do
1298 get :edit, :id => @sheet.id, :format => :js
1299 response.message.should match(/Unauthorized/)
1305 describe '更新に於いて' do
1307 @sheet = FactoryGirl.create :sheet, :author => @author
1308 @attr = FactoryGirl.attributes_for(:sheet, :author_id => @author.id, :caption => 'updated caption', :visible => 0)
1311 context 'つつがなく終わるとき' do
1313 it 'ステータスコード302 Foundを返す' do
1314 Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
1315 put :update, :id => @sheet.id, :sheet => @attr
1316 response.status.should eq 302
1318 it '更新された用紙の表示ページへ遷移する' do
1319 put :update, :id => @sheet.id, :sheet => @attr
1320 response.should redirect_to(@sheet)
1324 it 'ステータスコード200 OKを返す' do
1325 Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
1326 put :update, :id => @sheet.id, :sheet => @attr, :format => :json
1327 response.should be_success
1329 it 'ページ本体は特に返さない' do
1330 Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
1331 put :update, :id => @sheet.id, :sheet => @attr, :format => :json
1332 response.body.should match /./
1336 context 'ユーザ権限がないとき' do
1340 it 'ステータスコード302 Foundを返す' do
1341 put :update, :id => @sheet.id, :sheet => @attr
1342 response.status.should eq 302
1345 it 'サインインページへ遷移する' do
1346 put :update, :id => @sheet.id, :sheet => @attr
1347 response.body.should redirect_to '/users/sign_in'
1353 describe '削除に於いて' do
1355 @sheet = FactoryGirl.create :sheet, :author => @author
1358 context 'つつがなく終わるとき' do
1361 Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
1363 it 'ステータスコード302 Foundを返す' do
1364 delete :destroy, :id => @sheet.id
1365 response.status.should eq 302
1367 it 'マイ用紙の一覧ページへ遷移する' do
1368 delete :destroy, :id => @sheet.id
1369 response.should redirect_to('/home/sheet')
1374 Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
1376 it 'ステータスコード200 OKを返す' do
1377 delete :destroy, :id => @sheet.id, :format => :json
1378 response.should be_success
1380 it 'ページ本体は特に返さない' do
1381 delete :destroy, :id => @sheet.id, :format => :json
1382 response.body.should match /./
1386 context 'ユーザ権限がないとき' do
1390 it 'ステータスコード302 Foundを返す' do
1391 delete :destroy, :id => @sheet.id
1392 response.status.should eq 302
1395 it 'サインインページへ遷移する' do
1396 delete :destroy, :id => @sheet.id
1397 response.body.should redirect_to '/users/sign_in'
1401 it '応答メッセージにUnauthorizedを返す' do
1402 delete :destroy, :id => @sheet.id, :format => :json
1403 response.message.should match(/Unauthorized/)