OSDN Git Service

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