OSDN Git Service

fix: any
[pettanr/pettanr.git] / spec / controllers / scroll_panels_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #スクコマ
4 describe ScrollPanelsController 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     @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
13     @panel = FactoryGirl.create :panel, :author_id => @author.id
14   end
15   
16 if MagicNumber['run_mode'] == 1
17   describe '一覧表示に於いて' do
18     before do
19       sign_in @user
20       @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
21       ScrollPanel.stub(:list).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
22     end
23     context 'パラメータpageについて' do
24       it '@pageに値が入る' do
25         get :index, :page => 5
26         assigns(:page).should eq 5
27       end
28       it '省略されると@pageに1値が入る' do
29         get :index
30         assigns(:page).should eq 1
31       end
32       it '与えられたpage_sizeがセットされている' do
33         get :index, :page_size => 15
34         assigns(:page_size).should eq 15
35       end
36       it '省略されると@page_sizeにデフォルト値が入る' do
37         get :index
38         assigns(:page_size).should eq ScrollPanel.default_page_size
39       end
40       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
41         get :index, :page_size => 1500
42         assigns(:page_size).should eq ScrollPanel.max_page_size
43       end
44       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
45         get :index, :page_size => 0
46         assigns(:page_size).should eq ScrollPanel.default_page_size
47       end
48     end
49     context 'つつがなく終わるとき' do
50       it 'ステータスコード200 OKを返す' do
51         get :index
52         response.should be_success 
53       end
54       it 'スクコマモデルに一覧を問い合わせている' do
55         ScrollPanel.should_receive(:list).exactly(1)
56         get :index
57       end
58       it '@scroll_panelsにリストを取得している' do
59         get :index
60         assigns(:scroll_panels).should have_at_least(3).items
61       end
62       context 'html形式' do
63         it '@paginateにページ制御を取得している' do
64           get :index
65           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
66         end
67         it 'indexテンプレートを描画する' do
68           get :index
69           response.should render_template("index")
70         end
71       end
72       context 'json形式' do
73         it 'jsonデータを返す' do
74           get :index, :format => :json
75           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
76         end
77         it 'スクコマモデルにjson一覧出力オプションを問い合わせている' do
78           ScrollPanel.should_receive(:list_json_opt).exactly(1)
79           get :index, :format => :json
80         end
81         it 'データがリスト構造になっている' do
82           get :index, :format => :json
83           json = JSON.parse response.body
84           json.should have_at_least(3).items
85         end
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?("scroll_id").should be_true
91           json.first.has_key?("t").should be_true
92         end
93       end
94     end
95     context 'ユーザ権限がないとき' do
96       before do
97         sign_out @user
98       end
99       context 'html形式' do
100         it 'ステータスコード302 Foundを返す' do
101           get :index
102           response.status.should eq 302
103         end
104         it 'サインインページへ遷移する' do
105           get :index
106           response.should redirect_to '/users/sign_in'
107         end
108       end
109       context 'json形式' do
110         it 'ステータスコード401 Unauthorizedを返す' do
111           get :index, :format => :json
112           response.status.should eq 401
113         end
114         it '応答メッセージにUnauthorizedを返す' do
115           get :index, :format => :json
116           response.message.should match(/Unauthorized/)
117         end
118       end
119     end
120     context 'ユーザ権限はないが管理者権限があるとき' do
121       before do
122         sign_out @user
123         sign_in @admin
124       end
125       it 'ステータスコード200 OKを返す' do
126         get :index
127         response.should be_success 
128       end
129     end
130     context 'ユーザだが作家登録していないとき' do
131       before do
132         @author.destroy
133       end
134       it 'ステータスコード200 OKを返す' do
135         get :index
136         response.should be_success 
137       end
138     end
139   end
140   
141   describe '単体表示に於いて' do
142     before do
143       sign_in @user
144       @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
145       Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
146       Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
147       ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [@user, nil]).and_return(@scroll_panel)
148       ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [nil, @admin]).and_return(@scroll_panel)
149     end
150     context 'つつがなく終わるとき' do
151       it 'スクコマモデルに単体取得を問い合わせている' do
152         ScrollPanel.should_receive(:show).with(@scroll_panel.id.to_s, [@user, nil]).exactly(1)
153         get :show, :id => @scroll_panel.id
154       end
155       it '@scroll_panelにアレを取得している' do
156         get :show, :id => @scroll_panel.id
157         assigns(:scroll_panel).should eq @scroll_panel
158       end
159       context 'html形式' do
160         it 'ステータスコード200 OKを返す' do
161           get :show, :id => @scroll_panel.id
162           response.should be_success
163         end
164         it 'showテンプレートを描画する' do
165           get :show, :id => @scroll_panel.id
166           response.should render_template("show")
167         end
168       end
169       context 'json形式' do
170         it 'ステータスコード200 OKを返す' do
171           get :show, :id => @scroll_panel.id, :format => :json
172           response.should be_success
173         end
174         it 'jsonデータを返す' do
175           get :show, :id => @scroll_panel.id, :format => :json
176           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
177         end
178         it 'スクコマモデルにスクコマjson出力を問い合わせている' do
179           ScrollPanel.any_instance.should_receive(:scroll_panel_as_json).exactly(1)
180           get :show, :id => @scroll_panel.id, :format => :json
181         end
182         it 'データがアレになっている' do
183           get :show, :id => @scroll_panel.id, :format => :json
184           json = JSON.parse response.body
185           json.has_key?("panel_id").should be_true
186           json.has_key?("scroll_id").should be_true
187           json.has_key?("author_id").should be_true
188         end
189       end
190     end
191     context 'ユーザ権限がないとき' do
192       before do
193         sign_out @user
194       end
195       context 'html形式' do
196         it 'ステータスコード302 Foundを返す' do
197           get :show, :id => @scroll_panel.id
198           response.status.should eq 302
199         end
200         it 'サインインページへ遷移する' do
201           get :show, :id => @scroll_panel.id
202           response.body.should redirect_to '/users/sign_in'
203         end
204       end
205       context 'json形式' do
206         it 'ステータスコード401 Unauthorizedを返す' do
207           get :show, :id => @scroll_panel.id, :format => :json
208           response.status.should eq 401
209         end
210         it '応答メッセージにUnauthorizedを返す' do
211           get :show, :id => @scroll_panel.id, :format => :json
212           response.message.should match(/Unauthorized/)
213         end
214       end
215     end
216     context 'ユーザ権限はないが管理者権限があるとき' do
217       before do
218         sign_out @user
219         sign_in @admin
220       end
221       it 'ステータスコード200 OKを返す' do
222           get :show, :id => @scroll_panel.id
223         response.should be_success 
224       end
225     end
226     context 'ユーザだが作家登録していないとき' do
227       before do
228         @author.destroy
229       end
230       it 'ステータスコード200 OKを返す' do
231           get :show, :id => @scroll_panel.id
232         response.should be_success 
233       end
234     end
235   end
236   
237   describe '新規作成フォーム表示に於いて' do
238     before do
239       sign_in @user
240     end
241     context 'つつがなく終わるとき' do
242       it '@scroll_panelに新規データを用意している' do
243         get :new
244         assigns(:scroll_panel).should be_a_new(ScrollPanel)
245       end
246       it 'モデルにデフォルト値補充を依頼している' do
247         ScrollPanel.any_instance.should_receive(:supply_default).exactly(1)
248         get :new
249       end
250       context 'html形式' do
251         it 'ステータスコード200 OKを返す' do
252           get :new
253           response.should be_success 
254         end
255         it 'newテンプレートを描画する' do
256           get :new
257           response.should render_template("new")
258         end
259       end
260       context 'js形式' do
261         it 'ステータスコード200 OKを返す' do
262           get :new, :format => :js
263           response.should be_success 
264         end
265         it 'new.jsテンプレートを描画する' do
266           get :new, :format => :js
267           response.should render_template("new")
268         end
269       end
270       context 'json形式' do
271         it 'ステータスコード200 OKを返す' do
272           get :new, :format => :json
273           response.should be_success 
274         end
275         it 'jsonデータを返す' do
276           get :new, :format => :json
277           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
278         end
279         it 'スクコマモデルのスクコマのjson出力を問い合わせている' do
280           ScrollPanel.any_instance.should_receive(:scroll_panel_as_json).exactly(1)
281           get :new, :format => :json
282         end
283         it 'データがアレになっている' do
284           get :new, :format => :json
285           json = JSON.parse response.body
286           json.has_key?("panel_id").should be_true
287           json.has_key?("scroll_id").should be_true
288           json.has_key?("author_id").should be_true
289         end
290       end
291     end
292     context 'ユーザ権限がないとき' do
293       before do
294         sign_out @user
295       end
296       context 'html形式' do
297         it 'ステータスコード302 Foundを返す' do
298           get :new
299           response.status.should eq 302
300         end
301         it 'サインインページへ遷移する' do
302           get :new
303           response.body.should redirect_to '/users/sign_in'
304         end
305       end
306       context 'json形式' do
307         it 'ステータスコード401 Unauthorizedを返す' do
308           get :new, :format => :json
309           response.status.should eq 401
310         end
311         it '応答メッセージにUnauthorizedを返す' do
312           get :new, :format => :json
313           response.message.should match(/Unauthorized/)
314         end
315       end
316     end
317     context 'ユーザ権限はないが管理者権限があるとき' do
318       before do
319         sign_out @user
320         sign_in @admin
321       end
322       context 'html形式' do
323         it 'ステータスコード302 Foundを返す' do
324           get :new
325           response.status.should eq 302
326         end
327         it 'サインインページへ遷移する' do
328           get :new
329           response.body.should redirect_to '/users/sign_in'
330         end
331       end
332     end
333     context 'ユーザだが作家登録していないとき' do
334       before do
335         @author.destroy
336       end
337       context 'html形式' do
338         it 'ステータスコード302 Foundを返す' do
339           get :new
340           response.status.should eq 302
341         end
342         it '作家登録ページへ遷移する' do
343           get :new
344           response.body.should redirect_to new_author_path
345         end
346       end
347     end
348   end
349   
350   describe '新規作成に於いて' do
351     before do
352       @attr = FactoryGirl.attributes_for(:scroll_panel, :t => nil, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id)
353       sign_in @user
354     end
355     context 'つつがなく終わるとき' do
356       it 'デフォルト値補充を依頼する' do
357         ScrollPanel.any_instance.should_receive(:supply_default).exactly(1)
358         post :create, :scroll_panel => @attr
359       end
360       it 'POSTデータから、カラム値を復元している' do
361         ScrollPanel.any_instance.stub(:store).and_return(true)
362         post :create, :scroll_panel => @attr
363         assigns(:scroll_panel).scroll_id.should eq @scroll.id
364         assigns(:scroll_panel).panel_id.should eq @panel.id
365       end
366       it '上書き補充を依頼する' do
367         ScrollPanel.any_instance.should_receive(:overwrite).exactly(1)
368         post :create, :scroll_panel => @attr
369       end
370       it 'スクロールモデルに編集取得を依頼している' do
371         Scroll.stub(:edit).and_return(@scroll)
372         Scroll.should_receive(:edit).with(@scroll.id, @author).exactly(1)
373         post :create, :scroll_panel => @attr
374       end
375       it 'コマモデルに単体取得を依頼している' do
376         Panel.should_receive(:show).with(@panel.id, @author).exactly(1)
377         post :create, :scroll_panel => @attr
378       end
379       it 'モデルに保存依頼する' do
380         ScrollPanel.any_instance.should_receive(:store).exactly(1)
381         post :create, :scroll_panel => @attr
382       end
383       it "@scroll_panelに作成されたコマを保持していて、それがDBにある" do
384         post :create, :scroll_panel => @attr
385         assigns(:scroll_panel).should be_a(ScrollPanel)
386         assigns(:scroll_panel).should be_persisted
387       end
388       context 'html形式' do
389         it 'ステータスコード302 Foundを返す' do
390           ScrollPanel.any_instance.stub(:store).and_return(true)
391           post :create, :scroll_panel => @attr
392           response.status.should eq 302
393         end
394         it 'スクロールのスクコマ表示へ遷移する' do
395 #          ScrollPanel.any_instance.stub(:store).and_return(true)
396           post :create, :scroll_panel => @attr
397           response.should redirect_to(play_scroll_path(@attr[:scroll_id]))
398         end
399       end
400       context 'json形式' do
401         it 'ステータスコード200 OKを返す' do
402 #          ScrollPanel.any_instance.stub(:store).and_return(true)
403           post :create, :scroll_panel => @attr, :format => :json
404           response.should be_success 
405         end
406         it '作成されたコマをjsonデータで返す' do
407           post :create, :scroll_panel => @attr, :format => :json
408           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
409         end
410         it 'スクコマモデルのスクコマのjson出力を問い合わせている' do
411           ScrollPanel.any_instance.should_receive(:scroll_panel_as_json).exactly(1)
412           post :create, :scroll_panel => @attr, :format => :json
413         end
414         it 'データがアレになっている' do
415           post :create, :scroll_panel => @attr, :format => :json
416           json = JSON.parse response.body
417           json["t"].should eq 0
418         end
419       end
420     end
421     context 'ユーザ権限がないとき' do
422       before do
423         sign_out @user
424       end
425       context 'html形式' do
426         it 'ステータスコード302 Foundを返す' do
427           post :create, :scroll_panel => @attr
428           response.status.should eq 302
429         end
430         it 'サインインページへ遷移する' do
431           post :create, :scroll_panel => @attr
432           response.body.should redirect_to '/users/sign_in'
433         end
434       end
435       context 'json形式' do
436         it 'ステータスコード401 Unauthorizedを返す' do
437           post :create, :scroll_panel => @attr, :format => :json
438           response.status.should eq 401
439         end
440         it '応答メッセージにUnauthorizedを返す' do
441           post :create, :scroll_panel => @attr, :format => :json
442           response.message.should match(/Unauthorized/)
443         end
444       end
445     end
446     context 'ユーザ権限はないが管理者権限があるとき' do
447       before do
448         sign_out @user
449         sign_in @admin
450       end
451       context 'html形式' do
452         it 'ステータスコード302 Foundを返す' do
453           post :create, :scroll_panel => @attr
454           response.status.should eq 302
455         end
456         it 'サインインページへ遷移する' do
457           post :create, :scroll_panel => @attr
458           response.body.should redirect_to '/users/sign_in'
459         end
460       end
461     end
462     context 'ユーザだが作家登録していないとき' do
463       before do
464         @author.destroy
465       end
466       context 'html形式' do
467         it 'ステータスコード302 Foundを返す' do
468           post :create, :scroll_panel => @attr
469           response.status.should eq 302
470         end
471         it '作家登録ページへ遷移する' do
472           post :create, :scroll_panel => @attr
473           response.body.should redirect_to new_author_path
474         end
475       end
476     end
477     context '検証、保存に失敗した' do
478       before do
479         ScrollPanel.any_instance.stub(:store).and_return(false)
480       end
481       it "未保存のコマを保持している" do
482         post :create, :scroll_panel => @attr
483         assigns(:scroll_panel).should be_a_new(ScrollPanel)
484       end
485       context 'html形式' do
486         it 'ステータスコード200 OKを返す' do
487           post :create, :scroll_panel => @attr
488           response.status.should eq 200
489         end
490         it '新規ページを描画する' do
491           post :create, :scroll_panel => @attr
492           response.should render_template("new")
493         end
494       end
495       context 'json形式' do
496         it 'ステータスコード422 unprocessable_entity を返す' do
497           post :create, :scroll_panel => @attr, :format => :json
498           response.status.should eq 422
499         end
500         it '応答メッセージUnprocessable Entityを返す' do
501           post :create, :scroll_panel => @attr, :format => :json
502           response.message.should match(/Unprocessable/)
503         end
504       end
505     end
506   end
507
508   describe '編集フォーム表示に於いて' do
509     before do
510       @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id
511       sign_in @user
512       ScrollPanel.stub(:show).and_return(@scroll_panel)
513     end
514     context 'つつがなく終わるとき' do
515       it 'スクコマモデルに編集取得を問い合わせている' do
516         ScrollPanel.should_receive(:edit).exactly(1)
517         get :edit, :id => @scroll_panel.id
518       end
519       it '@scroll_panelにデータを用意している' do
520         get :edit, :id => @scroll_panel.id
521         assigns(:scroll_panel).should eq @scroll_panel
522       end
523       context 'html形式' do
524         it 'ステータスコード200 OKを返す' do
525           get :edit, :id => @scroll_panel.id
526           response.should be_success 
527         end
528         it 'editテンプレートを描画する' do
529           get :edit, :id => @scroll_panel.id
530           response.should render_template("edit")
531         end
532       end
533       context 'js形式' do
534         it 'ステータスコード200 OKを返す' do
535           get :edit, :id => @scroll_panel.id, :format => :js
536           response.should be_success 
537         end
538         it 'edit.jsテンプレートを描画する' do
539           get :edit, :id => @scroll_panel.id, :format => :js
540           response.should render_template("edit")
541         end
542       end
543     end
544     context 'ユーザ権限がないとき' do
545       before do
546         sign_out @user
547       end
548       context 'html形式' do
549         it 'ステータスコード302 Foundを返す' do
550           get :edit, :id => @scroll_panel.id
551           response.status.should eq 302
552         end
553         it 'サインインページへ遷移する' do
554           get :edit, :id => @scroll_panel.id
555           response.body.should redirect_to '/users/sign_in'
556         end
557       end
558       context 'js形式' do
559         it 'ステータスコード401 Unauthorizedを返す' do
560           get :edit, :id => @scroll_panel.id, :format => :js
561           response.status.should eq 401
562         end
563         it '応答メッセージにUnauthorizedを返す' do
564           get :edit, :id => @scroll_panel.id, :format => :js
565           response.message.should match(/Unauthorized/)
566         end
567       end
568     end
569     context 'ユーザ権限はないが管理者権限があるとき' do
570       before do
571         sign_out @user
572         sign_in @admin
573       end
574       context 'html形式' do
575         it 'ステータスコード302 Foundを返す' do
576           get :edit, :id => @scroll_panel.id
577           response.status.should eq 302
578         end
579         it 'サインインページへ遷移する' do
580           get :edit, :id => @scroll_panel.id
581           response.body.should redirect_to '/users/sign_in'
582         end
583       end
584     end
585     context 'ユーザだが作家登録していないとき' do
586       before do
587         @author.destroy
588       end
589       context 'html形式' do
590         it 'ステータスコード302 Foundを返す' do
591           get :edit, :id => @scroll_panel.id
592           response.status.should eq 302
593         end
594         it '作家登録ページへ遷移する' do
595           get :edit, :id => @scroll_panel.id
596           response.body.should redirect_to new_author_path
597         end
598       end
599     end
600   end
601
602   describe '更新に於いて' do
603     before do
604       @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @user.author.id
605       @attr = FactoryGirl.attributes_for(:scroll_panel, :author_id => @author.id)
606       sign_in @user
607     end
608     context 'つつがなく終わるとき' do
609       it 'モデルに編集取得依頼する' do
610         ScrollPanel.stub(:edit).with(any_args).and_return(@scroll_panel)
611         ScrollPanel.should_receive(:edit).exactly(1)
612         put :update, :id => @scroll_panel.id, :scroll_panel => @attr
613       end
614       it 'POSTデータから、カラム値を復元している' do
615         ScrollPanel.any_instance.stub(:store).and_return(true)
616         ScrollPanel.any_instance.should_receive(:attributes=).exactly(1)
617         put :update, :id => @scroll_panel.id, :scroll_panel => @attr
618       end
619       it '上書き補充を依頼する' do
620         ScrollPanel.any_instance.should_receive(:overwrite).exactly(1)
621         put :update, :id => @scroll_panel.id, :scroll_panel => @attr
622       end
623       it 'モデルに保存依頼する' do
624         ScrollPanel.any_instance.should_receive(:store).exactly(1)
625         put :update, :id => @scroll_panel.id, :scroll_panel => @attr
626       end
627       it "@scroll_panelに作成されたスクコマを保持していて、それがDBにある" do
628         put :update, :id => @scroll_panel.id, :scroll_panel => @attr
629         assigns(:scroll_panel).should be_a(ScrollPanel)
630         assigns(:scroll_panel).should be_persisted
631       end
632       context 'html形式' do
633         it 'ステータスコード302 Foundを返す' do
634           ScrollPanel.any_instance.stub(:store).and_return(true)
635           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
636           response.status.should eq 302
637         end
638         it 'スクコマ表示へ遷移する' do
639 #          ScrollPanel.any_instance.stub(:store).and_return(true)
640           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
641           response.should redirect_to(play_scroll_path(@attr[:scroll_id]))
642         end
643       end
644       context 'json形式' do
645         it 'ステータスコード200 OKを返す' do
646 #          ScrollPanel.any_instance.stub(:store).and_return(true)
647           put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
648           response.should be_success 
649         end
650       end
651     end
652     context 'ユーザ権限がないとき' do
653       before do
654         sign_out @user
655       end
656       context 'html形式' do
657         it 'ステータスコード302 Foundを返す' do
658           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
659           response.status.should eq 302
660         end
661         it 'サインインページへ遷移する' do
662           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
663           response.body.should redirect_to '/users/sign_in'
664         end
665       end
666       context 'json形式' do
667         it 'ステータスコード401 Unauthorizedを返す' do
668           put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
669           response.status.should eq 401
670         end
671         it '応答メッセージにUnauthorizedを返す' do
672           put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
673           response.message.should match(/Unauthorized/)
674         end
675       end
676     end
677     context 'ユーザ権限はないが管理者権限があるとき' do
678       before do
679         sign_out @user
680         sign_in @admin
681       end
682       context 'html形式' do
683         it 'ステータスコード302 Foundを返す' do
684           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
685           response.status.should eq 302
686         end
687         it 'サインインページへ遷移する' do
688           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
689           response.body.should redirect_to '/users/sign_in'
690         end
691       end
692     end
693     context 'ユーザだが作家登録していないとき' do
694       before do
695         @author.destroy
696       end
697       context 'html形式' do
698         it 'ステータスコード302 Foundを返す' do
699           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
700           response.status.should eq 302
701         end
702         it '作家登録ページへ遷移する' do
703           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
704           response.body.should redirect_to new_author_path
705         end
706       end
707     end
708     context '検証、保存に失敗した' do
709       before do
710         ScrollPanel.any_instance.stub(:store).and_return(false)
711       end
712       it "指定のコマを保持している" do
713         put :update, :id => @scroll_panel.id, :scroll_panel => @attr
714         assigns(:scroll_panel).should eq @scroll_panel
715       end
716       context 'html形式' do
717         it 'ステータスコード200 OKを返す' do
718           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
719           response.status.should eq 200
720         end
721         it '編集ページを描画する' do
722           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
723           response.should render_template("edit")
724         end
725       end
726       context 'json形式' do
727         it 'ステータスコード422 unprocessable_entity を返す' do
728           put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
729           response.status.should eq 422
730         end
731         it '応答メッセージUnprocessable Entityを返す' do
732           put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
733           response.message.should match(/Unprocessable/)
734         end
735       end
736     end
737   end
738
739   describe '削除に於いて' do
740     before do
741       @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id
742       sign_in @user
743       ScrollPanel.stub(:edit).and_return(@scroll_panel)
744     end
745     context '事前チェックしておく' do
746       before do
747         ScrollPanel.stub(:edit).with(any_args()).and_return @scroll_panel
748         ScrollPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
749       end
750       it 'スクコマモデルに編集取得を問い合わせている' do
751         ScrollPanel.should_receive(:edit).exactly(1)
752         delete :destroy, :id => @scroll_panel.id
753       end
754       it 'モデルに削除を依頼する' do
755         ScrollPanel.any_instance.should_receive(:destroy_and_shorten).exactly(1)
756         delete :destroy, :id => @scroll_panel.id
757       end
758       it '@scroll_panelにアレを取得している' do
759         delete :destroy, :id => @scroll_panel.id
760         assigns(:scroll_panel).id.should eq(@scroll_panel.id)
761       end
762     end
763     context 'つつがなく終わるとき' do
764       before do
765         ScrollPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
766       end
767       context 'html形式' do
768         it 'ステータスコード302 Foundを返す' do
769           delete :destroy, :id => @scroll_panel.id
770           response.status.should eq 302
771         end
772         it '閲覧ページへ遷移する' do
773           delete :destroy, :id => @scroll_panel.id
774           response.should redirect_to(play_scroll_path(@scroll_panel.scroll_id) )
775         end
776       end
777       context 'json形式' do
778         it 'ステータスコード200 OKを返す' do
779           delete :destroy, :id => @scroll_panel.id, :format => :json
780           response.should be_success
781         end
782       end
783     end
784     context 'ユーザ権限がないとき' do
785       before do
786         sign_out @user
787       end
788       context 'html形式' do
789         it 'ステータスコード302 Foundを返す' do
790           delete :destroy, :id => @scroll_panel.id
791           response.status.should eq 302
792         end
793         it 'サインインページへ遷移する' do
794           delete :destroy, :id => @scroll_panel.id
795           response.body.should redirect_to '/users/sign_in'
796         end
797       end
798       context 'json形式' do
799         it 'ステータスコード401 Unauthorizedを返す' do
800           delete :destroy, :id => @scroll_panel.id, :format => :json
801           response.status.should eq 401
802         end
803         it '応答メッセージにUnauthorizedを返す' do
804           delete :destroy, :id => @scroll_panel.id, :format => :json
805           response.message.should match(/Unauthorized/)
806         end
807       end
808     end
809     context 'ユーザ権限はないが管理者権限があるとき' do
810       before do
811         sign_out @user
812         sign_in @admin
813       end
814       context 'html形式' do
815         it 'ステータスコード302 Foundを返す' do
816           delete :destroy, :id => @scroll_panel.id
817           response.status.should eq 302
818         end
819         it 'サインインページへ遷移する' do
820           delete :destroy, :id => @scroll_panel.id
821           response.body.should redirect_to '/users/sign_in'
822         end
823       end
824     end
825     context 'ユーザだが作家登録していないとき' do
826       before do
827         @author.destroy
828       end
829       context 'html形式' do
830         it 'ステータスコード302 Foundを返す' do
831           delete :destroy, :id => @scroll_panel.id
832           response.status.should eq 302
833         end
834         it '作家登録ページへ遷移する' do
835           delete :destroy, :id => @scroll_panel.id
836           response.body.should redirect_to new_author_path
837         end
838       end
839     end
840     context '削除に失敗したとき' do
841       before do
842         ScrollPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(false)
843       end
844       context 'html形式' do
845         it 'ステータスコード302 Foundを返す' do
846           delete :destroy, :id => @scroll_panel.id
847           response.status.should eq 302
848         end
849         it 'そのスクロールの詳細ページへ遷移する' do
850           delete :destroy, :id => @scroll_panel.id
851           response.should redirect_to(scroll_panel_path(@scroll_panel))
852         end
853       end
854       context 'json形式' do
855         it 'ステータスコード422 unprocessable_entity を返す' do
856           delete :destroy, :id => @scroll_panel.id, :format => :json
857           response.status.should eq 422
858         end
859         it '応答メッセージUnprocessable Entityを返す' do
860           delete :destroy, :id => @scroll_panel.id, :format => :json
861           response.message.should match(/Unprocessable/)
862         end
863       end
864     end
865 =begin
866     context '対象スクコマがないとき' do
867     end
868     context '他人のスクコマだったとき' do
869     end
870 =end
871   end
872   
873 else
874   describe '一覧表示に於いて' do
875     before do
876       sign_in @user
877       @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
878       ScrollPanel.stub(:list).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
879     end
880     context 'つつがなく終わるとき' do
881       it 'ステータスコード200 OKを返す' do
882         get :index
883         response.should be_success 
884       end
885       context 'html形式' do
886         it 'indexテンプレートを描画する' do
887           get :index
888           response.should render_template("index")
889         end
890       end
891       context 'json形式' do
892         it 'jsonデータを返す' do
893           get :index, :format => :json
894           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
895         end
896       end
897     end
898     context 'ユーザ権限がないとき' do
899       before do
900         sign_out @user
901       end
902       it 'ステータスコード200 OKを返す' do
903         get :index
904         response.should be_success 
905       end
906       context 'html形式' do
907         it 'indexテンプレートを描画する' do
908           get :index
909           response.should render_template("index")
910         end
911       end
912       context 'json形式' do
913         it 'jsonデータを返す' do
914           get :index, :format => :json
915           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
916         end
917       end
918     end
919   end
920   
921   describe '単体表示に於いて' do
922     before do
923       sign_in @user
924       @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
925       Scroll.stub(:show).with(@scroll.id.to_s, [nil, nil]).and_return(@scroll)
926       Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
927       Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
928       ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [nil, nil]).and_return(@scroll_panel)
929       ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [@user, nil]).and_return(@scroll_panel)
930       ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [nil, @admin]).and_return(@scroll_panel)
931     end
932     context 'つつがなく終わるとき' do
933       context 'html形式' do
934         it 'ステータスコード200 OKを返す' do
935           get :show, :id => @scroll_panel.id
936           response.should be_success
937         end
938         it 'showテンプレートを描画する' do
939           get :show, :id => @scroll_panel.id
940           response.should render_template("show")
941         end
942       end
943       context 'json形式' do
944         it 'ステータスコード200 OKを返す' do
945           get :show, :id => @scroll_panel.id, :format => :json
946           response.should be_success
947         end
948         it 'jsonデータを返す' do
949           get :show, :id => @scroll_panel.id, :format => :json
950           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
951         end
952       end
953     end
954     context 'ユーザ権限がないとき' do
955       before do
956         sign_out @user
957       end
958       context 'html形式' do
959         it 'ステータスコード200 OKを返す' do
960           get :show, :id => @scroll_panel.id
961           response.should be_success
962         end
963         it 'showテンプレートを描画する' do
964           get :show, :id => @scroll_panel.id
965           response.should render_template("show")
966         end
967       end
968       context 'json形式' do
969         it 'ステータスコード200 OKを返す' do
970           get :show, :id => @scroll_panel.id, :format => :json
971           response.should be_success
972         end
973         it 'jsonデータを返す' do
974           get :show, :id => @scroll_panel.id, :format => :json
975           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
976         end
977       end
978     end
979   end
980   
981   describe '閲覧に於いて' do
982     before do
983       @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
984       Scroll.stub(:show).with(@scroll.id.to_s, [nil, nil]).and_return(@scroll)
985       Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
986       Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
987       ScrollPanel.stub(:count).and_return(10)
988       ScrollPanel.stub(:play_list).with(any_args).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
989       sign_in @user
990     end
991     context 'つつがなく終わるとき' do
992       context 'html形式' do
993         it 'ステータスコード200 OKを返す' do
994           get :scroll, :id => @scroll.id
995           response.should be_success 
996         end
997         it 'scrollテンプレートを描画する' do
998           get :scroll, :id => @scroll.id
999           response.should render_template("scroll")
1000         end
1001       end
1002       context 'json形式' do
1003         it 'ステータスコード200 OKを返す' do
1004           get :scroll, :id => @scroll.id, :format => :json
1005           response.should be_success 
1006         end
1007         it 'jsonデータを返す' do
1008           get :scroll, :id => @scroll.id, :format => :json
1009           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1010         end
1011       end
1012     end
1013     context 'ユーザ権限がないとき' do
1014       before do
1015         sign_out @user
1016       end
1017       context 'html形式' do
1018         it 'ステータスコード200 OKを返す' do
1019           get :scroll, :id => @scroll.id
1020           response.should be_success 
1021         end
1022         it 'scrollテンプレートを描画する' do
1023           get :scroll, :id => @scroll.id
1024           response.should render_template("scroll")
1025         end
1026       end
1027       context 'json形式' do
1028         it 'ステータスコード200 OKを返す' do
1029           get :scroll, :id => @scroll.id, :format => :json
1030           response.should be_success 
1031         end
1032         it 'jsonデータを返す' do
1033           get :scroll, :id => @scroll.id, :format => :json
1034           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1035         end
1036       end
1037     end
1038   end
1039
1040   describe '新規作成フォーム表示に於いて' do
1041     before do
1042       sign_in @user
1043     end
1044     context 'つつがなく終わるとき' do
1045       context 'html形式' do
1046         it 'ステータスコード200 OKを返す' do
1047           get :new
1048           response.should be_success 
1049         end
1050         it 'newテンプレートを描画する' do
1051           get :new
1052           response.should render_template("new")
1053         end
1054       end
1055       context 'js形式' do
1056         it 'ステータスコード200 OKを返す' do
1057           get :new, :format => :js
1058           response.should be_success 
1059         end
1060         it 'new.jsテンプレートを描画する' do
1061           get :new, :format => :js
1062           response.should render_template("new")
1063         end
1064       end
1065       context 'json形式' do
1066         it 'ステータスコード200 OKを返す' do
1067           get :new, :format => :json
1068           response.should be_success 
1069         end
1070         it 'jsonデータを返す' do
1071           get :new, :format => :json
1072           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1073         end
1074       end
1075     end
1076     context 'ユーザ権限がないとき' do
1077       before do
1078         sign_out @user
1079       end
1080       context 'html形式' do
1081         it 'ステータスコード302 Foundを返す' do
1082           get :new
1083           response.status.should eq 302
1084         end
1085         it 'サインインページへ遷移する' do
1086           get :new
1087           response.body.should redirect_to '/users/sign_in'
1088         end
1089       end
1090       context 'json形式' do
1091         it 'ステータスコード401 Unauthorizedを返す' do
1092           get :new, :format => :json
1093           response.status.should eq 401
1094         end
1095         it '応答メッセージにUnauthorizedを返す' do
1096           get :new, :format => :json
1097           response.message.should match(/Unauthorized/)
1098         end
1099       end
1100     end
1101   end
1102   
1103   describe '新規作成に於いて' do
1104     before do
1105       @attr = FactoryGirl.attributes_for(:scroll_panel, :t => nil, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id)
1106       sign_in @user
1107     end
1108     context 'つつがなく終わるとき' do
1109       context 'html形式' do
1110         it 'ステータスコード302 Foundを返す' do
1111           ScrollPanel.any_instance.stub(:store).and_return(true)
1112           post :create, :scroll_panel => @attr
1113           response.status.should eq 302
1114         end
1115         it 'スクロールのスクコマ表示へ遷移する' do
1116 #          ScrollPanel.any_instance.stub(:store).and_return(true)
1117           post :create, :scroll_panel => @attr
1118           response.should redirect_to(:action => :scroll, :id => @attr[:scroll_id])
1119         end
1120       end
1121       context 'json形式' do
1122         it 'ステータスコード200 OKを返す' do
1123 #          ScrollPanel.any_instance.stub(:store).and_return(true)
1124           post :create, :scroll_panel => @attr, :format => :json
1125           response.should be_success 
1126         end
1127         it '作成されたコマをjsonデータで返す' do
1128           post :create, :scroll_panel => @attr, :format => :json
1129           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1130         end
1131       end
1132     end
1133     context 'ユーザ権限がないとき' do
1134       before do
1135         sign_out @user
1136       end
1137       context 'html形式' do
1138         it 'ステータスコード302 Foundを返す' do
1139           post :create, :scroll_panel => @attr
1140           response.status.should eq 302
1141         end
1142         it 'サインインページへ遷移する' do
1143           post :create, :scroll_panel => @attr
1144           response.body.should redirect_to '/users/sign_in'
1145         end
1146       end
1147       context 'json形式' do
1148         it 'ステータスコード401 Unauthorizedを返す' do
1149           post :create, :scroll_panel => @attr, :format => :json
1150           response.status.should eq 401
1151         end
1152         it '応答メッセージにUnauthorizedを返す' do
1153           post :create, :scroll_panel => @attr, :format => :json
1154           response.message.should match(/Unauthorized/)
1155         end
1156       end
1157     end
1158   end
1159
1160   describe '編集フォーム表示に於いて' do
1161     before do
1162       @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id
1163       sign_in @user
1164       ScrollPanel.stub(:show).and_return(@scroll_panel)
1165     end
1166     context 'つつがなく終わるとき' do
1167       context 'html形式' do
1168         it 'ステータスコード200 OKを返す' do
1169           get :edit, :id => @scroll_panel.id
1170           response.should be_success 
1171         end
1172         it 'editテンプレートを描画する' do
1173           get :edit, :id => @scroll_panel.id
1174           response.should render_template("edit")
1175         end
1176       end
1177       context 'js形式' do
1178         it 'ステータスコード200 OKを返す' do
1179           get :edit, :id => @scroll_panel.id, :format => :js
1180           response.should be_success 
1181         end
1182         it 'edit.jsテンプレートを描画する' do
1183           get :edit, :id => @scroll_panel.id, :format => :js
1184           response.should render_template("edit")
1185         end
1186       end
1187     end
1188     context 'ユーザ権限がないとき' do
1189       before do
1190         sign_out @user
1191       end
1192       context 'html形式' do
1193         it 'ステータスコード302 Foundを返す' do
1194           get :edit, :id => @scroll_panel.id
1195           response.status.should eq 302
1196         end
1197         it 'サインインページへ遷移する' do
1198           get :edit, :id => @scroll_panel.id
1199           response.body.should redirect_to '/users/sign_in'
1200         end
1201       end
1202       context 'js形式' do
1203         it 'ステータスコード401 Unauthorizedを返す' do
1204           get :edit, :id => @scroll_panel.id, :format => :js
1205           response.status.should eq 401
1206         end
1207         it '応答メッセージにUnauthorizedを返す' do
1208           get :edit, :id => @scroll_panel.id, :format => :js
1209           response.message.should match(/Unauthorized/)
1210         end
1211       end
1212     end
1213   end
1214
1215   describe '更新に於いて' do
1216     before do
1217       @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @user.author.id
1218       @attr = FactoryGirl.attributes_for(:scroll_panel, :author_id => @author.id)
1219       sign_in @user
1220     end
1221     context 'つつがなく終わるとき' do
1222       context 'html形式' do
1223         it 'ステータスコード302 Foundを返す' do
1224           ScrollPanel.any_instance.stub(:store).and_return(true)
1225           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
1226           response.status.should eq 302
1227         end
1228         it 'スクコマ表示へ遷移する' do
1229 #          ScrollPanel.any_instance.stub(:store).and_return(true)
1230           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
1231           response.should redirect_to(:action => :scroll, :id => @attr[:scroll_id])
1232         end
1233       end
1234       context 'json形式' do
1235         it 'ステータスコード200 OKを返す' do
1236 #          ScrollPanel.any_instance.stub(:store).and_return(true)
1237           put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
1238           response.should be_success 
1239         end
1240       end
1241     end
1242     context 'ユーザ権限がないとき' do
1243       before do
1244         sign_out @user
1245       end
1246       context 'html形式' do
1247         it 'ステータスコード302 Foundを返す' do
1248           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
1249           response.status.should eq 302
1250         end
1251         it 'サインインページへ遷移する' do
1252           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
1253           response.body.should redirect_to '/users/sign_in'
1254         end
1255       end
1256       context 'json形式' do
1257         it 'ステータスコード401 Unauthorizedを返す' do
1258           put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
1259           response.status.should eq 401
1260         end
1261         it '応答メッセージにUnauthorizedを返す' do
1262           put :update, :id => @scroll_panel.id, :scroll_panel => @attr, :format => :json
1263           response.message.should match(/Unauthorized/)
1264         end
1265       end
1266     end
1267   end
1268
1269   describe '削除に於いて' do
1270     before do
1271       @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id
1272       sign_in @user
1273       ScrollPanel.stub(:edit).and_return(@scroll_panel)
1274     end
1275     context 'つつがなく終わるとき' do
1276       before do
1277         ScrollPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
1278       end
1279       context 'html形式' do
1280         it 'ステータスコード302 Foundを返す' do
1281           delete :destroy, :id => @scroll_panel.id
1282           response.status.should eq 302
1283         end
1284         it '閲覧ページへ遷移する' do
1285           delete :destroy, :id => @scroll_panel.id
1286           response.should redirect_to(:controller => 'scroll_panels', :action => :scroll, :id => @scroll_panel.scroll_id)
1287         end
1288       end
1289       context 'json形式' do
1290         it 'ステータスコード200 OKを返す' do
1291           delete :destroy, :id => @scroll_panel.id, :format => :json
1292           response.should be_success
1293         end
1294       end
1295     end
1296     context 'ユーザ権限がないとき' do
1297       before do
1298         sign_out @user
1299       end
1300       context 'html形式' do
1301         it 'ステータスコード302 Foundを返す' do
1302           delete :destroy, :id => @scroll_panel.id
1303           response.status.should eq 302
1304         end
1305         it 'サインインページへ遷移する' do
1306           delete :destroy, :id => @scroll_panel.id
1307           response.body.should redirect_to '/users/sign_in'
1308         end
1309       end
1310       context 'json形式' do
1311         it 'ステータスコード401 Unauthorizedを返す' do
1312           delete :destroy, :id => @scroll_panel.id, :format => :json
1313           response.status.should eq 401
1314         end
1315         it '応答メッセージにUnauthorizedを返す' do
1316           delete :destroy, :id => @scroll_panel.id, :format => :json
1317           response.message.should match(/Unauthorized/)
1318         end
1319       end
1320     end
1321   end
1322   
1323 end
1324 end