1 # -*- encoding: utf-8 -*-
4 describe StoriesController 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 @panel = FactoryGirl.create :panel, :author_id => @author.id
16 if MagicNumber['run_mode'] == 1
17 describe '一覧表示に於いて' do
20 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
21 Story.stub(:list).and_return([@story, @story, @story])
23 context 'パラメータpageについて' do
25 get :index, :page => 5
26 assigns(:page).should eq 5
28 it '省略されると@pageに1値が入る' do
30 assigns(:page).should eq 1
32 it '与えられたpage_sizeがセットされている' do
33 get :index, :page_size => 15
34 assigns(:page_size).should eq 15
36 it '省略されると@page_sizeにデフォルト値が入る' do
38 assigns(:page_size).should eq Story.default_page_size
40 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
41 get :index, :page_size => 1500
42 assigns(:page_size).should eq Story.max_page_size
44 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
45 get :index, :page_size => 0
46 assigns(:page_size).should eq Story.default_page_size
49 context 'つつがなく終わるとき' do
50 it 'ステータスコード200 OKを返す' do
52 response.should be_success
54 it 'ストーリーモデルに一覧を問い合わせている' do
55 Story.should_receive(:list).exactly(1)
58 it '@storiesにリストを取得している' do
60 assigns(:stories).should have_at_least(3).items
63 it '@paginateにページ制御を取得している' do
65 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
67 it 'indexテンプレートを描画する' do
69 response.should render_template("index")
74 get :index, :format => :json
75 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
77 it 'ストーリーモデルにjson一覧出力オプションを問い合わせている' do
78 Story.should_receive(:list_json_opt).exactly(1)
79 get :index, :format => :json
81 it 'データがリスト構造になっている' do
82 get :index, :format => :json
83 json = JSON.parse response.body
84 json.should have_at_least(3).items
86 it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
87 get :index, :format => :json
88 json = JSON.parse response.body
89 json.first.has_key?("panel_id").should be_true
90 json.first.has_key?("comic_id").should be_true
91 json.first.has_key?("t").should be_true
95 context 'ユーザ権限がないとき' do
100 it 'ステータスコード302 Foundを返す' do
102 response.status.should eq 302
104 it 'サインインページへ遷移する' do
106 response.should redirect_to '/users/sign_in'
110 it 'ステータスコード401 Unauthorizedを返す' do
111 get :index, :format => :json
112 response.status.should eq 401
114 it '応答メッセージにUnauthorizedを返す' do
115 get :index, :format => :json
116 response.message.should match(/Unauthorized/)
120 context 'ユーザ権限はないが管理者権限があるとき' do
125 it 'ステータスコード200 OKを返す' do
127 response.should be_success
130 context 'ユーザだが作家登録していないとき' do
134 it 'ステータスコード200 OKを返す' do
136 response.should be_success
141 describe '単体表示に於いて' do
144 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
145 Comic.stub(:show).with(@comic.id.to_s, [@user, nil]).and_return(@comic)
146 Comic.stub(:show).with(@comic.id.to_s, [nil, @admin]).and_return(@comic)
147 Story.stub(:show).with(@story.id.to_s, [@user, nil]).and_return(@story)
148 Story.stub(:show).with(@story.id.to_s, [nil, @admin]).and_return(@story)
150 context 'つつがなく終わるとき' do
151 it 'ストーリーモデルに単体取得を問い合わせている' do
152 Story.should_receive(:show).with(@story.id.to_s, [@user, nil]).exactly(1)
153 get :show, :id => @story.id
155 it '@storyにアレを取得している' do
156 get :show, :id => @story.id
157 assigns(:story).should eq @story
160 it 'ステータスコード200 OKを返す' do
161 get :show, :id => @story.id
162 response.should be_success
164 it 'showテンプレートを描画する' do
165 get :show, :id => @story.id
166 response.should render_template("show")
170 it 'ステータスコード200 OKを返す' do
171 get :show, :id => @story.id, :format => :json
172 response.should be_success
175 get :show, :id => @story.id, :format => :json
176 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
178 it 'ストーリーモデルにストーリーjson出力を問い合わせている' do
179 Story.any_instance.should_receive(:story_as_json).exactly(1)
180 get :show, :id => @story.id, :format => :json
183 get :show, :id => @story.id, :format => :json
184 json = JSON.parse response.body
185 json.has_key?("panel_id").should be_true
186 json.has_key?("comic_id").should be_true
187 json.has_key?("author_id").should be_true
191 context 'ユーザ権限がないとき' do
196 it 'ステータスコード302 Foundを返す' do
197 get :show, :id => @story.id
198 response.status.should eq 302
200 it 'サインインページへ遷移する' do
201 get :show, :id => @story.id
202 response.body.should redirect_to '/users/sign_in'
206 it 'ステータスコード401 Unauthorizedを返す' do
207 get :show, :id => @story.id, :format => :json
208 response.status.should eq 401
210 it '応答メッセージにUnauthorizedを返す' do
211 get :show, :id => @story.id, :format => :json
212 response.message.should match(/Unauthorized/)
216 context 'ユーザ権限はないが管理者権限があるとき' do
221 it 'ステータスコード200 OKを返す' do
222 get :show, :id => @story.id
223 response.should be_success
226 context 'ユーザだが作家登録していないとき' do
230 it 'ステータスコード200 OKを返す' do
231 get :show, :id => @story.id
232 response.should be_success
239 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
240 Comic.stub(:show).with(@comic.id.to_s, [@user, nil]).and_return(@comic)
241 Comic.stub(:show).with(@comic.id.to_s, [nil, @admin]).and_return(@comic)
242 Story.stub(:count).and_return(10)
243 Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])
246 context 'パラメータチェックする' do
247 it '与えられたoffsetがセットされている' do
248 get :comic, :id => @comic.id, :offset => 5
249 assigns(:offset).should eq 5
251 it '省略されると@offsetに0値が入る' do
252 get :comic, :id => @comic.id
253 assigns(:offset).should eq 0
255 it '与えられたcountがセットされている' do
256 get :comic, :id => @comic.id, :count => 4
257 assigns(:panel_count).should eq 4
259 it '省略されると@panel_countにデフォルト値が入る' do
260 get :comic, :id => @comic.id
261 assigns(:panel_count).should eq Story.default_panel_size
263 it '最大を超えると@panel_countにデフォルト最大値が入る' do
264 get :comic, :id => @comic.id, :count => 1500
265 assigns(:panel_count).should eq Story.max_panel_size
267 it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
268 get :comic, :id => @comic.id, :count => -1
269 assigns(:panel_count).should eq Story.default_panel_size
272 context '事前チェックする' do
273 it 'コミックモデルに単体取得を問い合わせている' do
274 Comic.should_receive(:show).with(@comic.id.to_s, [@user, nil]).exactly(1)
275 get :comic, :id => @comic.id
277 it 'ストーリーモデルにプレイリスト取得を問い合わせている' do
278 Story.should_receive(:play_list).with(@comic, @author, 0, 30).exactly(1)
279 get :comic, :id => @comic.id
282 context 'つつがなく終わるとき' do
283 it '@storiesにリストを取得している' do
284 get :comic, :id => @comic.id
285 assigns(:stories).should have_at_least(3).items
288 it '@paginateにページ制御を取得している' do
289 get :comic, :id => @comic.id
290 assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
292 it 'ステータスコード200 OKを返す' do
293 get :comic, :id => @comic.id
294 response.should be_success
296 it 'comicテンプレートを描画する' do
297 get :comic, :id => @comic.id
298 response.should render_template("comic")
302 it 'ステータスコード200 OKを返す' do
303 get :comic, :id => @comic.id, :format => :json
304 response.should be_success
307 get :comic, :id => @comic.id, :format => :json
308 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
310 it 'ストーリーモデルにストーリーリストのjson出力を問い合わせている' do
311 Story.should_receive(:list_as_json_text).exactly(1)
312 get :comic, :id => @comic.id, :format => :json
314 it 'データがリスト構造になっている' do
315 get :comic, :id => @comic.id, :format => :json
316 json = JSON.parse response.body
317 json.should have_at_least(3).items
319 it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
320 get :comic, :id => @comic.id, :format => :json
321 json = JSON.parse response.body
322 json.first.has_key?("panel_id").should be_true
323 json.first.has_key?("comic_id").should be_true
324 json.first.has_key?("author_id").should be_true
328 context 'ユーザ権限がないとき' do
333 it 'ステータスコード302 Foundを返す' do
334 get :comic, :id => @comic.id
335 response.status.should eq 302
337 it 'サインインページへ遷移する' do
338 get :comic, :id => @comic.id
339 response.should redirect_to '/users/sign_in'
343 it 'ステータスコード401 Unauthorizedを返す' do
344 get :comic, :id => @comic.id, :format => :json
345 response.status.should eq 401
347 it '応答メッセージにUnauthorizedを返す' do
348 get :comic, :id => @comic.id, :format => :json
349 response.message.should match(/Unauthorized/)
353 context 'ユーザ権限はないが管理者権限があるとき' do
358 it 'ステータスコード200 OKを返す' do
359 get :comic, :id => @comic.id
360 response.should be_success
363 context 'ユーザだが作家登録していないとき' do
367 it 'ステータスコード200 OKを返す' do
368 get :comic, :id => @comic.id
369 response.should be_success
374 describe '新規作成フォーム表示に於いて' do
378 context 'つつがなく終わるとき' do
379 it '@storyに新規データを用意している' do
381 assigns(:story).should be_a_new(Story)
383 it 'モデルにデフォルト値補充を依頼している' do
384 Story.any_instance.should_receive(:supply_default).exactly(1)
388 it 'ステータスコード200 OKを返す' do
390 response.should be_success
392 it 'newテンプレートを描画する' do
394 response.should render_template("new")
398 it 'ステータスコード200 OKを返す' do
399 get :new, :format => :js
400 response.should be_success
402 it 'new.jsテンプレートを描画する' do
403 get :new, :format => :js
404 response.should render_template("new")
408 it 'ステータスコード200 OKを返す' do
409 get :new, :format => :json
410 response.should be_success
413 get :new, :format => :json
414 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
416 it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
417 Story.any_instance.should_receive(:story_as_json).exactly(1)
418 get :new, :format => :json
421 get :new, :format => :json
422 json = JSON.parse response.body
423 json.has_key?("panel_id").should be_true
424 json.has_key?("comic_id").should be_true
425 json.has_key?("author_id").should be_true
429 context 'ユーザ権限がないとき' do
434 it 'ステータスコード302 Foundを返す' do
436 response.status.should eq 302
438 it 'サインインページへ遷移する' do
440 response.body.should redirect_to '/users/sign_in'
444 it 'ステータスコード401 Unauthorizedを返す' do
445 get :new, :format => :json
446 response.status.should eq 401
448 it '応答メッセージにUnauthorizedを返す' do
449 get :new, :format => :json
450 response.message.should match(/Unauthorized/)
454 context 'ユーザ権限はないが管理者権限があるとき' do
460 it 'ステータスコード302 Foundを返す' do
462 response.status.should eq 302
464 it 'サインインページへ遷移する' do
466 response.body.should redirect_to '/users/sign_in'
470 context 'ユーザだが作家登録していないとき' do
475 it 'ステータスコード302 Foundを返す' do
477 response.status.should eq 302
481 response.body.should redirect_to new_author_path
487 describe '新規作成に於いて' do
489 @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
492 context 'つつがなく終わるとき' do
493 it 'デフォルト値補充を依頼する' do
494 Story.any_instance.should_receive(:supply_default).exactly(1)
495 post :create, :story => @attr
497 it 'POSTデータから、カラム値を復元している' do
498 Story.any_instance.stub(:store).and_return(true)
499 post :create, :story => @attr
500 assigns(:story).comic_id.should eq @comic.id
501 assigns(:story).panel_id.should eq @panel.id
504 Story.any_instance.should_receive(:overwrite).exactly(1)
505 post :create, :story => @attr
507 it 'コミックモデルに編集取得を依頼している' do
508 Comic.should_receive(:edit).with(@comic.id, @author).exactly(1)
509 post :create, :story => @attr
511 it 'コマモデルに単体取得を依頼している' do
512 Panel.should_receive(:show).with(@panel.id, @author).exactly(1)
513 post :create, :story => @attr
516 Story.any_instance.should_receive(:store).exactly(1)
517 post :create, :story => @attr
519 it "@storyに作成されたコマを保持していて、それがDBにある" do
520 post :create, :story => @attr
521 assigns(:story).should be_a(Story)
522 assigns(:story).should be_persisted
525 it 'ステータスコード302 Foundを返す' do
526 Story.any_instance.stub(:store).and_return(true)
527 post :create, :story => @attr
528 response.status.should eq 302
530 it 'コミックのストーリー表示へ遷移する' do
531 # Story.any_instance.stub(:store).and_return(true)
532 post :create, :story => @attr
533 response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
537 it 'ステータスコード200 OKを返す' do
538 # Story.any_instance.stub(:store).and_return(true)
539 post :create, :story => @attr, :format => :json
540 response.should be_success
542 it '作成されたコマをjsonデータで返す' do
543 post :create, :story => @attr, :format => :json
544 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
546 it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
547 Story.any_instance.should_receive(:story_as_json).exactly(1)
548 post :create, :story => @attr, :format => :json
551 post :create, :story => @attr, :format => :json
552 json = JSON.parse response.body
553 json["t"].should eq 0
557 context 'ユーザ権限がないとき' do
562 it 'ステータスコード302 Foundを返す' do
563 post :create, :story => @attr
564 response.status.should eq 302
566 it 'サインインページへ遷移する' do
567 post :create, :story => @attr
568 response.body.should redirect_to '/users/sign_in'
572 it 'ステータスコード401 Unauthorizedを返す' do
573 post :create, :story => @attr, :format => :json
574 response.status.should eq 401
576 it '応答メッセージにUnauthorizedを返す' do
577 post :create, :story => @attr, :format => :json
578 response.message.should match(/Unauthorized/)
582 context 'ユーザ権限はないが管理者権限があるとき' do
588 it 'ステータスコード302 Foundを返す' do
589 post :create, :story => @attr
590 response.status.should eq 302
592 it 'サインインページへ遷移する' do
593 post :create, :story => @attr
594 response.body.should redirect_to '/users/sign_in'
598 context 'ユーザだが作家登録していないとき' do
603 it 'ステータスコード302 Foundを返す' do
604 post :create, :story => @attr
605 response.status.should eq 302
608 post :create, :story => @attr
609 response.body.should redirect_to new_author_path
613 context '検証、保存に失敗した' do
615 Story.any_instance.stub(:store).and_return(false)
617 it "未保存のコマを保持している" do
618 post :create, :story => @attr
619 assigns(:story).should be_a_new(Story)
622 it 'ステータスコード200 OKを返す' do
623 post :create, :story => @attr
624 response.status.should eq 200
627 post :create, :story => @attr
628 response.should render_template("new")
632 it 'ステータスコード422 unprocessable_entity を返す' do
633 post :create, :story => @attr, :format => :json
634 response.status.should eq 422
636 it '応答メッセージUnprocessable Entityを返す' do
637 post :create, :story => @attr, :format => :json
638 response.message.should match(/Unprocessable/)
644 describe '編集フォーム表示に於いて' do
646 @story = FactoryGirl.create :story, :author_id => @author.id
648 Story.stub(:show).and_return(@story)
650 context 'つつがなく終わるとき' do
651 it 'ストーリーモデルに編集取得を問い合わせている' do
652 Story.should_receive(:edit).exactly(1)
653 get :edit, :id => @story.id
655 it '@storyにデータを用意している' do
656 get :edit, :id => @story.id
657 assigns(:story).should eq @story
660 it 'ステータスコード200 OKを返す' do
661 get :edit, :id => @story.id
662 response.should be_success
664 it 'editテンプレートを描画する' do
665 get :edit, :id => @story.id
666 response.should render_template("edit")
670 it 'ステータスコード200 OKを返す' do
671 get :edit, :id => @story.id, :format => :js
672 response.should be_success
674 it 'edit.jsテンプレートを描画する' do
675 get :edit, :id => @story.id, :format => :js
676 response.should render_template("edit")
680 context 'ユーザ権限がないとき' do
685 it 'ステータスコード302 Foundを返す' do
686 get :edit, :id => @story.id
687 response.status.should eq 302
689 it 'サインインページへ遷移する' do
690 get :edit, :id => @story.id
691 response.body.should redirect_to '/users/sign_in'
695 it 'ステータスコード401 Unauthorizedを返す' do
696 get :edit, :id => @story.id, :format => :js
697 response.status.should eq 401
699 it '応答メッセージにUnauthorizedを返す' do
700 get :edit, :id => @story.id, :format => :js
701 response.message.should match(/Unauthorized/)
705 context 'ユーザ権限はないが管理者権限があるとき' do
711 it 'ステータスコード302 Foundを返す' do
712 get :edit, :id => @story.id
713 response.status.should eq 302
715 it 'サインインページへ遷移する' do
716 get :edit, :id => @story.id
717 response.body.should redirect_to '/users/sign_in'
721 context 'ユーザだが作家登録していないとき' do
726 it 'ステータスコード302 Foundを返す' do
727 get :edit, :id => @story.id
728 response.status.should eq 302
731 get :edit, :id => @story.id
732 response.body.should redirect_to new_author_path
740 @story = FactoryGirl.create :story, :author_id => @user.author.id
741 @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
744 context 'つつがなく終わるとき' do
746 Story.stub(:edit).with(any_args).and_return(@story)
747 Story.should_receive(:edit).exactly(1)
748 put :update, :id => @story.id, :story => @attr
750 it 'POSTデータから、カラム値を復元している' do
751 Story.any_instance.stub(:store).and_return(true)
752 Story.any_instance.should_receive(:attributes=).exactly(1)
753 put :update, :id => @story.id, :story => @attr
756 Story.any_instance.should_receive(:overwrite).exactly(1)
757 put :update, :id => @story.id, :story => @attr
760 Story.any_instance.should_receive(:store).exactly(1)
761 put :update, :id => @story.id, :story => @attr
763 it "@storyに作成されたストーリーを保持していて、それがDBにある" do
764 put :update, :id => @story.id, :story => @attr
765 assigns(:story).should be_a(Story)
766 assigns(:story).should be_persisted
769 it 'ステータスコード302 Foundを返す' do
770 Story.any_instance.stub(:store).and_return(true)
771 put :update, :id => @story.id, :story => @attr
772 response.status.should eq 302
775 # Story.any_instance.stub(:store).and_return(true)
776 put :update, :id => @story.id, :story => @attr
777 response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
781 it 'ステータスコード200 OKを返す' do
782 # Story.any_instance.stub(:store).and_return(true)
783 put :update, :id => @story.id, :story => @attr, :format => :json
784 response.should be_success
788 context 'ユーザ権限がないとき' do
793 it 'ステータスコード302 Foundを返す' do
794 put :update, :id => @story.id, :story => @attr
795 response.status.should eq 302
797 it 'サインインページへ遷移する' do
798 put :update, :id => @story.id, :story => @attr
799 response.body.should redirect_to '/users/sign_in'
803 it 'ステータスコード401 Unauthorizedを返す' do
804 put :update, :id => @story.id, :story => @attr, :format => :json
805 response.status.should eq 401
807 it '応答メッセージにUnauthorizedを返す' do
808 put :update, :id => @story.id, :story => @attr, :format => :json
809 response.message.should match(/Unauthorized/)
813 context 'ユーザ権限はないが管理者権限があるとき' do
819 it 'ステータスコード302 Foundを返す' do
820 put :update, :id => @story.id, :story => @attr
821 response.status.should eq 302
823 it 'サインインページへ遷移する' do
824 put :update, :id => @story.id, :story => @attr
825 response.body.should redirect_to '/users/sign_in'
829 context 'ユーザだが作家登録していないとき' do
834 it 'ステータスコード302 Foundを返す' do
835 put :update, :id => @story.id, :story => @attr
836 response.status.should eq 302
839 put :update, :id => @story.id, :story => @attr
840 response.body.should redirect_to new_author_path
844 context '検証、保存に失敗した' do
846 Story.any_instance.stub(:store).and_return(false)
849 put :update, :id => @story.id, :story => @attr
850 assigns(:story).should eq @story
853 it 'ステータスコード200 OKを返す' do
854 put :update, :id => @story.id, :story => @attr
855 response.status.should eq 200
858 put :update, :id => @story.id, :story => @attr
859 response.should render_template("edit")
863 it 'ステータスコード422 unprocessable_entity を返す' do
864 put :update, :id => @story.id, :story => @attr, :format => :json
865 response.status.should eq 422
867 it '応答メッセージUnprocessable Entityを返す' do
868 put :update, :id => @story.id, :story => @attr, :format => :json
869 response.message.should match(/Unprocessable/)
877 @story = FactoryGirl.create :story, :author_id => @author.id
879 Story.stub(:edit).and_return(@story)
881 context '事前チェックしておく' do
883 Story.stub(:edit).with(any_args()).and_return @story
884 Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
886 it 'ストーリーモデルに編集取得を問い合わせている' do
887 Story.should_receive(:edit).exactly(1)
888 delete :destroy, :id => @story.id
891 Story.any_instance.should_receive(:destroy_and_shorten).exactly(1)
892 delete :destroy, :id => @story.id
894 it '@storyにアレを取得している' do
895 delete :destroy, :id => @story.id
896 assigns(:story).id.should eq(@story.id)
899 context 'つつがなく終わるとき' do
901 Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
904 it 'ステータスコード302 Foundを返す' do
905 delete :destroy, :id => @story.id
906 response.status.should eq 302
909 delete :destroy, :id => @story.id
910 response.should redirect_to(:controller => 'stories', :action => :comic, :id => @story.comic_id)
914 it 'ステータスコード200 OKを返す' do
915 delete :destroy, :id => @story.id, :format => :json
916 response.should be_success
920 context 'ユーザ権限がないとき' do
925 it 'ステータスコード302 Foundを返す' do
926 delete :destroy, :id => @story.id
927 response.status.should eq 302
929 it 'サインインページへ遷移する' do
930 delete :destroy, :id => @story.id
931 response.body.should redirect_to '/users/sign_in'
935 it 'ステータスコード401 Unauthorizedを返す' do
936 delete :destroy, :id => @story.id, :format => :json
937 response.status.should eq 401
939 it '応答メッセージにUnauthorizedを返す' do
940 delete :destroy, :id => @story.id, :format => :json
941 response.message.should match(/Unauthorized/)
945 context 'ユーザ権限はないが管理者権限があるとき' do
951 it 'ステータスコード302 Foundを返す' do
952 delete :destroy, :id => @story.id
953 response.status.should eq 302
955 it 'サインインページへ遷移する' do
956 delete :destroy, :id => @story.id
957 response.body.should redirect_to '/users/sign_in'
961 context 'ユーザだが作家登録していないとき' do
966 it 'ステータスコード302 Foundを返す' do
967 delete :destroy, :id => @story.id
968 response.status.should eq 302
971 delete :destroy, :id => @story.id
972 response.body.should redirect_to new_author_path
976 context '削除に失敗したとき' do
978 Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(false)
981 it 'ステータスコード302 Foundを返す' do
982 delete :destroy, :id => @story.id
983 response.status.should eq 302
985 it 'そのコミックの詳細ページへ遷移する' do
986 delete :destroy, :id => @story.id
987 response.should redirect_to(story_path(@story))
991 it 'ステータスコード422 unprocessable_entity を返す' do
992 delete :destroy, :id => @story.id, :format => :json
993 response.status.should eq 422
995 it '応答メッセージUnprocessable Entityを返す' do
996 delete :destroy, :id => @story.id, :format => :json
997 response.message.should match(/Unprocessable/)
1002 context '対象ストーリーがないとき' do
1004 context '他人のストーリーだったとき' do
1010 describe '一覧表示に於いて' do
1013 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1014 Story.stub(:list).and_return([@story, @story, @story])
1016 context 'つつがなく終わるとき' do
1017 it 'ステータスコード200 OKを返す' do
1019 response.should be_success
1022 it 'indexテンプレートを描画する' do
1024 response.should render_template("index")
1029 get :index, :format => :json
1030 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1034 context 'ユーザ権限がないとき' do
1038 it 'ステータスコード200 OKを返す' do
1040 response.should be_success
1043 it 'indexテンプレートを描画する' do
1045 response.should render_template("index")
1050 get :index, :format => :json
1051 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1057 describe '単体表示に於いて' do
1060 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1061 Comic.stub(:show).with(@comic.id.to_s, [nil, nil]).and_return(@comic)
1062 Comic.stub(:show).with(@comic.id.to_s, [@user, nil]).and_return(@comic)
1063 Comic.stub(:show).with(@comic.id.to_s, [nil, @admin]).and_return(@comic)
1064 Story.stub(:show).with(@story.id.to_s, [nil, nil]).and_return(@story)
1065 Story.stub(:show).with(@story.id.to_s, [@user, nil]).and_return(@story)
1066 Story.stub(:show).with(@story.id.to_s, [nil, @admin]).and_return(@story)
1068 context 'つつがなく終わるとき' do
1070 it 'ステータスコード200 OKを返す' do
1071 get :show, :id => @story.id
1072 response.should be_success
1074 it 'showテンプレートを描画する' do
1075 get :show, :id => @story.id
1076 response.should render_template("show")
1080 it 'ステータスコード200 OKを返す' do
1081 get :show, :id => @story.id, :format => :json
1082 response.should be_success
1085 get :show, :id => @story.id, :format => :json
1086 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1090 context 'ユーザ権限がないとき' do
1095 it 'ステータスコード200 OKを返す' do
1096 get :show, :id => @story.id
1097 response.should be_success
1099 it 'showテンプレートを描画する' do
1100 get :show, :id => @story.id
1101 response.should render_template("show")
1105 it 'ステータスコード200 OKを返す' do
1106 get :show, :id => @story.id, :format => :json
1107 response.should be_success
1110 get :show, :id => @story.id, :format => :json
1111 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1117 describe '閲覧に於いて' do
1119 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1120 Comic.stub(:show).with(@comic.id.to_s, [nil, nil]).and_return(@comic)
1121 Comic.stub(:show).with(@comic.id.to_s, [@user, nil]).and_return(@comic)
1122 Comic.stub(:show).with(@comic.id.to_s, [nil, @admin]).and_return(@comic)
1123 Story.stub(:count).and_return(10)
1124 Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])
1127 context 'つつがなく終わるとき' do
1129 it 'ステータスコード200 OKを返す' do
1130 get :comic, :id => @comic.id
1131 response.should be_success
1133 it 'comicテンプレートを描画する' do
1134 get :comic, :id => @comic.id
1135 response.should render_template("comic")
1139 it 'ステータスコード200 OKを返す' do
1140 get :comic, :id => @comic.id, :format => :json
1141 response.should be_success
1144 get :comic, :id => @comic.id, :format => :json
1145 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1149 context 'ユーザ権限がないとき' do
1154 it 'ステータスコード200 OKを返す' do
1155 get :comic, :id => @comic.id
1156 response.should be_success
1158 it 'comicテンプレートを描画する' do
1159 get :comic, :id => @comic.id
1160 response.should render_template("comic")
1164 it 'ステータスコード200 OKを返す' do
1165 get :comic, :id => @comic.id, :format => :json
1166 response.should be_success
1169 get :comic, :id => @comic.id, :format => :json
1170 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1176 describe '新規作成フォーム表示に於いて' do
1180 context 'つつがなく終わるとき' do
1182 it 'ステータスコード200 OKを返す' do
1184 response.should be_success
1186 it 'newテンプレートを描画する' do
1188 response.should render_template("new")
1192 it 'ステータスコード200 OKを返す' do
1193 get :new, :format => :js
1194 response.should be_success
1196 it 'new.jsテンプレートを描画する' do
1197 get :new, :format => :js
1198 response.should render_template("new")
1202 it 'ステータスコード200 OKを返す' do
1203 get :new, :format => :json
1204 response.should be_success
1207 get :new, :format => :json
1208 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1212 context 'ユーザ権限がないとき' do
1217 it 'ステータスコード302 Foundを返す' do
1219 response.status.should eq 302
1221 it 'サインインページへ遷移する' do
1223 response.body.should redirect_to '/users/sign_in'
1227 it 'ステータスコード401 Unauthorizedを返す' do
1228 get :new, :format => :json
1229 response.status.should eq 401
1231 it '応答メッセージにUnauthorizedを返す' do
1232 get :new, :format => :json
1233 response.message.should match(/Unauthorized/)
1239 describe '新規作成に於いて' do
1241 @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
1244 context 'つつがなく終わるとき' do
1246 it 'ステータスコード302 Foundを返す' do
1247 Story.any_instance.stub(:store).and_return(true)
1248 post :create, :story => @attr
1249 response.status.should eq 302
1251 it 'コミックのストーリー表示へ遷移する' do
1252 # Story.any_instance.stub(:store).and_return(true)
1253 post :create, :story => @attr
1254 response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
1258 it 'ステータスコード200 OKを返す' do
1259 # Story.any_instance.stub(:store).and_return(true)
1260 post :create, :story => @attr, :format => :json
1261 response.should be_success
1263 it '作成されたコマをjsonデータで返す' do
1264 post :create, :story => @attr, :format => :json
1265 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1269 context 'ユーザ権限がないとき' do
1274 it 'ステータスコード302 Foundを返す' do
1275 post :create, :story => @attr
1276 response.status.should eq 302
1278 it 'サインインページへ遷移する' do
1279 post :create, :story => @attr
1280 response.body.should redirect_to '/users/sign_in'
1284 it 'ステータスコード401 Unauthorizedを返す' do
1285 post :create, :story => @attr, :format => :json
1286 response.status.should eq 401
1288 it '応答メッセージにUnauthorizedを返す' do
1289 post :create, :story => @attr, :format => :json
1290 response.message.should match(/Unauthorized/)
1296 describe '編集フォーム表示に於いて' do
1298 @story = FactoryGirl.create :story, :author_id => @author.id
1300 Story.stub(:show).and_return(@story)
1302 context 'つつがなく終わるとき' do
1304 it 'ステータスコード200 OKを返す' do
1305 get :edit, :id => @story.id
1306 response.should be_success
1308 it 'editテンプレートを描画する' do
1309 get :edit, :id => @story.id
1310 response.should render_template("edit")
1314 it 'ステータスコード200 OKを返す' do
1315 get :edit, :id => @story.id, :format => :js
1316 response.should be_success
1318 it 'edit.jsテンプレートを描画する' do
1319 get :edit, :id => @story.id, :format => :js
1320 response.should render_template("edit")
1324 context 'ユーザ権限がないとき' do
1329 it 'ステータスコード302 Foundを返す' do
1330 get :edit, :id => @story.id
1331 response.status.should eq 302
1333 it 'サインインページへ遷移する' do
1334 get :edit, :id => @story.id
1335 response.body.should redirect_to '/users/sign_in'
1339 it 'ステータスコード401 Unauthorizedを返す' do
1340 get :edit, :id => @story.id, :format => :js
1341 response.status.should eq 401
1343 it '応答メッセージにUnauthorizedを返す' do
1344 get :edit, :id => @story.id, :format => :js
1345 response.message.should match(/Unauthorized/)
1351 describe '更新に於いて' do
1353 @story = FactoryGirl.create :story, :author_id => @user.author.id
1354 @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
1357 context 'つつがなく終わるとき' do
1359 it 'ステータスコード302 Foundを返す' do
1360 Story.any_instance.stub(:store).and_return(true)
1361 put :update, :id => @story.id, :story => @attr
1362 response.status.should eq 302
1364 it 'ストーリー表示へ遷移する' do
1365 # Story.any_instance.stub(:store).and_return(true)
1366 put :update, :id => @story.id, :story => @attr
1367 response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
1371 it 'ステータスコード200 OKを返す' do
1372 # Story.any_instance.stub(:store).and_return(true)
1373 put :update, :id => @story.id, :story => @attr, :format => :json
1374 response.should be_success
1378 context 'ユーザ権限がないとき' do
1383 it 'ステータスコード302 Foundを返す' do
1384 put :update, :id => @story.id, :story => @attr
1385 response.status.should eq 302
1387 it 'サインインページへ遷移する' do
1388 put :update, :id => @story.id, :story => @attr
1389 response.body.should redirect_to '/users/sign_in'
1393 it 'ステータスコード401 Unauthorizedを返す' do
1394 put :update, :id => @story.id, :story => @attr, :format => :json
1395 response.status.should eq 401
1397 it '応答メッセージにUnauthorizedを返す' do
1398 put :update, :id => @story.id, :story => @attr, :format => :json
1399 response.message.should match(/Unauthorized/)
1405 describe '削除に於いて' do
1407 @story = FactoryGirl.create :story, :author_id => @author.id
1409 Story.stub(:edit).and_return(@story)
1411 context 'つつがなく終わるとき' do
1413 Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
1416 it 'ステータスコード302 Foundを返す' do
1417 delete :destroy, :id => @story.id
1418 response.status.should eq 302
1421 delete :destroy, :id => @story.id
1422 response.should redirect_to(:controller => 'stories', :action => :comic, :id => @story.comic_id)
1426 it 'ステータスコード200 OKを返す' do
1427 delete :destroy, :id => @story.id, :format => :json
1428 response.should be_success
1432 context 'ユーザ権限がないとき' do
1437 it 'ステータスコード302 Foundを返す' do
1438 delete :destroy, :id => @story.id
1439 response.status.should eq 302
1441 it 'サインインページへ遷移する' do
1442 delete :destroy, :id => @story.id
1443 response.body.should redirect_to '/users/sign_in'
1447 it 'ステータスコード401 Unauthorizedを返す' do
1448 delete :destroy, :id => @story.id, :format => :json
1449 response.status.should eq 401
1451 it '応答メッセージにUnauthorizedを返す' do
1452 delete :destroy, :id => @story.id, :format => :json
1453 response.message.should match(/Unauthorized/)