OSDN Git Service

t30329#:i18n flash message
[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     @admin =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 = FactoryGirl.create :author, :user_id => @user.id
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
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 'コマモデルに一覧を問い合わせている' do
155         Panel.should_receive(:mylist).exactly(1)
156         get :panel
157       end
158       it '@panelsにリストを取得している' do
159         get :panel
160         assigns(:panels).should have_at_least(3).items
161       end
162       context 'html形式' do
163         it 'ステータスコード200 OKを返す' do
164           get :panel
165           response.should be_success 
166         end
167         it 'panelテンプレートを描画する' do
168           get :panel
169           response.should render_template("panel")
170         end
171       end
172       context 'json形式' do
173         it 'ステータスコード200 OKを返す' do
174           get :panel, :format => :json
175           response.should be_success 
176         end
177         it 'jsonデータを返す' do
178           get :panel, :format => :json
179           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
180         end
181         it 'コマモデルにコマリストのjson出力を問い合わせている' do
182           Panel.should_receive(:list_as_json_text).exactly(1)
183           get :panel, :format => :json
184         end
185         it 'データがリスト構造になっている' do
186           get :panel, :format => :json
187           json = JSON.parse response.body
188           json.should have_at_least(3).items
189         end
190         it 'リストの先頭くらいはコマっぽいものであって欲しい' do
191           get :panel, :format => :json
192           json = JSON.parse response.body
193           json.first.has_key?("z").should be_true
194         end
195       end
196     end
197     context '作家権限がないとき' do
198       before do
199         sign_out @user
200       end
201       context 'html形式' do
202         it 'ステータスコード302 Foundを返す' do
203           get :panel
204           response.status.should eq 302
205         end
206         it 'サインインページへ遷移する' do
207           get :panel
208           response.should redirect_to '/users/sign_in'
209         end
210       end
211       context 'json形式' do
212         it 'ステータスコード401 Unauthorizedを返す' do
213           get :panel, :format => :json
214           response.status.should eq 401
215         end
216         it '応答メッセージにUnauthorizedを返す' do
217           get :panel, :format => :json
218           response.message.should match(/Unauthorized/)
219         end
220       end
221     end
222   end
223   
224   describe '自分のコマ絵一覧表示に於いて' do
225     before do
226       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
227         :width => @p.width, :height => @p.height
228       sign_in @user
229       PanelPicture.stub(:mylist).and_return([@pp, @pp, @pp])
230     end
231     context 'パラメータpageについて' do
232       it '@pageに値が入る' do
233         get :panel_picture, :page => 5
234         assigns(:page).should eq 5
235       end
236       it '省略されると@pageに1値が入る' do
237         get :panel_picture
238         assigns(:page).should eq 1
239       end
240       it '与えられたpage_sizeがセットされている' do
241         get :panel_picture, :page_size => 15
242         assigns(:page_size).should eq 15
243       end
244       it '省略されると@page_sizeにデフォルト値が入る' do
245         get :panel_picture
246         assigns(:page_size).should eq Author.default_panel_picture_page_size
247       end
248       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
249         get :panel_picture, :page_size => 1500
250         assigns(:page_size).should eq Author.panel_picture_max_page_size
251       end
252       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
253         get :panel_picture, :page_size => 0
254         assigns(:page_size).should eq Author.default_panel_picture_page_size
255       end
256     end
257     context 'つつがなく終わるとき' do
258       it 'ステータスコード200 OKを返す' do
259         get :panel_picture
260         response.should be_success 
261       end
262       it 'コマ絵モデルに一覧を問い合わせている' do
263         PanelPicture.should_receive(:mylist).exactly(1)
264         get :panel_picture
265       end
266       it '@panel_picturesにリストを取得している' do
267         get :panel_picture
268         assigns(:panel_pictures).should have_at_least(3).items
269       end
270       context 'html形式' do
271         it 'panel_pictureテンプレートを描画する' do
272           get :panel_picture
273           response.should render_template("panel_picture")
274         end
275       end
276       context 'json形式' do
277         it 'jsonデータを返す' do
278           get :panel_picture, :format => :json
279           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
280         end
281         it 'コマ絵モデルにjson一覧出力オプションを問い合わせている' do
282           PanelPicture.should_receive(:list_json_opt).exactly(1)
283           get :panel_picture, :format => :json
284         end
285         it 'データがリスト構造になっている' do
286           get :panel_picture, :format => :json
287           json = JSON.parse response.body
288           json.should have_at_least(3).items
289         end
290         it 'リストの先頭くらいはコマ絵っぽいものであって欲しい' do
291           get :panel_picture, :format => :json
292           json = JSON.parse response.body
293           json.first.has_key?("link").should be_true
294           json.first.has_key?("x").should be_true
295           json.first.has_key?("y").should be_true
296         end
297       end
298     end
299     context '作家権限がないとき' do
300       before do
301         sign_out @user
302       end
303       context 'html形式' do
304         it 'ステータスコード302 Foundを返す' do
305           get :panel_picture
306           response.status.should eq 302
307         end
308         it 'サインインページへ遷移する' do
309           get :panel_picture
310           response.should redirect_to '/users/sign_in'
311         end
312       end
313       context 'json形式' do
314         it 'ステータスコード401 Unauthorizedを返す' do
315           get :panel_picture, :format => :json
316           response.status.should eq 401
317         end
318         it '応答メッセージにUnauthorizedを返す' do
319           get :panel_picture, :format => :json
320           response.message.should match(/Unauthorized/)
321         end
322       end
323     end
324   end
325   
326   describe '自分のコマの色背景一覧表示に於いて' do
327     before do
328       @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
329       sign_in @user
330       PanelColor.stub(:mylist).and_return([@pc, @pc, @pc])
331     end
332     context 'パラメータpageについて' do
333       it '@pageに値が入る' do
334         get :panel_color, :page => 5
335         assigns(:page).should eq 5
336       end
337       it '省略されると@pageに1値が入る' do
338         get :panel_color
339         assigns(:page).should eq 1
340       end
341       it '与えられたpage_sizeがセットされている' do
342         get :panel_color, :page_size => 15
343         assigns(:page_size).should eq 15
344       end
345       it '省略されると@page_sizeにデフォルト値が入る' do
346         get :panel_color
347         assigns(:page_size).should eq PanelColor.default_page_size
348       end
349       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
350         get :panel_color, :page_size => 1500
351         assigns(:page_size).should eq PanelColor.max_page_size
352       end
353       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
354         get :panel_color, :page_size => 0
355         assigns(:page_size).should eq PanelColor.default_page_size
356       end
357     end
358     context 'つつがなく終わるとき' do
359       it 'ステータスコード200 OKを返す' do
360         get :panel_color
361         response.should be_success 
362       end
363       it 'コマの色背景モデルに一覧を問い合わせている' do
364         PanelColor.should_receive(:mylist).exactly(1)
365         get :panel_color
366       end
367       it '@panel_colorsにリストを取得している' do
368         get :panel_color
369         assigns(:panel_colors).should have_at_least(3).items
370       end
371       context 'html形式' do
372         it 'panel_colorテンプレートを描画する' do
373           get :panel_color
374           response.should render_template("panel_color")
375         end
376       end
377       context 'json形式' do
378         it 'jsonデータを返す' do
379           get :panel_color, :format => :json
380           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
381         end
382         it 'コマの色背景モデルにjson一覧出力オプションを問い合わせている' do
383           PanelColor.should_receive(:list_json_opt).exactly(1)
384           get :panel_color, :format => :json
385         end
386         it 'データがリスト構造になっている' do
387           get :panel_color, :format => :json
388           json = JSON.parse response.body
389           json.should have_at_least(3).items
390         end
391         it 'リストの先頭くらいはコマの色背景っぽいものであって欲しい' do
392           get :panel_color, :format => :json
393           json = JSON.parse response.body
394           json.first.has_key?("panel_id").should be_true
395           json.first.has_key?("code").should be_true
396           json.first.has_key?("z").should be_true
397         end
398       end
399     end
400     context '作家権限がないとき' do
401       before do
402         sign_out @user
403       end
404       context 'html形式' do
405         it 'ステータスコード302 Foundを返す' do
406           get :panel_color
407           response.status.should eq 302
408         end
409         it 'サインインページへ遷移する' do
410           get :panel_color
411           response.should redirect_to '/users/sign_in'
412         end
413       end
414       context 'json形式' do
415         it 'ステータスコード401 Unauthorizedを返す' do
416           get :panel_color, :format => :json
417           response.status.should eq 401
418         end
419         it '応答メッセージにUnauthorizedを返す' do
420           get :panel_color, :format => :json
421           response.message.should match(/Unauthorized/)
422         end
423       end
424     end
425   end
426   
427   describe '自分のコマの画像背景一覧表示に於いて' do
428     before do
429       @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
430       sign_in @user
431       GroundPicture.stub(:mylist).and_return([@gp, @gp, @gp])
432     end
433     context 'パラメータpageについて' do
434       it '@pageに値が入る' do
435         get :ground_picture, :page => 5
436         assigns(:page).should eq 5
437       end
438       it '省略されると@pageに1値が入る' do
439         get :ground_picture
440         assigns(:page).should eq 1
441       end
442       it '与えられたpage_sizeがセットされている' do
443         get :ground_picture, :page_size => 15
444         assigns(:page_size).should eq 15
445       end
446       it '省略されると@page_sizeにデフォルト値が入る' do
447         get :ground_picture
448         assigns(:page_size).should eq GroundPicture.default_page_size
449       end
450       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
451         get :ground_picture, :page_size => 1500
452         assigns(:page_size).should eq GroundPicture.max_page_size
453       end
454       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
455         get :ground_picture, :page_size => 0
456         assigns(:page_size).should eq GroundPicture.default_page_size
457       end
458     end
459     context 'つつがなく終わるとき' do
460       it 'ステータスコード200 OKを返す' do
461         get :ground_picture
462         response.should be_success 
463       end
464       it 'コマの画像背景モデルに一覧を問い合わせている' do
465         GroundPicture.should_receive(:mylist).exactly(1)
466         get :ground_picture
467       end
468       it '@ground_picturesにリストを取得している' do
469         get :ground_picture
470         assigns(:ground_pictures).should have_at_least(3).items
471       end
472       context 'html形式' do
473         it 'ground_pictureテンプレートを描画する' do
474           get :ground_picture
475           response.should render_template("ground_picture")
476         end
477       end
478       context 'json形式' do
479         it 'jsonデータを返す' do
480           get :ground_picture, :format => :json
481           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
482         end
483         it 'コマの画像背景モデルにjson一覧出力オプションを問い合わせている' do
484           GroundPicture.should_receive(:list_json_opt).exactly(1)
485           get :ground_picture, :format => :json
486         end
487         it 'データがリスト構造になっている' do
488           get :ground_picture, :format => :json
489           json = JSON.parse response.body
490           json.should have_at_least(3).items
491         end
492         it 'リストの先頭くらいはコマの画像背景っぽいものであって欲しい' do
493           get :ground_picture, :format => :json
494           json = JSON.parse response.body
495           json.first.has_key?("panel_id").should be_true
496           json.first.has_key?("picture_id").should be_true
497           json.first.has_key?("z").should be_true
498         end
499       end
500     end
501     context '作家権限がないとき' do
502       before do
503         sign_out @user
504       end
505       context 'html形式' do
506         it 'ステータスコード302 Foundを返す' do
507           get :ground_picture
508           response.status.should eq 302
509         end
510         it 'サインインページへ遷移する' do
511           get :ground_picture
512           response.should redirect_to '/users/sign_in'
513         end
514       end
515       context 'json形式' do
516         it 'ステータスコード401 Unauthorizedを返す' do
517           get :ground_picture, :format => :json
518           response.status.should eq 401
519         end
520         it '応答メッセージにUnauthorizedを返す' do
521           get :ground_picture, :format => :json
522           response.message.should match(/Unauthorized/)
523         end
524       end
525     end
526   end
527   
528   describe '自分の間接背景一覧表示に於いて' do
529     before do
530       @gc = FactoryGirl.create :ground_color
531       sign_in @user
532       GroundColor.stub(:mylist).and_return([@gc, @gc, @gc])
533     end
534     context 'パラメータpageについて' do
535       it '@pageに値が入る' do
536         get :ground_color, :page => 5
537         assigns(:page).should eq 5
538       end
539       it '省略されると@pageに1値が入る' do
540         get :ground_color
541         assigns(:page).should eq 1
542       end
543       it '与えられたpage_sizeがセットされている' do
544         get :ground_color, :page_size => 15
545         assigns(:page_size).should eq 15
546       end
547       it '省略されると@page_sizeにデフォルト値が入る' do
548         get :ground_color
549         assigns(:page_size).should eq GroundColor.default_page_size
550       end
551       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
552         get :ground_color, :page_size => 1500
553         assigns(:page_size).should eq GroundColor.max_page_size
554       end
555       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
556         get :ground_color, :page_size => 0
557         assigns(:page_size).should eq GroundColor.default_page_size
558       end
559     end
560     context 'つつがなく終わるとき' do
561       it 'ステータスコード200 OKを返す' do
562         get :ground_color
563         response.should be_success 
564       end
565       it '間接背景モデルに一覧を問い合わせている' do
566         GroundColor.should_receive(:mylist).exactly(1)
567         get :ground_color
568       end
569       it '@ground_colorsにリストを取得している' do
570         get :ground_color
571         assigns(:ground_colors).should have_at_least(3).items
572       end
573       context 'html形式' do
574         it 'ground_colorテンプレートを描画する' do
575           get :ground_color
576           response.should render_template("ground_color")
577         end
578       end
579       context 'json形式' do
580         it 'jsonデータを返す' do
581           get :ground_color, :format => :json
582           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
583         end
584         it '間接背景モデルにjson一覧出力オプションを問い合わせている' do
585           GroundColor.should_receive(:list_json_opt).exactly(1)
586           get :ground_color, :format => :json
587         end
588         it 'データがリスト構造になっている' do
589           get :ground_color, :format => :json
590           json = JSON.parse response.body
591           json.should have_at_least(3).items
592         end
593         it 'リストの先頭くらいは間接背景っぽいものであって欲しい' do
594           get :ground_color, :format => :json
595           json = JSON.parse response.body
596           json.first.has_key?("panel_id").should be_true
597           json.first.has_key?("color_id").should be_true
598           json.first.has_key?("z").should be_true
599         end
600       end
601     end
602     context '作家権限がないとき' do
603       before do
604         sign_out @user
605       end
606       context 'html形式' do
607         it 'ステータスコード302 Foundを返す' do
608           get :ground_color
609           response.status.should eq 302
610         end
611         it 'サインインページへ遷移する' do
612           get :ground_color
613           response.should redirect_to '/users/sign_in'
614         end
615       end
616       context 'json形式' do
617         it 'ステータスコード401 Unauthorizedを返す' do
618           get :ground_color, :format => :json
619           response.status.should eq 401
620         end
621         it '応答メッセージにUnauthorizedを返す' do
622           get :ground_color, :format => :json
623           response.message.should match(/Unauthorized/)
624         end
625       end
626     end
627   end
628   
629 end