OSDN Git Service

t#32046:
[pettanr/pettanr.git] / spec / controllers / authors_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #作家
4
5 describe AuthorsController do
6   before do
7     SpeechBalloonTemplate.delete_all
8     @admin =FactoryGirl.create :admin
9     @sp = FactoryGirl.create :system_picture
10     @lg = FactoryGirl.create :license_group
11     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
12     @speech_balloon_template = FactoryGirl.create :speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc",  "system_picture_id" => @sp.id, "settings" => '{}'
13     @writing_format = FactoryGirl.create :writing_format
14     @user = FactoryGirl.create( :user_yas)
15     @author = FactoryGirl.create :author, :user_id => @user.id
16     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
17   end
18
19 if MagicNumber['run_mode'] == 1
20   describe '一覧表示に於いて' do
21     before do
22       Author.stub(:list).and_return([@author, @author, @author])
23       sign_in @user
24     end
25     context '事前チェックする' do
26       it '与えられたpageがセットされている' do
27         get :index, :page => 5
28         assigns(:page).should eq 5
29       end
30       it '省略されると@pageに1値が入る' do
31         get :index
32         assigns(:page).should eq 1
33       end
34       it '与えられたpage_sizeがセットされている' do
35         get :index, :page_size => 15
36         assigns(:page_size).should eq 15
37       end
38       it '省略されると@page_sizeにデフォルト値が入る' do
39         get :index
40         assigns(:page_size).should eq Author.default_page_size
41       end
42       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
43         get :index, :page_size => 1500
44         assigns(:page_size).should eq Author.max_page_size
45       end
46       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
47         get :index, :page_size => 0
48         assigns(:page_size).should eq Author.default_page_size
49       end
50     end
51     context 'つつがなく終わるとき' do
52       it 'ステータスコード200 OKを返す' do
53         get :index
54         response.should be_success 
55       end
56       it '作家モデルに一覧を問い合わせている' do
57         Author.should_receive(:list).exactly(1)
58         get :index
59       end
60       it '@authorsにリストを取得している' do
61         get :index
62         assigns(:authors).should have_at_least(3).items
63       end
64       context 'html形式' do
65         it '@paginateにページ制御を取得している' do
66           get :index
67           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
68         end
69         it 'indexテンプレートを描画する' do
70           get :index
71           response.should render_template("index")
72         end
73       end
74       context 'json形式' do
75         it 'jsonデータを返す' do
76           get :index, :format => :json
77           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
78         end
79         it '作家モデルにjson一覧出力オプションを問い合わせている' do
80           Author.should_receive(:list_json_opt).exactly(1)
81           get :index, :format => :json
82         end
83         it 'データがリスト構造になっている' do
84           get :index, :format => :json
85           json = JSON.parse response.body
86           json.should have_at_least(3).items
87         end
88         it 'リストの先頭くらいは作家っぽいものであって欲しい' do
89           get :index, :format => :json
90           json = JSON.parse response.body
91           json.first.has_key?("name").should be_true
92           json.first.has_key?("user_id").should be_true
93         end
94       end
95     end
96     context 'ユーザ権限がないとき' do
97       before do
98         sign_out @user
99       end
100       context 'html形式' do
101         it 'ステータスコード302 Foundを返す' do
102           get :index
103           response.status.should eq 302
104         end
105         it 'サインインページへ遷移する' do
106           get :index
107           response.should redirect_to '/users/sign_in'
108         end
109       end
110       context 'json形式' do
111         it 'ステータスコード401 Unauthorizedを返す' do
112           get :index, :format => :json
113           response.status.should eq 401
114         end
115         it '応答メッセージにUnauthorizedを返す' do
116           get :index, :format => :json
117           response.message.should match(/Unauthorized/)
118         end
119       end
120     end
121     context 'ユーザ権限はないが管理者権限があるとき' do
122       before do
123         sign_out @user
124         sign_in @admin
125       end
126       it 'ステータスコード200 OKを返す' do
127         get :index
128         response.should be_success 
129       end
130     end
131     context 'ユーザだが作家登録していないとき' do
132       before do
133         @author.destroy
134       end
135       it 'ステータスコード200 OKを返す' do
136         get :index
137         response.should be_success 
138       end
139     end
140   end
141   
142   describe '閲覧に於いて' do
143     before do
144       Author.stub(:show).and_return(@author)
145       sign_in @user
146     end
147     context 'つつがなく終わるとき' do
148       it 'ステータスコード200 OKを返す' do
149         get :show, :id => @author.id
150         response.should be_success
151       end
152       it '作家モデルに単体取得を問い合わせている' do
153         Author.should_receive(:show).exactly(1)
154         get :show
155       end
156       #@authorだとログイン中のアカウントと干渉してしまう。
157       it '@auにアレを取得している' do
158         get :show, :id => @author.id
159         assigns(:au).should eq(@author)
160       end
161       context 'html形式' do
162         it 'showテンプレートを描画する' do
163           get :show, :id => @author.id
164           response.should render_template("show")
165         end
166       end
167       context 'json形式' do
168         it 'jsonデータを返す' do
169           get :show, :id => @author.id, :format => :json
170           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
171         end
172         it '作家モデルにjson単体出力オプションを問い合わせている' do
173           Author.should_receive(:show_json_opt).exactly(1)
174           get :show, :id => @author.id, :format => :json
175         end
176         it 'データがアレになっている' do
177           get :show, :id => @author.id, :format => :json
178           json = JSON.parse response.body
179           json["name"].should match(/test/)
180           json["user_id"].should eq @author.user_id
181         end
182       end
183     end
184     context 'ユーザ権限がないとき' do
185       before do
186         sign_out @user
187       end
188       context 'html形式' do
189         it 'ステータスコード302 Foundを返す' do
190           get :show, :id => @author.id
191           response.status.should eq 302
192         end
193         it 'サインインページへ遷移する' do
194           get :show, :id => @author.id
195           response.body.should redirect_to '/users/sign_in'
196         end
197       end
198       context 'json形式' do
199         it 'ステータスコード401 Unauthorizedを返す' do
200           get :show, :id => @author.id, :format => :json
201           response.status.should eq 401
202         end
203         it '応答メッセージにUnauthorizedを返す' do
204           get :show, :id => @author.id, :format => :json
205           response.message.should match(/Unauthorized/)
206         end
207       end
208     end
209     context 'ユーザ権限はないが管理者権限があるとき' do
210       before do
211         sign_out @user
212         sign_in @admin
213       end
214       it 'ステータスコード200 OKを返す' do
215         get :show, :id => @author.id
216         response.should be_success 
217       end
218     end
219     context 'ユーザだが作家登録していないとき' do
220       before do
221         @author.destroy
222       end
223       it 'ステータスコード200 OKを返す' do
224         get :show, :id => @author.id
225         response.should be_success 
226       end
227     end
228 =begin
229     context '対象作家がないとき' do
230       context 'html形式' do
231         it '例外404 not_foundを返す' do
232           lambda{
233             get :show, :id => 0
234           }.should raise_error(ActiveRecord::RecordNotFound)
235         end
236       end
237       context 'json形式' do
238         it '例外404 not_foundを返す' do
239           lambda{ 
240             get :show, :id => 0, :format => :json
241           }.should raise_error(ActiveRecord::RecordNotFound)
242         end
243       end
244     end
245 =end
246   end
247   
248   describe '対象作家のコミック一覧表示に於いて' do
249     before do
250       @other_user = FactoryGirl.create( :user_yas)
251       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
252       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
253       @scroll = FactoryGirl.create :scroll, :author_id => @other_user.author.id
254       Author.stub(:show).and_return(@other_author)
255       Scroll.stub(:himlist).and_return([@scroll, @scroll, @scroll])
256       sign_in @user
257     end
258     context 'パラメータpageについて' do
259       it '@pageに値が入る' do
260         get :scrolls, :id => @other_author.id, :page => 5
261         assigns(:page).should eq 5
262       end
263       it '省略されると@pageに1値が入る' do
264         get :scrolls, :id => @other_author.id
265         assigns(:page).should eq 1
266       end
267       it '与えられたpage_sizeがセットされている' do
268         get :scrolls, :id => @other_author.id, :page_size => 15
269         assigns(:page_size).should eq 15
270       end
271       it '省略されると@page_sizeにデフォルト値が入る' do
272         get :scrolls, :id => @other_author.id
273         assigns(:page_size).should eq Author.default_scroll_page_size
274       end
275       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
276         get :scrolls, :id => @other_author.id, :page_size => 1500
277         assigns(:page_size).should eq Author.scroll_max_page_size
278       end
279       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
280         get :scrolls, :id => @other_author.id, :page_size => 0
281         assigns(:page_size).should eq Author.default_scroll_page_size
282       end
283     end
284     context 'つつがなく終わるとき' do
285       it 'ステータスコード200 OKを返す' do
286         get :scrolls, :id => @other_author.id
287         response.should be_success 
288       end
289       it '作家モデルに単体取得を問い合わせている' do
290         Author.should_receive(:show).exactly(1)
291         get :scrolls, :id => @other_author.id
292       end
293       it 'コミックモデルに一覧を問い合わせている' do
294         Scroll.should_receive(:himlist).exactly(1)
295         get :scrolls, :id => @other_author.id
296       end
297       it '@scrollsにリストを取得している' do
298         get :scrolls, :id => @other_author.id
299         assigns(:scrolls).should have_at_least(3).items
300       end
301       context 'html形式' do
302         it '@paginateにページ制御を取得している' do
303           get :scrolls, :id => @other_author.id
304           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
305         end
306         it 'scrollsテンプレートを描画する' do
307           get :scrolls, :id => @other_author.id
308           response.should render_template("scrolls")
309         end
310       end
311       context 'json形式' do
312         it 'jsonデータを返す' do
313           get :scrolls, :id => @other_author.id, :format => :json
314           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
315         end
316         it 'コミックモデルにjson一覧出力オプションを問い合わせている' do
317           Scroll.should_receive(:list_json_opt).exactly(1)
318           get :scrolls, :id => @other_author.id, :format => :json
319         end
320         it 'データがリスト構造になっている' do
321           get :scrolls, :id => @other_author.id, :format => :json
322           json = JSON.parse response.body
323           json.should have_at_least(3).items
324         end
325         it 'リストの先頭くらいはコミックっぽいものであって欲しい' do
326           get :scrolls, :id => @other_author.id, :format => :json
327           json = JSON.parse response.body
328           json.first.has_key?("title").should be_true
329           json.first.has_key?("visible").should be_true
330         end
331       end
332     end
333     context 'ユーザ権限がないとき' do
334       before do
335         sign_out @user
336       end
337       context 'html形式' do
338         it 'ステータスコード302 Foundを返す' do
339           get :scrolls, :id => @other_author.id
340           response.status.should eq 302
341         end
342         it 'サインインページへ遷移する' do
343           get :scrolls, :id => @other_author.id
344           response.should redirect_to '/users/sign_in'
345         end
346       end
347       context 'json形式' do
348         it 'ステータスコード401 Unauthorizedを返す' do
349           get :scrolls, :id => @other_author.id, :format => :json
350           response.status.should eq 401
351         end
352         it '応答メッセージにUnauthorizedを返す' do
353           get :scrolls, :id => @other_author.id, :format => :json
354           response.message.should match(/Unauthorized/)
355         end
356       end
357     end
358     context 'ユーザ権限はないが管理者権限があるとき' do
359       before do
360         sign_out @user
361         sign_in @admin
362       end
363       it 'ステータスコード200 OKを返す' do
364         get :scrolls, :id => @other_author.id
365         response.should be_success 
366       end
367     end
368     context 'ユーザだが作家登録していないとき' do
369       before do
370         @author.destroy
371       end
372       it 'ステータスコード200 OKを返す' do
373         get :scrolls, :id => @other_author.id
374         response.should be_success 
375       end
376     end
377   end
378   
379   describe '対象作家のストーリー一覧表示に於いて' do
380     before do
381       @other_user = FactoryGirl.create( :user_yas)
382       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
383       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
384       @scroll = FactoryGirl.create :scroll, :author_id => @other_user.author.id
385       @panel = FactoryGirl.create :panel, :author_id => @other_user.author.id
386       @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @other_user.author.id
387       Author.stub(:show).and_return(@other_author)
388       ScrollPanel.stub(:himlist).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
389       sign_in @user
390     end
391     context 'パラメータpageについて' do
392       it '@pageに値が入る' do
393         get :scroll_panels, :id => @other_author.id, :page => 5
394         assigns(:page).should eq 5
395       end
396       it '省略されると@pageに1値が入る' do
397         get :scroll_panels, :id => @other_author.id
398         assigns(:page).should eq 1
399       end
400       it '与えられたpage_sizeがセットされている' do
401         get :scroll_panels, :id => @other_author.id, :page_size => 15
402         assigns(:page_size).should eq 15
403       end
404       it '省略されると@page_sizeにデフォルト値が入る' do
405         get :scroll_panels, :id => @other_author.id
406         assigns(:page_size).should eq Author.default_scroll_panel_page_size
407       end
408       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
409         get :scroll_panels, :id => @other_author.id, :page_size => 1500
410         assigns(:page_size).should eq Author.scroll_panel_max_page_size
411       end
412       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
413         get :scroll_panels, :id => @other_author.id, :page_size => 0
414         assigns(:page_size).should eq Author.default_scroll_panel_page_size
415       end
416     end
417     context 'つつがなく終わるとき' do
418       it 'ステータスコード200 OKを返す' do
419         get :scroll_panels, :id => @other_author.id
420         response.should be_success 
421       end
422       it '作家モデルに単体取得を問い合わせている' do
423         Author.should_receive(:show).exactly(1)
424         get :scroll_panels, :id => @other_author.id
425       end
426       it 'ストーリーモデルに他作家のストーリー一覧を問い合わせている' do
427         ScrollPanel.should_receive(:himlist).exactly(1)
428         get :scroll_panels, :id => @other_author.id
429       end
430       it '@scroll_panelsにリストを取得している' do
431         get :scroll_panels, :id => @other_author.id
432         assigns(:scroll_panels).should have_at_least(3).items
433       end
434       context 'html形式' do
435         it '@paginateにページ制御を取得している' do
436           get :scroll_panels, :id => @other_author.id
437           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
438         end
439         it 'scroll_panelsテンプレートを描画する' do
440           get :scroll_panels, :id => @other_author.id
441           response.should render_template("scroll_panels")
442         end
443       end
444       context 'json形式' do
445         it 'jsonデータを返す' do
446           get :scroll_panels, :id => @other_author.id, :format => :json
447           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
448         end
449         it 'ストーリーモデルにjson一覧出力オプションを問い合わせている' do
450           ScrollPanel.should_receive(:list_json_opt).exactly(1)
451           get :scroll_panels, :id => @other_author.id, :format => :json
452         end
453         it 'データがリスト構造になっている' do
454           get :scroll_panels, :id => @other_author.id, :format => :json
455           json = JSON.parse response.body
456           json.should have_at_least(3).items
457         end
458         it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
459           get :scroll_panels, :id => @other_author.id, :format => :json
460           json = JSON.parse response.body
461           json.first.has_key?("panel_id").should be_true
462           json.first.has_key?("scroll_id").should be_true
463           json.first.has_key?("t").should be_true
464         end
465       end
466     end
467     context 'ユーザ権限がないとき' do
468       before do
469         sign_out @user
470       end
471       context 'html形式' do
472         it 'ステータスコード302 Foundを返す' do
473           get :scroll_panels, :id => @other_author.id
474           response.status.should eq 302
475         end
476         it 'サインインページへ遷移する' do
477           get :scroll_panels, :id => @other_author.id
478           response.should redirect_to '/users/sign_in'
479         end
480       end
481       context 'json形式' do
482         it 'ステータスコード401 Unauthorizedを返す' do
483           get :scroll_panels, :id => @other_author.id, :format => :json
484           response.status.should eq 401
485         end
486         it '応答メッセージにUnauthorizedを返す' do
487           get :scroll_panels, :id => @other_author.id, :format => :json
488           response.message.should match(/Unauthorized/)
489         end
490       end
491     end
492     context 'ユーザ権限はないが管理者権限があるとき' do
493       before do
494         sign_out @user
495         sign_in @admin
496       end
497       it 'ステータスコード200 OKを返す' do
498         get :scroll_panels, :id => @other_author.id
499         response.should be_success 
500       end
501     end
502     context 'ユーザだが作家登録していないとき' do
503       before do
504         @author.destroy
505       end
506       it 'ステータスコード200 OKを返す' do
507         get :scroll_panels, :id => @other_author.id
508         response.should be_success 
509       end
510     end
511   end
512   
513   describe '対象作家の用紙一覧表示に於いて' do
514     before do
515       @other_user = FactoryGirl.create( :user_yas)
516       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
517       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
518       @sheet = FactoryGirl.create :sheet, :author_id => @other_user.author.id
519       Author.stub(:show).and_return(@other_author)
520       Sheet.stub(:himlist).and_return([@sheet, @sheet, @sheet])
521       sign_in @user
522     end
523     context 'パラメータpageについて' do
524       it '@pageに値が入る' do
525         get :sheets, :id => @other_author.id, :page => 5
526         assigns(:page).should eq 5
527       end
528       it '省略されると@pageに1値が入る' do
529         get :sheets, :id => @other_author.id
530         assigns(:page).should eq 1
531       end
532       it '与えられたpage_sizeがセットされている' do
533         get :sheets, :id => @other_author.id, :page_size => 15
534         assigns(:page_size).should eq 15
535       end
536       it '省略されると@page_sizeにデフォルト値が入る' do
537         get :sheets, :id => @other_author.id
538         assigns(:page_size).should eq Author.default_sheet_page_size
539       end
540       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
541         get :sheets, :id => @other_author.id, :page_size => 1500
542         assigns(:page_size).should eq Author.sheet_max_page_size
543       end
544       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
545         get :sheets, :id => @other_author.id, :page_size => 0
546         assigns(:page_size).should eq Author.default_sheet_page_size
547       end
548     end
549     context 'つつがなく終わるとき' do
550       it 'ステータスコード200 OKを返す' do
551         get :sheets, :id => @other_author.id
552         response.should be_success 
553       end
554       it '作家モデルに単体取得を問い合わせている' do
555         Author.should_receive(:show).exactly(1)
556         get :sheets, :id => @other_author.id
557       end
558       it '用紙モデルに一覧を問い合わせている' do
559         Sheet.should_receive(:himlist).exactly(1)
560         get :sheets, :id => @other_author.id
561       end
562       it '@sheetsにリストを取得している' do
563         get :sheets, :id => @other_author.id
564         assigns(:sheets).should have_at_least(3).items
565       end
566       context 'html形式' do
567         it '@paginateにページ制御を取得している' do
568           get :sheets, :id => @other_author.id
569           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
570         end
571         it 'sheetsテンプレートを描画する' do
572           get :sheets, :id => @other_author.id
573           response.should render_template("sheets")
574         end
575       end
576       context 'json形式' do
577         it 'jsonデータを返す' do
578           get :sheets, :id => @other_author.id, :format => :json
579           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
580         end
581         it '用紙モデルにjson一覧出力オプションを問い合わせている' do
582           Sheet.should_receive(:list_json_opt).exactly(1)
583           get :sheets, :id => @other_author.id, :format => :json
584         end
585         it 'データがリスト構造になっている' do
586           get :sheets, :id => @other_author.id, :format => :json
587           json = JSON.parse response.body
588           json.should have_at_least(3).items
589         end
590         it 'リストの先頭くらいは用紙っぽいものであって欲しい' do
591           get :sheets, :id => @other_author.id, :format => :json
592           json = JSON.parse response.body
593           json.first.has_key?("caption").should be_true
594           json.first.has_key?("visible").should be_true
595         end
596       end
597     end
598     context 'ユーザ権限がないとき' do
599       before do
600         sign_out @user
601       end
602       context 'html形式' do
603         it 'ステータスコード302 Foundを返す' do
604           get :sheets, :id => @other_author.id
605           response.status.should eq 302
606         end
607         it 'サインインページへ遷移する' do
608           get :sheets, :id => @other_author.id
609           response.should redirect_to '/users/sign_in'
610         end
611       end
612       context 'json形式' do
613         it 'ステータスコード401 Unauthorizedを返す' do
614           get :sheets, :id => @other_author.id, :format => :json
615           response.status.should eq 401
616         end
617         it '応答メッセージにUnauthorizedを返す' do
618           get :sheets, :id => @other_author.id, :format => :json
619           response.message.should match(/Unauthorized/)
620         end
621       end
622     end
623     context 'ユーザ権限はないが管理者権限があるとき' do
624       before do
625         sign_out @user
626         sign_in @admin
627       end
628       it 'ステータスコード200 OKを返す' do
629         get :sheets, :id => @other_author.id
630         response.should be_success 
631       end
632     end
633     context 'ユーザだが作家登録していないとき' do
634       before do
635         @author.destroy
636       end
637       it 'ステータスコード200 OKを返す' do
638         get :sheets, :id => @other_author.id
639         response.should be_success 
640       end
641     end
642   end
643   
644   describe '対象作家の紙コマ一覧表示に於いて' do
645     before do
646       @other_user = FactoryGirl.create( :user_yas)
647       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
648       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
649       @sheet = FactoryGirl.create :sheet, :author_id => @other_user.author.id
650       @panel = FactoryGirl.create :panel, :author_id => @other_user.author.id
651       @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @other_user.author.id
652       Author.stub(:show).and_return(@other_author)
653       SheetPanel.stub(:himlist).and_return([@sheet_panel, @sheet_panel, @sheet_panel])
654       sign_in @user
655     end
656     context 'パラメータpageについて' do
657       it '@pageに値が入る' do
658         get :sheet_panels, :id => @other_author.id, :page => 5
659         assigns(:page).should eq 5
660       end
661       it '省略されると@pageに1値が入る' do
662         get :sheet_panels, :id => @other_author.id
663         assigns(:page).should eq 1
664       end
665       it '与えられたpage_sizeがセットされている' do
666         get :sheet_panels, :id => @other_author.id, :page_size => 15
667         assigns(:page_size).should eq 15
668       end
669       it '省略されると@page_sizeにデフォルト値が入る' do
670         get :sheet_panels, :id => @other_author.id
671         assigns(:page_size).should eq Author.default_sheet_panel_page_size
672       end
673       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
674         get :sheet_panels, :id => @other_author.id, :page_size => 1500
675         assigns(:page_size).should eq Author.sheet_panel_max_page_size
676       end
677       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
678         get :sheet_panels, :id => @other_author.id, :page_size => 0
679         assigns(:page_size).should eq Author.default_sheet_panel_page_size
680       end
681     end
682     context 'つつがなく終わるとき' do
683       it 'ステータスコード200 OKを返す' do
684         get :sheet_panels, :id => @other_author.id
685         response.should be_success 
686       end
687       it '作家モデルに単体取得を問い合わせている' do
688         Author.should_receive(:show).exactly(1)
689         get :sheet_panels, :id => @other_author.id
690       end
691       it '紙コマモデルに他作家の紙コマ一覧を問い合わせている' do
692         SheetPanel.should_receive(:himlist).exactly(1)
693         get :sheet_panels, :id => @other_author.id
694       end
695       it '@sheet_panelsにリストを取得している' do
696         get :sheet_panels, :id => @other_author.id
697         assigns(:sheet_panels).should have_at_least(3).items
698       end
699       context 'html形式' do
700         it '@paginateにページ制御を取得している' do
701           get :sheet_panels, :id => @other_author.id
702           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
703         end
704         it 'sheet_panelsテンプレートを描画する' do
705           get :sheet_panels, :id => @other_author.id
706           response.should render_template("sheet_panels")
707         end
708       end
709       context 'json形式' do
710         it 'jsonデータを返す' do
711           get :sheet_panels, :id => @other_author.id, :format => :json
712           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
713         end
714         it '紙コマモデルにjson一覧出力オプションを問い合わせている' do
715           SheetPanel.should_receive(:list_json_opt).exactly(1)
716           get :sheet_panels, :id => @other_author.id, :format => :json
717         end
718         it 'データがリスト構造になっている' do
719           get :sheet_panels, :id => @other_author.id, :format => :json
720           json = JSON.parse response.body
721           json.should have_at_least(3).items
722         end
723         it 'リストの先頭くらいは紙コマっぽいものであって欲しい' do
724           get :sheet_panels, :id => @other_author.id, :format => :json
725           json = JSON.parse response.body
726           json.first.has_key?("panel_id").should be_true
727           json.first.has_key?("sheet_id").should be_true
728           json.first.has_key?("t").should be_true
729         end
730       end
731     end
732     context 'ユーザ権限がないとき' do
733       before do
734         sign_out @user
735       end
736       context 'html形式' do
737         it 'ステータスコード302 Foundを返す' do
738           get :sheet_panels, :id => @other_author.id
739           response.status.should eq 302
740         end
741         it 'サインインページへ遷移する' do
742           get :sheet_panels, :id => @other_author.id
743           response.should redirect_to '/users/sign_in'
744         end
745       end
746       context 'json形式' do
747         it 'ステータスコード401 Unauthorizedを返す' do
748           get :sheet_panels, :id => @other_author.id, :format => :json
749           response.status.should eq 401
750         end
751         it '応答メッセージにUnauthorizedを返す' do
752           get :sheet_panels, :id => @other_author.id, :format => :json
753           response.message.should match(/Unauthorized/)
754         end
755       end
756     end
757     context 'ユーザ権限はないが管理者権限があるとき' do
758       before do
759         sign_out @user
760         sign_in @admin
761       end
762       it 'ステータスコード200 OKを返す' do
763         get :sheet_panels, :id => @other_author.id
764         response.should be_success 
765       end
766     end
767     context 'ユーザだが作家登録していないとき' do
768       before do
769         @author.destroy
770       end
771       it 'ステータスコード200 OKを返す' do
772         get :sheet_panels, :id => @other_author.id
773         response.should be_success 
774       end
775     end
776   end
777   
778   describe '対象作家のコマ一覧表示に於いて' do
779     before do
780       @other_user = FactoryGirl.create( :user_yas)
781       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
782       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
783       @panel = FactoryGirl.create :panel, :author_id => @other_author.id
784       Author.stub(:show).and_return(@other_author)
785       Panel.stub(:himlist).and_return([@panel, @panel, @panel])
786       sign_in @user
787     end
788     context 'パラメータpageについて' do
789       it '@pageに値が入る' do
790         get :panels, :id => @other_author.id, :page => 5
791         assigns(:page).should eq 5
792       end
793       it '省略されると@pageに1値が入る' do
794         get :panels, :id => @other_author.id
795         assigns(:page).should eq 1
796       end
797       it '与えられたpage_sizeがセットされている' do
798         get :panels, :id => @other_author.id, :page_size => 15
799         assigns(:page_size).should eq 15
800       end
801       it '省略されると@page_sizeにデフォルト値が入る' do
802         get :panels, :id => @other_author.id
803         assigns(:page_size).should eq Author.default_panel_page_size
804       end
805       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
806         get :panels, :id => @other_author.id, :page_size => 1500
807         assigns(:page_size).should eq Author.panel_max_page_size
808       end
809       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
810         get :panels, :id => @other_author.id, :page_size => 0
811         assigns(:page_size).should eq Author.default_panel_page_size
812       end
813     end
814     context 'つつがなく終わるとき' do
815       it 'ステータスコード200 OKを返す' do
816         get :panels, :id => @other_author.id
817         response.should be_success 
818       end
819       it '作家モデルに単体取得を問い合わせている' do
820         Author.should_receive(:show).exactly(1)
821         get :panels, :id => @other_author.id
822       end
823       it 'コマモデルに他作家のコマ一覧を問い合わせている' do
824         Panel.should_receive(:himlist).exactly(1)
825         get :panels, :id => @other_author.id
826       end
827       it '@panelsにリストを取得している' do
828         get :panels, :id => @other_author.id
829         assigns(:panels).should have_at_least(3).items
830       end
831       context 'html形式' do
832         it '@paginateにページ制御を取得している' do
833           get :panels, :id => @other_author.id
834           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
835         end
836         it 'panelsテンプレートを描画する' do
837           get :panels, :id => @other_author.id
838           response.should render_template("panels")
839         end
840       end
841       context 'json形式' do
842         it 'jsonデータを返す' do
843           get :panels, :id => @other_author.id, :format => :json
844           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
845         end
846         it 'コマモデルにコマリストのjson出力を問い合わせている' do
847           Panel.should_receive(:list_as_json_text).exactly(1)
848           get :panels, :id => @other_author.id, :format => :json
849         end
850         it 'データがリスト構造になっている' do
851           get :panels, :id => @other_author.id, :format => :json
852           json = JSON.parse response.body
853           json.should have_at_least(3).items
854         end
855         it 'リストの先頭くらいはコマっぽいものであって欲しい' do
856           get :panels, :id => @other_author.id, :format => :json
857           json = JSON.parse response.body
858           json.first.has_key?("z").should be_true
859         end
860       end
861     end
862     context 'ユーザ権限がないとき' do
863       before do
864         sign_out @user
865       end
866       context 'html形式' do
867         it 'ステータスコード302 Foundを返す' do
868           get :panels, :id => @other_author.id
869           response.status.should eq 302
870         end
871         it 'サインインページへ遷移する' do
872           get :panels, :id => @other_author.id
873           response.should redirect_to '/users/sign_in'
874         end
875       end
876       context 'json形式' do
877         it 'ステータスコード401 Unauthorizedを返す' do
878           get :panels, :id => @other_author.id, :format => :json
879           response.status.should eq 401
880         end
881         it '応答メッセージにUnauthorizedを返す' do
882           get :panels, :id => @other_author.id, :format => :json
883           response.message.should match(/Unauthorized/)
884         end
885       end
886     end
887     context 'ユーザ権限はないが管理者権限があるとき' do
888       before do
889         sign_out @user
890         sign_in @admin
891       end
892       it 'ステータスコード200 OKを返す' do
893         get :panels, :id => @other_author.id
894         response.should be_success 
895       end
896     end
897     context 'ユーザだが作家登録していないとき' do
898       before do
899         @author.destroy
900       end
901       it 'ステータスコード200 OKを返す' do
902         get :panels, :id => @other_author.id
903         response.should be_success 
904       end
905     end
906   end
907   
908   describe '対象作家のコマ絵一覧表示に於いて' do
909     before do
910       @other_user = FactoryGirl.create( :user_yas)
911       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
912       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
913       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
914       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
915       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
916       @panel = FactoryGirl.create :panel, :author_id => @author.id
917       @panel_picture = FactoryGirl.create :panel_picture, :picture_id => @p.id, :panel_id => @panel.id, :width => @p.width, :height => @p.height
918       Author.stub(:show).and_return(@other_author)
919       PanelPicture.stub(:himlist).and_return([@panel_picture, @panel_picture, @panel_picture])
920       sign_in @user
921     end
922     context 'パラメータpageについて' do
923       it '@pageに値が入る' do
924         get :panel_pictures, :id => @other_author.id, :page => 5
925         assigns(:page).should eq 5
926       end
927       it '省略されると@pageに1値が入る' do
928         get :panel_pictures, :id => @other_author.id
929         assigns(:page).should eq 1
930       end
931       it '与えられたpage_sizeがセットされている' do
932         get :panel_pictures, :id => @other_author.id, :page_size => 15
933         assigns(:page_size).should eq 15
934       end
935       it '省略されると@page_sizeにデフォルト値が入る' do
936         get :panel_pictures, :id => @other_author.id
937         assigns(:page_size).should eq Author.default_panel_picture_page_size
938       end
939       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
940         get :panel_pictures, :id => @other_author.id, :page_size => 1500
941         assigns(:page_size).should eq Author.panel_picture_max_page_size
942       end
943       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
944         get :panel_pictures, :id => @other_author.id, :page_size => 0
945         assigns(:page_size).should eq Author.default_panel_picture_page_size
946       end
947     end
948     context 'つつがなく終わるとき' do
949       it 'ステータスコード200 OKを返す' do
950         get :panel_pictures, :id => @other_author.id
951         response.should be_success 
952       end
953       it '作家モデルに単体取得を問い合わせている' do
954         Author.should_receive(:show).exactly(1)
955         get :panel_pictures, :id => @other_author.id
956       end
957       it 'コマ絵モデルに他作家のコマ絵一覧を問い合わせている' do
958         PanelPicture.should_receive(:himlist).exactly(1)
959         get :panel_pictures, :id => @other_author.id
960       end
961       it '@panel_picturesにリストを取得している' do
962         get :panel_pictures, :id => @other_author.id
963         assigns(:panel_pictures).should have_at_least(3).items
964       end
965       context 'html形式' do
966         it '@paginateにページ制御を取得している' do
967           get :panel_pictures, :id => @other_author.id
968           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
969         end
970         it 'panel_picturesテンプレートを描画する' do
971           get :panel_pictures, :id => @other_author.id
972           response.should render_template("panel_pictures")
973         end
974       end
975       context 'json形式' do
976         it 'jsonデータを返す' do
977           get :panel_pictures, :id => @other_author.id, :format => :json
978           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
979         end
980         it 'コマ絵モデルにjson一覧出力オプションを問い合わせている' do
981           PanelPicture.should_receive(:list_json_opt).exactly(1)
982           get :panel_pictures, :id => @other_author.id, :format => :json
983         end
984         it 'データがリスト構造になっている' do
985           get :panel_pictures, :id => @other_author.id, :format => :json
986           json = JSON.parse response.body
987           json.should have_at_least(3).items
988         end
989         it 'リストの先頭くらいはコマ絵っぽいものであって欲しい' do
990           get :panel_pictures, :id => @other_author.id, :format => :json
991           json = JSON.parse response.body
992           json.first.has_key?("link").should be_true
993           json.first.has_key?("x").should be_true
994           json.first.has_key?("y").should be_true
995         end
996       end
997     end
998     context 'ユーザ権限がないとき' do
999       before do
1000         sign_out @user
1001       end
1002       context 'html形式' do
1003         it 'ステータスコード302 Foundを返す' do
1004           get :panel_pictures, :id => @other_author.id
1005           response.status.should eq 302
1006         end
1007         it 'サインインページへ遷移する' do
1008           get :panel_pictures, :id => @other_author.id
1009           response.should redirect_to '/users/sign_in'
1010         end
1011       end
1012       context 'json形式' do
1013         it 'ステータスコード401 Unauthorizedを返す' do
1014           get :panel_pictures, :id => @other_author.id, :format => :json
1015           response.status.should eq 401
1016         end
1017         it '応答メッセージにUnauthorizedを返す' do
1018           get :panel_pictures, :id => @other_author.id, :format => :json
1019           response.message.should match(/Unauthorized/)
1020         end
1021       end
1022     end
1023     context 'ユーザ権限はないが管理者権限があるとき' do
1024       before do
1025         sign_out @user
1026         sign_in @admin
1027       end
1028       it 'ステータスコード200 OKを返す' do
1029         get :panel_pictures, :id => @other_author.id
1030         response.should be_success 
1031       end
1032     end
1033     context 'ユーザだが作家登録していないとき' do
1034       before do
1035         @author.destroy
1036       end
1037       it 'ステータスコード200 OKを返す' do
1038         get :panel_pictures, :id => @other_author.id
1039         response.should be_success 
1040       end
1041     end
1042   end
1043   
1044   describe '対象作家のフキダシ一覧表示に於いて' do
1045     before do
1046       @other_user = FactoryGirl.create( :user_yas)
1047       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1048       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1049       @panel = FactoryGirl.create :panel, :author_id => @other_author.id
1050       @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
1051       @speech = @sb.build_speech(
1052         FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
1053       )
1054       @balloon = @sb.build_balloon(
1055         FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
1056       )
1057       @sb.boost
1058       @sb.save!
1059       Author.stub(:show).and_return(@other_author)
1060       SpeechBalloon.stub(:himlist).and_return([@sb, @sb, @sb])
1061       sign_in @user
1062     end
1063     context 'パラメータpageについて' do
1064       it '@pageに値が入る' do
1065         get :speech_balloons, :id => @other_author.id, :page => 5
1066         assigns(:page).should eq 5
1067       end
1068       it '省略されると@pageに1値が入る' do
1069         get :speech_balloons, :id => @other_author.id
1070         assigns(:page).should eq 1
1071       end
1072       it '与えられたpage_sizeがセットされている' do
1073         get :speech_balloons, :id => @other_author.id, :page_size => 15
1074         assigns(:page_size).should eq 15
1075       end
1076       it '省略されると@page_sizeにデフォルト値が入る' do
1077         get :speech_balloons, :id => @other_author.id
1078         assigns(:page_size).should eq Author.default_speech_balloon_page_size
1079       end
1080       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
1081         get :speech_balloons, :id => @other_author.id, :page_size => 1500
1082         assigns(:page_size).should eq Author.speech_balloon_max_page_size
1083       end
1084       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
1085         get :speech_balloons, :id => @other_author.id, :page_size => 0
1086         assigns(:page_size).should eq Author.default_speech_balloon_page_size
1087       end
1088     end
1089     context 'つつがなく終わるとき' do
1090       it 'ステータスコード200 OKを返す' do
1091         get :speech_balloons, :id => @other_author.id
1092         response.should be_success 
1093       end
1094       it '作家モデルに単体取得を問い合わせている' do
1095         Author.should_receive(:show).exactly(1)
1096         get :speech_balloons, :id => @other_author.id
1097       end
1098       it 'フキダシモデルに他作家のフキダシ一覧を問い合わせている' do
1099         SpeechBalloon.should_receive(:himlist).exactly(1)
1100         get :speech_balloons, :id => @other_author.id
1101       end
1102       it '@speech_balloonsにリストを取得している' do
1103         get :speech_balloons, :id => @other_author.id
1104         assigns(:speech_balloons).should have_at_least(3).items
1105       end
1106       context 'html形式' do
1107         it '@paginateにページ制御を取得している' do
1108           get :speech_balloons, :id => @other_author.id
1109           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
1110         end
1111         it 'speech_balloonsテンプレートを描画する' do
1112           get :speech_balloons, :id => @other_author.id
1113           response.should render_template("speech_balloons")
1114         end
1115       end
1116       context 'json形式' do
1117         it 'jsonデータを返す' do
1118           get :speech_balloons, :id => @other_author.id, :format => :json
1119           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1120         end
1121         it 'フキダシモデルにjson一覧出力オプションを問い合わせている' do
1122           SpeechBalloon.should_receive(:list_json_opt).exactly(1)
1123           get :speech_balloons, :id => @other_author.id, :format => :json
1124         end
1125         it 'データがリスト構造になっている' do
1126           get :speech_balloons, :id => @other_author.id, :format => :json
1127           json = JSON.parse response.body
1128           json.should have_at_least(3).items
1129         end
1130         it 'リストの先頭くらいはフキダシっぽいものであって欲しい' do
1131           get :speech_balloons, :id => @other_author.id, :format => :json
1132           json = JSON.parse response.body
1133           json.first.has_key?("speech_balloon_template_id").should be_true
1134           json.first.has_key?("z").should be_true
1135           json.first.has_key?("t").should be_true
1136         end
1137       end
1138     end
1139     context 'ユーザ権限がないとき' do
1140       before do
1141         sign_out @user
1142       end
1143       context 'html形式' do
1144         it 'ステータスコード302 Foundを返す' do
1145           get :speech_balloons, :id => @other_author.id
1146           response.status.should eq 302
1147         end
1148         it 'サインインページへ遷移する' do
1149           get :speech_balloons, :id => @other_author.id
1150           response.should redirect_to '/users/sign_in'
1151         end
1152       end
1153       context 'json形式' do
1154         it 'ステータスコード401 Unauthorizedを返す' do
1155           get :speech_balloons, :id => @other_author.id, :format => :json
1156           response.status.should eq 401
1157         end
1158         it '応答メッセージにUnauthorizedを返す' do
1159           get :speech_balloons, :id => @other_author.id, :format => :json
1160           response.message.should match(/Unauthorized/)
1161         end
1162       end
1163     end
1164     context 'ユーザ権限はないが管理者権限があるとき' do
1165       before do
1166         sign_out @user
1167         sign_in @admin
1168       end
1169       it 'ステータスコード200 OKを返す' do
1170         get :speech_balloons, :id => @other_author.id
1171         response.should be_success 
1172       end
1173     end
1174     context 'ユーザだが作家登録していないとき' do
1175       before do
1176         @author.destroy
1177       end
1178       it 'ステータスコード200 OKを返す' do
1179         get :speech_balloons, :id => @other_author.id
1180         response.should be_success 
1181       end
1182     end
1183   end
1184   
1185   describe '対象作家の絵地一覧表示に於いて' do
1186     before do
1187       @other_user = FactoryGirl.create( :user_yas)
1188       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1189       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1190       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1191       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
1192       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
1193       @panel = FactoryGirl.create :panel, :author_id => @author.id
1194       @ground_picture = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
1195       Author.stub(:show).and_return(@other_author)
1196       GroundPicture.stub(:himlist).and_return([@ground_picture, @ground_picture, @ground_picture])
1197       sign_in @user
1198     end
1199     context 'パラメータpageについて' do
1200       it '@pageに値が入る' do
1201         get :ground_pictures, :id => @other_author.id, :page => 5
1202         assigns(:page).should eq 5
1203       end
1204       it '省略されると@pageに1値が入る' do
1205         get :ground_pictures, :id => @other_author.id
1206         assigns(:page).should eq 1
1207       end
1208       it '与えられたpage_sizeがセットされている' do
1209         get :ground_pictures, :id => @other_author.id, :page_size => 15
1210         assigns(:page_size).should eq 15
1211       end
1212       it '省略されると@page_sizeにデフォルト値が入る' do
1213         get :ground_pictures, :id => @other_author.id
1214         assigns(:page_size).should eq Author.default_ground_picture_page_size
1215       end
1216       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
1217         get :ground_pictures, :id => @other_author.id, :page_size => 1500
1218         assigns(:page_size).should eq Author.ground_picture_max_page_size
1219       end
1220       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
1221         get :ground_pictures, :id => @other_author.id, :page_size => 0
1222         assigns(:page_size).should eq Author.default_ground_picture_page_size
1223       end
1224     end
1225     context 'つつがなく終わるとき' do
1226       it 'ステータスコード200 OKを返す' do
1227         get :ground_pictures, :id => @other_author.id
1228         response.should be_success 
1229       end
1230       it '作家モデルに単体取得を問い合わせている' do
1231         Author.should_receive(:show).exactly(1)
1232         get :ground_pictures, :id => @other_author.id
1233       end
1234       it '絵地モデルに他作家の絵地一覧を問い合わせている' do
1235         GroundPicture.should_receive(:himlist).exactly(1)
1236         get :ground_pictures, :id => @other_author.id
1237       end
1238       it '@ground_picturesにリストを取得している' do
1239         get :ground_pictures, :id => @other_author.id
1240         assigns(:ground_pictures).should have_at_least(3).items
1241       end
1242       context 'html形式' do
1243         it '@paginateにページ制御を取得している' do
1244           get :ground_pictures, :id => @other_author.id
1245           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
1246         end
1247         it 'ground_picturesテンプレートを描画する' do
1248           get :ground_pictures, :id => @other_author.id
1249           response.should render_template("ground_pictures")
1250         end
1251       end
1252       context 'json形式' do
1253         it 'jsonデータを返す' do
1254           get :ground_pictures, :id => @other_author.id, :format => :json
1255           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1256         end
1257         it '絵地モデルにjson一覧出力オプションを問い合わせている' do
1258           GroundPicture.should_receive(:list_json_opt).exactly(1)
1259           get :ground_pictures, :id => @other_author.id, :format => :json
1260         end
1261         it 'データがリスト構造になっている' do
1262           get :ground_pictures, :id => @other_author.id, :format => :json
1263           json = JSON.parse response.body
1264           json.should have_at_least(3).items
1265         end
1266         it 'リストの先頭くらいは絵地っぽいものであって欲しい' do
1267           get :ground_pictures, :id => @other_author.id, :format => :json
1268           json = JSON.parse response.body
1269           json.first.has_key?("panel_id").should be_true
1270           json.first.has_key?("picture_id").should be_true
1271           json.first.has_key?("z").should be_true
1272         end
1273       end
1274     end
1275     context 'ユーザ権限がないとき' do
1276       before do
1277         sign_out @user
1278       end
1279       context 'html形式' do
1280         it 'ステータスコード302 Foundを返す' do
1281           get :ground_pictures, :id => @other_author.id
1282           response.status.should eq 302
1283         end
1284         it 'サインインページへ遷移する' do
1285           get :ground_pictures, :id => @other_author.id
1286           response.should redirect_to '/users/sign_in'
1287         end
1288       end
1289       context 'json形式' do
1290         it 'ステータスコード401 Unauthorizedを返す' do
1291           get :ground_pictures, :id => @other_author.id, :format => :json
1292           response.status.should eq 401
1293         end
1294         it '応答メッセージにUnauthorizedを返す' do
1295           get :ground_pictures, :id => @other_author.id, :format => :json
1296           response.message.should match(/Unauthorized/)
1297         end
1298       end
1299     end
1300     context 'ユーザ権限はないが管理者権限があるとき' do
1301       before do
1302         sign_out @user
1303         sign_in @admin
1304       end
1305       it 'ステータスコード200 OKを返す' do
1306         get :ground_pictures, :id => @other_author.id
1307         response.should be_success 
1308       end
1309     end
1310     context 'ユーザだが作家登録していないとき' do
1311       before do
1312         @author.destroy
1313       end
1314       it 'ステータスコード200 OKを返す' do
1315         get :ground_pictures, :id => @other_author.id
1316         response.should be_success 
1317       end
1318     end
1319   end
1320   
1321   describe '対象作家の色地一覧表示に於いて' do
1322     before do
1323       @other_user = FactoryGirl.create( :user_yas)
1324       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1325       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1326       @gc = FactoryGirl.create :ground_color
1327       @panel = FactoryGirl.create :panel, :author_id => @author.id
1328       Author.stub(:show).and_return(@other_author)
1329       GroundColor.stub(:himlist).and_return([@gc, @gc, @gc])
1330       sign_in @user
1331     end
1332     context 'パラメータpageについて' do
1333       it '@pageに値が入る' do
1334         get :ground_colors, :id => @other_author.id, :page => 5
1335         assigns(:page).should eq 5
1336       end
1337       it '省略されると@pageに1値が入る' do
1338         get :ground_colors, :id => @other_author.id
1339         assigns(:page).should eq 1
1340       end
1341       it '与えられたpage_sizeがセットされている' do
1342         get :ground_colors, :id => @other_author.id, :page_size => 15
1343         assigns(:page_size).should eq 15
1344       end
1345       it '省略されると@page_sizeにデフォルト値が入る' do
1346         get :ground_colors, :id => @other_author.id
1347         assigns(:page_size).should eq Author.default_ground_color_page_size
1348       end
1349       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
1350         get :ground_colors, :id => @other_author.id, :page_size => 1500
1351         assigns(:page_size).should eq Author.ground_color_max_page_size
1352       end
1353       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
1354         get :ground_colors, :id => @other_author.id, :page_size => 0
1355         assigns(:page_size).should eq Author.ground_color_page_size
1356       end
1357     end
1358     context 'つつがなく終わるとき' do
1359       it 'ステータスコード200 OKを返す' do
1360         get :ground_colors, :id => @other_author.id
1361         response.should be_success 
1362       end
1363       it '作家モデルに単体取得を問い合わせている' do
1364         Author.should_receive(:show).exactly(1)
1365         get :ground_colors, :id => @other_author.id
1366       end
1367       it '色地モデルに他作家の色地一覧を問い合わせている' do
1368         GroundColor.should_receive(:himlist).exactly(1)
1369         get :ground_colors, :id => @other_author.id
1370       end
1371       it '@ground_colorsにリストを取得している' do
1372         get :ground_colors, :id => @other_author.id
1373         assigns(:ground_colors).should have_at_least(3).items
1374       end
1375       context 'html形式' do
1376         it '@paginateにページ制御を取得している' do
1377           get :ground_colors, :id => @other_author.id
1378           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
1379         end
1380         it 'ground_colorsテンプレートを描画する' do
1381           get :ground_colors, :id => @other_author.id
1382           response.should render_template("ground_colors")
1383         end
1384       end
1385       context 'json形式' do
1386         it 'jsonデータを返す' do
1387           get :ground_colors, :id => @other_author.id, :format => :json
1388           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1389         end
1390         it '色地モデルにjson一覧出力オプションを問い合わせている' do
1391           GroundColor.should_receive(:list_json_opt).exactly(1)
1392           get :ground_colors, :id => @other_author.id, :format => :json
1393         end
1394         it 'データがリスト構造になっている' do
1395           get :ground_colors, :id => @other_author.id, :format => :json
1396           json = JSON.parse response.body
1397           json.should have_at_least(3).items
1398         end
1399         it 'リストの先頭くらいは色地っぽいものであって欲しい' do
1400           get :ground_colors, :id => @other_author.id, :format => :json
1401           json = JSON.parse response.body
1402           json.first.has_key?("panel_id").should be_true
1403           json.first.has_key?("code").should be_true
1404           json.first.has_key?("z").should be_true
1405         end
1406       end
1407     end
1408     context 'ユーザ権限がないとき' do
1409       before do
1410         sign_out @user
1411       end
1412       context 'html形式' do
1413         it 'ステータスコード302 Foundを返す' do
1414           get :ground_colors, :id => @other_author.id
1415           response.status.should eq 302
1416         end
1417         it 'サインインページへ遷移する' do
1418           get :ground_colors, :id => @other_author.id
1419           response.should redirect_to '/users/sign_in'
1420         end
1421       end
1422       context 'json形式' do
1423         it 'ステータスコード401 Unauthorizedを返す' do
1424           get :ground_colors, :id => @other_author.id, :format => :json
1425           response.status.should eq 401
1426         end
1427         it '応答メッセージにUnauthorizedを返す' do
1428           get :ground_colors, :id => @other_author.id, :format => :json
1429           response.message.should match(/Unauthorized/)
1430         end
1431       end
1432     end
1433     context 'ユーザ権限はないが管理者権限があるとき' do
1434       before do
1435         sign_out @user
1436         sign_in @admin
1437       end
1438       it 'ステータスコード200 OKを返す' do
1439         get :ground_colors, :id => @other_author.id
1440         response.should be_success 
1441       end
1442     end
1443     context 'ユーザだが作家登録していないとき' do
1444       before do
1445         @author.destroy
1446       end
1447       it 'ステータスコード200 OKを返す' do
1448         get :ground_colors, :id => @other_author.id
1449         response.should be_success 
1450       end
1451     end
1452   end
1453   
1454   describe '作家数取得に於いて' do
1455     before do
1456       Author.should_receive(:visible_count).and_return(3)
1457 #      sign_in @user
1458     end
1459     context 'つつがなく終わるとき' do
1460       it 'ステータスコード200 OKを返す' do
1461         get :count, :format => :json
1462         response.should be_success 
1463       end
1464       context 'json形式' do
1465         it 'jsonデータを返す' do
1466           get :count, :format => :json
1467           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1468         end
1469         it 'データがHash構造になっていて作家数が3である' do
1470           get :count, :format => :json
1471           json = JSON.parse response.body
1472           json["count"].should == 3
1473         end
1474       end
1475     end
1476   end
1477   
1478   describe '新規作成フォーム表示に於いて' do
1479     before do
1480       @new_user = FactoryGirl.create( :user_yas)
1481       sign_in @new_user
1482     end
1483     context 'つつがなく終わるとき' do
1484       it 'ステータスコード200 OKを返す' do
1485         get :new
1486         response.should be_success 
1487       end
1488       it '@auに新規データを用意している' do
1489         get :new
1490         assigns(:au).should be_a_new(Author)
1491       end
1492       it '作家モデルにデフォルト値補充を依頼している' do
1493         Author.any_instance.should_receive(:supply_default).exactly(1)
1494         get :new
1495       end
1496       context 'html形式' do
1497         it 'newテンプレートを描画する' do
1498           get :new
1499           response.should render_template("new")
1500         end
1501       end
1502       context 'js形式' do
1503         it 'new.jsテンプレートを描画する' do
1504           get :new, :format => :js
1505           response.should render_template("new")
1506         end
1507       end
1508       context 'json形式' do
1509         it 'jsonデータを返す' do
1510           get :new, :format => :json
1511           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1512         end
1513         it '作家モデルにjson単体出力オプションを問い合わせている' do
1514           Author.should_receive(:show_json_opt).exactly(1)
1515           get :new, :format => :json
1516         end
1517       end
1518     end
1519     context 'ユーザ権限がないとき' do
1520       before do
1521         sign_out @new_user
1522       end
1523       context 'html形式' do
1524         it 'ステータスコード302 Foundを返す' do
1525           get :new
1526           response.status.should eq 302
1527         end
1528         it 'サインインページへ遷移する' do
1529           get :new
1530           response.body.should redirect_to '/users/sign_in'
1531         end
1532       end
1533       context 'js形式' do
1534         it 'ステータスコード401 Unauthorizedを返す' do
1535           get :new, :format => :js
1536           response.status.should eq 401
1537         end
1538         it '応答メッセージにUnauthorizedを返す' do
1539           get :new, :format => :js
1540           response.message.should match(/Unauthorized/)
1541         end
1542       end
1543       context 'json形式' do
1544         it 'ステータスコード401 Unauthorizedを返す' do
1545           get :new, :format => :json
1546           response.status.should eq 401
1547         end
1548         it '応答メッセージにUnauthorizedを返す' do
1549           get :new, :format => :json
1550           response.message.should match(/Unauthorized/)
1551         end
1552       end
1553     end
1554     context 'ユーザ権限はないが管理者権限があるとき' do
1555       before do
1556         sign_out @user
1557         sign_in @admin
1558       end
1559       context 'html形式' do
1560         it 'ステータスコード302 Foundを返す' do
1561           get :new
1562           response.status.should eq 302
1563         end
1564         it 'サインインページへ遷移する' do
1565           get :new
1566           response.body.should redirect_to '/users/sign_in'
1567         end
1568       end
1569     end
1570     context 'ユーザだが作家登録していないとき' do
1571       before do
1572         @author.destroy
1573       end
1574       it 'ステータスコード200 OKを返す' do
1575           get :new
1576         response.should be_success 
1577       end
1578     end
1579   end
1580
1581   describe '新規作成に於いて' do
1582     before do
1583       @new_user = FactoryGirl.create( :user_yas)
1584       sign_in @new_user
1585       @attr = FactoryGirl.attributes_for(:author, :user_id => @new_user.id, :name => 'ken')
1586     end
1587     context '事前チェックしておく' do
1588       it '作家モデルにデフォルト値補充を依頼している' do
1589         Author.any_instance.should_receive(:supply_default).exactly(1)
1590         post :create, :author => @attr
1591       end
1592       it '作家モデルにカラム値復元を依頼している' do
1593         Author.any_instance.should_receive(:attributes=).exactly(1)
1594         post :create, :author => @attr
1595       end
1596       it '作家モデルに上書き補充を依頼している' do
1597         Author.any_instance.should_receive(:overwrite).exactly(1)
1598         post :create, :author => @attr
1599       end
1600       it 'モデルに保存依頼する' do
1601         Author.any_instance.should_receive(:save).exactly(1)
1602         post :create, :author => @attr
1603       end
1604     end
1605     context 'つつがなく終わるとき' do
1606       it "@auに作成された作家を保持していて、それがDBにある" do
1607         post :create, :author => @attr
1608         assigns(:au).should be_a(Author)
1609         assigns(:au).should be_persisted
1610       end
1611       context 'html形式' do
1612         it 'ステータスコード302 Foundを返す' do
1613           Author.any_instance.stub(:save).and_return(true)
1614           post :create, :author => @attr
1615           response.status.should eq 302
1616         end
1617         it 'トップページへ遷移する' do
1618 #          Author.any_instance.stub(:save).and_return(true)
1619           post :create, :author => @attr
1620           response.should redirect_to(root_path)
1621         end
1622       end
1623       context 'json形式' do
1624         it 'ステータスコード200 OKを返す' do
1625 #          Author.any_instance.stub(:save).and_return(true)
1626           post :create, :author => @attr, :format => :json
1627           response.should be_success 
1628         end
1629         it '作成された作家をjsonデータで返す' do
1630           post :create, :author => @attr, :format => :json
1631           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1632         end
1633         it '作家モデルにjson単体出力オプションを問い合わせている' do
1634           Author.should_receive(:show_json_opt).exactly(1)
1635           post :create, :author => @attr, :format => :json
1636         end
1637         it 'データがアレになっている' do
1638           post :create, :author => @attr, :format => :json
1639           json = JSON.parse response.body
1640           json["name"].should match(/ken/)
1641         end
1642       end
1643     end
1644     context 'ユーザ権限がないとき' do
1645       before do
1646         sign_out @new_user
1647       end
1648       context 'html形式' do
1649         it 'ステータスコード302 Foundを返す' do
1650           post :create, :author => @attr
1651           response.status.should eq 302
1652         end
1653         it 'サインインページへ遷移する' do
1654           post :create, :author => @attr
1655           response.body.should redirect_to '/users/sign_in'
1656         end
1657       end
1658       context 'json形式' do
1659         it 'ステータスコード401 Unauthorizedを返す' do
1660           post :create, :author => @attr, :format => :json
1661           response.status.should eq 401
1662         end
1663         it '応答メッセージにUnauthorizedを返す' do
1664           post :create, :author => @attr, :format => :json
1665           response.message.should match(/Unauthorized/)
1666         end
1667       end
1668     end
1669     context 'ユーザ権限はないが管理者権限があるとき' do
1670       before do
1671         sign_out @user
1672         sign_in @admin
1673       end
1674       context 'html形式' do
1675         it 'ステータスコード302 Foundを返す' do
1676           post :create, :author => @attr
1677           response.status.should eq 302
1678         end
1679         it 'サインインページへ遷移する' do
1680           post :create, :author => @attr
1681           response.body.should redirect_to '/users/sign_in'
1682         end
1683       end
1684     end
1685     context '検証、保存に失敗した' do
1686       before do
1687         Author.any_instance.stub(:save).and_return(false)
1688       end
1689       it "未保存の作家を保持している" do
1690         post :create, :author => @attr
1691         assigns(:au).should be_a_new(Author)
1692       end
1693       context 'html形式' do
1694         it 'ステータスコード200 OKを返す' do
1695           post :create, :author => @attr
1696           response.status.should eq 200
1697         end
1698         it '新規ページを描画する' do
1699           post :create, :author => @attr
1700           response.should render_template("new")
1701         end
1702       end
1703       context 'json形式' do
1704         it 'ステータスコード422 unprocessable_entity を返す' do
1705           post :create, :author => @attr, :format => :json
1706           response.status.should eq 422
1707         end
1708         it '応答メッセージUnprocessable Entityを返す' do
1709           post :create, :author => @attr, :format => :json
1710           response.message.should match(/Unprocessable/)
1711         end
1712       end
1713     end
1714   end
1715
1716   describe '編集フォーム表示に於いて' do
1717     before do
1718       sign_in @user
1719       Author.stub(:edit).and_return(@author)
1720     end
1721     context 'つつがなく終わるとき' do
1722       it 'ステータスコード200 OKを返す' do
1723         get :edit, :id => @author.id
1724         response.should be_success 
1725       end
1726       it '作家モデルに編集取得を問い合わせている' do
1727         Author.should_receive(:edit).exactly(1)
1728         get :edit, :id => @author.id
1729       end
1730       #@authorだとログイン中のアカウントと干渉してしまう。
1731       it '@auにデータを用意している' do
1732         get :edit, :id => @author.id
1733         assigns(:au).should eq @author
1734       end
1735       context 'html形式' do
1736         it 'editテンプレートを描画する' do
1737           get :edit, :id => @author.id
1738           response.should render_template("edit")
1739         end
1740       end
1741       context 'js形式' do
1742         it 'edit.jsテンプレートを描画する' do
1743           get :edit, :id => @author.id, :format => :js
1744           response.should render_template("edit")
1745         end
1746       end
1747     end
1748     context 'ユーザ権限がないとき' do
1749       before do
1750         sign_out @user
1751       end
1752       context 'html形式' do
1753         it 'ステータスコード302 Foundを返す' do
1754           get :edit, :id => @author.id
1755           response.status.should eq 302
1756         end
1757         it 'サインインページへ遷移する' do
1758           get :edit, :id => @author.id
1759           response.body.should redirect_to '/users/sign_in'
1760         end
1761       end
1762       context 'js形式' do
1763         it 'ステータスコード401 Unauthorizedを返す' do
1764           get :edit, :id => @author.id, :format => :js
1765           response.status.should eq 401
1766         end
1767         it '応答メッセージにUnauthorizedを返す' do
1768           get :edit, :id => @author.id, :format => :js
1769           response.message.should match(/Unauthorized/)
1770         end
1771       end
1772     end
1773     context 'ユーザ権限はないが管理者権限があるとき' do
1774       before do
1775         sign_out @user
1776         sign_in @admin
1777       end
1778       context 'html形式' do
1779         it 'ステータスコード302 Foundを返す' do
1780           get :edit, :id => @author.id
1781           response.status.should eq 302
1782         end
1783         it 'サインインページへ遷移する' do
1784           get :edit, :id => @author.id
1785           response.body.should redirect_to '/users/sign_in'
1786         end
1787       end
1788     end
1789     context 'ユーザだが作家登録していないとき' do
1790       before do
1791         @other_user = FactoryGirl.create( :user_yas)
1792         @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1793         @author.destroy
1794       end
1795       context 'html形式' do
1796         it 'ステータスコード302 Foundを返す' do
1797           get :edit, :id => @other_author.id
1798           response.status.should eq 302
1799         end
1800         it '作家登録ページへ遷移する' do
1801           get :edit, :id => @other_author.id
1802           response.body.should redirect_to new_author_path
1803         end
1804       end
1805     end
1806   end
1807
1808   describe '更新に於いて' do
1809     before do
1810       @attr = @author.attributes
1811       @attr['name'] = 'ryu'
1812       sign_in @user
1813     end
1814     context '事前チェックしておく' do
1815       it '作家モデルに編集取得を問い合わせている' do
1816         Author.stub(:edit).with(any_args()).and_return @author
1817         Author.should_receive(:edit).exactly(1)
1818         put :update, :id => @author.id, :author => @attr
1819       end
1820       it 'モデルにpostデータ転送を依頼する' do
1821         Author.any_instance.stub(:attributes=).with(any_args)
1822         Author.any_instance.should_receive(:attributes=).exactly(1)
1823         put :update, :id => @author.id, :author => @attr
1824       end
1825       it 'モデルに上書き補充を依頼する' do
1826         Author.any_instance.stub(:overwrite).with(any_args)
1827         Author.any_instance.should_receive(:overwrite).exactly(1)
1828         put :update, :id => @author.id, :author => @attr
1829       end
1830       it 'モデルに更新を依頼する' do
1831         Author.any_instance.stub(:save).with(any_args).and_return true
1832         Author.any_instance.should_receive(:save).exactly(1)
1833         put :update, :id => @author.id, :author => @attr
1834       end
1835       it '@auにアレを取得している' do
1836         put :update, :id => @author.id, :author => @attr
1837         assigns(:au).should eq @author
1838       end
1839     end
1840     context 'つつがなく終わるとき' do
1841       it '更新される' do
1842         put :update, :id => @author.id, :author => @attr
1843         Author.find(@author.id).name.should eq 'ryu'
1844       end
1845       context 'html形式' do
1846         it 'ステータスコード302 Foundを返す' do
1847           Author.any_instance.stub(:save).with(any_args()).and_return(true)
1848           put :update, :id => @author.id, :author => @attr
1849           response.status.should eq 302
1850         end
1851         it '設定ページへ遷移する' do
1852           put :update, :id => @author.id, :author => @attr
1853           response.should redirect_to('/home/configure')
1854         end
1855       end
1856       context 'json形式' do
1857         it 'ステータスコード200 OKを返す' do
1858           Author.any_instance.stub(:save).with(any_args()).and_return(true)
1859           put :update, :id => @author.id, :author => @attr, :format => :json
1860           response.should be_success 
1861         end
1862         it 'ページ本体は特に返さない' do
1863           Author.any_instance.stub(:save).with(any_args()).and_return(true)
1864           put :update, :id => @author.id, :author => @attr, :format => :json
1865           response.body.should match /./
1866         end
1867       end
1868     end
1869     context 'ユーザ権限がないとき' do
1870       before do
1871         sign_out @user
1872       end
1873       context 'html形式' do
1874         it 'ステータスコード302 Foundを返す' do
1875           put :update, :id => @author.id, :author => @attr
1876           response.status.should eq 302
1877         end
1878         it 'サインインページへ遷移する' do
1879           put :update, :id => @author.id, :author => @attr
1880           response.body.should redirect_to '/users/sign_in'
1881         end
1882       end
1883       context 'json形式' do
1884         it '応答メッセージにUnauthorizedを返す' do
1885           put :update, :id => @author.id, :author => @attr, :format => :json
1886           response.message.should match(/Unauthorized/)
1887         end
1888       end
1889     end
1890     context 'ユーザ権限はないが管理者権限があるとき' do
1891       before do
1892         sign_out @user
1893         sign_in @admin
1894       end
1895       context 'html形式' do
1896         it 'ステータスコード302 Foundを返す' do
1897           put :update, :id => @author.id, :author => @attr
1898           response.status.should eq 302
1899         end
1900         it 'サインインページへ遷移する' do
1901           put :update, :id => @author.id, :author => @attr
1902           response.body.should redirect_to '/users/sign_in'
1903         end
1904       end
1905     end
1906     context 'ユーザだが作家登録していないとき' do
1907       before do
1908         @other_user = FactoryGirl.create( :user_yas)
1909         @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1910         @author.destroy
1911       end
1912       context 'html形式' do
1913         it 'ステータスコード302 Foundを返す' do
1914           get :update, :id => @other_author.id
1915           response.status.should eq 302
1916         end
1917         it '作家登録ページへ遷移する' do
1918           get :update, :id => @other_author.id
1919           response.body.should redirect_to new_author_path
1920         end
1921       end
1922     end
1923     context '検証、保存に失敗したとき' do
1924       before do
1925         Author.any_instance.stub(:save).and_return(false)
1926       end
1927       context 'html形式' do
1928         it 'ステータスコード200 Okを返す' do
1929           put :update, :id => @author.id, :author => @attr
1930           response.status.should eq 200
1931         end
1932         it '編集ページを描画する' do
1933           put :update, :id => @author.id, :author => @attr
1934           response.should render_template("edit")
1935         end
1936       end
1937       context 'json形式' do
1938         it 'ステータスコード422 unprocessable_entity を返す' do
1939           Author.any_instance.stub(:save).and_return(false)
1940           put :update, :id => @author.id, :author => @attr, :format => :json
1941           response.status.should eq 422
1942         end
1943         it '応答メッセージUnprocessable Entityを返す' do
1944           put :update, :id => @author.id, :author => @attr, :format => :json
1945           response.message.should match(/Unprocessable/)
1946         end
1947       end
1948     end
1949   end
1950
1951 else
1952   describe '一覧表示に於いて' do
1953     before do
1954       Author.stub(:list).and_return([@author, @author, @author])
1955       sign_in @user
1956     end
1957     context 'つつがなく終わるとき' do
1958       it 'ステータスコード200 OKを返す' do
1959         get :index
1960         response.should be_success 
1961       end
1962       context 'html形式' do
1963         it 'indexテンプレートを描画する' do
1964           get :index
1965           response.should render_template("index")
1966         end
1967       end
1968       context 'json形式' do
1969         it 'jsonデータを返す' do
1970           get :index, :format => :json
1971           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1972         end
1973       end
1974     end
1975     context 'ユーザ権限がないとき' do
1976       before do
1977         sign_out @user
1978       end
1979       it 'ステータスコード200 OKを返す' do
1980         get :index
1981         response.should be_success 
1982       end
1983       context 'html形式' do
1984         it 'indexテンプレートを描画する' do
1985           get :index
1986           response.should render_template("index")
1987         end
1988       end
1989       context 'json形式' do
1990         it 'jsonデータを返す' do
1991           get :index, :format => :json
1992           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1993         end
1994       end
1995     end
1996   end
1997   
1998   describe '閲覧に於いて' do
1999     before do
2000       Author.stub(:show).and_return(@author)
2001       sign_in @user
2002     end
2003     context 'つつがなく終わるとき' do
2004       it 'ステータスコード200 OKを返す' do
2005         get :show, :id => @author.id
2006         response.should be_success
2007       end
2008       context 'html形式' do
2009         it 'showテンプレートを描画する' do
2010           get :show, :id => @author.id
2011           response.should render_template("show")
2012         end
2013       end
2014       context 'json形式' do
2015         it 'jsonデータを返す' do
2016           get :show, :id => @author.id, :format => :json
2017           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2018         end
2019       end
2020     end
2021     context 'ユーザ権限がないとき' do
2022       before do
2023         sign_out @user
2024       end
2025       it 'ステータスコード200 OKを返す' do
2026         get :show, :id => @author.id
2027         response.should be_success
2028       end
2029       context 'html形式' do
2030         it 'showテンプレートを描画する' do
2031           get :show, :id => @author.id
2032           response.should render_template("show")
2033         end
2034       end
2035       context 'json形式' do
2036         it 'jsonデータを返す' do
2037           get :show, :id => @author.id, :format => :json
2038           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2039         end
2040       end
2041     end
2042   end
2043   
2044   describe '対象作家のコミック一覧表示に於いて' do
2045     before do
2046       @other_user = FactoryGirl.create( :user_yas)
2047       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
2048       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
2049       @scroll = FactoryGirl.create :scroll, :author_id => @other_user.author.id
2050       Scroll.stub(:mylist).and_return([@scroll, @scroll, @scroll])
2051       sign_in @user
2052     end
2053     context 'つつがなく終わるとき' do
2054       it 'ステータスコード200 OKを返す' do
2055         get :scrolls, :id => @other_author.id
2056         response.should be_success 
2057       end
2058       context 'html形式' do
2059         it 'scrollテンプレートを描画する' do
2060           get :scrolls, :id => @other_author.id
2061           response.should render_template("scroll")
2062         end
2063       end
2064       context 'json形式' do
2065         it 'jsonデータを返す' do
2066           get :scrolls, :id => @other_author.id, :format => :json
2067           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2068         end
2069       end
2070     end
2071     context 'ユーザ権限がないとき' do
2072       before do
2073         sign_out @user
2074       end
2075       it 'ステータスコード200 OKを返す' do
2076         get :scrolls, :id => @other_author.id
2077         response.should be_success 
2078       end
2079       context 'html形式' do
2080         it 'scrollsテンプレートを描画する' do
2081           get :scrolls, :id => @other_author.id
2082           response.should render_template("scrolls")
2083         end
2084       end
2085       context 'json形式' do
2086         it 'jsonデータを返す' do
2087           get :scrolls, :id => @other_author.id, :format => :json
2088           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2089         end
2090       end
2091     end
2092   end
2093   
2094   describe '対象作家のストーリー一覧表示に於いて' do
2095     before do
2096       @other_user = FactoryGirl.create( :user_yas)
2097       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
2098       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
2099       @scroll = FactoryGirl.create :scroll, :author_id => @other_user.author.id
2100       @panel = FactoryGirl.create :panel, :author_id => @other_author.id
2101       @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @other_author.id
2102       ScrollPanel.stub(:mylist).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
2103       sign_in @user
2104     end
2105     context 'つつがなく終わるとき' do
2106       it 'ステータスコード200 OKを返す' do
2107         get :scroll_panels, :id => @other_author.id
2108         response.should be_success 
2109       end
2110       context 'html形式' do
2111         it 'scroll_panelsテンプレートを描画する' do
2112           get :scroll_panels, :id => @other_author.id
2113           response.should render_template("scroll_panels")
2114         end
2115       end
2116       context 'json形式' do
2117         it 'jsonデータを返す' do
2118           get :scroll_panels, :id => @other_author.id, :format => :json
2119           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2120         end
2121       end
2122     end
2123     context 'ユーザ権限がないとき' do
2124       before do
2125         sign_out @user
2126       end
2127       it 'ステータスコード200 OKを返す' do
2128         get :scroll_panels, :id => @other_author.id
2129         response.should be_success 
2130       end
2131       context 'html形式' do
2132         it 'scroll_panelsテンプレートを描画する' do
2133           get :scroll_panels, :id => @other_author.id
2134           response.should render_template("scroll_panels")
2135         end
2136       end
2137       context 'json形式' do
2138         it 'jsonデータを返す' do
2139           get :scroll_panels, :id => @other_author.id, :format => :json
2140           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2141         end
2142       end
2143     end
2144   end
2145   
2146   describe '対象作家のコマ一覧表示に於いて' do
2147     before do
2148       @other_user = FactoryGirl.create( :user_yas)
2149       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
2150       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
2151       @panel = FactoryGirl.create :panel, :author_id => @other_author.id
2152       Panel.stub(:mylist).and_return([@panel, @panel, @panel])
2153       sign_in @user
2154     end
2155     context 'つつがなく終わるとき' do
2156       it 'ステータスコード200 OKを返す' do
2157         get :panels, :id => @other_author.id
2158         response.should be_success 
2159       end
2160       context 'html形式' do
2161         it 'panelsテンプレートを描画する' do
2162           get :panels, :id => @other_author.id
2163           response.should render_template("panels")
2164         end
2165       end
2166       context 'json形式' do
2167         it 'jsonデータを返す' do
2168           get :panels, :id => @other_author.id, :format => :json
2169           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2170         end
2171       end
2172     end
2173     context 'ユーザ権限がないとき' do
2174       before do
2175         sign_out @user
2176       end
2177       it 'ステータスコード200 OKを返す' do
2178         get :panels, :id => @other_author.id
2179         response.should be_success 
2180       end
2181       context 'html形式' do
2182         it 'panelsテンプレートを描画する' do
2183           get :panels, :id => @other_author.id
2184           response.should render_template("panels")
2185         end
2186       end
2187       context 'json形式' do
2188         it 'jsonデータを返す' do
2189           get :panels, :id => @other_author.id, :format => :json
2190           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2191         end
2192       end
2193     end
2194   end
2195   
2196   describe '対象作家のコマ絵一覧表示に於いて' do
2197     before do
2198       @other_user = FactoryGirl.create( :user_yas)
2199       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
2200       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
2201       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
2202       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
2203       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
2204       @panel = FactoryGirl.create :panel, :author_id => @author.id
2205       @panel_picture = FactoryGirl.create :panel_picture, :picture_id => @p.id, :panel_id => @panel.id, :width => @p.width, :height => @p.height
2206       PanelPicture.stub(:list).and_return([@panel_picture, @panel_picture, @panel_picture])
2207       sign_in @user
2208     end
2209     context 'つつがなく終わるとき' do
2210       it 'ステータスコード200 OKを返す' do
2211         get :panel_pictures, :id => @other_author.id
2212         response.should be_success 
2213       end
2214       context 'html形式' do
2215         it 'panel_picturesテンプレートを描画する' do
2216           get :panel_pictures, :id => @other_author.id
2217           response.should render_template("panel_pictures")
2218         end
2219       end
2220       context 'json形式' do
2221         it 'jsonデータを返す' do
2222           get :panel_pictures, :id => @other_author.id, :format => :json
2223           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2224         end
2225       end
2226     end
2227     context 'ユーザ権限がないとき' do
2228       before do
2229         sign_out @user
2230       end
2231       it 'ステータスコード200 OKを返す' do
2232         get :panel_pictures, :id => @other_author.id
2233         response.should be_success 
2234       end
2235       context 'html形式' do
2236         it 'panel_picturesテンプレートを描画する' do
2237           get :panel_pictures, :id => @other_author.id
2238           response.should render_template("panel_pictures")
2239         end
2240       end
2241       context 'json形式' do
2242         it 'jsonデータを返す' do
2243           get :panel_pictures, :id => @other_author.id, :format => :json
2244           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2245         end
2246       end
2247     end
2248   end
2249   
2250   describe '対象作家の絵地一覧表示に於いて' do
2251     before do
2252       @other_user = FactoryGirl.create( :user_yas)
2253       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
2254       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
2255       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
2256       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
2257       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
2258       @panel = FactoryGirl.create :panel, :author_id => @author.id
2259       @ground_picture = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
2260       GroundPicture.stub(:himlist).and_return([@ground_picture, @ground_picture, @ground_picture])
2261       sign_in @user
2262     end
2263     context 'つつがなく終わるとき' do
2264       it 'ステータスコード200 OKを返す' do
2265         get :ground_pictures, :id => @other_author.id
2266         response.should be_success 
2267       end
2268       context 'html形式' do
2269         it 'ground_picturesテンプレートを描画する' do
2270           get :ground_pictures, :id => @other_author.id
2271           response.should render_template("ground_pictures")
2272         end
2273       end
2274       context 'json形式' do
2275         it 'jsonデータを返す' do
2276           get :ground_pictures, :id => @other_author.id, :format => :json
2277           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2278         end
2279       end
2280     end
2281     context 'ユーザ権限がないとき' do
2282       before do
2283         sign_out @user
2284       end
2285       context 'html形式' do
2286         it 'ground_picturesテンプレートを描画する' do
2287           get :ground_pictures, :id => @other_author.id
2288           response.should render_template("ground_pictures")
2289         end
2290       end
2291       context 'json形式' do
2292         it 'jsonデータを返す' do
2293           get :ground_pictures, :id => @other_author.id, :format => :json
2294           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2295         end
2296       end
2297     end
2298   end
2299   
2300   describe '対象作家の色地一覧表示に於いて' do
2301     before do
2302       @other_user = FactoryGirl.create( :user_yas)
2303       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
2304       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
2305       @gc = FactoryGirl.create :ground_color
2306       @panel = FactoryGirl.create :panel, :author_id => @author.id
2307       GroundColor.stub(:himlist).and_return([@gc, @gc, @gc])
2308       sign_in @user
2309     end
2310     context 'つつがなく終わるとき' do
2311       it 'ステータスコード200 OKを返す' do
2312         get :ground_colors, :id => @other_author.id
2313         response.should be_success 
2314       end
2315       context 'html形式' do
2316         it 'ground_colorsテンプレートを描画する' do
2317           get :ground_colors, :id => @other_author.id
2318           response.should render_template("ground_colors")
2319         end
2320       end
2321       context 'json形式' do
2322         it 'jsonデータを返す' do
2323           get :ground_colors, :id => @other_author.id, :format => :json
2324           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2325         end
2326       end
2327     end
2328     context 'ユーザ権限がないとき' do
2329       before do
2330         sign_out @user
2331       end
2332       context 'html形式' do
2333         it 'ground_colorsテンプレートを描画する' do
2334           get :ground_colors, :id => @other_author.id
2335           response.should render_template("ground_colors")
2336         end
2337       end
2338       context 'json形式' do
2339         it 'jsonデータを返す' do
2340           get :ground_colors, :id => @other_author.id, :format => :json
2341           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2342         end
2343       end
2344     end
2345   end
2346   
2347   describe '作家数取得に於いて' do
2348     before do
2349       Author.should_receive(:visible_count).and_return(3)
2350 #      sign_in @user
2351     end
2352     context 'つつがなく終わるとき' do
2353       it 'ステータスコード200 OKを返す' do
2354         get :count, :format => :json
2355         response.should be_success 
2356       end
2357       context 'json形式' do
2358         it 'jsonデータを返す' do
2359           get :count, :format => :json
2360           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2361         end
2362       end
2363     end
2364   end
2365   
2366   describe '新規作成フォーム表示に於いて' do
2367     before do
2368       @new_user = FactoryGirl.create( :user_yas)
2369       sign_in @new_user
2370     end
2371     context 'つつがなく終わるとき' do
2372       it 'ステータスコード200 OKを返す' do
2373         get :new
2374         response.should be_success 
2375       end
2376       context 'html形式' do
2377         it 'newテンプレートを描画する' do
2378           get :new
2379           response.should render_template("new")
2380         end
2381       end
2382       context 'js形式' do
2383         it 'new.jsテンプレートを描画する' do
2384           get :new, :format => :js
2385           response.should render_template("new")
2386         end
2387       end
2388       context 'json形式' do
2389         it 'jsonデータを返す' do
2390           get :new, :format => :json
2391           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2392         end
2393       end
2394     end
2395     context 'ユーザ権限がないとき' do
2396       before do
2397         sign_out @new_user
2398       end
2399       context 'html形式' do
2400         it 'ステータスコード302 Foundを返す' do
2401           get :new
2402           response.status.should eq 302
2403         end
2404         it 'サインインページへ遷移する' do
2405           get :new
2406           response.body.should redirect_to '/users/sign_in'
2407         end
2408       end
2409       context 'js形式' do
2410         it 'ステータスコード401 Unauthorizedを返す' do
2411           get :new, :format => :js
2412           response.status.should eq 401
2413         end
2414         it '応答メッセージにUnauthorizedを返す' do
2415           get :new, :format => :js
2416           response.message.should match(/Unauthorized/)
2417         end
2418       end
2419       context 'json形式' do
2420         it 'ステータスコード401 Unauthorizedを返す' do
2421           get :new, :format => :json
2422           response.status.should eq 401
2423         end
2424         it '応答メッセージにUnauthorizedを返す' do
2425           get :new, :format => :json
2426           response.message.should match(/Unauthorized/)
2427         end
2428       end
2429     end
2430   end
2431
2432   describe '新規作成に於いて' do
2433     before do
2434       @new_user = FactoryGirl.create( :user_yas)
2435       sign_in @new_user
2436       @attr = FactoryGirl.attributes_for(:author, :user_id => @new_user.id, :name => 'ken')
2437     end
2438     context 'つつがなく終わるとき' do
2439       context 'html形式' do
2440         it 'ステータスコード302 Foundを返す' do
2441           Author.any_instance.stub(:save).and_return(true)
2442           post :create, :author => @attr
2443           response.status.should eq 302
2444         end
2445         it 'トップページへ遷移する' do
2446 #          Author.any_instance.stub(:save).and_return(true)
2447           post :create, :author => @attr
2448           response.should redirect_to(root_path)
2449         end
2450       end
2451       context 'json形式' do
2452         it 'ステータスコード200 OKを返す' do
2453 #          Author.any_instance.stub(:save).and_return(true)
2454           post :create, :author => @attr, :format => :json
2455           response.should be_success 
2456         end
2457       end
2458     end
2459     context 'ユーザ権限がないとき' do
2460       before do
2461         sign_out @new_user
2462       end
2463       context 'html形式' do
2464         it 'ステータスコード302 Foundを返す' do
2465           post :create, :author => @attr
2466           response.status.should eq 302
2467         end
2468         it 'サインインページへ遷移する' do
2469           post :create, :author => @attr
2470           response.body.should redirect_to '/users/sign_in'
2471         end
2472       end
2473       context 'json形式' do
2474         it 'ステータスコード401 Unauthorizedを返す' do
2475           post :create, :author => @attr, :format => :json
2476           response.status.should eq 401
2477         end
2478         it '応答メッセージにUnauthorizedを返す' do
2479           post :create, :author => @attr, :format => :json
2480           response.message.should match(/Unauthorized/)
2481         end
2482       end
2483     end
2484   end
2485
2486   describe '編集フォーム表示に於いて' do
2487     before do
2488       sign_in @user
2489       Author.stub(:edit).and_return(@author)
2490     end
2491     context 'つつがなく終わるとき' do
2492       it 'ステータスコード200 OKを返す' do
2493         get :edit, :id => @author.id
2494         response.should be_success 
2495       end
2496       context 'html形式' do
2497         it 'editテンプレートを描画する' do
2498           get :edit, :id => @author.id
2499           response.should render_template("edit")
2500         end
2501       end
2502       context 'js形式' do
2503         it 'edit.jsテンプレートを描画する' do
2504           get :edit, :id => @author.id, :format => :js
2505           response.should render_template("edit")
2506         end
2507       end
2508     end
2509     context 'ユーザ権限がないとき' do
2510       before do
2511         sign_out @user
2512       end
2513       context 'html形式' do
2514         it 'ステータスコード302 Foundを返す' do
2515           get :edit, :id => @author.id
2516           response.status.should eq 302
2517         end
2518         it 'サインインページへ遷移する' do
2519           get :edit, :id => @author.id
2520           response.body.should redirect_to '/users/sign_in'
2521         end
2522       end
2523       context 'js形式' do
2524         it 'ステータスコード401 Unauthorizedを返す' do
2525           get :edit, :id => @author.id, :format => :js
2526           response.status.should eq 401
2527         end
2528         it '応答メッセージにUnauthorizedを返す' do
2529           get :edit, :id => @author.id, :format => :js
2530           response.message.should match(/Unauthorized/)
2531         end
2532       end
2533     end
2534   end
2535
2536   describe '更新に於いて' do
2537     before do
2538       @attr = @author.attributes
2539       @attr['name'] = 'ryu'
2540       sign_in @user
2541     end
2542     context 'つつがなく終わるとき' do
2543       it '更新される' do
2544         put :update, :id => @author.id, :author => @attr
2545         Author.find(@author.id).name.should eq 'ryu'
2546       end
2547       context 'html形式' do
2548         it 'ステータスコード302 Foundを返す' do
2549           Author.any_instance.stub(:save).with(any_args()).and_return(true)
2550           put :update, :id => @author.id, :author => @attr
2551           response.status.should eq 302
2552         end
2553         it '設定ページへ遷移する' do
2554           put :update, :id => @author.id, :author => @attr
2555           response.should redirect_to('/home/configure')
2556         end
2557       end
2558       context 'json形式' do
2559         it 'ステータスコード200 OKを返す' do
2560           Author.any_instance.stub(:save).with(any_args()).and_return(true)
2561           put :update, :id => @author.id, :author => @attr, :format => :json
2562           response.should be_success 
2563         end
2564         it 'ページ本体は特に返さない' do
2565           Author.any_instance.stub(:save).with(any_args()).and_return(true)
2566           put :update, :id => @author.id, :author => @attr, :format => :json
2567           response.body.should match /./
2568         end
2569       end
2570     end
2571     context 'ユーザ権限がないとき' do
2572       before do
2573         sign_out @user
2574       end
2575       it 'ステータスコード302 Foundを返す' do
2576         put :update, :id => @author.id, :author => @attr
2577         response.status.should eq 302
2578       end
2579       context 'html形式' do
2580         it 'サインインページへ遷移する' do
2581           put :update, :id => @author.id, :author => @attr
2582           response.body.should redirect_to '/users/sign_in'
2583         end
2584       end
2585       context 'json形式' do
2586         it '応答メッセージにUnauthorizedを返す' do
2587           put :update, :id => @author.id, :author => @attr, :format => :json
2588           response.message.should match(/Unauthorized/)
2589         end
2590       end
2591     end
2592   end
2593
2594 end
2595 end