OSDN Git Service

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