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 'indexテンプレートを描画する' do
65 response.should render_template("index")
70 get :index, :format => :json
71 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
73 it 'ストーリーモデルにjson一覧出力オプションを問い合わせている' do
74 Story.should_receive(:list_json_opt).exactly(1)
75 get :index, :format => :json
77 it 'データがリスト構造になっている' do
78 get :index, :format => :json
79 json = JSON.parse response.body
80 json.should have_at_least(3).items
82 it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
83 get :index, :format => :json
84 json = JSON.parse response.body
85 json.first.has_key?("panel_id").should be_true
86 json.first.has_key?("comic_id").should be_true
87 json.first.has_key?("t").should be_true
91 context '作家権限がないとき' do
96 it 'ステータスコード302 Foundを返す' do
98 response.status.should eq 302
100 it 'サインインページへ遷移する' do
102 response.should redirect_to '/users/sign_in'
106 it 'ステータスコード401 Unauthorizedを返す' do
107 get :index, :format => :json
108 response.status.should eq 401
110 it '応答メッセージにUnauthorizedを返す' do
111 get :index, :format => :json
112 response.message.should match(/Unauthorized/)
116 context '作家権限はないが管理者権限があるとき' do
121 it 'ステータスコード200 OKを返す' do
123 response.should be_success
128 describe '単体表示に於いて' do
131 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
132 Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic)
133 Comic.stub(:show).with(@comic.id.to_s, nil).and_return(@comic)
134 Story.stub(:show).with(@story.id.to_s, @author).and_return(@story)
135 Story.stub(:show).with(@story.id.to_s, nil).and_return(@story)
137 context 'つつがなく終わるとき' do
138 it 'ストーリーモデルに単体取得を問い合わせている' do
139 Story.should_receive(:show).with(@story.id.to_s, @author).exactly(1)
140 get :show, :id => @story.id
142 it '@storyにアレを取得している' do
143 get :show, :id => @story.id
144 assigns(:story).should eq @story
147 it 'ステータスコード200 OKを返す' do
148 get :show, :id => @story.id
149 response.should be_success
151 it 'showテンプレートを描画する' do
152 get :show, :id => @story.id
153 response.should render_template("show")
157 it 'ステータスコード200 OKを返す' do
158 get :show, :id => @story.id, :format => :json
159 response.should be_success
162 get :show, :id => @story.id, :format => :json
163 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
165 it 'ストーリーモデルにストーリーjson出力を問い合わせている' do
166 Story.any_instance.should_receive(:story_as_json).exactly(1)
167 get :show, :id => @story.id, :format => :json
170 get :show, :id => @story.id, :format => :json
171 json = JSON.parse response.body
172 json.has_key?("panel_id").should be_true
173 json.has_key?("comic_id").should be_true
174 json.has_key?("author_id").should be_true
178 context '作家権限がないとき' do
183 it 'ステータスコード302 Foundを返す' do
184 get :show, :id => @story.id
185 response.status.should eq 302
187 it 'サインインページへ遷移する' do
188 get :show, :id => @story.id
189 response.body.should redirect_to '/users/sign_in'
193 it 'ステータスコード401 Unauthorizedを返す' do
194 get :show, :id => @story.id, :format => :json
195 response.status.should eq 401
197 it '応答メッセージにUnauthorizedを返す' do
198 get :show, :id => @story.id, :format => :json
199 response.message.should match(/Unauthorized/)
203 context '作家権限はないが管理者権限があるとき' do
208 it 'ステータスコード200 OKを返す' do
209 get :show, :id => @story.id
210 response.should be_success
217 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
218 Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic)
219 Comic.stub(:show).with(@comic.id.to_s, nil).and_return(@comic)
220 Story.stub(:count).and_return(10)
221 Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])
224 context 'パラメータチェックする' do
225 it '与えられたoffsetがセットされている' do
226 get :comic, :id => @comic.id, :offset => 5
227 assigns(:offset).should eq 5
229 it '省略されると@offsetに0値が入る' do
230 get :comic, :id => @comic.id
231 assigns(:offset).should eq 0
233 it '与えられたcountがセットされている' do
234 get :comic, :id => @comic.id, :count => 4
235 assigns(:panel_count).should eq 4
237 it '省略されると@panel_countにデフォルト値が入る' do
238 get :comic, :id => @comic.id
239 assigns(:panel_count).should eq Story.default_panel_size
241 it '最大を超えると@panel_countにデフォルト最大値が入る' do
242 get :comic, :id => @comic.id, :count => 1500
243 assigns(:panel_count).should eq Story.max_panel_size
245 it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
246 get :comic, :id => @comic.id, :count => -1
247 assigns(:panel_count).should eq Story.default_panel_size
250 context '事前チェックする' do
251 it 'コミックモデルに単体取得を問い合わせている' do
252 Comic.should_receive(:show).with(@comic.id.to_s, @author).exactly(1)
253 get :comic, :id => @comic.id
255 it 'ストーリーモデルにプレイリスト取得を問い合わせている' do
256 Story.should_receive(:play_list).with(@comic, @author, 0, 30).exactly(1)
257 get :comic, :id => @comic.id
260 context 'つつがなく終わるとき' do
261 it '@storiesにリストを取得している' do
262 get :comic, :id => @comic.id
263 assigns(:stories).should have_at_least(3).items
266 it 'ステータスコード200 OKを返す' do
267 get :comic, :id => @comic.id
268 response.should be_success
270 it 'comicテンプレートを描画する' do
271 get :comic, :id => @comic.id
272 response.should render_template("comic")
276 it 'ステータスコード200 OKを返す' do
277 get :comic, :id => @comic.id, :format => :json
278 response.should be_success
281 get :comic, :id => @comic.id, :format => :json
282 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
284 it 'ストーリーモデルにストーリーリストのjson出力を問い合わせている' do
285 Story.should_receive(:list_as_json_text).exactly(1)
286 get :comic, :id => @comic.id, :format => :json
288 it 'データがリスト構造になっている' do
289 get :comic, :id => @comic.id, :format => :json
290 json = JSON.parse response.body
291 json.should have_at_least(3).items
293 it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
294 get :comic, :id => @comic.id, :format => :json
295 json = JSON.parse response.body
296 json.first.has_key?("panel_id").should be_true
297 json.first.has_key?("comic_id").should be_true
298 json.first.has_key?("author_id").should be_true
302 context '作家権限がないとき' do
307 it 'ステータスコード302 Foundを返す' do
308 get :comic, :id => @comic.id
309 response.status.should eq 302
311 it 'サインインページへ遷移する' do
312 get :comic, :id => @comic.id
313 response.should redirect_to '/users/sign_in'
317 it 'ステータスコード401 Unauthorizedを返す' do
318 get :comic, :id => @comic.id, :format => :json
319 response.status.should eq 401
321 it '応答メッセージにUnauthorizedを返す' do
322 get :comic, :id => @comic.id, :format => :json
323 response.message.should match(/Unauthorized/)
327 context '作家権限はないが管理者権限があるとき' do
332 it 'ステータスコード200 OKを返す' do
333 get :comic, :id => @comic.id
334 response.should be_success
339 describe '新規作成フォーム表示に於いて' do
343 context 'つつがなく終わるとき' do
344 it '@storyに新規データを用意している' do
346 assigns(:story).should be_a_new(Story)
348 it 'モデルにデフォルト値補充を依頼している' do
349 Story.any_instance.should_receive(:supply_default).exactly(1)
353 it 'ステータスコード200 OKを返す' do
355 response.should be_success
357 it 'newテンプレートを描画する' do
359 response.should render_template("new")
363 it 'ステータスコード200 OKを返す' do
364 get :new, :format => :js
365 response.should be_success
367 it 'new.jsテンプレートを描画する' do
368 get :new, :format => :js
369 response.should render_template("new")
373 it 'ステータスコード200 OKを返す' do
374 get :new, :format => :json
375 response.should be_success
378 get :new, :format => :json
379 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
381 it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
382 Story.any_instance.should_receive(:story_as_json).exactly(1)
383 get :new, :format => :json
386 get :new, :format => :json
387 json = JSON.parse response.body
388 json.has_key?("panel_id").should be_true
389 json.has_key?("comic_id").should be_true
390 json.has_key?("author_id").should be_true
394 context '作家権限がないとき' do
399 it 'ステータスコード302 Foundを返す' do
401 response.status.should eq 302
403 it 'サインインページへ遷移する' do
405 response.body.should redirect_to '/users/sign_in'
409 it 'ステータスコード401 Unauthorizedを返す' do
410 get :new, :format => :json
411 response.status.should eq 401
413 it '応答メッセージにUnauthorizedを返す' do
414 get :new, :format => :json
415 response.message.should match(/Unauthorized/)
419 context '作家権限はないが管理者権限があるとき' do
425 it 'ステータスコード302 Foundを返す' do
427 response.status.should eq 302
429 it 'サインインページへ遷移する' do
431 response.body.should redirect_to '/users/sign_in'
437 describe '新規作成に於いて' do
439 @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
442 context 'つつがなく終わるとき' do
443 it 'デフォルト値補充を依頼する' do
444 Story.any_instance.should_receive(:supply_default).exactly(1)
445 post :create, :story => @attr
447 it 'POSTデータから、カラム値を復元している' do
448 Story.any_instance.stub(:store).and_return(true)
449 post :create, :story => @attr
450 assigns(:story).comic_id.should eq @comic.id
451 assigns(:story).panel_id.should eq @panel.id
454 Story.any_instance.should_receive(:overwrite).exactly(1)
455 post :create, :story => @attr
457 it 'コミックモデルに編集取得を依頼している' do
458 Comic.should_receive(:edit).with(@comic.id, @author).exactly(1)
459 post :create, :story => @attr
461 it 'コマモデルに単体取得を依頼している' do
462 Panel.should_receive(:show).with(@panel.id, @author).exactly(1)
463 post :create, :story => @attr
466 Story.any_instance.should_receive(:store).exactly(1)
467 post :create, :story => @attr
469 it "@storyに作成されたコマを保持していて、それがDBにある" do
470 post :create, :story => @attr
471 assigns(:story).should be_a(Story)
472 assigns(:story).should be_persisted
475 it 'ステータスコード302 Foundを返す' do
476 Story.any_instance.stub(:store).and_return(true)
477 post :create, :story => @attr
478 response.status.should eq 302
480 it 'コミックのストーリー表示へ遷移する' do
481 # Story.any_instance.stub(:store).and_return(true)
482 post :create, :story => @attr
483 response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
487 it 'ステータスコード200 OKを返す' do
488 # Story.any_instance.stub(:store).and_return(true)
489 post :create, :story => @attr, :format => :json
490 response.should be_success
492 it '作成されたコマをjsonデータで返す' do
493 post :create, :story => @attr, :format => :json
494 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
496 it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
497 Story.any_instance.should_receive(:story_as_json).exactly(1)
498 post :create, :story => @attr, :format => :json
501 post :create, :story => @attr, :format => :json
502 json = JSON.parse response.body
503 json["t"].should eq 0
507 context '作家権限がないとき' do
512 it 'ステータスコード302 Foundを返す' do
513 post :create, :story => @attr
514 response.status.should eq 302
516 it 'サインインページへ遷移する' do
517 post :create, :story => @attr
518 response.body.should redirect_to '/users/sign_in'
522 it 'ステータスコード401 Unauthorizedを返す' do
523 post :create, :story => @attr, :format => :json
524 response.status.should eq 401
526 it '応答メッセージにUnauthorizedを返す' do
527 post :create, :story => @attr, :format => :json
528 response.message.should match(/Unauthorized/)
532 context '作家権限はないが管理者権限があるとき' do
538 it 'ステータスコード302 Foundを返す' do
539 post :create, :story => @attr
540 response.status.should eq 302
542 it 'サインインページへ遷移する' do
543 post :create, :story => @attr
544 response.body.should redirect_to '/users/sign_in'
548 context '検証、保存に失敗した' do
550 Story.any_instance.stub(:store).and_return(false)
552 it "未保存のコマを保持している" do
553 post :create, :story => @attr
554 assigns(:story).should be_a_new(Story)
557 it 'ステータスコード200 OKを返す' do
558 post :create, :story => @attr
559 response.status.should eq 200
562 post :create, :story => @attr
563 response.should render_template("new")
567 it 'ステータスコード422 unprocessable_entity を返す' do
568 post :create, :story => @attr, :format => :json
569 response.status.should eq 422
571 it '応答メッセージUnprocessable Entityを返す' do
572 post :create, :story => @attr, :format => :json
573 response.message.should match(/Unprocessable/)
579 describe '編集フォーム表示に於いて' do
581 @story = FactoryGirl.create :story, :author_id => @author.id
583 Story.stub(:show).and_return(@story)
585 context 'つつがなく終わるとき' do
586 it 'ストーリーモデルに編集取得を問い合わせている' do
587 Story.should_receive(:edit).exactly(1)
588 get :edit, :id => @story.id
590 it '@storyにデータを用意している' do
591 get :edit, :id => @story.id
592 assigns(:story).should eq @story
595 it 'ステータスコード200 OKを返す' do
596 get :edit, :id => @story.id
597 response.should be_success
599 it 'editテンプレートを描画する' do
600 get :edit, :id => @story.id
601 response.should render_template("edit")
605 it 'ステータスコード200 OKを返す' do
606 get :edit, :id => @story.id, :format => :js
607 response.should be_success
609 it 'edit.jsテンプレートを描画する' do
610 get :edit, :id => @story.id, :format => :js
611 response.should render_template("edit")
615 context '作家権限がないとき' do
620 it 'ステータスコード302 Foundを返す' do
621 get :edit, :id => @story.id
622 response.status.should eq 302
624 it 'サインインページへ遷移する' do
625 get :edit, :id => @story.id
626 response.body.should redirect_to '/users/sign_in'
630 it 'ステータスコード401 Unauthorizedを返す' do
631 get :edit, :id => @story.id, :format => :js
632 response.status.should eq 401
634 it '応答メッセージにUnauthorizedを返す' do
635 get :edit, :id => @story.id, :format => :js
636 response.message.should match(/Unauthorized/)
640 context '作家権限はないが管理者権限があるとき' do
646 it 'ステータスコード302 Foundを返す' do
647 get :edit, :id => @story.id
648 response.status.should eq 302
650 it 'サインインページへ遷移する' do
651 get :edit, :id => @story.id
652 response.body.should redirect_to '/users/sign_in'
660 @story = FactoryGirl.create :story, :author_id => @user.author.id
661 @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
664 context 'つつがなく終わるとき' do
666 Story.stub(:edit).with(any_args).and_return(@story)
667 Story.should_receive(:edit).exactly(1)
668 put :update, :id => @story.id, :story => @attr
670 it 'POSTデータから、カラム値を復元している' do
671 Story.any_instance.stub(:store).and_return(true)
672 Story.any_instance.should_receive(:attributes=).exactly(1)
673 put :update, :id => @story.id, :story => @attr
676 Story.any_instance.should_receive(:overwrite).exactly(1)
677 put :update, :id => @story.id, :story => @attr
680 Story.any_instance.should_receive(:store).exactly(1)
681 put :update, :id => @story.id, :story => @attr
683 it "@storyに作成されたストーリーを保持していて、それがDBにある" do
684 put :update, :id => @story.id, :story => @attr
685 assigns(:story).should be_a(Story)
686 assigns(:story).should be_persisted
689 it 'ステータスコード302 Foundを返す' do
690 Story.any_instance.stub(:store).and_return(true)
691 put :update, :id => @story.id, :story => @attr
692 response.status.should eq 302
695 # Story.any_instance.stub(:store).and_return(true)
696 put :update, :id => @story.id, :story => @attr
697 response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
701 it 'ステータスコード200 OKを返す' do
702 # Story.any_instance.stub(:store).and_return(true)
703 put :update, :id => @story.id, :story => @attr, :format => :json
704 response.should be_success
708 context '作家権限がないとき' do
713 it 'ステータスコード302 Foundを返す' do
714 put :update, :id => @story.id, :story => @attr
715 response.status.should eq 302
717 it 'サインインページへ遷移する' do
718 put :update, :id => @story.id, :story => @attr
719 response.body.should redirect_to '/users/sign_in'
723 it 'ステータスコード401 Unauthorizedを返す' do
724 put :update, :id => @story.id, :story => @attr, :format => :json
725 response.status.should eq 401
727 it '応答メッセージにUnauthorizedを返す' do
728 put :update, :id => @story.id, :story => @attr, :format => :json
729 response.message.should match(/Unauthorized/)
733 context '作家権限はないが管理者権限があるとき' do
739 it 'ステータスコード302 Foundを返す' do
740 put :update, :id => @story.id, :story => @attr
741 response.status.should eq 302
743 it 'サインインページへ遷移する' do
744 put :update, :id => @story.id, :story => @attr
745 response.body.should redirect_to '/users/sign_in'
749 context '検証、保存に失敗した' do
751 Story.any_instance.stub(:store).and_return(false)
754 put :update, :id => @story.id, :story => @attr
755 assigns(:story).should eq @story
758 it 'ステータスコード200 OKを返す' do
759 put :update, :id => @story.id, :story => @attr
760 response.status.should eq 200
763 put :update, :id => @story.id, :story => @attr
764 response.should render_template("edit")
768 it 'ステータスコード422 unprocessable_entity を返す' do
769 put :update, :id => @story.id, :story => @attr, :format => :json
770 response.status.should eq 422
772 it '応答メッセージUnprocessable Entityを返す' do
773 put :update, :id => @story.id, :story => @attr, :format => :json
774 response.message.should match(/Unprocessable/)
782 @story = FactoryGirl.create :story, :author_id => @author.id
784 Story.stub(:edit).and_return(@story)
786 context '事前チェックしておく' do
788 Story.stub(:edit).with(any_args()).and_return @story
789 Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
791 it 'ストーリーモデルに編集取得を問い合わせている' do
792 Story.should_receive(:edit).exactly(1)
793 delete :destroy, :id => @story.id
796 Story.any_instance.should_receive(:destroy_and_shorten).exactly(1)
797 delete :destroy, :id => @story.id
799 it '@storyにアレを取得している' do
800 delete :destroy, :id => @story.id
801 assigns(:story).id.should eq(@story.id)
804 context 'つつがなく終わるとき' do
806 Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
809 it 'ステータスコード302 Foundを返す' do
810 delete :destroy, :id => @story.id
811 response.status.should eq 302
814 delete :destroy, :id => @story.id
815 response.should redirect_to(:controller => 'stories', :action => :comic, :id => @story.comic_id)
819 it 'ステータスコード200 OKを返す' do
820 delete :destroy, :id => @story.id, :format => :json
821 response.should be_success
825 context '作家権限がないとき' do
830 it 'ステータスコード302 Foundを返す' do
831 delete :destroy, :id => @story.id
832 response.status.should eq 302
834 it 'サインインページへ遷移する' do
835 delete :destroy, :id => @story.id
836 response.body.should redirect_to '/users/sign_in'
840 it 'ステータスコード401 Unauthorizedを返す' do
841 delete :destroy, :id => @story.id, :format => :json
842 response.status.should eq 401
844 it '応答メッセージにUnauthorizedを返す' do
845 delete :destroy, :id => @story.id, :format => :json
846 response.message.should match(/Unauthorized/)
850 context '作家権限はないが管理者権限があるとき' do
856 it 'ステータスコード302 Foundを返す' do
857 delete :destroy, :id => @story.id
858 response.status.should eq 302
860 it 'サインインページへ遷移する' do
861 delete :destroy, :id => @story.id
862 response.body.should redirect_to '/users/sign_in'
866 context '削除に失敗したとき' do
868 Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(false)
871 it 'ステータスコード302 Foundを返す' do
872 delete :destroy, :id => @story.id
873 response.status.should eq 302
875 it 'そのコミックの詳細ページへ遷移する' do
876 delete :destroy, :id => @story.id
877 response.should redirect_to(story_path(@story))
881 it 'ステータスコード422 unprocessable_entity を返す' do
882 delete :destroy, :id => @story.id, :format => :json
883 response.status.should eq 422
885 it '応答メッセージUnprocessable Entityを返す' do
886 delete :destroy, :id => @story.id, :format => :json
887 response.message.should match(/Unprocessable/)
892 context '対象ストーリーがないとき' do
894 context '他人のストーリーだったとき' do
900 describe '一覧表示に於いて' do
903 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
904 Story.stub(:list).and_return([@story, @story, @story])
906 context 'つつがなく終わるとき' do
907 it 'ステータスコード200 OKを返す' do
909 response.should be_success
912 it 'indexテンプレートを描画する' do
914 response.should render_template("index")
919 get :index, :format => :json
920 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
924 context '作家権限がないとき' do
928 it 'ステータスコード200 OKを返す' do
930 response.should be_success
933 it 'indexテンプレートを描画する' do
935 response.should render_template("index")
940 get :index, :format => :json
941 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
947 describe '単体表示に於いて' do
950 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
951 Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic)
952 Comic.stub(:show).with(@comic.id.to_s, nil).and_return(@comic)
953 Story.stub(:show).with(@story.id.to_s, @author).and_return(@story)
954 Story.stub(:show).with(@story.id.to_s, nil).and_return(@story)
956 context 'つつがなく終わるとき' do
958 it 'ステータスコード200 OKを返す' do
959 get :show, :id => @story.id
960 response.should be_success
962 it 'showテンプレートを描画する' do
963 get :show, :id => @story.id
964 response.should render_template("show")
968 it 'ステータスコード200 OKを返す' do
969 get :show, :id => @story.id, :format => :json
970 response.should be_success
973 get :show, :id => @story.id, :format => :json
974 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
978 context '作家権限がないとき' do
983 it 'ステータスコード200 OKを返す' do
984 get :show, :id => @story.id
985 response.should be_success
987 it 'showテンプレートを描画する' do
988 get :show, :id => @story.id
989 response.should render_template("show")
993 it 'ステータスコード200 OKを返す' do
994 get :show, :id => @story.id, :format => :json
995 response.should be_success
998 get :show, :id => @story.id, :format => :json
999 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1005 describe '閲覧に於いて' do
1007 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1008 Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic)
1009 Comic.stub(:show).with(@comic.id.to_s, nil).and_return(@comic)
1010 Story.stub(:count).and_return(10)
1011 Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])
1014 context 'つつがなく終わるとき' do
1016 it 'ステータスコード200 OKを返す' do
1017 get :comic, :id => @comic.id
1018 response.should be_success
1020 it 'comicテンプレートを描画する' do
1021 get :comic, :id => @comic.id
1022 response.should render_template("comic")
1026 it 'ステータスコード200 OKを返す' do
1027 get :comic, :id => @comic.id, :format => :json
1028 response.should be_success
1031 get :comic, :id => @comic.id, :format => :json
1032 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1036 context '作家権限がないとき' do
1041 it 'ステータスコード200 OKを返す' do
1042 get :comic, :id => @comic.id
1043 response.should be_success
1045 it 'comicテンプレートを描画する' do
1046 get :comic, :id => @comic.id
1047 response.should render_template("comic")
1051 it 'ステータスコード200 OKを返す' do
1052 get :comic, :id => @comic.id, :format => :json
1053 response.should be_success
1056 get :comic, :id => @comic.id, :format => :json
1057 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1063 describe '新規作成フォーム表示に於いて' do
1067 context 'つつがなく終わるとき' do
1069 it 'ステータスコード200 OKを返す' do
1071 response.should be_success
1073 it 'newテンプレートを描画する' do
1075 response.should render_template("new")
1079 it 'ステータスコード200 OKを返す' do
1080 get :new, :format => :js
1081 response.should be_success
1083 it 'new.jsテンプレートを描画する' do
1084 get :new, :format => :js
1085 response.should render_template("new")
1089 it 'ステータスコード200 OKを返す' do
1090 get :new, :format => :json
1091 response.should be_success
1094 get :new, :format => :json
1095 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1099 context '作家権限がないとき' do
1104 it 'ステータスコード302 Foundを返す' do
1106 response.status.should eq 302
1108 it 'サインインページへ遷移する' do
1110 response.body.should redirect_to '/users/sign_in'
1114 it 'ステータスコード401 Unauthorizedを返す' do
1115 get :new, :format => :json
1116 response.status.should eq 401
1118 it '応答メッセージにUnauthorizedを返す' do
1119 get :new, :format => :json
1120 response.message.should match(/Unauthorized/)
1126 describe '新規作成に於いて' do
1128 @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
1131 context 'つつがなく終わるとき' do
1133 it 'ステータスコード302 Foundを返す' do
1134 Story.any_instance.stub(:store).and_return(true)
1135 post :create, :story => @attr
1136 response.status.should eq 302
1138 it 'コミックのストーリー表示へ遷移する' do
1139 # Story.any_instance.stub(:store).and_return(true)
1140 post :create, :story => @attr
1141 response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
1145 it 'ステータスコード200 OKを返す' do
1146 # Story.any_instance.stub(:store).and_return(true)
1147 post :create, :story => @attr, :format => :json
1148 response.should be_success
1150 it '作成されたコマをjsonデータで返す' do
1151 post :create, :story => @attr, :format => :json
1152 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1156 context '作家権限がないとき' do
1161 it 'ステータスコード302 Foundを返す' do
1162 post :create, :story => @attr
1163 response.status.should eq 302
1165 it 'サインインページへ遷移する' do
1166 post :create, :story => @attr
1167 response.body.should redirect_to '/users/sign_in'
1171 it 'ステータスコード401 Unauthorizedを返す' do
1172 post :create, :story => @attr, :format => :json
1173 response.status.should eq 401
1175 it '応答メッセージにUnauthorizedを返す' do
1176 post :create, :story => @attr, :format => :json
1177 response.message.should match(/Unauthorized/)
1183 describe '編集フォーム表示に於いて' do
1185 @story = FactoryGirl.create :story, :author_id => @author.id
1187 Story.stub(:show).and_return(@story)
1189 context 'つつがなく終わるとき' do
1191 it 'ステータスコード200 OKを返す' do
1192 get :edit, :id => @story.id
1193 response.should be_success
1195 it 'editテンプレートを描画する' do
1196 get :edit, :id => @story.id
1197 response.should render_template("edit")
1201 it 'ステータスコード200 OKを返す' do
1202 get :edit, :id => @story.id, :format => :js
1203 response.should be_success
1205 it 'edit.jsテンプレートを描画する' do
1206 get :edit, :id => @story.id, :format => :js
1207 response.should render_template("edit")
1211 context '作家権限がないとき' do
1216 it 'ステータスコード302 Foundを返す' do
1217 get :edit, :id => @story.id
1218 response.status.should eq 302
1220 it 'サインインページへ遷移する' do
1221 get :edit, :id => @story.id
1222 response.body.should redirect_to '/users/sign_in'
1226 it 'ステータスコード401 Unauthorizedを返す' do
1227 get :edit, :id => @story.id, :format => :js
1228 response.status.should eq 401
1230 it '応答メッセージにUnauthorizedを返す' do
1231 get :edit, :id => @story.id, :format => :js
1232 response.message.should match(/Unauthorized/)
1238 describe '更新に於いて' do
1240 @story = FactoryGirl.create :story, :author_id => @user.author.id
1241 @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
1244 context 'つつがなく終わるとき' do
1246 it 'ステータスコード302 Foundを返す' do
1247 Story.any_instance.stub(:store).and_return(true)
1248 put :update, :id => @story.id, :story => @attr
1249 response.status.should eq 302
1251 it 'ストーリー表示へ遷移する' do
1252 # Story.any_instance.stub(:store).and_return(true)
1253 put :update, :id => @story.id, :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 put :update, :id => @story.id, :story => @attr, :format => :json
1261 response.should be_success
1265 context '作家権限がないとき' do
1270 it 'ステータスコード302 Foundを返す' do
1271 put :update, :id => @story.id, :story => @attr
1272 response.status.should eq 302
1274 it 'サインインページへ遷移する' do
1275 put :update, :id => @story.id, :story => @attr
1276 response.body.should redirect_to '/users/sign_in'
1280 it 'ステータスコード401 Unauthorizedを返す' do
1281 put :update, :id => @story.id, :story => @attr, :format => :json
1282 response.status.should eq 401
1284 it '応答メッセージにUnauthorizedを返す' do
1285 put :update, :id => @story.id, :story => @attr, :format => :json
1286 response.message.should match(/Unauthorized/)
1292 describe '削除に於いて' do
1294 @story = FactoryGirl.create :story, :author_id => @author.id
1296 Story.stub(:edit).and_return(@story)
1298 context 'つつがなく終わるとき' do
1300 Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
1303 it 'ステータスコード302 Foundを返す' do
1304 delete :destroy, :id => @story.id
1305 response.status.should eq 302
1308 delete :destroy, :id => @story.id
1309 response.should redirect_to(:controller => 'stories', :action => :comic, :id => @story.comic_id)
1313 it 'ステータスコード200 OKを返す' do
1314 delete :destroy, :id => @story.id, :format => :json
1315 response.should be_success
1319 context '作家権限がないとき' do
1324 it 'ステータスコード302 Foundを返す' do
1325 delete :destroy, :id => @story.id
1326 response.status.should eq 302
1328 it 'サインインページへ遷移する' do
1329 delete :destroy, :id => @story.id
1330 response.body.should redirect_to '/users/sign_in'
1334 it 'ステータスコード401 Unauthorizedを返す' do
1335 delete :destroy, :id => @story.id, :format => :json
1336 response.status.should eq 401
1338 it '応答メッセージにUnauthorizedを返す' do
1339 delete :destroy, :id => @story.id, :format => :json
1340 response.message.should match(/Unauthorized/)