OSDN Git Service

t#30469:fix artist auth error
[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_comic_page_size
654       end
655       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
656         get :resource_picture, :page_size => 1500
657         assigns(:page_size).should eq Author.comic_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_comic_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 '応答メッセージにUnauthorizedを返す' do
746           get :resource_picture, :format => :json
747           response.message.should match(/Unauthorized/)
748         end
749       end
750     end
751   end
752   
753 else
754   describe '自分のコミック一覧表示に於いて' do
755     before do
756       @comic = FactoryGirl.create :comic, :author_id => @author.id
757       sign_in @user
758       Comic.stub(:mylist).and_return([@comic, @comic, @comic])
759     end
760     context 'つつがなく終わるとき' do
761       it 'ステータスコード200 OKを返す' do
762         get :comic
763         response.should be_success 
764       end
765       context 'html形式' do
766         it 'comicテンプレートを描画する' do
767           get :comic
768           response.should render_template("comic")
769         end
770       end
771       context 'json形式' do
772         it 'jsonデータを返す' do
773           get :comic, :format => :json
774           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
775         end
776       end
777     end
778     context '作家権限がないとき' do
779       before do
780         sign_out @user
781       end
782       context 'html形式' do
783         it 'ステータスコード302 Foundを返す' do
784           get :comic
785           response.status.should eq 302
786         end
787         it 'サインインページへ遷移する' do
788           get :comic
789           response.should redirect_to '/users/sign_in'
790         end
791       end
792       context 'json形式' do
793         it 'ステータスコード401 Unauthorizedを返す' do
794           get :comic, :format => :json
795           response.status.should eq 401
796         end
797         it '応答メッセージにUnauthorizedを返す' do
798           get :comic, :format => :json
799           response.message.should match(/Unauthorized/)
800         end
801       end
802     end
803   end
804   
805   describe '自分のコマ一覧表示に於いて' do
806     before do
807       @panel = FactoryGirl.create :panel, :author_id => @author.id
808       sign_in @user
809       Panel.stub(:mylist).and_return([@panel, @panel, @panel])
810     end
811     context 'つつがなく終わるとき' do
812       context 'html形式' do
813         it 'ステータスコード200 OKを返す' do
814           get :panel
815           response.should be_success 
816         end
817         it 'panelテンプレートを描画する' do
818           get :panel
819           response.should render_template("panel")
820         end
821       end
822       context 'json形式' do
823         it 'ステータスコード200 OKを返す' do
824           get :panel, :format => :json
825           response.should be_success 
826         end
827         it 'jsonデータを返す' do
828           get :panel, :format => :json
829           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
830         end
831       end
832     end
833     context '作家権限がないとき' do
834       before do
835         sign_out @user
836       end
837       context 'html形式' do
838         it 'ステータスコード302 Foundを返す' do
839           get :panel
840           response.status.should eq 302
841         end
842         it 'サインインページへ遷移する' do
843           get :panel
844           response.should redirect_to '/users/sign_in'
845         end
846       end
847       context 'json形式' do
848         it 'ステータスコード401 Unauthorizedを返す' do
849           get :panel, :format => :json
850           response.status.should eq 401
851         end
852         it '応答メッセージにUnauthorizedを返す' do
853           get :panel, :format => :json
854           response.message.should match(/Unauthorized/)
855         end
856       end
857     end
858   end
859   
860   describe '自分のコマ絵一覧表示に於いて' do
861     before do
862       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
863         :width => @p.width, :height => @p.height
864       sign_in @user
865       PanelPicture.stub(:mylist).and_return([@pp, @pp, @pp])
866     end
867     context 'つつがなく終わるとき' do
868       it 'ステータスコード200 OKを返す' do
869         get :panel_picture
870         response.should be_success 
871       end
872       context 'html形式' do
873         it 'panel_pictureテンプレートを描画する' do
874           get :panel_picture
875           response.should render_template("panel_picture")
876         end
877       end
878       context 'json形式' do
879         it 'jsonデータを返す' do
880           get :panel_picture, :format => :json
881           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
882         end
883       end
884     end
885     context '作家権限がないとき' do
886       before do
887         sign_out @user
888       end
889       context 'html形式' do
890         it 'ステータスコード302 Foundを返す' do
891           get :panel_picture
892           response.status.should eq 302
893         end
894         it 'サインインページへ遷移する' do
895           get :panel_picture
896           response.should redirect_to '/users/sign_in'
897         end
898       end
899       context 'json形式' do
900         it 'ステータスコード401 Unauthorizedを返す' do
901           get :panel_picture, :format => :json
902           response.status.should eq 401
903         end
904         it '応答メッセージにUnauthorizedを返す' do
905           get :panel_picture, :format => :json
906           response.message.should match(/Unauthorized/)
907         end
908       end
909     end
910   end
911   
912   describe '自分のコマの色背景一覧表示に於いて' do
913     before do
914       @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
915       sign_in @user
916       PanelColor.stub(:mylist).and_return([@pc, @pc, @pc])
917     end
918     context 'つつがなく終わるとき' do
919       it 'ステータスコード200 OKを返す' do
920         get :panel_color
921         response.should be_success 
922       end
923       context 'html形式' do
924         it 'panel_colorテンプレートを描画する' do
925           get :panel_color
926           response.should render_template("panel_color")
927         end
928       end
929       context 'json形式' do
930         it 'jsonデータを返す' do
931           get :panel_color, :format => :json
932           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
933         end
934       end
935     end
936     context '作家権限がないとき' do
937       before do
938         sign_out @user
939       end
940       context 'html形式' do
941         it 'ステータスコード302 Foundを返す' do
942           get :panel_color
943           response.status.should eq 302
944         end
945         it 'サインインページへ遷移する' do
946           get :panel_color
947           response.should redirect_to '/users/sign_in'
948         end
949       end
950       context 'json形式' do
951         it 'ステータスコード401 Unauthorizedを返す' do
952           get :panel_color, :format => :json
953           response.status.should eq 401
954         end
955         it '応答メッセージにUnauthorizedを返す' do
956           get :panel_color, :format => :json
957           response.message.should match(/Unauthorized/)
958         end
959       end
960     end
961   end
962   
963   describe '自分のコマの画像背景一覧表示に於いて' do
964     before do
965       @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
966       sign_in @user
967       GroundPicture.stub(:mylist).and_return([@gp, @gp, @gp])
968     end
969     context 'つつがなく終わるとき' do
970       it 'ステータスコード200 OKを返す' do
971         get :ground_picture
972         response.should be_success 
973       end
974       context 'html形式' do
975         it 'ground_pictureテンプレートを描画する' do
976           get :ground_picture
977           response.should render_template("ground_picture")
978         end
979       end
980       context 'json形式' do
981         it 'jsonデータを返す' do
982           get :ground_picture, :format => :json
983           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
984         end
985       end
986     end
987     context '作家権限がないとき' do
988       before do
989         sign_out @user
990       end
991       context 'html形式' do
992         it 'ステータスコード302 Foundを返す' do
993           get :ground_picture
994           response.status.should eq 302
995         end
996         it 'サインインページへ遷移する' do
997           get :ground_picture
998           response.should redirect_to '/users/sign_in'
999         end
1000       end
1001       context 'json形式' do
1002         it 'ステータスコード401 Unauthorizedを返す' do
1003           get :ground_picture, :format => :json
1004           response.status.should eq 401
1005         end
1006         it '応答メッセージにUnauthorizedを返す' do
1007           get :ground_picture, :format => :json
1008           response.message.should match(/Unauthorized/)
1009         end
1010       end
1011     end
1012   end
1013   
1014   describe '自分の間接背景一覧表示に於いて' do
1015     before do
1016       @gc = FactoryGirl.create :ground_color
1017       sign_in @user
1018       GroundColor.stub(:mylist).and_return([@gc, @gc, @gc])
1019     end
1020     context 'つつがなく終わるとき' do
1021       it 'ステータスコード200 OKを返す' do
1022         get :ground_color
1023         response.should be_success 
1024       end
1025       context 'html形式' do
1026         it 'ground_colorテンプレートを描画する' do
1027           get :ground_color
1028           response.should render_template("ground_color")
1029         end
1030       end
1031       context 'json形式' do
1032         it 'jsonデータを返す' do
1033           get :ground_color, :format => :json
1034           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1035         end
1036       end
1037     end
1038     context '作家権限がないとき' do
1039       before do
1040         sign_out @user
1041       end
1042       context 'html形式' do
1043         it 'ステータスコード302 Foundを返す' do
1044           get :ground_color
1045           response.status.should eq 302
1046         end
1047         it 'サインインページへ遷移する' do
1048           get :ground_color
1049           response.should redirect_to '/users/sign_in'
1050         end
1051       end
1052       context 'json形式' do
1053         it 'ステータスコード401 Unauthorizedを返す' do
1054           get :ground_color, :format => :json
1055           response.status.should eq 401
1056         end
1057         it '応答メッセージにUnauthorizedを返す' do
1058           get :ground_color, :format => :json
1059           response.message.should match(/Unauthorized/)
1060         end
1061       end
1062     end
1063   end
1064   
1065   describe '自分の素材一覧表示に於いて' do
1066     before do
1067       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1068       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
1069       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
1070       sign_in @user
1071       ResourcePicture.stub(:mylist).and_return([@rp, @rp, @rp])
1072     end
1073     context 'つつがなく終わるとき' do
1074       it 'ステータスコード200 OKを返す' do
1075         get :resource_picture
1076         response.should be_success 
1077       end
1078       context 'html形式' do
1079         it 'resource_pictureテンプレートを描画する' do
1080           get :resource_picture
1081           response.should render_template("resource_picture")
1082         end
1083       end
1084       context 'json形式' do
1085         it 'jsonデータを返す' do
1086           get :resource_picture, :format => :json
1087           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1088         end
1089       end
1090     end
1091     context '作家権限がないとき' do
1092       before do
1093         sign_out @user
1094       end
1095       context 'html形式' do
1096         it 'ステータスコード302 Foundを返す' do
1097           get :resource_picture
1098           response.status.should eq 302
1099         end
1100         it 'サインインページへ遷移する' do
1101           get :resource_picture
1102           response.should redirect_to '/users/sign_in'
1103         end
1104       end
1105       context 'json形式' do
1106         it 'ステータスコード401 Unauthorizedを返す' do
1107           get :resource_picture, :format => :json
1108           response.status.should eq 401
1109         end
1110         it '応答メッセージにUnauthorizedを返す' do
1111           get :resource_picture, :format => :json
1112           response.message.should match(/Unauthorized/)
1113         end
1114       end
1115     end
1116     context '作家が絵師でないとき' do
1117       before do
1118         Author.any_instance.stub(:artist?).and_return(false)
1119       end
1120       context 'html形式' do
1121         it 'ステータスコード302 Foundを返す' do
1122           get :resource_picture
1123           response.status.should eq 302
1124         end
1125         it '絵師登録ページへ遷移する' do
1126           get :resource_picture
1127           response.should redirect_to new_artist_path
1128         end
1129       end
1130       context 'json形式' do
1131         it '例外403 forbiddenを返す' do
1132           lambda{
1133             get :resource_picture, :format => :json
1134           }.should raise_error(ActiveRecord::Forbidden)
1135         end
1136       end
1137     end
1138   end
1139   
1140 end
1141 end