OSDN Git Service

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