OSDN Git Service

t#31470:create pager
[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     @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
15     @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
16     @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
17     @panel = FactoryGirl.create :panel, :author_id => @author.id
18   end
19   
20 if MagicNumber['run_mode'] == 1
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 :comics, :page => 5
30         assigns(:page).should eq 5
31       end
32       it '省略されると@pageに1値が入る' do
33         get :comics
34         assigns(:page).should eq 1
35       end
36       it '与えられたpage_sizeがセットされている' do
37         get :comics, :page_size => 15
38         assigns(:page_size).should eq 15
39       end
40       it '省略されると@page_sizeにデフォルト値が入る' do
41         get :comics
42         assigns(:page_size).should eq Author.default_comic_page_size
43       end
44       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
45         get :comics, :page_size => 1500
46         assigns(:page_size).should eq Author.comic_max_page_size
47       end
48       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
49         get :comics, :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 :comics
56         response.should be_success 
57       end
58       it 'コミックモデルに一覧を問い合わせている' do
59         Comic.should_receive(:mylist).exactly(1)
60         get :comics
61       end
62       it '@comicsにリストを取得している' do
63         get :comics
64         assigns(:comics).should have_at_least(3).items
65       end
66       context 'html形式' do
67         it '@paginateにページ制御を取得している' do
68           get :comics
69           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
70         end
71         it 'comicsテンプレートを描画する' do
72           get :comics
73           response.should render_template("comics")
74         end
75       end
76       context 'json形式' do
77         it 'jsonデータを返す' do
78           get :comics, :format => :json
79           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
80         end
81         it 'コミックモデルにjson一覧出力オプションを問い合わせている' do
82           Comic.should_receive(:list_json_opt).exactly(1)
83           get :comics, :format => :json
84         end
85         it 'データがリスト構造になっている' do
86           get :comics, :format => :json
87           json = JSON.parse response.body
88           json.should have_at_least(3).items
89         end
90         it 'リストの先頭くらいはコミックっぽいものであって欲しい' do
91           get :comics, :format => :json
92           json = JSON.parse response.body
93           json.first.has_key?("title").should be_true
94           json.first.has_key?("visible").should be_true
95         end
96       end
97     end
98     context '作家権限がないとき' do
99       before do
100         sign_out @user
101       end
102       context 'html形式' do
103         it 'ステータスコード302 Foundを返す' do
104           get :comics
105           response.status.should eq 302
106         end
107         it 'サインインページへ遷移する' do
108           get :comics
109           response.should redirect_to '/users/sign_in'
110         end
111       end
112       context 'json形式' do
113         it 'ステータスコード401 Unauthorizedを返す' do
114           get :comics, :format => :json
115           response.status.should eq 401
116         end
117         it '応答メッセージにUnauthorizedを返す' do
118           get :comics, :format => :json
119           response.message.should match(/Unauthorized/)
120         end
121       end
122     end
123   end
124   
125   describe '自分のコマ一覧表示に於いて' do
126     before do
127       @panel = FactoryGirl.create :panel, :author_id => @author.id
128       sign_in @user
129       Panel.stub(:mylist).and_return([@panel, @panel, @panel])
130     end
131     context 'パラメータpageについて' do
132       it '@pageに値が入る' do
133         get :panels, :page => 5
134         assigns(:page).should eq 5
135       end
136       it '省略されると@pageに1値が入る' do
137         get :panels
138         assigns(:page).should eq 1
139       end
140       it '与えられたpage_sizeがセットされている' do
141         get :panels, :page_size => 15
142         assigns(:page_size).should eq 15
143       end
144       it '省略されると@page_sizeにデフォルト値が入る' do
145         get :panels
146         assigns(:page_size).should eq Author.default_panel_page_size
147       end
148       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
149         get :panels, :page_size => 1500
150         assigns(:page_size).should eq Author.panel_max_page_size
151       end
152       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
153         get :panels, :page_size => 0
154         assigns(:page_size).should eq Author.default_panel_page_size
155       end
156     end
157     context 'つつがなく終わるとき' do
158       it 'コマモデルに一覧を問い合わせている' do
159         Panel.should_receive(:mylist).exactly(1)
160         get :panels
161       end
162       it '@panelsにリストを取得している' do
163         get :panels
164         assigns(:panels).should have_at_least(3).items
165       end
166       context 'html形式' do
167         it '@paginateにページ制御を取得している' do
168           get :panels
169           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
170         end
171         it 'ステータスコード200 OKを返す' do
172           get :panels
173           response.should be_success 
174         end
175         it 'panelsテンプレートを描画する' do
176           get :panels
177           response.should render_template("panels")
178         end
179       end
180       context 'json形式' do
181         it 'ステータスコード200 OKを返す' do
182           get :panels, :format => :json
183           response.should be_success 
184         end
185         it 'jsonデータを返す' do
186           get :panels, :format => :json
187           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
188         end
189         it 'コマモデルにコマリストのjson出力を問い合わせている' do
190           Panel.should_receive(:list_as_json_text).exactly(1)
191           get :panels, :format => :json
192         end
193         it 'データがリスト構造になっている' do
194           get :panels, :format => :json
195           json = JSON.parse response.body
196           json.should have_at_least(3).items
197         end
198         it 'リストの先頭くらいはコマっぽいものであって欲しい' do
199           get :panels, :format => :json
200           json = JSON.parse response.body
201           json.first.has_key?("z").should be_true
202         end
203       end
204     end
205     context '作家権限がないとき' do
206       before do
207         sign_out @user
208       end
209       context 'html形式' do
210         it 'ステータスコード302 Foundを返す' do
211           get :panels
212           response.status.should eq 302
213         end
214         it 'サインインページへ遷移する' do
215           get :panels
216           response.should redirect_to '/users/sign_in'
217         end
218       end
219       context 'json形式' do
220         it 'ステータスコード401 Unauthorizedを返す' do
221           get :panels, :format => :json
222           response.status.should eq 401
223         end
224         it '応答メッセージにUnauthorizedを返す' do
225           get :panels, :format => :json
226           response.message.should match(/Unauthorized/)
227         end
228       end
229     end
230   end
231   
232   describe '自分のコマ絵一覧表示に於いて' do
233     before do
234       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
235         :width => @p.width, :height => @p.height
236       sign_in @user
237       PanelPicture.stub(:mylist).and_return([@pp, @pp, @pp])
238     end
239     context 'パラメータpageについて' do
240       it '@pageに値が入る' do
241         get :panel_pictures, :page => 5
242         assigns(:page).should eq 5
243       end
244       it '省略されると@pageに1値が入る' do
245         get :panel_pictures
246         assigns(:page).should eq 1
247       end
248       it '与えられたpage_sizeがセットされている' do
249         get :panel_pictures, :page_size => 15
250         assigns(:page_size).should eq 15
251       end
252       it '省略されると@page_sizeにデフォルト値が入る' do
253         get :panel_pictures
254         assigns(:page_size).should eq Author.default_panel_picture_page_size
255       end
256       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
257         get :panel_pictures, :page_size => 1500
258         assigns(:page_size).should eq Author.panel_picture_max_page_size
259       end
260       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
261         get :panel_pictures, :page_size => 0
262         assigns(:page_size).should eq Author.default_panel_picture_page_size
263       end
264     end
265     context 'つつがなく終わるとき' do
266       it 'ステータスコード200 OKを返す' do
267         response.should be_success 
268       end
269       it 'コマ絵モデルに一覧を問い合わせている' do
270         PanelPicture.should_receive(:mylist).exactly(1)
271         get :panel_pictures
272       end
273       it '@panel_picturesにリストを取得している' do
274         get :panel_pictures
275         assigns(:panel_pictures).should have_at_least(3).items
276       end
277       context 'html形式' do
278         it '@paginateにページ制御を取得している' do
279           get :panel_pictures
280           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
281         end
282         it 'panel_picturesテンプレートを描画する' do
283           get :panel_pictures
284           response.should render_template("panel_pictures")
285         end
286       end
287       context 'json形式' do
288         it 'jsonデータを返す' do
289           get :panel_pictures, :format => :json
290           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
291         end
292         it 'コマ絵モデルにjson一覧出力オプションを問い合わせている' do
293           PanelPicture.should_receive(:list_json_opt).exactly(1)
294           get :panel_pictures, :format => :json
295         end
296         it 'データがリスト構造になっている' do
297           get :panel_pictures, :format => :json
298           json = JSON.parse response.body
299           json.should have_at_least(3).items
300         end
301         it 'リストの先頭くらいはコマ絵っぽいものであって欲しい' do
302           get :panel_pictures, :format => :json
303           json = JSON.parse response.body
304           json.first.has_key?("link").should be_true
305           json.first.has_key?("x").should be_true
306           json.first.has_key?("y").should be_true
307         end
308       end
309     end
310     context '作家権限がないとき' do
311       before do
312         sign_out @user
313       end
314       context 'html形式' do
315         it 'ステータスコード302 Foundを返す' do
316           get :panel_pictures
317           response.status.should eq 302
318         end
319         it 'サインインページへ遷移する' do
320           get :panel_pictures
321           response.should redirect_to '/users/sign_in'
322         end
323       end
324       context 'json形式' do
325         it 'ステータスコード401 Unauthorizedを返す' do
326           get :panel_pictures, :format => :json
327           response.status.should eq 401
328         end
329         it '応答メッセージにUnauthorizedを返す' do
330           get :panel_pictures, :format => :json
331           response.message.should match(/Unauthorized/)
332         end
333       end
334     end
335   end
336   
337   describe '自分のコマの絵地一覧表示に於いて' do
338     before do
339       @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
340       sign_in @user
341       GroundPicture.stub(:mylist).and_return([@gp, @gp, @gp])
342     end
343     context 'パラメータpageについて' do
344       it '@pageに値が入る' do
345         get :ground_pictures, :page => 5
346         assigns(:page).should eq 5
347       end
348       it '省略されると@pageに1値が入る' do
349         get :ground_pictures
350         assigns(:page).should eq 1
351       end
352       it '与えられたpage_sizeがセットされている' do
353         get :ground_pictures, :page_size => 15
354         assigns(:page_size).should eq 15
355       end
356       it '省略されると@page_sizeにデフォルト値が入る' do
357         get :ground_pictures
358         assigns(:page_size).should eq Author.default_ground_picture_page_size
359       end
360       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
361         get :ground_pictures, :page_size => 1500
362         assigns(:page_size).should eq Author.ground_picture_max_page_size
363       end
364       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
365         get :ground_pictures, :page_size => 0
366         assigns(:page_size).should eq Author.default_ground_picture_page_size
367       end
368     end
369     context 'つつがなく終わるとき' do
370       it 'ステータスコード200 OKを返す' do
371         get :ground_pictures
372         response.should be_success 
373       end
374       it '絵地モデルに一覧を問い合わせている' do
375         GroundPicture.should_receive(:mylist).exactly(1)
376         get :ground_pictures
377       end
378       it '@ground_picturesにリストを取得している' do
379         get :ground_pictures
380         assigns(:ground_pictures).should have_at_least(3).items
381       end
382       context 'html形式' do
383         it '@paginateにページ制御を取得している' do
384           get :ground_pictures
385           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
386         end
387         it 'ground_picturesテンプレートを描画する' do
388           get :ground_pictures
389           response.should render_template("ground_pictures")
390         end
391       end
392       context 'json形式' do
393         it 'jsonデータを返す' do
394           get :ground_pictures, :format => :json
395           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
396         end
397         it '絵地モデルにjson一覧出力オプションを問い合わせている' do
398           GroundPicture.should_receive(:list_json_opt).exactly(1)
399           get :ground_pictures, :format => :json
400         end
401         it 'データがリスト構造になっている' do
402           get :ground_pictures, :format => :json
403           json = JSON.parse response.body
404           json.should have_at_least(3).items
405         end
406         it 'リストの先頭くらいは絵地っぽいものであって欲しい' do
407           get :ground_pictures, :format => :json
408           json = JSON.parse response.body
409           json.first.has_key?("panel_id").should be_true
410           json.first.has_key?("picture_id").should be_true
411           json.first.has_key?("z").should be_true
412         end
413       end
414     end
415     context '作家権限がないとき' do
416       before do
417         sign_out @user
418       end
419       context 'html形式' do
420         it 'ステータスコード302 Foundを返す' do
421           get :ground_pictures
422           response.status.should eq 302
423         end
424         it 'サインインページへ遷移する' do
425           get :ground_pictures
426           response.should redirect_to '/users/sign_in'
427         end
428       end
429       context 'json形式' do
430         it 'ステータスコード401 Unauthorizedを返す' do
431           get :ground_pictures, :format => :json
432           response.status.should eq 401
433         end
434         it '応答メッセージにUnauthorizedを返す' do
435           get :ground_pictures, :format => :json
436           response.message.should match(/Unauthorized/)
437         end
438       end
439     end
440   end
441   
442   describe '自分の色地一覧表示に於いて' do
443     before do
444       @gc = FactoryGirl.create :ground_color
445       sign_in @user
446       GroundColor.stub(:mylist).and_return([@gc, @gc, @gc])
447     end
448     context 'パラメータpageについて' do
449       it '@pageに値が入る' do
450         get :ground_colors, :page => 5
451         assigns(:page).should eq 5
452       end
453       it '省略されると@pageに1値が入る' do
454         get :ground_colors
455         assigns(:page).should eq 1
456       end
457       it '与えられたpage_sizeがセットされている' do
458         get :ground_colors, :page_size => 15
459         assigns(:page_size).should eq 15
460       end
461       it '省略されると@page_sizeにデフォルト値が入る' do
462         get :ground_colors
463         assigns(:page_size).should eq Author.default_ground_color_page_size
464       end
465       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
466         get :ground_colors, :page_size => 1500
467         assigns(:page_size).should eq Author.ground_color_max_page_size
468       end
469       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
470         get :ground_colors, :page_size => 0
471         assigns(:page_size).should eq Author.default_ground_color_page_size
472       end
473     end
474     context 'つつがなく終わるとき' do
475       it 'ステータスコード200 OKを返す' do
476         get :ground_colors
477         response.should be_success 
478       end
479       it '色地モデルに一覧を問い合わせている' do
480         GroundColor.should_receive(:mylist).exactly(1)
481         get :ground_colors
482       end
483       it '@ground_colorsにリストを取得している' do
484         get :ground_colors
485         assigns(:ground_colors).should have_at_least(3).items
486       end
487       context 'html形式' do
488         it '@paginateにページ制御を取得している' do
489           get :ground_colors
490           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
491         end
492         it 'ground_colorsテンプレートを描画する' do
493           get :ground_colors
494           response.should render_template("ground_colors")
495         end
496       end
497       context 'json形式' do
498         it 'jsonデータを返す' do
499           get :ground_colors, :format => :json
500           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
501         end
502           it '色地モデルにjson一覧出力オプションを問い合わせている' do
503           GroundColor.should_receive(:list_json_opt).exactly(1)
504           get :ground_colors, :format => :json
505         end
506         it 'データがリスト構造になっている' do
507           get :ground_colors, :format => :json
508           json = JSON.parse response.body
509           json.should have_at_least(3).items
510         end
511         it 'リストの先頭くらいは色地っぽいものであって欲しい' do
512           get :ground_colors, :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 :ground_colors
527           response.status.should eq 302
528         end
529         it 'サインインページへ遷移する' do
530           get :ground_colors
531           response.should redirect_to '/users/sign_in'
532         end
533       end
534       context 'json形式' do
535         it 'ステータスコード401 Unauthorizedを返す' do
536           get :ground_colors, :format => :json
537           response.status.should eq 401
538         end
539         it '応答メッセージにUnauthorizedを返す' do
540           get :ground_colors, :format => :json
541           response.message.should match(/Unauthorized/)
542         end
543       end
544     end
545   end
546   
547   describe '自分の素材一覧表示に於いて' do
548     before do
549       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
550       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
551       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
552       sign_in @user
553       ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp])
554     end
555     context 'パラメータpageについて' do
556       it '@pageに値が入る' do
557         get :resource_pictures, :page => 5
558         assigns(:page).should eq 5
559       end
560       it '省略されると@pageに1値が入る' do
561         get :resource_pictures
562         assigns(:page).should eq 1
563       end
564       it '与えられたpage_sizeがセットされている' do
565         get :resource_pictures, :page_size => 15
566         assigns(:page_size).should eq 15
567       end
568       it '省略されると@page_sizeにデフォルト値が入る' do
569         get :resource_pictures
570         assigns(:page_size).should eq Author.default_resource_picture_page_size
571       end
572       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
573         get :resource_pictures, :page_size => 1500
574         assigns(:page_size).should eq Author.resource_picture_max_page_size
575       end
576       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
577         get :resource_pictures, :page_size => 0
578         assigns(:page_size).should eq Author.default_resource_picture_page_size
579       end
580     end
581     context 'つつがなく終わるとき' do
582       it 'ステータスコード200 OKを返す' do
583         get :resource_pictures
584         response.should be_success 
585       end
586       it '素材モデルに一覧を問い合わせている' do
587         ResourcePicture.should_receive(:mylist).exactly(1)
588         get :resource_pictures
589       end
590       it '@resource_picturesにリストを取得している' do
591         get :resource_pictures
592         assigns(:resource_pictures).should have_at_least(3).items
593       end
594       context 'html形式' do
595         it '@paginateにページ制御を取得している' do
596           get :resource_pictures
597           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
598         end
599         it 'resource_picturesテンプレートを描画する' do
600           get :resource_pictures
601           response.should render_template("resource_pictures")
602         end
603       end
604       context 'json形式' do
605         it 'jsonデータを返す' do
606           get :resource_pictures, :format => :json
607           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
608         end
609         it '素材モデルにjson一覧出力オプションを問い合わせている' do
610           ResourcePicture.should_receive(:list_json_opt).exactly(1)
611           get :resource_pictures, :format => :json
612         end
613         it 'データがリスト構造になっている' do
614           get :resource_pictures, :format => :json
615           json = JSON.parse response.body
616           json.should have_at_least(3).items
617         end
618         it 'リストの先頭くらいは素材っぽいものであって欲しい' do
619           get :resource_pictures, :format => :json
620           json = JSON.parse response.body
621           json.first.has_key?("original_picture_id").should be_true
622           json.first.has_key?("license_id").should be_true
623         end
624       end
625     end
626     context '作家権限がないとき' do
627       before do
628         sign_out @user
629       end
630       context 'html形式' do
631         it 'ステータスコード302 Foundを返す' do
632           get :resource_pictures
633           response.status.should eq 302
634         end
635         it 'サインインページへ遷移する' do
636           get :resource_pictures
637           response.should redirect_to '/users/sign_in'
638         end
639       end
640       context 'json形式' do
641         it 'ステータスコード401 Unauthorizedを返す' do
642           get :resource_pictures, :format => :json
643           response.status.should eq 401
644         end
645         it '応答メッセージにUnauthorizedを返す' do
646           get :resource_pictures, :format => :json
647           response.message.should match(/Unauthorized/)
648         end
649       end
650     end
651     context '作家が絵師でないとき' do
652       before do
653         Author.any_instance.stub(:artist?).and_return(false)
654       end
655       context 'html形式' do
656         it 'ステータスコード302 Foundを返す' do
657           get :resource_pictures
658           response.status.should eq 302
659         end
660         it '絵師登録ページへ遷移する' do
661           get :resource_pictures
662           response.should redirect_to new_artist_path
663         end
664       end
665       context 'json形式' do
666         it '例外403 forbiddenを返す' do
667           lambda{
668             get :resource_pictures, :format => :json
669           }.should raise_error(ActiveRecord::Forbidden)
670         end
671       end
672     end
673   end
674   
675 else
676   describe '自分のコミック一覧表示に於いて' do
677     before do
678       @comic = FactoryGirl.create :comic, :author_id => @author.id
679       sign_in @user
680       Comic.stub(:mylist).and_return([@comic, @comic, @comic])
681     end
682     context 'つつがなく終わるとき' do
683       it 'ステータスコード200 OKを返す' do
684         get :comics
685         response.should be_success 
686       end
687       context 'html形式' do
688         it 'comicsテンプレートを描画する' do
689           get :comics
690           response.should render_template("comics")
691         end
692       end
693       context 'json形式' do
694         it 'jsonデータを返す' do
695           get :comics, :format => :json
696           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
697         end
698       end
699     end
700     context '作家権限がないとき' do
701       before do
702         sign_out @user
703       end
704       context 'html形式' do
705         it 'ステータスコード302 Foundを返す' do
706           get :comics
707           response.status.should eq 302
708         end
709         it 'サインインページへ遷移する' do
710           get :comics
711           response.should redirect_to '/users/sign_in'
712         end
713       end
714       context 'json形式' do
715         it 'ステータスコード401 Unauthorizedを返す' do
716           get :comics, :format => :json
717           response.status.should eq 401
718         end
719         it '応答メッセージにUnauthorizedを返す' do
720           get :comics, :format => :json
721           response.message.should match(/Unauthorized/)
722         end
723       end
724     end
725   end
726   
727   describe '自分のコマ一覧表示に於いて' do
728     before do
729       @panel = FactoryGirl.create :panel, :author_id => @author.id
730       sign_in @user
731       Panel.stub(:mylist).and_return([@panel, @panel, @panel])
732     end
733     context 'つつがなく終わるとき' do
734       context 'html形式' do
735         it 'ステータスコード200 OKを返す' do
736           get :panels
737           response.should be_success 
738         end
739         it 'panelsテンプレートを描画する' do
740           get :panels
741           response.should render_template("panels")
742         end
743       end
744       context 'json形式' do
745         it 'ステータスコード200 OKを返す' do
746           get :panels, :format => :json
747           response.should be_success 
748         end
749         it 'jsonデータを返す' do
750           get :panels, :format => :json
751           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
752         end
753       end
754     end
755     context '作家権限がないとき' do
756       before do
757         sign_out @user
758       end
759       context 'html形式' do
760         it 'ステータスコード302 Foundを返す' do
761           get :panels
762           response.status.should eq 302
763         end
764         it 'サインインページへ遷移する' do
765           get :panels
766           response.should redirect_to '/users/sign_in'
767         end
768       end
769       context 'json形式' do
770         it 'ステータスコード401 Unauthorizedを返す' do
771           get :panels, :format => :json
772           response.status.should eq 401
773         end
774         it '応答メッセージにUnauthorizedを返す' do
775           get :panels, :format => :json
776           response.message.should match(/Unauthorized/)
777         end
778       end
779     end
780   end
781   
782   describe '自分のコマ絵一覧表示に於いて' do
783     before do
784       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
785         :width => @p.width, :height => @p.height
786       sign_in @user
787       PanelPicture.stub(:mylist).and_return([@pp, @pp, @pp])
788     end
789     context 'つつがなく終わるとき' do
790       it 'ステータスコード200 OKを返す' do
791         get :panel_pictures
792         response.should be_success 
793       end
794       context 'html形式' do
795         it 'panel_picturesテンプレートを描画する' do
796           get :panel_pictures
797           response.should render_template("panel_pictures")
798         end
799       end
800       context 'json形式' do
801         it 'jsonデータを返す' do
802           get :panel_pictures, :format => :json
803           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
804         end
805       end
806     end
807     context '作家権限がないとき' do
808       before do
809         sign_out @user
810       end
811       context 'html形式' do
812         it 'ステータスコード302 Foundを返す' do
813           get :panel_pictures
814           response.status.should eq 302
815         end
816         it 'サインインページへ遷移する' do
817           get :panel_pictures
818           response.should redirect_to '/users/sign_in'
819         end
820       end
821       context 'json形式' do
822         it 'ステータスコード401 Unauthorizedを返す' do
823           get :panel_pictures, :format => :json
824           response.status.should eq 401
825         end
826         it '応答メッセージにUnauthorizedを返す' do
827           get :panel_pictures, :format => :json
828           response.message.should match(/Unauthorized/)
829         end
830       end
831     end
832   end
833   
834   
835   describe '自分のコマの絵地一覧表示に於いて' do
836     before do
837       @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
838       sign_in @user
839       GroundPicture.stub(:mylist).and_return([@gp, @gp, @gp])
840     end
841     context 'つつがなく終わるとき' do
842       it 'ステータスコード200 OKを返す' do
843         get :ground_pictures
844         response.should be_success 
845       end
846       context 'html形式' do
847         it 'ground_picturesテンプレートを描画する' do
848           get :ground_pictures
849           response.should render_template("ground_pictures")
850         end
851       end
852       context 'json形式' do
853         it 'jsonデータを返す' do
854           get :ground_pictures, :format => :json
855           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
856         end
857       end
858     end
859     context '作家権限がないとき' do
860       before do
861         sign_out @user
862       end
863       context 'html形式' do
864         it 'ステータスコード302 Foundを返す' do
865           get :ground_pictures
866           response.status.should eq 302
867         end
868         it 'サインインページへ遷移する' do
869           get :ground_pictures
870           response.should redirect_to '/users/sign_in'
871         end
872       end
873       context 'json形式' do
874         it 'ステータスコード401 Unauthorizedを返す' do
875           get :ground_pictures, :format => :json
876           response.status.should eq 401
877         end
878         it '応答メッセージにUnauthorizedを返す' do
879           get :ground_pictures, :format => :json
880           response.message.should match(/Unauthorized/)
881         end
882       end
883     end
884   end
885   
886   describe '自分の色地一覧表示に於いて' do
887     before do
888       @gc = FactoryGirl.create :ground_color
889       sign_in @user
890       GroundColor.stub(:mylist).and_return([@gc, @gc, @gc])
891     end
892     context 'つつがなく終わるとき' do
893       it 'ステータスコード200 OKを返す' do
894         get :ground_colors
895         response.should be_success 
896       end
897       context 'html形式' do
898         it 'ground_colorsテンプレートを描画する' do
899           get :ground_colors
900           response.should render_template("ground_colors")
901         end
902       end
903       context 'json形式' do
904         it 'jsonデータを返す' do
905           get :ground_colors, :format => :json
906           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
907         end
908       end
909     end
910     context '作家権限がないとき' do
911       before do
912         sign_out @user
913       end
914       context 'html形式' do
915         it 'ステータスコード302 Foundを返す' do
916           get :ground_colors
917           response.status.should eq 302
918         end
919         it 'サインインページへ遷移する' do
920           get :ground_colors
921           response.should redirect_to '/users/sign_in'
922         end
923       end
924       context 'json形式' do
925         it 'ステータスコード401 Unauthorizedを返す' do
926           get :ground_colors, :format => :json
927           response.status.should eq 401
928         end
929         it '応答メッセージにUnauthorizedを返す' do
930           get :ground_colors, :format => :json
931           response.message.should match(/Unauthorized/)
932         end
933       end
934     end
935   end
936   
937   describe '自分の素材一覧表示に於いて' do
938     before do
939       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
940       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
941       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
942       sign_in @user
943       ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp])
944     end
945     context 'つつがなく終わるとき' do
946       it 'ステータスコード200 OKを返す' do
947         get :resource_pictures
948         response.should be_success 
949       end
950       context 'html形式' do
951         it 'resource_picturesテンプレートを描画する' do
952           get :resource_pictures
953           response.should render_template("resource_pictures")
954         end
955       end
956       context 'json形式' do
957         it 'jsonデータを返す' do
958           get :resource_pictures, :format => :json
959           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
960         end
961       end
962     end
963     context '作家権限がないとき' do
964       before do
965         sign_out @user
966       end
967       context 'html形式' do
968         it 'ステータスコード302 Foundを返す' do
969           get :resource_pictures
970           response.status.should eq 302
971         end
972         it 'サインインページへ遷移する' do
973           get :resource_pictures
974           response.should redirect_to '/users/sign_in'
975         end
976       end
977       context 'json形式' do
978         it 'ステータスコード401 Unauthorizedを返す' do
979           get :resource_pictures, :format => :json
980           response.status.should eq 401
981         end
982         it '応答メッセージにUnauthorizedを返す' do
983           get :resource_pictures, :format => :json
984           response.message.should match(/Unauthorized/)
985         end
986       end
987     end
988     context '作家が絵師でないとき' do
989       before do
990         @artist.destroy
991       end
992       context 'html形式' do
993         it 'ステータスコード302 Foundを返す' do
994           get :resource_pictures
995           response.status.should eq 302
996         end
997         it '絵師登録ページへ遷移する' do
998           get :resource_pictures
999           response.should redirect_to new_artist_path
1000         end
1001       end
1002       context 'json形式' do
1003         it '例外403 forbiddenを返す' do
1004           lambda{
1005             get :resource_pictures, :format => :json
1006           }.should raise_error(ActiveRecord::Forbidden)
1007         end
1008       end
1009     end
1010   end
1011   
1012 end
1013 end