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/)
118 describe '単体表示に於いて' do
121 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
122 Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic)
123 Story.stub(:show).with(@story.id.to_s, @author).and_return(@story)
125 context 'つつがなく終わるとき' do
126 it 'ストーリーモデルに単体取得を問い合わせている' do
127 Story.should_receive(:show).with(@story.id.to_s, @author).exactly(1)
128 get :show, :id => @story.id
130 it '@storyにアレを取得している' do
131 get :show, :id => @story.id
132 assigns(:story).should eq @story
135 it 'ステータスコード200 OKを返す' do
136 get :show, :id => @story.id
137 response.should be_success
139 it 'showテンプレートを描画する' do
140 get :show, :id => @story.id
141 response.should render_template("show")
145 it 'ステータスコード200 OKを返す' do
146 get :show, :id => @story.id, :format => :json
147 response.should be_success
150 get :show, :id => @story.id, :format => :json
151 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
153 it 'ストーリーモデルにストーリーjson出力を問い合わせている' do
154 Story.any_instance.should_receive(:story_as_json).exactly(1)
155 get :show, :id => @story.id, :format => :json
158 get :show, :id => @story.id, :format => :json
159 json = JSON.parse response.body
160 json.has_key?("panel_id").should be_true
161 json.has_key?("comic_id").should be_true
162 json.has_key?("author_id").should be_true
166 context '作家権限がないとき' do
171 it 'ステータスコード302 Foundを返す' do
172 get :show, :id => @story.id
173 response.status.should eq 302
175 it 'サインインページへ遷移する' do
176 get :show, :id => @story.id
177 response.body.should redirect_to '/users/sign_in'
181 it 'ステータスコード401 Unauthorizedを返す' do
182 get :show, :id => @story.id, :format => :json
183 response.status.should eq 401
185 it '応答メッセージにUnauthorizedを返す' do
186 get :show, :id => @story.id, :format => :json
187 response.message.should match(/Unauthorized/)
195 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
196 Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic)
197 Story.stub(:count).and_return(10)
198 Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])
201 context 'パラメータチェックする' do
202 it '与えられたoffsetがセットされている' do
203 get :comic, :id => @comic.id, :offset => 5
204 assigns(:offset).should eq 5
206 it '省略されると@offsetに0値が入る' do
207 get :comic, :id => @comic.id
208 assigns(:offset).should eq 0
210 it '与えられたcountがセットされている' do
211 get :comic, :id => @comic.id, :count => 4
212 assigns(:panel_count).should eq 4
214 it '省略されると@panel_countにデフォルト値が入る' do
215 get :comic, :id => @comic.id
216 assigns(:panel_count).should eq Story.default_panel_size
218 it '最大を超えると@panel_countにデフォルト最大値が入る' do
219 get :comic, :id => @comic.id, :count => 1500
220 assigns(:panel_count).should eq Story.max_panel_size
222 it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
223 get :comic, :id => @comic.id, :count => -1
224 assigns(:panel_count).should eq Story.default_panel_size
227 context '事前チェックする' do
228 it 'コミックモデルに単体取得を問い合わせている' do
229 Comic.should_receive(:show).with(@comic.id.to_s, @author).exactly(1)
230 get :comic, :id => @comic.id
232 it 'ストーリーモデルにプレイリスト取得を問い合わせている' do
233 Story.should_receive(:play_list).with(@comic, @author, 0, 30).exactly(1)
234 get :comic, :id => @comic.id
237 context 'つつがなく終わるとき' do
238 it '@storiesにリストを取得している' do
239 get :comic, :id => @comic.id
240 assigns(:stories).should have_at_least(3).items
243 it 'ステータスコード200 OKを返す' do
244 get :comic, :id => @comic.id
245 response.should be_success
247 it 'comicテンプレートを描画する' do
248 get :comic, :id => @comic.id
249 response.should render_template("comic")
253 it 'ステータスコード200 OKを返す' do
254 get :comic, :id => @comic.id, :format => :json
255 response.should be_success
258 get :comic, :id => @comic.id, :format => :json
259 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
261 it 'ストーリーモデルにストーリーリストのjson出力を問い合わせている' do
262 Story.should_receive(:list_as_json_text).exactly(1)
263 get :comic, :id => @comic.id, :format => :json
265 it 'データがリスト構造になっている' do
266 get :comic, :id => @comic.id, :format => :json
267 json = JSON.parse response.body
268 json.should have_at_least(3).items
270 it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
271 get :comic, :id => @comic.id, :format => :json
272 json = JSON.parse response.body
273 json.first.has_key?("panel_id").should be_true
274 json.first.has_key?("comic_id").should be_true
275 json.first.has_key?("author_id").should be_true
279 context '作家権限がないとき' do
284 it 'ステータスコード302 Foundを返す' do
285 get :comic, :id => @comic.id
286 response.status.should eq 302
288 it 'サインインページへ遷移する' do
289 get :comic, :id => @comic.id
290 response.should redirect_to '/users/sign_in'
294 it 'ステータスコード401 Unauthorizedを返す' do
295 get :comic, :id => @comic.id, :format => :json
296 response.status.should eq 401
298 it '応答メッセージにUnauthorizedを返す' do
299 get :comic, :id => @comic.id, :format => :json
300 response.message.should match(/Unauthorized/)
306 describe '新規作成フォーム表示に於いて' do
310 context 'つつがなく終わるとき' do
311 it '@storyに新規データを用意している' do
313 assigns(:story).should be_a_new(Story)
315 it 'モデルにデフォルト値補充を依頼している' do
316 Story.any_instance.should_receive(:supply_default).exactly(1)
320 it 'ステータスコード200 OKを返す' do
322 response.should be_success
324 it 'newテンプレートを描画する' do
326 response.should render_template("new")
330 it 'ステータスコード200 OKを返す' do
331 get :new, :format => :js
332 response.should be_success
334 it 'new.jsテンプレートを描画する' do
335 get :new, :format => :js
336 response.should render_template("new")
340 it 'ステータスコード200 OKを返す' do
341 get :new, :format => :json
342 response.should be_success
345 get :new, :format => :json
346 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
348 it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
349 Story.any_instance.should_receive(:story_as_json).exactly(1)
350 get :new, :format => :json
353 get :new, :format => :json
354 json = JSON.parse response.body
355 json.has_key?("panel_id").should be_true
356 json.has_key?("comic_id").should be_true
357 json.has_key?("author_id").should be_true
361 context '作家権限がないとき' do
366 it 'ステータスコード302 Foundを返す' do
368 response.status.should eq 302
370 it 'サインインページへ遷移する' do
372 response.body.should redirect_to '/users/sign_in'
376 it 'ステータスコード401 Unauthorizedを返す' do
377 get :new, :format => :json
378 response.status.should eq 401
380 it '応答メッセージにUnauthorizedを返す' do
381 get :new, :format => :json
382 response.message.should match(/Unauthorized/)
388 describe '新規作成に於いて' do
390 @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
393 context 'つつがなく終わるとき' do
394 it 'デフォルト値補充を依頼する' do
395 Story.any_instance.should_receive(:supply_default).exactly(1)
396 post :create, :story => @attr
398 it 'POSTデータから、カラム値を復元している' do
399 Story.any_instance.stub(:store).and_return(true)
400 post :create, :story => @attr
401 assigns(:story).comic_id.should eq @comic.id
402 assigns(:story).panel_id.should eq @panel.id
405 Story.any_instance.should_receive(:overwrite).exactly(1)
406 post :create, :story => @attr
408 it 'コミックモデルに編集取得を依頼している' do
409 Comic.should_receive(:edit).with(@comic.id, @author).exactly(1)
410 post :create, :story => @attr
412 it 'コマモデルに単体取得を依頼している' do
413 Panel.should_receive(:show).with(@panel.id, @author).exactly(1)
414 post :create, :story => @attr
417 Story.any_instance.should_receive(:store).exactly(1)
418 post :create, :story => @attr
420 it "@storyに作成されたコマを保持していて、それがDBにある" do
421 post :create, :story => @attr
422 assigns(:story).should be_a(Story)
423 assigns(:story).should be_persisted
426 it 'ステータスコード302 Foundを返す' do
427 Story.any_instance.stub(:store).and_return(true)
428 post :create, :story => @attr
429 response.status.should eq 302
431 it 'コミックのストーリー表示へ遷移する' do
432 # Story.any_instance.stub(:store).and_return(true)
433 post :create, :story => @attr
434 response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
438 it 'ステータスコード200 OKを返す' do
439 # Story.any_instance.stub(:store).and_return(true)
440 post :create, :story => @attr, :format => :json
441 response.should be_success
443 it '作成されたコマをjsonデータで返す' do
444 post :create, :story => @attr, :format => :json
445 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
447 it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
448 Story.any_instance.should_receive(:story_as_json).exactly(1)
449 post :create, :story => @attr, :format => :json
452 post :create, :story => @attr, :format => :json
453 json = JSON.parse response.body
454 json["t"].should eq 0
458 context '作家権限がないとき' do
463 it 'ステータスコード302 Foundを返す' do
464 post :create, :story => @attr
465 response.status.should eq 302
467 it 'サインインページへ遷移する' do
468 post :create, :story => @attr
469 response.body.should redirect_to '/users/sign_in'
473 it 'ステータスコード401 Unauthorizedを返す' do
474 post :create, :story => @attr, :format => :json
475 response.status.should eq 401
477 it '応答メッセージにUnauthorizedを返す' do
478 post :create, :story => @attr, :format => :json
479 response.message.should match(/Unauthorized/)
483 context '検証、保存に失敗した' do
485 Story.any_instance.stub(:store).and_return(false)
487 it "未保存のコマを保持している" do
488 post :create, :story => @attr
489 assigns(:story).should be_a_new(Story)
492 it 'ステータスコード200 OKを返す' do
493 post :create, :story => @attr
494 response.status.should eq 200
497 post :create, :story => @attr
498 response.should render_template("new")
502 it 'ステータスコード422 unprocessable_entity を返す' do
503 post :create, :story => @attr, :format => :json
504 response.status.should eq 422
506 it '応答メッセージUnprocessable Entityを返す' do
507 post :create, :story => @attr, :format => :json
508 response.message.should match(/Unprocessable/)
514 describe '編集フォーム表示に於いて' do
516 @story = FactoryGirl.create :story, :author_id => @author.id
518 Story.stub(:show).and_return(@story)
520 context 'つつがなく終わるとき' do
521 it 'ストーリーモデルに編集取得を問い合わせている' do
522 Story.should_receive(:edit).exactly(1)
523 get :edit, :id => @story.id
525 it '@storyにデータを用意している' do
526 get :edit, :id => @story.id
527 assigns(:story).should eq @story
530 it 'ステータスコード200 OKを返す' do
531 get :edit, :id => @story.id
532 response.should be_success
534 it 'editテンプレートを描画する' do
535 get :edit, :id => @story.id
536 response.should render_template("edit")
540 it 'ステータスコード200 OKを返す' do
541 get :edit, :id => @story.id, :format => :js
542 response.should be_success
544 it 'edit.jsテンプレートを描画する' do
545 get :edit, :id => @story.id, :format => :js
546 response.should render_template("edit")
550 context '作家権限がないとき' do
555 it 'ステータスコード302 Foundを返す' do
556 get :edit, :id => @story.id
557 response.status.should eq 302
559 it 'サインインページへ遷移する' do
560 get :edit, :id => @story.id
561 response.body.should redirect_to '/users/sign_in'
565 it 'ステータスコード401 Unauthorizedを返す' do
566 get :edit, :id => @story.id, :format => :js
567 response.status.should eq 401
569 it '応答メッセージにUnauthorizedを返す' do
570 get :edit, :id => @story.id, :format => :js
571 response.message.should match(/Unauthorized/)
579 @story = FactoryGirl.create :story, :author_id => @user.author.id
580 @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
583 context 'つつがなく終わるとき' do
585 Story.stub(:edit).with(any_args).and_return(@story)
586 Story.should_receive(:edit).exactly(1)
587 put :update, :id => @story.id, :story => @attr
589 it 'POSTデータから、カラム値を復元している' do
590 Story.any_instance.stub(:store).and_return(true)
591 Story.any_instance.should_receive(:attributes=).exactly(1)
592 put :update, :id => @story.id, :story => @attr
595 Story.any_instance.should_receive(:overwrite).exactly(1)
596 put :update, :id => @story.id, :story => @attr
599 Story.any_instance.should_receive(:store).exactly(1)
600 put :update, :id => @story.id, :story => @attr
602 it "@storyに作成されたストーリーを保持していて、それがDBにある" do
603 put :update, :id => @story.id, :story => @attr
604 assigns(:story).should be_a(Story)
605 assigns(:story).should be_persisted
608 it 'ステータスコード302 Foundを返す' do
609 Story.any_instance.stub(:store).and_return(true)
610 put :update, :id => @story.id, :story => @attr
611 response.status.should eq 302
614 # Story.any_instance.stub(:store).and_return(true)
615 put :update, :id => @story.id, :story => @attr
616 response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
620 it 'ステータスコード200 OKを返す' do
621 # Story.any_instance.stub(:store).and_return(true)
622 put :update, :id => @story.id, :story => @attr, :format => :json
623 response.should be_success
627 context '作家権限がないとき' do
632 it 'ステータスコード302 Foundを返す' do
633 put :update, :id => @story.id, :story => @attr
634 response.status.should eq 302
636 it 'サインインページへ遷移する' do
637 put :update, :id => @story.id, :story => @attr
638 response.body.should redirect_to '/users/sign_in'
642 it 'ステータスコード401 Unauthorizedを返す' do
643 put :update, :id => @story.id, :story => @attr, :format => :json
644 response.status.should eq 401
646 it '応答メッセージにUnauthorizedを返す' do
647 put :update, :id => @story.id, :story => @attr, :format => :json
648 response.message.should match(/Unauthorized/)
652 context '検証、保存に失敗した' do
654 Story.any_instance.stub(:store).and_return(false)
657 put :update, :id => @story.id, :story => @attr
658 assigns(:story).should eq @story
661 it 'ステータスコード200 OKを返す' do
662 put :update, :id => @story.id, :story => @attr
663 response.status.should eq 200
666 put :update, :id => @story.id, :story => @attr
667 response.should render_template("edit")
671 it 'ステータスコード422 unprocessable_entity を返す' do
672 put :update, :id => @story.id, :story => @attr, :format => :json
673 response.status.should eq 422
675 it '応答メッセージUnprocessable Entityを返す' do
676 put :update, :id => @story.id, :story => @attr, :format => :json
677 response.message.should match(/Unprocessable/)
685 @story = FactoryGirl.create :story, :author_id => @author.id
687 Story.stub(:edit).and_return(@story)
689 context '事前チェックしておく' do
691 Story.stub(:edit).with(any_args()).and_return @story
692 Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
694 it 'ストーリーモデルに編集取得を問い合わせている' do
695 Story.should_receive(:edit).exactly(1)
696 delete :destroy, :id => @story.id
699 Story.any_instance.should_receive(:destroy_and_shorten).exactly(1)
700 delete :destroy, :id => @story.id
702 it '@storyにアレを取得している' do
703 delete :destroy, :id => @story.id
704 assigns(:story).id.should eq(@story.id)
707 context 'つつがなく終わるとき' do
709 Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
712 it 'ステータスコード302 Foundを返す' do
713 delete :destroy, :id => @story.id
714 response.status.should eq 302
717 delete :destroy, :id => @story.id
718 response.should redirect_to(:controller => 'stories', :action => :comic, :id => @story.comic_id)
722 it 'ステータスコード200 OKを返す' do
723 delete :destroy, :id => @story.id, :format => :json
724 response.should be_success
728 context '作家権限がないとき' do
733 it 'ステータスコード302 Foundを返す' do
734 delete :destroy, :id => @story.id
735 response.status.should eq 302
737 it 'サインインページへ遷移する' do
738 delete :destroy, :id => @story.id
739 response.body.should redirect_to '/users/sign_in'
743 it 'ステータスコード401 Unauthorizedを返す' do
744 delete :destroy, :id => @story.id, :format => :json
745 response.status.should eq 401
747 it '応答メッセージにUnauthorizedを返す' do
748 delete :destroy, :id => @story.id, :format => :json
749 response.message.should match(/Unauthorized/)
753 context '削除に失敗したとき' do
755 Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(false)
758 it 'ステータスコード302 Foundを返す' do
759 delete :destroy, :id => @story.id
760 response.status.should eq 302
762 it 'そのコミックの詳細ページへ遷移する' do
763 delete :destroy, :id => @story.id
764 response.should redirect_to(story_path(@story))
768 it 'ステータスコード422 unprocessable_entity を返す' do
769 delete :destroy, :id => @story.id, :format => :json
770 response.status.should eq 422
772 it '応答メッセージUnprocessable Entityを返す' do
773 delete :destroy, :id => @story.id, :format => :json
774 response.message.should match(/Unprocessable/)
779 context '対象ストーリーがないとき' do
781 context '他人のストーリーだったとき' do
787 describe '一覧表示に於いて' do
790 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
791 Story.stub(:list).and_return([@story, @story, @story])
793 context 'つつがなく終わるとき' do
794 it 'ステータスコード200 OKを返す' do
796 response.should be_success
799 it 'indexテンプレートを描画する' do
801 response.should render_template("index")
806 get :index, :format => :json
807 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
811 context '作家権限がないとき' do
815 it 'ステータスコード200 OKを返す' do
817 response.should be_success
820 it 'indexテンプレートを描画する' do
822 response.should render_template("index")
827 get :index, :format => :json
828 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
834 describe '単体表示に於いて' do
837 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
838 Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic)
839 Comic.stub(:show).with(@comic.id.to_s, nil).and_return(@comic)
840 Story.stub(:show).with(@story.id.to_s, @author).and_return(@story)
841 Story.stub(:show).with(@story.id.to_s, nil).and_return(@story)
843 context 'つつがなく終わるとき' do
845 it 'ステータスコード200 OKを返す' do
846 get :show, :id => @story.id
847 response.should be_success
849 it 'showテンプレートを描画する' do
850 get :show, :id => @story.id
851 response.should render_template("show")
855 it 'ステータスコード200 OKを返す' do
856 get :show, :id => @story.id, :format => :json
857 response.should be_success
860 get :show, :id => @story.id, :format => :json
861 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
865 context '作家権限がないとき' do
870 it 'ステータスコード200 OKを返す' do
871 get :show, :id => @story.id
872 response.should be_success
874 it 'showテンプレートを描画する' do
875 get :show, :id => @story.id
876 response.should render_template("show")
880 it 'ステータスコード200 OKを返す' do
881 get :show, :id => @story.id, :format => :json
882 response.should be_success
885 get :show, :id => @story.id, :format => :json
886 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
894 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
895 Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic)
896 Comic.stub(:show).with(@comic.id.to_s, nil).and_return(@comic)
897 Story.stub(:count).and_return(10)
898 Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])
901 context 'つつがなく終わるとき' do
903 it 'ステータスコード200 OKを返す' do
904 get :comic, :id => @comic.id
905 response.should be_success
907 it 'comicテンプレートを描画する' do
908 get :comic, :id => @comic.id
909 response.should render_template("comic")
913 it 'ステータスコード200 OKを返す' do
914 get :comic, :id => @comic.id, :format => :json
915 response.should be_success
918 get :comic, :id => @comic.id, :format => :json
919 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
923 context '作家権限がないとき' do
928 it 'ステータスコード200 OKを返す' do
929 get :comic, :id => @comic.id
930 response.should be_success
932 it 'comicテンプレートを描画する' do
933 get :comic, :id => @comic.id
934 response.should render_template("comic")
938 it 'ステータスコード200 OKを返す' do
939 get :comic, :id => @comic.id, :format => :json
940 response.should be_success
943 get :comic, :id => @comic.id, :format => :json
944 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
950 describe '新規作成フォーム表示に於いて' do
954 context 'つつがなく終わるとき' do
956 it 'ステータスコード200 OKを返す' do
958 response.should be_success
960 it 'newテンプレートを描画する' do
962 response.should render_template("new")
966 it 'ステータスコード200 OKを返す' do
967 get :new, :format => :js
968 response.should be_success
970 it 'new.jsテンプレートを描画する' do
971 get :new, :format => :js
972 response.should render_template("new")
976 it 'ステータスコード200 OKを返す' do
977 get :new, :format => :json
978 response.should be_success
981 get :new, :format => :json
982 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
986 context '作家権限がないとき' do
991 it 'ステータスコード302 Foundを返す' do
993 response.status.should eq 302
995 it 'サインインページへ遷移する' do
997 response.body.should redirect_to '/users/sign_in'
1001 it 'ステータスコード401 Unauthorizedを返す' do
1002 get :new, :format => :json
1003 response.status.should eq 401
1005 it '応答メッセージにUnauthorizedを返す' do
1006 get :new, :format => :json
1007 response.message.should match(/Unauthorized/)
1013 describe '新規作成に於いて' do
1015 @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
1018 context 'つつがなく終わるとき' do
1020 it 'ステータスコード302 Foundを返す' do
1021 Story.any_instance.stub(:store).and_return(true)
1022 post :create, :story => @attr
1023 response.status.should eq 302
1025 it 'コミックのストーリー表示へ遷移する' do
1026 # Story.any_instance.stub(:store).and_return(true)
1027 post :create, :story => @attr
1028 response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
1032 it 'ステータスコード200 OKを返す' do
1033 # Story.any_instance.stub(:store).and_return(true)
1034 post :create, :story => @attr, :format => :json
1035 response.should be_success
1037 it '作成されたコマをjsonデータで返す' do
1038 post :create, :story => @attr, :format => :json
1039 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1043 context '作家権限がないとき' do
1048 it 'ステータスコード302 Foundを返す' do
1049 post :create, :story => @attr
1050 response.status.should eq 302
1052 it 'サインインページへ遷移する' do
1053 post :create, :story => @attr
1054 response.body.should redirect_to '/users/sign_in'
1058 it 'ステータスコード401 Unauthorizedを返す' do
1059 post :create, :story => @attr, :format => :json
1060 response.status.should eq 401
1062 it '応答メッセージにUnauthorizedを返す' do
1063 post :create, :story => @attr, :format => :json
1064 response.message.should match(/Unauthorized/)
1070 describe '編集フォーム表示に於いて' do
1072 @story = FactoryGirl.create :story, :author_id => @author.id
1074 Story.stub(:show).and_return(@story)
1076 context 'つつがなく終わるとき' do
1078 it 'ステータスコード200 OKを返す' do
1079 get :edit, :id => @story.id
1080 response.should be_success
1082 it 'editテンプレートを描画する' do
1083 get :edit, :id => @story.id
1084 response.should render_template("edit")
1088 it 'ステータスコード200 OKを返す' do
1089 get :edit, :id => @story.id, :format => :js
1090 response.should be_success
1092 it 'edit.jsテンプレートを描画する' do
1093 get :edit, :id => @story.id, :format => :js
1094 response.should render_template("edit")
1098 context '作家権限がないとき' do
1103 it 'ステータスコード302 Foundを返す' do
1104 get :edit, :id => @story.id
1105 response.status.should eq 302
1107 it 'サインインページへ遷移する' do
1108 get :edit, :id => @story.id
1109 response.body.should redirect_to '/users/sign_in'
1113 it 'ステータスコード401 Unauthorizedを返す' do
1114 get :edit, :id => @story.id, :format => :js
1115 response.status.should eq 401
1117 it '応答メッセージにUnauthorizedを返す' do
1118 get :edit, :id => @story.id, :format => :js
1119 response.message.should match(/Unauthorized/)
1125 describe '更新に於いて' do
1127 @story = FactoryGirl.create :story, :author_id => @user.author.id
1128 @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
1131 context 'つつがなく終わるとき' do
1133 it 'ステータスコード302 Foundを返す' do
1134 Story.any_instance.stub(:store).and_return(true)
1135 put :update, :id => @story.id, :story => @attr
1136 response.status.should eq 302
1138 it 'ストーリー表示へ遷移する' do
1139 # Story.any_instance.stub(:store).and_return(true)
1140 put :update, :id => @story.id, :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 put :update, :id => @story.id, :story => @attr, :format => :json
1148 response.should be_success
1152 context '作家権限がないとき' do
1157 it 'ステータスコード302 Foundを返す' do
1158 put :update, :id => @story.id, :story => @attr
1159 response.status.should eq 302
1161 it 'サインインページへ遷移する' do
1162 put :update, :id => @story.id, :story => @attr
1163 response.body.should redirect_to '/users/sign_in'
1167 it 'ステータスコード401 Unauthorizedを返す' do
1168 put :update, :id => @story.id, :story => @attr, :format => :json
1169 response.status.should eq 401
1171 it '応答メッセージにUnauthorizedを返す' do
1172 put :update, :id => @story.id, :story => @attr, :format => :json
1173 response.message.should match(/Unauthorized/)
1179 describe '削除に於いて' do
1181 @story = FactoryGirl.create :story, :author_id => @author.id
1183 Story.stub(:edit).and_return(@story)
1185 context 'つつがなく終わるとき' do
1187 Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
1190 it 'ステータスコード302 Foundを返す' do
1191 delete :destroy, :id => @story.id
1192 response.status.should eq 302
1195 delete :destroy, :id => @story.id
1196 response.should redirect_to(:controller => 'stories', :action => :comic, :id => @story.comic_id)
1200 it 'ステータスコード200 OKを返す' do
1201 delete :destroy, :id => @story.id, :format => :json
1202 response.should be_success
1206 context '作家権限がないとき' do
1211 it 'ステータスコード302 Foundを返す' do
1212 delete :destroy, :id => @story.id
1213 response.status.should eq 302
1215 it 'サインインページへ遷移する' do
1216 delete :destroy, :id => @story.id
1217 response.body.should redirect_to '/users/sign_in'
1221 it 'ステータスコード401 Unauthorizedを返す' do
1222 delete :destroy, :id => @story.id, :format => :json
1223 response.status.should eq 401
1225 it '応答メッセージにUnauthorizedを返す' do
1226 delete :destroy, :id => @story.id, :format => :json
1227 response.message.should match(/Unauthorized/)