OSDN Git Service

2809d269373400f1249959c41dbd2619ccf559d5
[pettanr/pettanr.git] / spec / controllers / home_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #ユーザホーム
4
5 describe HomeController do
6   before do
7     FactoryGirl.create :admin
8     @sp = FactoryGirl.create :system_picture
9     @lg = FactoryGirl.create :license_group
10     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
11     @user = FactoryGirl.create( :user_yas)
12     @author = @user.author
13     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
14     @color = FactoryGirl.create :color
15     @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
16     @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
17     @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
18     @panel = FactoryGirl.create :panel, :author_id => @author.id
19   end
20   
21   describe '自分のコミック一覧表示に於いて' do
22     before do
23       @comic = FactoryGirl.create :comic, :author_id => @author.id
24       sign_in @user
25       Comic.stub(:mylist).and_return([@comic, @comic, @comic])
26     end
27     context 'パラメータpageについて' do
28       it '@pageに値が入る' do
29         get :comic, :page => 5
30         assigns(:page).should eq 5
31       end
32       it '省略されると@pageに1値が入る' do
33         get :comic
34         assigns(:page).should eq 1
35       end
36       it '与えられたpage_sizeがセットされている' do
37         get :comic, :page_size => 15
38         assigns(:page_size).should eq 15
39       end
40       it '省略されると@page_sizeにデフォルト値が入る' do
41         get :comic
42         assigns(:page_size).should eq Author.default_comic_page_size
43       end
44       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
45         get :comic, :page_size => 1500
46         assigns(:page_size).should eq Author.comic_max_page_size
47       end
48       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
49         get :comic, :page_size => 0
50         assigns(:page_size).should eq Author.default_comic_page_size
51       end
52     end
53     context 'つつがなく終わるとき' do
54       it 'ステータスコード200 OKを返す' do
55         get :comic
56         response.should be_success 
57       end
58       it 'コミックモデルに一覧を問い合わせている' do
59         Comic.should_receive(:mylist).exactly(1)
60         get :comic
61       end
62       it '@comicsにリストを取得している' do
63         get :comic
64         assigns(:comics).should have_at_least(3).items
65       end
66       context 'html形式' do
67         it 'comicテンプレートを描画する' do
68           get :comic
69           response.should render_template("comic")
70         end
71       end
72       context 'json形式' do
73         it 'jsonデータを返す' do
74           get :comic, :format => :json
75           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
76         end
77         it 'コミックモデルにjson一覧出力オプションを問い合わせている' do
78           Comic.should_receive(:list_json_opt).exactly(1)
79           get :comic, :format => :json
80         end
81         it 'データがリスト構造になっている' do
82           get :comic, :format => :json
83           json = JSON.parse response.body
84           json.should have_at_least(3).items
85         end
86         it 'リストの先頭くらいはコミックっぽいものであって欲しい' do
87           get :comic, :format => :json
88           json = JSON.parse response.body
89           json.first.has_key?("title").should be_true
90           json.first.has_key?("visible").should be_true\r
91         end
92       end
93     end
94     context '作家権限がないとき' do
95       before do
96         sign_out @user
97       end
98       context 'html形式' do
99         it 'ステータスコード302 Foundを返す' do
100           get :comic
101           response.status.should eq 302
102         end
103         it 'サインインページへ遷移する' do
104           get :comic
105           response.should redirect_to '/users/sign_in'
106         end
107       end
108       context 'json形式' do
109         it 'ステータスコード401 Unauthorizedを返す' do
110           get :comic, :format => :json
111           response.status.should eq 401
112         end
113         it '応答メッセージにUnauthorizedを返す' do
114           get :comic, :format => :json
115           response.message.should match(/Unauthorized/)
116         end
117       end
118     end
119   end
120   
121   describe '自分のコマ一覧表示に於いて' do
122     before do
123       @panel = FactoryGirl.create :panel, :author_id => @author.id
124       sign_in @user
125       Panel.stub(:mylist).and_return([@panel, @panel, @panel])
126     end
127     context 'パラメータpageについて' do
128       it '@pageに値が入る' do
129         get :panel, :page => 5
130         assigns(:page).should eq 5
131       end
132       it '省略されると@pageに1値が入る' do
133         get :panel
134         assigns(:page).should eq 1
135       end
136       it '与えられたpage_sizeがセットされている' do
137         get :panel, :page_size => 15
138         assigns(:page_size).should eq 15
139       end
140       it '省略されると@page_sizeにデフォルト値が入る' do
141         get :panel
142         assigns(:page_size).should eq Author.default_panel_page_size
143       end
144       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
145         get :panel, :page_size => 1500
146         assigns(:page_size).should eq Author.panel_max_page_size
147       end
148       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
149         get :panel, :page_size => 0
150         assigns(:page_size).should eq Author.default_panel_page_size
151       end
152     end
153     context 'つつがなく終わるとき' do
154       it 'ステータスコード200 OKを返す' do
155         get :panel
156         response.should be_success 
157       end
158       it 'コマモデルに一覧を問い合わせている' do
159         Panel.should_receive(:mylist).exactly(1)
160         get :panel
161       end
162       it '@panelsにリストを取得している' do
163         get :panel
164         assigns(:panels).should have_at_least(3).items
165       end
166       context 'html形式' do
167         it 'panelテンプレートを描画する' do
168           get :panel
169           response.should render_template("panel")
170         end
171       end
172       context 'json形式' do
173         it 'jsonデータを返す' do
174           get :panel, :format => :json
175           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
176         end
177         it 'コマモデルにjson一覧出力オプションを問い合わせている' do
178           Panel.should_receive(:list_json_opt).exactly(1)
179           get :panel, :format => :json
180         end
181         it 'データがリスト構造になっている' do
182           get :panel, :format => :json
183           json = JSON.parse response.body
184           json.should have_at_least(3).items
185         end
186         it 'リストの先頭くらいはコマっぽいものであって欲しい' do
187           get :panel, :format => :json
188           json = JSON.parse response.body
189           json.first.has_key?("z").should be_true
190         end
191       end
192     end
193     context '作家権限がないとき' do
194       before do
195         sign_out @user
196       end
197       context 'html形式' do
198         it 'ステータスコード302 Foundを返す' do
199           get :panel
200           response.status.should eq 302
201         end
202         it 'サインインページへ遷移する' do
203           get :panel
204           response.should redirect_to '/users/sign_in'
205         end
206       end
207       context 'json形式' do
208         it 'ステータスコード401 Unauthorizedを返す' do
209           get :panel, :format => :json
210           response.status.should eq 401
211         end
212         it '応答メッセージにUnauthorizedを返す' do
213           get :panel, :format => :json
214           response.message.should match(/Unauthorized/)
215         end
216       end
217     end
218   end
219   
220   describe '自分のコマ絵一覧表示に於いて' do
221     before do
222       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
223         :width => @p.width, :height => @p.height
224       sign_in @user
225       PanelPicture.stub(:mylist).and_return([@pp, @pp, @pp])
226     end
227     context 'パラメータpageについて' do
228       it '@pageに値が入る' do
229         get :panel_picture, :page => 5
230         assigns(:page).should eq 5
231       end
232       it '省略されると@pageに1値が入る' do
233         get :panel_picture
234         assigns(:page).should eq 1
235       end
236       it '与えられたpage_sizeがセットされている' do
237         get :panel_picture, :page_size => 15
238         assigns(:page_size).should eq 15
239       end
240       it '省略されると@page_sizeにデフォルト値が入る' do
241         get :panel_picture
242         assigns(:page_size).should eq Author.default_panel_picture_page_size
243       end
244       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
245         get :panel_picture, :page_size => 1500
246         assigns(:page_size).should eq Author.panel_picture_max_page_size
247       end
248       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
249         get :panel_picture, :page_size => 0
250         assigns(:page_size).should eq Author.default_panel_picture_page_size
251       end
252     end
253     context 'つつがなく終わるとき' do
254       it 'ステータスコード200 OKを返す' do
255         get :panel_picture
256         response.should be_success 
257       end
258       it 'コマ絵モデルに一覧を問い合わせている' do
259         PanelPicture.should_receive(:mylist).exactly(1)
260         get :panel_picture
261       end
262       it '@panel_picturesにリストを取得している' do
263         get :panel_picture
264         assigns(:panel_pictures).should have_at_least(3).items
265       end
266       context 'html形式' do
267         it 'panel_pictureテンプレートを描画する' do
268           get :panel_picture
269           response.should render_template("panel_picture")
270         end
271       end
272       context 'json形式' do
273         it 'jsonデータを返す' do
274           get :panel_picture, :format => :json
275           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
276         end
277         it 'コマ絵モデルにjson一覧出力オプションを問い合わせている' do
278           PanelPicture.should_receive(:list_json_opt).exactly(1)
279           get :panel_picture, :format => :json
280         end
281         it 'データがリスト構造になっている' do
282           get :panel_picture, :format => :json
283           json = JSON.parse response.body
284           json.should have_at_least(3).items
285         end
286         it 'リストの先頭くらいはコマ絵っぽいものであって欲しい' do
287           get :panel_picture, :format => :json
288           json = JSON.parse response.body
289           json.first.has_key?("link").should be_true
290           json.first.has_key?("x").should be_true
291           json.first.has_key?("y").should be_true
292         end
293       end
294     end
295     context '作家権限がないとき' do
296       before do
297         sign_out @user
298       end
299       context 'html形式' do
300         it 'ステータスコード302 Foundを返す' do
301           get :panel_picture
302           response.status.should eq 302
303         end
304         it 'サインインページへ遷移する' do
305           get :panel_picture
306           response.should redirect_to '/users/sign_in'
307         end
308       end
309       context 'json形式' do
310         it 'ステータスコード401 Unauthorizedを返す' do
311           get :panel_picture, :format => :json
312           response.status.should eq 401
313         end
314         it '応答メッセージにUnauthorizedを返す' do
315           get :panel_picture, :format => :json
316           response.message.should match(/Unauthorized/)
317         end
318       end
319     end
320   end
321   
322   describe '自分の原画一覧表示に於いて' do
323     before do
324       sign_in @user
325       OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
326     end
327     context 'パラメータpageについて' do
328       it '@pageに値が入る' do
329         get :picture, :page => 5
330         assigns(:page).should eq 5
331       end
332       it '省略されると@pageに1値が入る' do
333         get :picture
334         assigns(:page).should eq 1
335       end
336       it '与えられたpage_sizeがセットされている' do
337         get :picture, :page_size => 15
338         assigns(:page_size).should eq 15
339       end
340       it '省略されると@page_sizeにデフォルト値が入る' do
341         get :picture
342         assigns(:page_size).should eq OriginalPicture.default_page_size
343       end
344       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
345         get :picture, :page_size => 1500
346         assigns(:page_size).should eq OriginalPicture.max_page_size
347       end
348       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
349         get :picture, :page_size => 0
350         assigns(:page_size).should eq OriginalPicture.default_page_size
351       end
352     end
353     context 'つつがなく終わるとき' do
354       it 'ステータスコード200 OKを返す' do
355         get :picture
356         response.should be_success 
357       end
358       it '原画モデルに一覧を問い合わせている' do
359         #原画は他人が使えないので「自分の」リストはない
360         OriginalPicture.should_receive(:mylist).exactly(1)
361         get :picture
362       end
363       it '@original_picturesにリストを取得している' do
364         get :picture
365         assigns(:original_pictures).should have_at_least(3).items
366       end
367       context 'html形式' do
368         it 'pictureテンプレートを描画する' do
369           get :picture
370           response.should render_template("picture")
371         end
372       end
373       context 'json形式' do
374         it 'jsonデータを返す' do
375           get :picture, :format => :json
376           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
377         end
378         it '原画モデルにjson一覧出力オプションを問い合わせている' do
379           OriginalPicture.should_receive(:list_json_opt).exactly(1)
380           get :picture, :format => :json
381         end
382         it 'データがリスト構造になっている' do
383           get :picture, :format => :json
384           json = JSON.parse response.body
385           json.should have_at_least(3).items
386         end
387         it 'リストの先頭くらいは原画っぽいものであって欲しい' do
388           get :picture, :format => :json
389           json = JSON.parse response.body
390           json.first.has_key?("ext").should be_true
391           json.first.has_key?("md5").should be_true
392           json.first.has_key?("artist_id").should be_true
393           json.first.has_key?("width").should be_true
394         end
395       end
396     end
397     context '作家権限がないとき' do
398       before do
399         sign_out @user
400       end
401       context 'html形式' do
402         it 'ステータスコード302 Foundを返す' do
403           get :picture
404           response.status.should eq 302
405         end
406         it 'サインインページへ遷移する' do
407           get :picture
408           response.should redirect_to '/users/sign_in'
409         end
410       end
411       context 'json形式' do
412         it 'ステータスコード401 Unauthorizedを返す' do
413           get :picture, :format => :json
414           response.status.should eq 401
415         end
416         it '応答メッセージにUnauthorizedを返す' do
417           get :picture, :format => :json
418           response.message.should match(/Unauthorized/)
419         end
420       end
421     end
422     context '作家が絵師でないとき' do
423       before do
424         Author.any_instance.stub(:artist?).and_return(false)
425       end
426       context 'html形式' do
427         it 'ステータスコード302 Foundを返す' do
428           get :picture
429           response.status.should eq 302
430         end
431         it '絵師登録ページへ遷移する' do
432           get :picture
433           response.should redirect_to new_artist_path
434         end
435       end
436       context 'json形式' do
437         it '例外403 forbiddenを返す' do
438           lambda{
439             get :picture, :format => :json
440           }.should raise_error(ActiveRecord::Forbidden)
441         end
442       end
443     end
444   end
445   
446   describe '自分のコマの色背景一覧表示に於いて' do
447     before do
448       @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
449       sign_in @user
450       PanelColor.stub(:mylist).and_return([@pc, @pc, @pc])
451     end
452     context 'パラメータpageについて' do
453       it '@pageに値が入る' do
454         get :panel_color, :page => 5
455         assigns(:page).should eq 5
456       end
457       it '省略されると@pageに1値が入る' do
458         get :panel_color
459         assigns(:page).should eq 1
460       end
461       it '与えられたpage_sizeがセットされている' do
462         get :panel_color, :page_size => 15
463         assigns(:page_size).should eq 15
464       end
465       it '省略されると@page_sizeにデフォルト値が入る' do
466         get :panel_color
467         assigns(:page_size).should eq PanelColor.default_page_size
468       end
469       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
470         get :panel_color, :page_size => 1500
471         assigns(:page_size).should eq PanelColor.max_page_size
472       end
473       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
474         get :panel_color, :page_size => 0
475         assigns(:page_size).should eq PanelColor.default_page_size
476       end
477     end
478     context 'つつがなく終わるとき' do
479       it 'ステータスコード200 OKを返す' do
480         get :panel_color
481         response.should be_success 
482       end
483       it 'コマの色背景モデルに一覧を問い合わせている' do
484         PanelColor.should_receive(:mylist).exactly(1)
485         get :panel_color
486       end
487       it '@panel_colorsにリストを取得している' do
488         get :panel_color
489         assigns(:panel_colors).should have_at_least(3).items
490       end
491       context 'html形式' do
492         it 'panel_colorテンプレートを描画する' do
493           get :panel_color
494           response.should render_template("panel_color")
495         end
496       end
497       context 'json形式' do
498         it 'jsonデータを返す' do
499           get :panel_color, :format => :json
500           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
501         end
502         it 'コマの色背景モデルにjson一覧出力オプションを問い合わせている' do
503           PanelColor.should_receive(:list_json_opt).exactly(1)
504           get :panel_color, :format => :json
505         end
506         it 'データがリスト構造になっている' do
507           get :panel_color, :format => :json
508           json = JSON.parse response.body
509           json.should have_at_least(3).items
510         end
511         it 'リストの先頭くらいはコマの色背景っぽいものであって欲しい' do
512           get :panel_color, :format => :json
513           json = JSON.parse response.body
514           json.first.has_key?("panel_id").should be_true
515           json.first.has_key?("code").should be_true
516           json.first.has_key?("z").should be_true
517         end
518       end
519     end
520     context '作家権限がないとき' do
521       before do
522         sign_out @user
523       end
524       context 'html形式' do
525         it 'ステータスコード302 Foundを返す' do
526           get :panel_color
527           response.status.should eq 302
528         end
529         it 'サインインページへ遷移する' do
530           get :panel_color
531           response.should redirect_to '/users/sign_in'
532         end
533       end
534       context 'json形式' do
535         it 'ステータスコード401 Unauthorizedを返す' do
536           get :panel_color, :format => :json
537           response.status.should eq 401
538         end
539         it '応答メッセージにUnauthorizedを返す' do
540           get :panel_color, :format => :json
541           response.message.should match(/Unauthorized/)
542         end
543       end
544     end
545   end
546   
547   describe '自分のコマの画像背景一覧表示に於いて' do
548     before do
549       @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
550       sign_in @user
551       GroundPicture.stub(:mylist).and_return([@gp, @gp, @gp])
552     end
553     context 'パラメータpageについて' do
554       it '@pageに値が入る' do
555         get :ground_picture, :page => 5
556         assigns(:page).should eq 5
557       end
558       it '省略されると@pageに1値が入る' do
559         get :ground_picture
560         assigns(:page).should eq 1
561       end
562       it '与えられたpage_sizeがセットされている' do
563         get :ground_picture, :page_size => 15
564         assigns(:page_size).should eq 15
565       end
566       it '省略されると@page_sizeにデフォルト値が入る' do
567         get :ground_picture
568         assigns(:page_size).should eq GroundPicture.default_page_size
569       end
570       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
571         get :ground_picture, :page_size => 1500
572         assigns(:page_size).should eq GroundPicture.max_page_size
573       end
574       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
575         get :ground_picture, :page_size => 0
576         assigns(:page_size).should eq GroundPicture.default_page_size
577       end
578     end
579     context 'つつがなく終わるとき' do
580       it 'ステータスコード200 OKを返す' do
581         get :ground_picture
582         response.should be_success 
583       end
584       it 'コマの画像背景モデルに一覧を問い合わせている' do
585         GroundPicture.should_receive(:mylist).exactly(1)
586         get :ground_picture
587       end
588       it '@ground_picturesにリストを取得している' do
589         get :ground_picture
590         assigns(:ground_pictures).should have_at_least(3).items
591       end
592       context 'html形式' do
593         it 'ground_pictureテンプレートを描画する' do
594           get :ground_picture
595           response.should render_template("ground_picture")
596         end
597       end
598       context 'json形式' do
599         it 'jsonデータを返す' do
600           get :ground_picture, :format => :json
601           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
602         end
603         it 'コマの画像背景モデルにjson一覧出力オプションを問い合わせている' do
604           GroundPicture.should_receive(:list_json_opt).exactly(1)
605           get :ground_picture, :format => :json
606         end
607         it 'データがリスト構造になっている' do
608           get :ground_picture, :format => :json
609           json = JSON.parse response.body
610           json.should have_at_least(3).items
611         end
612         it 'リストの先頭くらいはコマの画像背景っぽいものであって欲しい' do
613           get :ground_picture, :format => :json
614           json = JSON.parse response.body
615           json.first.has_key?("panel_id").should be_true
616           json.first.has_key?("picture_id").should be_true
617           json.first.has_key?("z").should be_true
618         end
619       end
620     end
621     context '作家権限がないとき' do
622       before do
623         sign_out @user
624       end
625       context 'html形式' do
626         it 'ステータスコード302 Foundを返す' do
627           get :ground_picture
628           response.status.should eq 302
629         end
630         it 'サインインページへ遷移する' do
631           get :ground_picture
632           response.should redirect_to '/users/sign_in'
633         end
634       end
635       context 'json形式' do
636         it 'ステータスコード401 Unauthorizedを返す' do
637           get :ground_picture, :format => :json
638           response.status.should eq 401
639         end
640         it '応答メッセージにUnauthorizedを返す' do
641           get :ground_picture, :format => :json
642           response.message.should match(/Unauthorized/)
643         end
644       end
645     end
646   end
647   
648   describe '自分の間接背景一覧表示に於いて' do
649     before do
650       @gc = FactoryGirl.create :ground_color
651       sign_in @user
652       GroundColor.stub(:mylist).and_return([@gc, @gc, @gc])
653     end
654     context 'パラメータpageについて' do
655       it '@pageに値が入る' do
656         get :ground_color, :page => 5
657         assigns(:page).should eq 5
658       end
659       it '省略されると@pageに1値が入る' do
660         get :ground_color
661         assigns(:page).should eq 1
662       end
663       it '与えられたpage_sizeがセットされている' do
664         get :ground_color, :page_size => 15
665         assigns(:page_size).should eq 15
666       end
667       it '省略されると@page_sizeにデフォルト値が入る' do
668         get :ground_color
669         assigns(:page_size).should eq GroundColor.default_page_size
670       end
671       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
672         get :ground_color, :page_size => 1500
673         assigns(:page_size).should eq GroundColor.max_page_size
674       end
675       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
676         get :ground_color, :page_size => 0
677         assigns(:page_size).should eq GroundColor.default_page_size
678       end
679     end
680     context 'つつがなく終わるとき' do
681       it 'ステータスコード200 OKを返す' do
682         get :ground_color
683         response.should be_success 
684       end
685       it '間接背景モデルに一覧を問い合わせている' do
686         GroundColor.should_receive(:mylist).exactly(1)
687         get :ground_color
688       end
689       it '@ground_colorsにリストを取得している' do
690         get :ground_color
691         assigns(:ground_colors).should have_at_least(3).items
692       end
693       context 'html形式' do
694         it 'ground_colorテンプレートを描画する' do
695           get :ground_color
696           response.should render_template("ground_color")
697         end
698       end
699       context 'json形式' do
700         it 'jsonデータを返す' do
701           get :ground_color, :format => :json
702           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
703         end
704         it '間接背景モデルにjson一覧出力オプションを問い合わせている' do
705           GroundColor.should_receive(:list_json_opt).exactly(1)
706           get :ground_color, :format => :json
707         end
708         it 'データがリスト構造になっている' do
709           get :ground_color, :format => :json
710           json = JSON.parse response.body
711           json.should have_at_least(3).items
712         end
713         it 'リストの先頭くらいは間接背景っぽいものであって欲しい' do
714           get :ground_color, :format => :json
715           json = JSON.parse response.body
716           json.first.has_key?("panel_id").should be_true
717           json.first.has_key?("color_id").should be_true
718           json.first.has_key?("z").should be_true
719         end
720       end
721     end
722     context '作家権限がないとき' do
723       before do
724         sign_out @user
725       end
726       context 'html形式' do
727         it 'ステータスコード302 Foundを返す' do
728           get :ground_color
729           response.status.should eq 302
730         end
731         it 'サインインページへ遷移する' do
732           get :ground_color
733           response.should redirect_to '/users/sign_in'
734         end
735       end
736       context 'json形式' do
737         it 'ステータスコード401 Unauthorizedを返す' do
738           get :ground_color, :format => :json
739           response.status.should eq 401
740         end
741         it '応答メッセージにUnauthorizedを返す' do
742           get :ground_color, :format => :json
743           response.message.should match(/Unauthorized/)
744         end
745       end
746     end
747   end
748   
749 end