OSDN Git Service

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