OSDN Git Service

t30350#:fix destroy
[pettanr/pettanr.git] / spec / controllers / stories_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #ストーリー
4 describe StoriesController do
5   before 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
14   end
15   
16   describe '一覧表示に於いて' do
17     before do
18       sign_in @user
19       @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
20       Story.stub(:list).and_return([@story, @story, @story])
21     end
22     context 'パラメータpageについて' do
23       it '@pageに値が入る' do
24         get :index, :page => 5
25         assigns(:page).should eq 5
26       end
27       it '省略されると@pageに1値が入る' do
28         get :index
29         assigns(:page).should eq 1
30       end
31       it '与えられたpage_sizeがセットされている' do
32         get :index, :page_size => 15
33         assigns(:page_size).should eq 15
34       end
35       it '省略されると@page_sizeにデフォルト値が入る' do
36         get :index
37         assigns(:page_size).should eq Story.default_page_size
38       end
39       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
40         get :index, :page_size => 1500
41         assigns(:page_size).should eq Story.max_page_size
42       end
43       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
44         get :index, :page_size => 0
45         assigns(:page_size).should eq Story.default_page_size
46       end
47     end
48     context 'つつがなく終わるとき' do
49       it 'ステータスコード200 OKを返す' do
50         get :index
51         response.should be_success 
52       end
53       it 'ストーリーモデルに一覧を問い合わせている' do
54         Story.should_receive(:list).exactly(1)
55         get :index
56       end
57       it '@storiesにリストを取得している' do
58         get :index
59         assigns(:stories).should have_at_least(3).items
60       end
61       context 'html形式' do
62         it 'indexテンプレートを描画する' do
63           get :index
64           response.should render_template("index")
65         end
66       end
67       context 'json形式' do
68         it 'jsonデータを返す' do
69           get :index, :format => :json
70           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
71         end
72         it 'ストーリーモデルにjson一覧出力オプションを問い合わせている' do
73           Story.should_receive(:list_json_opt).exactly(1)
74           get :index, :format => :json
75         end
76         it 'データがリスト構造になっている' do
77           get :index, :format => :json
78           json = JSON.parse response.body
79           json.should have_at_least(3).items
80         end
81         it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
82           get :index, :format => :json
83           json = JSON.parse response.body
84           json.first.has_key?("panel_id").should be_true
85           json.first.has_key?("comic_id").should be_true
86           json.first.has_key?("t").should be_true
87         end
88       end
89     end
90     context '作家権限がないとき' do
91       before do
92         sign_out @user
93       end
94       context 'html形式' do
95         it 'ステータスコード302 Foundを返す' do
96           get :index
97           response.status.should eq 302
98         end
99         it 'サインインページへ遷移する' do
100           get :index
101           response.should redirect_to '/users/sign_in'
102         end
103       end
104       context 'json形式' do
105         it 'ステータスコード401 Unauthorizedを返す' do
106           get :index, :format => :json
107           response.status.should eq 401
108         end
109         it '応答メッセージにUnauthorizedを返す' do
110           get :index, :format => :json
111           response.message.should match(/Unauthorized/)
112         end
113       end
114     end
115   end
116   
117   describe '単体表示に於いて' do
118     before do
119       sign_in @user
120       @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
121       Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic)
122       Story.stub(:show).with(@story.id.to_s, @author).and_return(@story)
123     end
124     context 'つつがなく終わるとき' do
125       it 'ストーリーモデルに単体取得を問い合わせている' do
126         Story.should_receive(:show).with(@story.id.to_s, @author).exactly(1)
127         get :show, :id => @story.id
128       end
129       it '@storyにアレを取得している' do
130         get :show, :id => @story.id
131         assigns(:story).should eq @story
132       end
133       context 'html形式' do
134         it 'ステータスコード200 OKを返す' do
135           get :show, :id => @story.id
136           response.should be_success
137         end
138         it 'showテンプレートを描画する' do
139           get :show, :id => @story.id
140           response.should render_template("show")
141         end
142       end
143       context 'json形式' do
144         it 'ステータスコード200 OKを返す' do
145           get :show, :id => @story.id, :format => :json
146           response.should be_success
147         end
148         it 'jsonデータを返す' do
149           get :show, :id => @story.id, :format => :json
150           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
151         end
152         it 'ストーリーモデルにストーリーjson出力を問い合わせている' do
153           Story.any_instance.should_receive(:story_as_json).exactly(1)
154           get :show, :id => @story.id, :format => :json
155         end
156         it 'データがアレになっている' do
157           get :show, :id => @story.id, :format => :json
158           json = JSON.parse response.body
159           json.has_key?("panel_id").should be_true
160           json.has_key?("comic_id").should be_true
161           json.has_key?("author_id").should be_true
162         end
163       end
164     end
165     context '作家権限がないとき' do
166       before do
167         sign_out @user
168       end
169       context 'html形式' do
170         it 'ステータスコード302 Foundを返す' do
171           get :show, :id => @story.id
172           response.status.should eq 302
173         end
174         it 'サインインページへ遷移する' do
175           get :show, :id => @story.id
176           response.body.should redirect_to '/users/sign_in'
177         end
178       end
179       context 'json形式' do
180         it 'ステータスコード401 Unauthorizedを返す' do
181           get :show, :id => @story.id, :format => :json
182           response.status.should eq 401
183         end
184         it '応答メッセージにUnauthorizedを返す' do
185           get :show, :id => @story.id, :format => :json
186           response.message.should match(/Unauthorized/)
187         end
188       end
189     end
190   end
191   
192   describe '閲覧に於いて' do
193     before do
194       @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
195       Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic)
196       Story.stub(:count).and_return(10)
197       Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])
198       sign_in @user
199     end
200     context 'パラメータチェックする' do
201       it '与えられたoffsetがセットされている' do
202         get :comic, :id => @comic.id, :offset => 5
203         assigns(:offset).should eq 5
204       end
205       it '省略されると@offsetに0値が入る' do
206         get :comic, :id => @comic.id
207         assigns(:offset).should eq 0
208       end
209       it '与えられたcountがセットされている' do
210         get :comic, :id => @comic.id, :count => 4
211         assigns(:panel_count).should eq 4
212       end
213       it '省略されると@panel_countにデフォルト値が入る' do
214         get :comic, :id => @comic.id
215         assigns(:panel_count).should eq Story.default_panel_size
216       end
217       it '最大を超えると@panel_countにデフォルト最大値が入る' do
218         get :comic, :id => @comic.id, :count => 1500
219         assigns(:panel_count).should eq Story.max_panel_size
220       end
221       it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
222         get :comic, :id => @comic.id, :count => -1
223         assigns(:panel_count).should eq Story.default_panel_size
224       end
225     end
226     context '事前チェックする' do
227       it 'コミックモデルに単体取得を問い合わせている' do
228         Comic.should_receive(:show).with(@comic.id.to_s, @author).exactly(1)
229         get :comic, :id => @comic.id
230       end
231       it 'ストーリーモデルにプレイリスト取得を問い合わせている' do
232         Story.should_receive(:play_list).with(@comic, @author, 0, 30).exactly(1)
233         get :comic, :id => @comic.id
234       end
235     end
236     context 'つつがなく終わるとき' do
237       it '@storiesにリストを取得している' do
238         get :comic, :id => @comic.id
239         assigns(:stories).should have_at_least(3).items
240       end
241       context 'html形式' do
242         it 'ステータスコード200 OKを返す' do
243           get :comic, :id => @comic.id
244           response.should be_success 
245         end
246         it 'comicテンプレートを描画する' do
247           get :comic, :id => @comic.id
248           response.should render_template("comic")
249         end
250       end
251       context 'json形式' do
252         it 'ステータスコード200 OKを返す' do
253           get :comic, :id => @comic.id, :format => :json
254           response.should be_success 
255         end
256         it 'jsonデータを返す' do
257           get :comic, :id => @comic.id, :format => :json
258           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
259         end
260         it 'ストーリーモデルにストーリーリストのjson出力を問い合わせている' do
261           Story.should_receive(:list_as_json_text).exactly(1)
262           get :comic, :id => @comic.id, :format => :json
263         end
264         it 'データがリスト構造になっている' do
265           get :comic, :id => @comic.id, :format => :json
266           json = JSON.parse response.body
267           json.should have_at_least(3).items
268         end
269         it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
270           get :comic, :id => @comic.id, :format => :json
271           json = JSON.parse response.body
272           json.first.has_key?("panel_id").should be_true
273           json.first.has_key?("comic_id").should be_true
274           json.first.has_key?("author_id").should be_true
275         end
276       end
277     end
278     context '作家権限がないとき' do
279       before do
280         sign_out @user
281       end
282       context 'html形式' do
283         it 'ステータスコード302 Foundを返す' do
284           get :comic, :id => @comic.id
285           response.status.should eq 302
286         end
287         it 'サインインページへ遷移する' do
288           get :comic, :id => @comic.id
289           response.should redirect_to '/users/sign_in'
290         end
291       end
292       context 'json形式' do
293         it 'ステータスコード401 Unauthorizedを返す' do
294           get :comic, :id => @comic.id, :format => :json
295           response.status.should eq 401
296         end
297         it '応答メッセージにUnauthorizedを返す' do
298           get :comic, :id => @comic.id, :format => :json
299           response.message.should match(/Unauthorized/)
300         end
301       end
302     end
303   end
304
305   describe '新規作成フォーム表示に於いて' do
306     before do
307       sign_in @user
308     end
309     context 'つつがなく終わるとき' do
310       it '@storyに新規データを用意している' do
311         get :new
312         assigns(:story).should be_a_new(Story)
313       end
314       it 'モデルにデフォルト値補充を依頼している' do
315         Story.any_instance.should_receive(:supply_default).exactly(1)
316         get :new
317       end
318       context 'html形式' do
319         it 'ステータスコード200 OKを返す' do
320           get :new
321           response.should be_success 
322         end
323         it 'newテンプレートを描画する' do
324           get :new
325           response.should render_template("new")
326         end
327       end
328       context 'js形式' do
329         it 'ステータスコード200 OKを返す' do
330           get :new, :format => :js
331           response.should be_success 
332         end
333         it 'new.jsテンプレートを描画する' do
334           get :new, :format => :js
335           response.should render_template("new")
336         end
337       end
338       context 'json形式' do
339         it 'ステータスコード200 OKを返す' do
340           get :new, :format => :json
341           response.should be_success 
342         end
343         it 'jsonデータを返す' do
344           get :new, :format => :json
345           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
346         end
347         it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
348           Story.any_instance.should_receive(:story_as_json).exactly(1)
349           get :new, :format => :json
350         end
351         it 'データがアレになっている' do
352           get :new, :format => :json
353           json = JSON.parse response.body
354           json.has_key?("panel_id").should be_true
355           json.has_key?("comic_id").should be_true
356           json.has_key?("author_id").should be_true
357         end
358       end
359     end
360     context '作家権限がないとき' do
361       before do
362         sign_out @user
363       end
364       context 'html形式' do
365         it 'ステータスコード302 Foundを返す' do
366           get :new
367           response.status.should eq 302
368         end
369         it 'サインインページへ遷移する' do
370           get :new
371           response.body.should redirect_to '/users/sign_in'
372         end
373       end
374       context 'json形式' do
375         it 'ステータスコード401 Unauthorizedを返す' do
376           get :new, :format => :json
377           response.status.should eq 401
378         end
379         it '応答メッセージにUnauthorizedを返す' do
380           get :new, :format => :json
381           response.message.should match(/Unauthorized/)
382         end
383       end
384     end
385   end
386   
387   describe '新規作成に於いて' do
388     before do
389       @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
390       sign_in @user
391     end
392     context 'つつがなく終わるとき' do
393       it 'デフォルト値補充を依頼する' do
394         Story.any_instance.should_receive(:supply_default).exactly(1)
395         post :create, :story => @attr
396       end
397       it 'POSTデータから、カラム値を復元している' do
398         Story.any_instance.stub(:store).and_return(true)
399         post :create, :story => @attr
400         assigns(:story).comic_id.should eq @comic.id
401         assigns(:story).panel_id.should eq @panel.id
402       end
403       it '上書き補充を依頼する' do
404         Story.any_instance.should_receive(:overwrite).exactly(1)
405         post :create, :story => @attr
406       end
407       it 'コミックモデルに編集取得を依頼している' do
408         Comic.should_receive(:edit).with(@comic.id, @author).exactly(1)
409         post :create, :story => @attr
410       end
411       it 'コマモデルに単体取得を依頼している' do
412         Panel.should_receive(:show).with(@panel.id, @author).exactly(1)
413         post :create, :story => @attr
414       end
415       it 'モデルに保存依頼する' do
416         Story.any_instance.should_receive(:store).exactly(1)
417         post :create, :story => @attr
418       end
419       it "@storyに作成されたコマを保持していて、それがDBにある" do
420         post :create, :story => @attr
421         assigns(:story).should be_a(Story)
422         assigns(:story).should be_persisted
423       end
424       context 'html形式' do
425         it 'ステータスコード302 Foundを返す' do
426           Story.any_instance.stub(:store).and_return(true)
427           post :create, :story => @attr
428           response.status.should eq 302
429         end
430         it 'コミックのストーリー表示へ遷移する' do
431 #          Story.any_instance.stub(:store).and_return(true)
432           post :create, :story => @attr
433           response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
434         end
435       end
436       context 'json形式' do
437         it 'ステータスコード200 OKを返す' do
438 #          Story.any_instance.stub(:store).and_return(true)
439           post :create, :story => @attr, :format => :json
440           response.should be_success 
441         end
442         it '作成されたコマをjsonデータで返す' do
443           post :create, :story => @attr, :format => :json
444           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
445         end
446         it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
447           Story.any_instance.should_receive(:story_as_json).exactly(1)
448           post :create, :story => @attr, :format => :json
449         end
450         it 'データがアレになっている' do
451           post :create, :story => @attr, :format => :json
452           json = JSON.parse response.body
453           json["t"].should eq 0
454         end
455       end
456     end
457     context '作家権限がないとき' do
458       before do
459         sign_out @user
460       end
461       context 'html形式' do
462         it 'ステータスコード302 Foundを返す' do
463           post :create, :story => @attr
464           response.status.should eq 302
465         end
466         it 'サインインページへ遷移する' do
467           post :create, :story => @attr
468           response.body.should redirect_to '/users/sign_in'
469         end
470       end
471       context 'json形式' do
472         it 'ステータスコード401 Unauthorizedを返す' do
473           post :create, :story => @attr, :format => :json
474           response.status.should eq 401
475         end
476         it '応答メッセージにUnauthorizedを返す' do
477           post :create, :story => @attr, :format => :json
478           response.message.should match(/Unauthorized/)
479         end
480       end
481     end
482     context '検証、保存に失敗した' do
483       before do
484         Story.any_instance.stub(:store).and_return(false)
485       end
486       it "未保存のコマを保持している" do
487         post :create, :story => @attr
488         assigns(:story).should be_a_new(Story)
489       end
490       context 'html形式' do
491         it 'ステータスコード200 OKを返す' do
492           post :create, :story => @attr
493           response.status.should eq 200
494         end
495         it '新規ページを描画する' do
496           post :create, :story => @attr
497           response.should render_template("new")
498         end
499       end
500       context 'json形式' do
501         it 'ステータスコード422 unprocessable_entity を返す' do
502           post :create, :story => @attr, :format => :json
503           response.status.should eq 422
504         end
505         it '応答メッセージUnprocessable Entityを返す' do
506           post :create, :story => @attr, :format => :json
507           response.message.should match(/Unprocessable/)
508         end
509       end
510     end
511   end
512
513   describe '編集フォーム表示に於いて' do
514     before do
515       @story = FactoryGirl.create :story, :author_id => @author.id
516       sign_in @user
517       Story.stub(:show).and_return(@story)
518     end
519     context 'つつがなく終わるとき' do
520       it 'ストーリーモデルに編集取得を問い合わせている' do
521         Story.should_receive(:edit).exactly(1)
522         get :edit, :id => @story.id
523       end
524       it '@storyにデータを用意している' do
525         get :edit, :id => @story.id
526         assigns(:story).should eq @story
527       end
528       context 'html形式' do
529         it 'ステータスコード200 OKを返す' do
530           get :edit, :id => @story.id
531           response.should be_success 
532         end
533         it 'editテンプレートを描画する' do
534           get :edit, :id => @story.id
535           response.should render_template("edit")
536         end
537       end
538       context 'js形式' do
539         it 'ステータスコード200 OKを返す' do
540           get :edit, :id => @story.id, :format => :js
541           response.should be_success 
542         end
543         it 'edit.jsテンプレートを描画する' do
544           get :edit, :id => @story.id, :format => :js
545           response.should render_template("edit")
546         end
547       end
548     end
549     context '作家権限がないとき' do
550       before do
551         sign_out @user
552       end
553       context 'html形式' do
554         it 'ステータスコード302 Foundを返す' do
555           get :edit, :id => @story.id
556           response.status.should eq 302
557         end
558         it 'サインインページへ遷移する' do
559           get :edit, :id => @story.id
560           response.body.should redirect_to '/users/sign_in'
561         end
562       end
563       context 'js形式' do
564         it 'ステータスコード401 Unauthorizedを返す' do
565           get :edit, :id => @story.id, :format => :js
566           response.status.should eq 401
567         end
568         it '応答メッセージにUnauthorizedを返す' do
569           get :edit, :id => @story.id, :format => :js
570           response.message.should match(/Unauthorized/)
571         end
572       end
573     end
574   end
575
576   describe '更新に於いて' do
577     before do
578       @story = FactoryGirl.create :story, :author_id => @user.author.id
579       @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
580       sign_in @user
581     end
582     context 'つつがなく終わるとき' do
583       it 'モデルに編集取得依頼する' do
584         Story.stub(:edit).with(any_args).and_return(@story)
585         Story.should_receive(:edit).exactly(1)
586         put :update, :id => @story.id, :story => @attr
587       end
588       it 'POSTデータから、カラム値を復元している' do
589         Story.any_instance.stub(:store).and_return(true)
590         Story.any_instance.should_receive(:attributes=).exactly(1)
591         put :update, :id => @story.id, :story => @attr
592       end
593       it '上書き補充を依頼する' do
594         Story.any_instance.should_receive(:overwrite).exactly(1)
595         put :update, :id => @story.id, :story => @attr
596       end
597       it 'モデルに保存依頼する' do
598         Story.any_instance.should_receive(:store).exactly(1)
599         put :update, :id => @story.id, :story => @attr
600       end
601       it "@storyに作成されたストーリーを保持していて、それがDBにある" do
602         put :update, :id => @story.id, :story => @attr
603         assigns(:story).should be_a(Story)
604         assigns(:story).should be_persisted
605       end
606       context 'html形式' do
607         it 'ステータスコード302 Foundを返す' do
608           Story.any_instance.stub(:store).and_return(true)
609           put :update, :id => @story.id, :story => @attr
610           response.status.should eq 302
611         end
612         it 'ストーリー表示へ遷移する' do
613 #          Story.any_instance.stub(:store).and_return(true)
614           put :update, :id => @story.id, :story => @attr
615           response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
616         end
617       end
618       context 'json形式' do
619         it 'ステータスコード200 OKを返す' do
620 #          Story.any_instance.stub(:store).and_return(true)
621           put :update, :id => @story.id, :story => @attr, :format => :json
622           response.should be_success 
623         end
624       end
625     end
626     context '作家権限がないとき' do
627       before do
628         sign_out @user
629       end
630       context 'html形式' do
631         it 'ステータスコード302 Foundを返す' do
632           put :update, :id => @story.id, :story => @attr
633           response.status.should eq 302
634         end
635         it 'サインインページへ遷移する' do
636           put :update, :id => @story.id, :story => @attr
637           response.body.should redirect_to '/users/sign_in'
638         end
639       end
640       context 'json形式' do
641         it 'ステータスコード401 Unauthorizedを返す' do
642           put :update, :id => @story.id, :story => @attr, :format => :json
643           response.status.should eq 401
644         end
645         it '応答メッセージにUnauthorizedを返す' do
646           put :update, :id => @story.id, :story => @attr, :format => :json
647           response.message.should match(/Unauthorized/)
648         end
649       end
650     end
651     context '検証、保存に失敗した' do
652       before do
653         Story.any_instance.stub(:store).and_return(false)
654       end
655       it "指定のコマを保持している" do
656         put :update, :id => @story.id, :story => @attr
657         assigns(:story).should eq @story
658       end
659       context 'html形式' do
660         it 'ステータスコード200 OKを返す' do
661           put :update, :id => @story.id, :story => @attr
662           response.status.should eq 200
663         end
664         it '編集ページを描画する' do
665           put :update, :id => @story.id, :story => @attr
666           response.should render_template("edit")
667         end
668       end
669       context 'json形式' do
670         it 'ステータスコード422 unprocessable_entity を返す' do
671           put :update, :id => @story.id, :story => @attr, :format => :json
672           response.status.should eq 422
673         end
674         it '応答メッセージUnprocessable Entityを返す' do
675           put :update, :id => @story.id, :story => @attr, :format => :json
676           response.message.should match(/Unprocessable/)
677         end
678       end
679     end
680   end
681
682   describe '削除に於いて' do
683     before do
684       @story = FactoryGirl.create :story, :author_id => @author.id
685       sign_in @user
686       Story.stub(:edit).and_return(@story)
687     end
688     context '事前チェックしておく' do
689       before do
690         Story.stub(:edit).with(any_args()).and_return @story
691         Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
692       end
693       it 'ストーリーモデルに編集取得を問い合わせている' do
694         Story.should_receive(:edit).exactly(1)
695         delete :destroy, :id => @story.id
696       end
697       it 'モデルに削除を依頼する' do
698         Story.any_instance.should_receive(:destroy_and_shorten).exactly(1)
699         delete :destroy, :id => @story.id
700       end
701       it '@storyにアレを取得している' do
702         delete :destroy, :id => @story.id
703         assigns(:story).id.should eq(@story.id)
704       end
705     end
706     context 'つつがなく終わるとき' do
707       before do
708         Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
709       end
710       context 'html形式' do
711         it 'ステータスコード302 Foundを返す' do
712           delete :destroy, :id => @story.id
713           response.status.should eq 302
714         end
715         it '閲覧ページへ遷移する' do
716           delete :destroy, :id => @story.id
717           response.should redirect_to(:controller => 'stories', :action => :comic, :id => @story.comic_id)
718         end
719       end
720       context 'json形式' do
721         it 'ステータスコード200 OKを返す' do
722           delete :destroy, :id => @story.id, :format => :json
723           response.should be_success
724         end
725       end
726     end
727     context '作家権限がないとき' do
728       before do
729         sign_out @user
730       end
731       context 'html形式' do
732         it 'ステータスコード302 Foundを返す' do
733           delete :destroy, :id => @story.id
734           response.status.should eq 302
735         end
736         it 'サインインページへ遷移する' do
737           delete :destroy, :id => @story.id
738           response.body.should redirect_to '/users/sign_in'
739         end
740       end
741       context 'json形式' do
742         it 'ステータスコード401 Unauthorizedを返す' do
743           delete :destroy, :id => @story.id, :format => :json
744           response.status.should eq 401
745         end
746         it '応答メッセージにUnauthorizedを返す' do
747           delete :destroy, :id => @story.id, :format => :json
748           response.message.should match(/Unauthorized/)
749         end
750       end
751     end
752     context '削除に失敗したとき' do
753       before do
754         Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(false)
755       end
756       context 'html形式' do
757         it 'ステータスコード302 Foundを返す' do
758           delete :destroy, :id => @story.id
759           response.status.should eq 302
760         end
761         it 'そのコミックの詳細ページへ遷移する' do
762           delete :destroy, :id => @story.id
763           response.should redirect_to(story_path(@story))
764         end
765       end
766       context 'json形式' do
767         it 'ステータスコード422 unprocessable_entity を返す' do
768           delete :destroy, :id => @story.id, :format => :json
769           response.status.should eq 422
770         end
771         it '応答メッセージUnprocessable Entityを返す' do
772           delete :destroy, :id => @story.id, :format => :json
773           response.message.should match(/Unprocessable/)
774         end
775       end
776     end
777 =begin
778     context '対象ストーリーがないとき' do
779     end
780     context '他人のストーリーだったとき' do
781     end
782 =end
783   end
784   
785 end