OSDN Git Service

fix: any
[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       @comic = FactoryGirl.create :comic, :author_id => @author.id
519       Author.stub(:show).and_return(@other_author)
520       Comic.stub(:himlist).and_return([@comic, @comic, @comic])
521       sign_in @user
522     end
523     context 'パラメータpageについて' do
524       it '@pageに値が入る' do
525         get :comics, :id => @other_author.id, :page => 5
526         assigns(:page).should eq 5
527       end
528       it '省略されると@pageに1値が入る' do
529         get :comics, :id => @other_author.id
530         assigns(:page).should eq 1
531       end
532       it '与えられたpage_sizeがセットされている' do
533         get :comics, :id => @other_author.id, :page_size => 15
534         assigns(:page_size).should eq 15
535       end
536       it '省略されると@page_sizeにデフォルト値が入る' do
537         get :comics, :id => @other_author.id
538         assigns(:page_size).should eq Author.default_comic_page_size
539       end
540       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
541         get :comics, :id => @other_author.id, :page_size => 1500
542         assigns(:page_size).should eq Author.comic_max_page_size
543       end
544       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
545         get :comics, :id => @other_author.id, :page_size => 0
546         assigns(:page_size).should eq Author.default_comic_page_size
547       end
548     end
549     context 'つつがなく終わるとき' do
550       it 'ステータスコード200 OKを返す' do
551         get :comics, :id => @other_author.id
552         response.should be_success 
553       end
554       it '作家モデルに単体取得を問い合わせている' do
555         Author.should_receive(:show).exactly(1)
556         get :comics, :id => @other_author.id
557       end
558       it 'コミックモデルに一覧を問い合わせている' do
559         Comic.should_receive(:himlist).exactly(1)
560         get :comics, :id => @other_author.id
561       end
562       it '@comicsにリストを取得している' do
563         get :comics, :id => @other_author.id
564         assigns(:comics).should have_at_least(3).items
565       end
566       context 'html形式' do
567         it '@paginateにページ制御を取得している' do
568           get :comics, :id => @other_author.id
569           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
570         end
571         it 'comicsテンプレートを描画する' do
572           get :comics, :id => @other_author.id
573           response.should render_template("comics")
574         end
575       end
576       context 'json形式' do
577         it 'jsonデータを返す' do
578           get :comics, :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           Comic.should_receive(:list_json_opt).exactly(1)
583           get :comics, :id => @other_author.id, :format => :json
584         end
585         it 'データがリスト構造になっている' do
586           get :comics, :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 :comics, :id => @other_author.id, :format => :json
592           json = JSON.parse response.body
593           json.first.has_key?("title").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 :comics, :id => @other_author.id
605           response.status.should eq 302
606         end
607         it 'サインインページへ遷移する' do
608           get :comics, :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 :comics, :id => @other_author.id, :format => :json
615           response.status.should eq 401
616         end
617         it '応答メッセージにUnauthorizedを返す' do
618           get :comics, :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 :comics, :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 :comics, :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       @comic = FactoryGirl.create :comic, :author_id => @author.id
650       @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
651       Author.stub(:show).and_return(@other_author)
652       Story.stub(:himlist).and_return([@story, @story, @story])
653       sign_in @user
654     end
655     context 'パラメータpageについて' do
656       it '@pageに値が入る' do
657         get :stories, :id => @other_author.id, :page => 5
658         assigns(:page).should eq 5
659       end
660       it '省略されると@pageに1値が入る' do
661         get :stories, :id => @other_author.id
662         assigns(:page).should eq 1
663       end
664       it '与えられたpage_sizeがセットされている' do
665         get :stories, :id => @other_author.id, :page_size => 15
666         assigns(:page_size).should eq 15
667       end
668       it '省略されると@page_sizeにデフォルト値が入る' do
669         get :stories, :id => @other_author.id
670         assigns(:page_size).should eq Author.default_story_page_size
671       end
672       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
673         get :stories, :id => @other_author.id, :page_size => 1500
674         assigns(:page_size).should eq Author.story_max_page_size
675       end
676       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
677         get :stories, :id => @other_author.id, :page_size => 0
678         assigns(:page_size).should eq Author.default_story_page_size
679       end
680     end
681     context 'つつがなく終わるとき' do
682       it 'ステータスコード200 OKを返す' do
683         get :stories, :id => @other_author.id
684         response.should be_success 
685       end
686       it '作家モデルに単体取得を問い合わせている' do
687         Author.should_receive(:show).exactly(1)
688         get :stories, :id => @other_author.id
689       end
690       it 'ストーリーモデルに他作家のストーリー一覧を問い合わせている' do
691         Story.should_receive(:himlist).exactly(1)
692         get :stories, :id => @other_author.id
693       end
694       it '@storiesにリストを取得している' do
695         get :stories, :id => @other_author.id
696         assigns(:stories).should have_at_least(3).items
697       end
698       context 'html形式' do
699         it '@paginateにページ制御を取得している' do
700           get :stories, :id => @other_author.id
701           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
702         end
703         it 'storiesテンプレートを描画する' do
704           get :stories, :id => @other_author.id
705           response.should render_template("stories")
706         end
707       end
708       context 'json形式' do
709         it 'jsonデータを返す' do
710           get :stories, :id => @other_author.id, :format => :json
711           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
712         end
713         it 'ストーリーモデルにjson一覧出力オプションを問い合わせている' do
714           Story.should_receive(:list_json_opt).exactly(1)
715           get :stories, :id => @other_author.id, :format => :json
716         end
717         it 'データがリスト構造になっている' do
718           get :stories, :id => @other_author.id, :format => :json
719           json = JSON.parse response.body
720           json.should have_at_least(3).items
721         end
722         it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
723           get :stories, :id => @other_author.id, :format => :json
724           json = JSON.parse response.body
725           json.first.has_key?("comic_id").should be_true
726           json.first.has_key?("title").should be_true
727         end
728       end
729     end
730     context 'ユーザ権限がないとき' do
731       before do
732         sign_out @user
733       end
734       context 'html形式' do
735         it 'ステータスコード302 Foundを返す' do
736           get :stories, :id => @other_author.id
737           response.status.should eq 302
738         end
739         it 'サインインページへ遷移する' do
740           get :stories, :id => @other_author.id
741           response.should redirect_to '/users/sign_in'
742         end
743       end
744       context 'json形式' do
745         it 'ステータスコード401 Unauthorizedを返す' do
746           get :stories, :id => @other_author.id, :format => :json
747           response.status.should eq 401
748         end
749         it '応答メッセージにUnauthorizedを返す' do
750           get :stories, :id => @other_author.id, :format => :json
751           response.message.should match(/Unauthorized/)
752         end
753       end
754     end
755     context 'ユーザ権限はないが管理者権限があるとき' do
756       before do
757         sign_out @user
758         sign_in @admin
759       end
760       it 'ステータスコード200 OKを返す' do
761         get :stories, :id => @other_author.id
762         response.should be_success 
763       end
764     end
765     context 'ユーザだが作家登録していないとき' do
766       before do
767         @author.destroy
768       end
769       it 'ステータスコード200 OKを返す' do
770         get :stories, :id => @other_author.id
771         response.should be_success 
772       end
773     end
774   end
775   
776   describe '対象作家のスト紙一覧表示に於いて' do
777     before do
778       @other_user = FactoryGirl.create( :user_yas)
779       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
780       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
781       @comic = FactoryGirl.create :comic, :author_id => @author.id
782       @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
783       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
784       @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
785       Author.stub(:show).and_return(@other_author)
786       StorySheet.stub(:himlist).and_return([@story_sheet, @story_sheet, @story_sheet])
787       sign_in @user
788     end
789     context 'パラメータpageについて' do
790       it '@pageに値が入る' do
791         get :story_sheets, :id => @other_author.id, :page => 5
792         assigns(:page).should eq 5
793       end
794       it '省略されると@pageに1値が入る' do
795         get :story_sheets, :id => @other_author.id
796         assigns(:page).should eq 1
797       end
798       it '与えられたpage_sizeがセットされている' do
799         get :story_sheets, :id => @other_author.id, :page_size => 15
800         assigns(:page_size).should eq 15
801       end
802       it '省略されると@page_sizeにデフォルト値が入る' do
803         get :story_sheets, :id => @other_author.id
804         assigns(:page_size).should eq Author.default_story_sheet_page_size
805       end
806       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
807         get :story_sheets, :id => @other_author.id, :page_size => 1500
808         assigns(:page_size).should eq Author.story_sheet_max_page_size
809       end
810       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
811         get :story_sheets, :id => @other_author.id, :page_size => 0
812         assigns(:page_size).should eq Author.default_story_sheet_page_size
813       end
814     end
815     context 'つつがなく終わるとき' do
816       it 'ステータスコード200 OKを返す' do
817         get :story_sheets, :id => @other_author.id
818         response.should be_success 
819       end
820       it '作家モデルに単体取得を問い合わせている' do
821         Author.should_receive(:show).exactly(1)
822         get :story_sheets, :id => @other_author.id
823       end
824       it 'スト紙モデルに他作家のスト紙一覧を問い合わせている' do
825         StorySheet.should_receive(:himlist).exactly(1)
826         get :story_sheets, :id => @other_author.id
827       end
828       it '@story_sheetsにリストを取得している' do
829         get :story_sheets, :id => @other_author.id
830         assigns(:story_sheets).should have_at_least(3).items
831       end
832       context 'html形式' do
833         it '@paginateにページ制御を取得している' do
834           get :story_sheets, :id => @other_author.id
835           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
836         end
837         it 'story_sheetsテンプレートを描画する' do
838           get :story_sheets, :id => @other_author.id
839           response.should render_template("story_sheets")
840         end
841       end
842       context 'json形式' do
843         it 'jsonデータを返す' do
844           get :story_sheets, :id => @other_author.id, :format => :json
845           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
846         end
847         it 'スト紙モデルにjson一覧出力オプションを問い合わせている' do
848           StorySheet.should_receive(:list_json_opt).exactly(1)
849           get :story_sheets, :id => @other_author.id, :format => :json
850         end
851         it 'データがリスト構造になっている' do
852           get :story_sheets, :id => @other_author.id, :format => :json
853           json = JSON.parse response.body
854           json.should have_at_least(3).items
855         end
856         it 'リストの先頭くらいはスト紙っぽいものであって欲しい' do
857           get :story_sheets, :id => @other_author.id, :format => :json
858           json = JSON.parse response.body
859           json.first.has_key?("story_id").should be_true
860           json.first.has_key?("sheet_id").should be_true
861         end
862       end
863     end
864     context 'ユーザ権限がないとき' do
865       before do
866         sign_out @user
867       end
868       context 'html形式' do
869         it 'ステータスコード302 Foundを返す' do
870           get :story_sheets, :id => @other_author.id
871           response.status.should eq 302
872         end
873         it 'サインインページへ遷移する' do
874           get :story_sheets, :id => @other_author.id
875           response.should redirect_to '/users/sign_in'
876         end
877       end
878       context 'json形式' do
879         it 'ステータスコード401 Unauthorizedを返す' do
880           get :story_sheets, :id => @other_author.id, :format => :json
881           response.status.should eq 401
882         end
883         it '応答メッセージにUnauthorizedを返す' do
884           get :story_sheets, :id => @other_author.id, :format => :json
885           response.message.should match(/Unauthorized/)
886         end
887       end
888     end
889     context 'ユーザ権限はないが管理者権限があるとき' do
890       before do
891         sign_out @user
892         sign_in @admin
893       end
894       it 'ステータスコード200 OKを返す' do
895         get :story_sheets, :id => @other_author.id
896         response.should be_success 
897       end
898     end
899     context 'ユーザだが作家登録していないとき' do
900       before do
901         @author.destroy
902       end
903       it 'ステータスコード200 OKを返す' do
904         get :story_sheets, :id => @other_author.id
905         response.should be_success 
906       end
907     end
908   end
909   
910   describe '対象作家の用紙一覧表示に於いて' do
911     before do
912       @other_user = FactoryGirl.create( :user_yas)
913       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
914       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
915       @sheet = FactoryGirl.create :sheet, :author_id => @other_user.author.id
916       Author.stub(:show).and_return(@other_author)
917       Sheet.stub(:himlist).and_return([@sheet, @sheet, @sheet])
918       sign_in @user
919     end
920     context 'パラメータpageについて' do
921       it '@pageに値が入る' do
922         get :sheets, :id => @other_author.id, :page => 5
923         assigns(:page).should eq 5
924       end
925       it '省略されると@pageに1値が入る' do
926         get :sheets, :id => @other_author.id
927         assigns(:page).should eq 1
928       end
929       it '与えられたpage_sizeがセットされている' do
930         get :sheets, :id => @other_author.id, :page_size => 15
931         assigns(:page_size).should eq 15
932       end
933       it '省略されると@page_sizeにデフォルト値が入る' do
934         get :sheets, :id => @other_author.id
935         assigns(:page_size).should eq Author.default_sheet_page_size
936       end
937       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
938         get :sheets, :id => @other_author.id, :page_size => 1500
939         assigns(:page_size).should eq Author.sheet_max_page_size
940       end
941       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
942         get :sheets, :id => @other_author.id, :page_size => 0
943         assigns(:page_size).should eq Author.default_sheet_page_size
944       end
945     end
946     context 'つつがなく終わるとき' do
947       it 'ステータスコード200 OKを返す' do
948         get :sheets, :id => @other_author.id
949         response.should be_success 
950       end
951       it '作家モデルに単体取得を問い合わせている' do
952         Author.should_receive(:show).exactly(1)
953         get :sheets, :id => @other_author.id
954       end
955       it '用紙モデルに一覧を問い合わせている' do
956         Sheet.should_receive(:himlist).exactly(1)
957         get :sheets, :id => @other_author.id
958       end
959       it '@sheetsにリストを取得している' do
960         get :sheets, :id => @other_author.id
961         assigns(:sheets).should have_at_least(3).items
962       end
963       context 'html形式' do
964         it '@paginateにページ制御を取得している' do
965           get :sheets, :id => @other_author.id
966           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
967         end
968         it 'sheetsテンプレートを描画する' do
969           get :sheets, :id => @other_author.id
970           response.should render_template("sheets")
971         end
972       end
973       context 'json形式' do
974         it 'jsonデータを返す' do
975           get :sheets, :id => @other_author.id, :format => :json
976           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
977         end
978         it '用紙モデルにjson一覧出力オプションを問い合わせている' do
979           Sheet.should_receive(:list_json_opt).exactly(1)
980           get :sheets, :id => @other_author.id, :format => :json
981         end
982         it 'データがリスト構造になっている' do
983           get :sheets, :id => @other_author.id, :format => :json
984           json = JSON.parse response.body
985           json.should have_at_least(3).items
986         end
987         it 'リストの先頭くらいは用紙っぽいものであって欲しい' do
988           get :sheets, :id => @other_author.id, :format => :json
989           json = JSON.parse response.body
990           json.first.has_key?("caption").should be_true
991           json.first.has_key?("visible").should be_true
992         end
993       end
994     end
995     context 'ユーザ権限がないとき' do
996       before do
997         sign_out @user
998       end
999       context 'html形式' do
1000         it 'ステータスコード302 Foundを返す' do
1001           get :sheets, :id => @other_author.id
1002           response.status.should eq 302
1003         end
1004         it 'サインインページへ遷移する' do
1005           get :sheets, :id => @other_author.id
1006           response.should redirect_to '/users/sign_in'
1007         end
1008       end
1009       context 'json形式' do
1010         it 'ステータスコード401 Unauthorizedを返す' do
1011           get :sheets, :id => @other_author.id, :format => :json
1012           response.status.should eq 401
1013         end
1014         it '応答メッセージにUnauthorizedを返す' do
1015           get :sheets, :id => @other_author.id, :format => :json
1016           response.message.should match(/Unauthorized/)
1017         end
1018       end
1019     end
1020     context 'ユーザ権限はないが管理者権限があるとき' do
1021       before do
1022         sign_out @user
1023         sign_in @admin
1024       end
1025       it 'ステータスコード200 OKを返す' do
1026         get :sheets, :id => @other_author.id
1027         response.should be_success 
1028       end
1029     end
1030     context 'ユーザだが作家登録していないとき' do
1031       before do
1032         @author.destroy
1033       end
1034       it 'ステータスコード200 OKを返す' do
1035         get :sheets, :id => @other_author.id
1036         response.should be_success 
1037       end
1038     end
1039   end
1040   
1041   describe '対象作家の紙コマ一覧表示に於いて' do
1042     before do
1043       @other_user = FactoryGirl.create( :user_yas)
1044       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1045       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1046       @sheet = FactoryGirl.create :sheet, :author_id => @other_user.author.id
1047       @panel = FactoryGirl.create :panel, :author_id => @other_user.author.id
1048       @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @other_user.author.id
1049       Author.stub(:show).and_return(@other_author)
1050       SheetPanel.stub(:himlist).and_return([@sheet_panel, @sheet_panel, @sheet_panel])
1051       sign_in @user
1052     end
1053     context 'パラメータpageについて' do
1054       it '@pageに値が入る' do
1055         get :sheet_panels, :id => @other_author.id, :page => 5
1056         assigns(:page).should eq 5
1057       end
1058       it '省略されると@pageに1値が入る' do
1059         get :sheet_panels, :id => @other_author.id
1060         assigns(:page).should eq 1
1061       end
1062       it '与えられたpage_sizeがセットされている' do
1063         get :sheet_panels, :id => @other_author.id, :page_size => 15
1064         assigns(:page_size).should eq 15
1065       end
1066       it '省略されると@page_sizeにデフォルト値が入る' do
1067         get :sheet_panels, :id => @other_author.id
1068         assigns(:page_size).should eq Author.default_sheet_panel_page_size
1069       end
1070       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
1071         get :sheet_panels, :id => @other_author.id, :page_size => 1500
1072         assigns(:page_size).should eq Author.sheet_panel_max_page_size
1073       end
1074       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
1075         get :sheet_panels, :id => @other_author.id, :page_size => 0
1076         assigns(:page_size).should eq Author.default_sheet_panel_page_size
1077       end
1078     end
1079     context 'つつがなく終わるとき' do
1080       it 'ステータスコード200 OKを返す' do
1081         get :sheet_panels, :id => @other_author.id
1082         response.should be_success 
1083       end
1084       it '作家モデルに単体取得を問い合わせている' do
1085         Author.should_receive(:show).exactly(1)
1086         get :sheet_panels, :id => @other_author.id
1087       end
1088       it '紙コマモデルに他作家の紙コマ一覧を問い合わせている' do
1089         SheetPanel.should_receive(:himlist).exactly(1)
1090         get :sheet_panels, :id => @other_author.id
1091       end
1092       it '@sheet_panelsにリストを取得している' do
1093         get :sheet_panels, :id => @other_author.id
1094         assigns(:sheet_panels).should have_at_least(3).items
1095       end
1096       context 'html形式' do
1097         it '@paginateにページ制御を取得している' do
1098           get :sheet_panels, :id => @other_author.id
1099           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
1100         end
1101         it 'sheet_panelsテンプレートを描画する' do
1102           get :sheet_panels, :id => @other_author.id
1103           response.should render_template("sheet_panels")
1104         end
1105       end
1106       context 'json形式' do
1107         it 'jsonデータを返す' do
1108           get :sheet_panels, :id => @other_author.id, :format => :json
1109           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1110         end
1111         it '紙コマモデルにjson一覧出力オプションを問い合わせている' do
1112           SheetPanel.should_receive(:list_json_opt).exactly(1)
1113           get :sheet_panels, :id => @other_author.id, :format => :json
1114         end
1115         it 'データがリスト構造になっている' do
1116           get :sheet_panels, :id => @other_author.id, :format => :json
1117           json = JSON.parse response.body
1118           json.should have_at_least(3).items
1119         end
1120         it 'リストの先頭くらいは紙コマっぽいものであって欲しい' do
1121           get :sheet_panels, :id => @other_author.id, :format => :json
1122           json = JSON.parse response.body
1123           json.first.has_key?("panel_id").should be_true
1124           json.first.has_key?("sheet_id").should be_true
1125           json.first.has_key?("t").should be_true
1126         end
1127       end
1128     end
1129     context 'ユーザ権限がないとき' do
1130       before do
1131         sign_out @user
1132       end
1133       context 'html形式' do
1134         it 'ステータスコード302 Foundを返す' do
1135           get :sheet_panels, :id => @other_author.id
1136           response.status.should eq 302
1137         end
1138         it 'サインインページへ遷移する' do
1139           get :sheet_panels, :id => @other_author.id
1140           response.should redirect_to '/users/sign_in'
1141         end
1142       end
1143       context 'json形式' do
1144         it 'ステータスコード401 Unauthorizedを返す' do
1145           get :sheet_panels, :id => @other_author.id, :format => :json
1146           response.status.should eq 401
1147         end
1148         it '応答メッセージにUnauthorizedを返す' do
1149           get :sheet_panels, :id => @other_author.id, :format => :json
1150           response.message.should match(/Unauthorized/)
1151         end
1152       end
1153     end
1154     context 'ユーザ権限はないが管理者権限があるとき' do
1155       before do
1156         sign_out @user
1157         sign_in @admin
1158       end
1159       it 'ステータスコード200 OKを返す' do
1160         get :sheet_panels, :id => @other_author.id
1161         response.should be_success 
1162       end
1163     end
1164     context 'ユーザだが作家登録していないとき' do
1165       before do
1166         @author.destroy
1167       end
1168       it 'ステータスコード200 OKを返す' do
1169         get :sheet_panels, :id => @other_author.id
1170         response.should be_success 
1171       end
1172     end
1173   end
1174   
1175   describe '対象作家のコマ一覧表示に於いて' do
1176     before do
1177       @other_user = FactoryGirl.create( :user_yas)
1178       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1179       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1180       @panel = FactoryGirl.create :panel, :author_id => @other_author.id
1181       Author.stub(:show).and_return(@other_author)
1182       Panel.stub(:himlist).and_return([@panel, @panel, @panel])
1183       sign_in @user
1184     end
1185     context 'パラメータpageについて' do
1186       it '@pageに値が入る' do
1187         get :panels, :id => @other_author.id, :page => 5
1188         assigns(:page).should eq 5
1189       end
1190       it '省略されると@pageに1値が入る' do
1191         get :panels, :id => @other_author.id
1192         assigns(:page).should eq 1
1193       end
1194       it '与えられたpage_sizeがセットされている' do
1195         get :panels, :id => @other_author.id, :page_size => 15
1196         assigns(:page_size).should eq 15
1197       end
1198       it '省略されると@page_sizeにデフォルト値が入る' do
1199         get :panels, :id => @other_author.id
1200         assigns(:page_size).should eq Author.default_panel_page_size
1201       end
1202       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
1203         get :panels, :id => @other_author.id, :page_size => 1500
1204         assigns(:page_size).should eq Author.panel_max_page_size
1205       end
1206       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
1207         get :panels, :id => @other_author.id, :page_size => 0
1208         assigns(:page_size).should eq Author.default_panel_page_size
1209       end
1210     end
1211     context 'つつがなく終わるとき' do
1212       it 'ステータスコード200 OKを返す' do
1213         get :panels, :id => @other_author.id
1214         response.should be_success 
1215       end
1216       it '作家モデルに単体取得を問い合わせている' do
1217         Author.should_receive(:show).exactly(1)
1218         get :panels, :id => @other_author.id
1219       end
1220       it 'コマモデルに他作家のコマ一覧を問い合わせている' do
1221         Panel.should_receive(:himlist).exactly(1)
1222         get :panels, :id => @other_author.id
1223       end
1224       it '@panelsにリストを取得している' do
1225         get :panels, :id => @other_author.id
1226         assigns(:panels).should have_at_least(3).items
1227       end
1228       context 'html形式' do
1229         it '@paginateにページ制御を取得している' do
1230           get :panels, :id => @other_author.id
1231           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
1232         end
1233         it 'panelsテンプレートを描画する' do
1234           get :panels, :id => @other_author.id
1235           response.should render_template("panels")
1236         end
1237       end
1238       context 'json形式' do
1239         it 'jsonデータを返す' do
1240           get :panels, :id => @other_author.id, :format => :json
1241           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1242         end
1243         it 'コマモデルにコマリストのjson出力を問い合わせている' do
1244           Panel.should_receive(:list_as_json_text).exactly(1)
1245           get :panels, :id => @other_author.id, :format => :json
1246         end
1247         it 'データがリスト構造になっている' do
1248           get :panels, :id => @other_author.id, :format => :json
1249           json = JSON.parse response.body
1250           json.should have_at_least(3).items
1251         end
1252         it 'リストの先頭くらいはコマっぽいものであって欲しい' do
1253           get :panels, :id => @other_author.id, :format => :json
1254           json = JSON.parse response.body
1255           json.first.has_key?("z").should be_true
1256         end
1257       end
1258     end
1259     context 'ユーザ権限がないとき' do
1260       before do
1261         sign_out @user
1262       end
1263       context 'html形式' do
1264         it 'ステータスコード302 Foundを返す' do
1265           get :panels, :id => @other_author.id
1266           response.status.should eq 302
1267         end
1268         it 'サインインページへ遷移する' do
1269           get :panels, :id => @other_author.id
1270           response.should redirect_to '/users/sign_in'
1271         end
1272       end
1273       context 'json形式' do
1274         it 'ステータスコード401 Unauthorizedを返す' do
1275           get :panels, :id => @other_author.id, :format => :json
1276           response.status.should eq 401
1277         end
1278         it '応答メッセージにUnauthorizedを返す' do
1279           get :panels, :id => @other_author.id, :format => :json
1280           response.message.should match(/Unauthorized/)
1281         end
1282       end
1283     end
1284     context 'ユーザ権限はないが管理者権限があるとき' do
1285       before do
1286         sign_out @user
1287         sign_in @admin
1288       end
1289       it 'ステータスコード200 OKを返す' do
1290         get :panels, :id => @other_author.id
1291         response.should be_success 
1292       end
1293     end
1294     context 'ユーザだが作家登録していないとき' do
1295       before do
1296         @author.destroy
1297       end
1298       it 'ステータスコード200 OKを返す' do
1299         get :panels, :id => @other_author.id
1300         response.should be_success 
1301       end
1302     end
1303   end
1304   
1305   describe '対象作家のコマ絵一覧表示に於いて' do
1306     before do
1307       @other_user = FactoryGirl.create( :user_yas)
1308       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1309       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1310       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1311       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
1312       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
1313       @panel = FactoryGirl.create :panel, :author_id => @author.id
1314       @panel_picture = FactoryGirl.create :panel_picture, :picture_id => @p.id, :panel_id => @panel.id, :width => @p.width, :height => @p.height
1315       Author.stub(:show).and_return(@other_author)
1316       PanelPicture.stub(:himlist).and_return([@panel_picture, @panel_picture, @panel_picture])
1317       sign_in @user
1318     end
1319     context 'パラメータpageについて' do
1320       it '@pageに値が入る' do
1321         get :panel_pictures, :id => @other_author.id, :page => 5
1322         assigns(:page).should eq 5
1323       end
1324       it '省略されると@pageに1値が入る' do
1325         get :panel_pictures, :id => @other_author.id
1326         assigns(:page).should eq 1
1327       end
1328       it '与えられたpage_sizeがセットされている' do
1329         get :panel_pictures, :id => @other_author.id, :page_size => 15
1330         assigns(:page_size).should eq 15
1331       end
1332       it '省略されると@page_sizeにデフォルト値が入る' do
1333         get :panel_pictures, :id => @other_author.id
1334         assigns(:page_size).should eq Author.default_panel_picture_page_size
1335       end
1336       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
1337         get :panel_pictures, :id => @other_author.id, :page_size => 1500
1338         assigns(:page_size).should eq Author.panel_picture_max_page_size
1339       end
1340       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
1341         get :panel_pictures, :id => @other_author.id, :page_size => 0
1342         assigns(:page_size).should eq Author.default_panel_picture_page_size
1343       end
1344     end
1345     context 'つつがなく終わるとき' do
1346       it 'ステータスコード200 OKを返す' do
1347         get :panel_pictures, :id => @other_author.id
1348         response.should be_success 
1349       end
1350       it '作家モデルに単体取得を問い合わせている' do
1351         Author.should_receive(:show).exactly(1)
1352         get :panel_pictures, :id => @other_author.id
1353       end
1354       it 'コマ絵モデルに他作家のコマ絵一覧を問い合わせている' do
1355         PanelPicture.should_receive(:himlist).exactly(1)
1356         get :panel_pictures, :id => @other_author.id
1357       end
1358       it '@panel_picturesにリストを取得している' do
1359         get :panel_pictures, :id => @other_author.id
1360         assigns(:panel_pictures).should have_at_least(3).items
1361       end
1362       context 'html形式' do
1363         it '@paginateにページ制御を取得している' do
1364           get :panel_pictures, :id => @other_author.id
1365           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
1366         end
1367         it 'panel_picturesテンプレートを描画する' do
1368           get :panel_pictures, :id => @other_author.id
1369           response.should render_template("panel_pictures")
1370         end
1371       end
1372       context 'json形式' do
1373         it 'jsonデータを返す' do
1374           get :panel_pictures, :id => @other_author.id, :format => :json
1375           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1376         end
1377         it 'コマ絵モデルにjson一覧出力オプションを問い合わせている' do
1378           PanelPicture.should_receive(:list_json_opt).exactly(1)
1379           get :panel_pictures, :id => @other_author.id, :format => :json
1380         end
1381         it 'データがリスト構造になっている' do
1382           get :panel_pictures, :id => @other_author.id, :format => :json
1383           json = JSON.parse response.body
1384           json.should have_at_least(3).items
1385         end
1386         it 'リストの先頭くらいはコマ絵っぽいものであって欲しい' do
1387           get :panel_pictures, :id => @other_author.id, :format => :json
1388           json = JSON.parse response.body
1389           json.first.has_key?("link").should be_true
1390           json.first.has_key?("x").should be_true
1391           json.first.has_key?("y").should be_true
1392         end
1393       end
1394     end
1395     context 'ユーザ権限がないとき' do
1396       before do
1397         sign_out @user
1398       end
1399       context 'html形式' do
1400         it 'ステータスコード302 Foundを返す' do
1401           get :panel_pictures, :id => @other_author.id
1402           response.status.should eq 302
1403         end
1404         it 'サインインページへ遷移する' do
1405           get :panel_pictures, :id => @other_author.id
1406           response.should redirect_to '/users/sign_in'
1407         end
1408       end
1409       context 'json形式' do
1410         it 'ステータスコード401 Unauthorizedを返す' do
1411           get :panel_pictures, :id => @other_author.id, :format => :json
1412           response.status.should eq 401
1413         end
1414         it '応答メッセージにUnauthorizedを返す' do
1415           get :panel_pictures, :id => @other_author.id, :format => :json
1416           response.message.should match(/Unauthorized/)
1417         end
1418       end
1419     end
1420     context 'ユーザ権限はないが管理者権限があるとき' do
1421       before do
1422         sign_out @user
1423         sign_in @admin
1424       end
1425       it 'ステータスコード200 OKを返す' do
1426         get :panel_pictures, :id => @other_author.id
1427         response.should be_success 
1428       end
1429     end
1430     context 'ユーザだが作家登録していないとき' do
1431       before do
1432         @author.destroy
1433       end
1434       it 'ステータスコード200 OKを返す' do
1435         get :panel_pictures, :id => @other_author.id
1436         response.should be_success 
1437       end
1438     end
1439   end
1440   
1441   describe '対象作家のフキダシ一覧表示に於いて' do
1442     before do
1443       @other_user = FactoryGirl.create( :user_yas)
1444       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1445       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1446       @panel = FactoryGirl.create :panel, :author_id => @other_author.id
1447       @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
1448       @speech = @sb.build_speech(
1449         FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
1450       )
1451       @balloon = @sb.build_balloon(
1452         FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
1453       )
1454       @sb.boost
1455       @sb.save!
1456       Author.stub(:show).and_return(@other_author)
1457       SpeechBalloon.stub(:himlist).and_return([@sb, @sb, @sb])
1458       sign_in @user
1459     end
1460     context 'パラメータpageについて' do
1461       it '@pageに値が入る' do
1462         get :speech_balloons, :id => @other_author.id, :page => 5
1463         assigns(:page).should eq 5
1464       end
1465       it '省略されると@pageに1値が入る' do
1466         get :speech_balloons, :id => @other_author.id
1467         assigns(:page).should eq 1
1468       end
1469       it '与えられたpage_sizeがセットされている' do
1470         get :speech_balloons, :id => @other_author.id, :page_size => 15
1471         assigns(:page_size).should eq 15
1472       end
1473       it '省略されると@page_sizeにデフォルト値が入る' do
1474         get :speech_balloons, :id => @other_author.id
1475         assigns(:page_size).should eq Author.default_speech_balloon_page_size
1476       end
1477       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
1478         get :speech_balloons, :id => @other_author.id, :page_size => 1500
1479         assigns(:page_size).should eq Author.speech_balloon_max_page_size
1480       end
1481       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
1482         get :speech_balloons, :id => @other_author.id, :page_size => 0
1483         assigns(:page_size).should eq Author.default_speech_balloon_page_size
1484       end
1485     end
1486     context 'つつがなく終わるとき' do
1487       it 'ステータスコード200 OKを返す' do
1488         get :speech_balloons, :id => @other_author.id
1489         response.should be_success 
1490       end
1491       it '作家モデルに単体取得を問い合わせている' do
1492         Author.should_receive(:show).exactly(1)
1493         get :speech_balloons, :id => @other_author.id
1494       end
1495       it 'フキダシモデルに他作家のフキダシ一覧を問い合わせている' do
1496         SpeechBalloon.should_receive(:himlist).exactly(1)
1497         get :speech_balloons, :id => @other_author.id
1498       end
1499       it '@speech_balloonsにリストを取得している' do
1500         get :speech_balloons, :id => @other_author.id
1501         assigns(:speech_balloons).should have_at_least(3).items
1502       end
1503       context 'html形式' do
1504         it '@paginateにページ制御を取得している' do
1505           get :speech_balloons, :id => @other_author.id
1506           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
1507         end
1508         it 'speech_balloonsテンプレートを描画する' do
1509           get :speech_balloons, :id => @other_author.id
1510           response.should render_template("speech_balloons")
1511         end
1512       end
1513       context 'json形式' do
1514         it 'jsonデータを返す' do
1515           get :speech_balloons, :id => @other_author.id, :format => :json
1516           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1517         end
1518         it 'フキダシモデルにjson一覧出力オプションを問い合わせている' do
1519           SpeechBalloon.should_receive(:list_json_opt).exactly(1)
1520           get :speech_balloons, :id => @other_author.id, :format => :json
1521         end
1522         it 'データがリスト構造になっている' do
1523           get :speech_balloons, :id => @other_author.id, :format => :json
1524           json = JSON.parse response.body
1525           json.should have_at_least(3).items
1526         end
1527         it 'リストの先頭くらいはフキダシっぽいものであって欲しい' do
1528           get :speech_balloons, :id => @other_author.id, :format => :json
1529           json = JSON.parse response.body
1530           json.first.has_key?("speech_balloon_template_id").should be_true
1531           json.first.has_key?("z").should be_true
1532           json.first.has_key?("t").should be_true
1533         end
1534       end
1535     end
1536     context 'ユーザ権限がないとき' do
1537       before do
1538         sign_out @user
1539       end
1540       context 'html形式' do
1541         it 'ステータスコード302 Foundを返す' do
1542           get :speech_balloons, :id => @other_author.id
1543           response.status.should eq 302
1544         end
1545         it 'サインインページへ遷移する' do
1546           get :speech_balloons, :id => @other_author.id
1547           response.should redirect_to '/users/sign_in'
1548         end
1549       end
1550       context 'json形式' do
1551         it 'ステータスコード401 Unauthorizedを返す' do
1552           get :speech_balloons, :id => @other_author.id, :format => :json
1553           response.status.should eq 401
1554         end
1555         it '応答メッセージにUnauthorizedを返す' do
1556           get :speech_balloons, :id => @other_author.id, :format => :json
1557           response.message.should match(/Unauthorized/)
1558         end
1559       end
1560     end
1561     context 'ユーザ権限はないが管理者権限があるとき' do
1562       before do
1563         sign_out @user
1564         sign_in @admin
1565       end
1566       it 'ステータスコード200 OKを返す' do
1567         get :speech_balloons, :id => @other_author.id
1568         response.should be_success 
1569       end
1570     end
1571     context 'ユーザだが作家登録していないとき' do
1572       before do
1573         @author.destroy
1574       end
1575       it 'ステータスコード200 OKを返す' do
1576         get :speech_balloons, :id => @other_author.id
1577         response.should be_success 
1578       end
1579     end
1580   end
1581   
1582   describe '対象作家の絵地一覧表示に於いて' do
1583     before do
1584       @other_user = FactoryGirl.create( :user_yas)
1585       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1586       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1587       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
1588       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
1589       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
1590       @panel = FactoryGirl.create :panel, :author_id => @author.id
1591       @ground_picture = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
1592       Author.stub(:show).and_return(@other_author)
1593       GroundPicture.stub(:himlist).and_return([@ground_picture, @ground_picture, @ground_picture])
1594       sign_in @user
1595     end
1596     context 'パラメータpageについて' do
1597       it '@pageに値が入る' do
1598         get :ground_pictures, :id => @other_author.id, :page => 5
1599         assigns(:page).should eq 5
1600       end
1601       it '省略されると@pageに1値が入る' do
1602         get :ground_pictures, :id => @other_author.id
1603         assigns(:page).should eq 1
1604       end
1605       it '与えられたpage_sizeがセットされている' do
1606         get :ground_pictures, :id => @other_author.id, :page_size => 15
1607         assigns(:page_size).should eq 15
1608       end
1609       it '省略されると@page_sizeにデフォルト値が入る' do
1610         get :ground_pictures, :id => @other_author.id
1611         assigns(:page_size).should eq Author.default_ground_picture_page_size
1612       end
1613       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
1614         get :ground_pictures, :id => @other_author.id, :page_size => 1500
1615         assigns(:page_size).should eq Author.ground_picture_max_page_size
1616       end
1617       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
1618         get :ground_pictures, :id => @other_author.id, :page_size => 0
1619         assigns(:page_size).should eq Author.default_ground_picture_page_size
1620       end
1621     end
1622     context 'つつがなく終わるとき' do
1623       it 'ステータスコード200 OKを返す' do
1624         get :ground_pictures, :id => @other_author.id
1625         response.should be_success 
1626       end
1627       it '作家モデルに単体取得を問い合わせている' do
1628         Author.should_receive(:show).exactly(1)
1629         get :ground_pictures, :id => @other_author.id
1630       end
1631       it '絵地モデルに他作家の絵地一覧を問い合わせている' do
1632         GroundPicture.should_receive(:himlist).exactly(1)
1633         get :ground_pictures, :id => @other_author.id
1634       end
1635       it '@ground_picturesにリストを取得している' do
1636         get :ground_pictures, :id => @other_author.id
1637         assigns(:ground_pictures).should have_at_least(3).items
1638       end
1639       context 'html形式' do
1640         it '@paginateにページ制御を取得している' do
1641           get :ground_pictures, :id => @other_author.id
1642           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
1643         end
1644         it 'ground_picturesテンプレートを描画する' do
1645           get :ground_pictures, :id => @other_author.id
1646           response.should render_template("ground_pictures")
1647         end
1648       end
1649       context 'json形式' do
1650         it 'jsonデータを返す' do
1651           get :ground_pictures, :id => @other_author.id, :format => :json
1652           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1653         end
1654         it '絵地モデルにjson一覧出力オプションを問い合わせている' do
1655           GroundPicture.should_receive(:list_json_opt).exactly(1)
1656           get :ground_pictures, :id => @other_author.id, :format => :json
1657         end
1658         it 'データがリスト構造になっている' do
1659           get :ground_pictures, :id => @other_author.id, :format => :json
1660           json = JSON.parse response.body
1661           json.should have_at_least(3).items
1662         end
1663         it 'リストの先頭くらいは絵地っぽいものであって欲しい' do
1664           get :ground_pictures, :id => @other_author.id, :format => :json
1665           json = JSON.parse response.body
1666           json.first.has_key?("panel_id").should be_true
1667           json.first.has_key?("picture_id").should be_true
1668           json.first.has_key?("z").should be_true
1669         end
1670       end
1671     end
1672     context 'ユーザ権限がないとき' do
1673       before do
1674         sign_out @user
1675       end
1676       context 'html形式' do
1677         it 'ステータスコード302 Foundを返す' do
1678           get :ground_pictures, :id => @other_author.id
1679           response.status.should eq 302
1680         end
1681         it 'サインインページへ遷移する' do
1682           get :ground_pictures, :id => @other_author.id
1683           response.should redirect_to '/users/sign_in'
1684         end
1685       end
1686       context 'json形式' do
1687         it 'ステータスコード401 Unauthorizedを返す' do
1688           get :ground_pictures, :id => @other_author.id, :format => :json
1689           response.status.should eq 401
1690         end
1691         it '応答メッセージにUnauthorizedを返す' do
1692           get :ground_pictures, :id => @other_author.id, :format => :json
1693           response.message.should match(/Unauthorized/)
1694         end
1695       end
1696     end
1697     context 'ユーザ権限はないが管理者権限があるとき' do
1698       before do
1699         sign_out @user
1700         sign_in @admin
1701       end
1702       it 'ステータスコード200 OKを返す' do
1703         get :ground_pictures, :id => @other_author.id
1704         response.should be_success 
1705       end
1706     end
1707     context 'ユーザだが作家登録していないとき' do
1708       before do
1709         @author.destroy
1710       end
1711       it 'ステータスコード200 OKを返す' do
1712         get :ground_pictures, :id => @other_author.id
1713         response.should be_success 
1714       end
1715     end
1716   end
1717   
1718   describe '対象作家の色地一覧表示に於いて' do
1719     before do
1720       @other_user = FactoryGirl.create( :user_yas)
1721       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1722       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1723       @gc = FactoryGirl.create :ground_color
1724       @panel = FactoryGirl.create :panel, :author_id => @author.id
1725       Author.stub(:show).and_return(@other_author)
1726       GroundColor.stub(:himlist).and_return([@gc, @gc, @gc])
1727       sign_in @user
1728     end
1729     context 'パラメータpageについて' do
1730       it '@pageに値が入る' do
1731         get :ground_colors, :id => @other_author.id, :page => 5
1732         assigns(:page).should eq 5
1733       end
1734       it '省略されると@pageに1値が入る' do
1735         get :ground_colors, :id => @other_author.id
1736         assigns(:page).should eq 1
1737       end
1738       it '与えられたpage_sizeがセットされている' do
1739         get :ground_colors, :id => @other_author.id, :page_size => 15
1740         assigns(:page_size).should eq 15
1741       end
1742       it '省略されると@page_sizeにデフォルト値が入る' do
1743         get :ground_colors, :id => @other_author.id
1744         assigns(:page_size).should eq Author.default_ground_color_page_size
1745       end
1746       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
1747         get :ground_colors, :id => @other_author.id, :page_size => 1500
1748         assigns(:page_size).should eq Author.ground_color_max_page_size
1749       end
1750       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
1751         get :ground_colors, :id => @other_author.id, :page_size => 0
1752         assigns(:page_size).should eq Author.ground_color_page_size
1753       end
1754     end
1755     context 'つつがなく終わるとき' do
1756       it 'ステータスコード200 OKを返す' do
1757         get :ground_colors, :id => @other_author.id
1758         response.should be_success 
1759       end
1760       it '作家モデルに単体取得を問い合わせている' do
1761         Author.should_receive(:show).exactly(1)
1762         get :ground_colors, :id => @other_author.id
1763       end
1764       it '色地モデルに他作家の色地一覧を問い合わせている' do
1765         GroundColor.should_receive(:himlist).exactly(1)
1766         get :ground_colors, :id => @other_author.id
1767       end
1768       it '@ground_colorsにリストを取得している' do
1769         get :ground_colors, :id => @other_author.id
1770         assigns(:ground_colors).should have_at_least(3).items
1771       end
1772       context 'html形式' do
1773         it '@paginateにページ制御を取得している' do
1774           get :ground_colors, :id => @other_author.id
1775           assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
1776         end
1777         it 'ground_colorsテンプレートを描画する' do
1778           get :ground_colors, :id => @other_author.id
1779           response.should render_template("ground_colors")
1780         end
1781       end
1782       context 'json形式' do
1783         it 'jsonデータを返す' do
1784           get :ground_colors, :id => @other_author.id, :format => :json
1785           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1786         end
1787         it '色地モデルにjson一覧出力オプションを問い合わせている' do
1788           GroundColor.should_receive(:list_json_opt).exactly(1)
1789           get :ground_colors, :id => @other_author.id, :format => :json
1790         end
1791         it 'データがリスト構造になっている' do
1792           get :ground_colors, :id => @other_author.id, :format => :json
1793           json = JSON.parse response.body
1794           json.should have_at_least(3).items
1795         end
1796         it 'リストの先頭くらいは色地っぽいものであって欲しい' do
1797           get :ground_colors, :id => @other_author.id, :format => :json
1798           json = JSON.parse response.body
1799           json.first.has_key?("panel_id").should be_true
1800           json.first.has_key?("code").should be_true
1801           json.first.has_key?("z").should be_true
1802         end
1803       end
1804     end
1805     context 'ユーザ権限がないとき' do
1806       before do
1807         sign_out @user
1808       end
1809       context 'html形式' do
1810         it 'ステータスコード302 Foundを返す' do
1811           get :ground_colors, :id => @other_author.id
1812           response.status.should eq 302
1813         end
1814         it 'サインインページへ遷移する' do
1815           get :ground_colors, :id => @other_author.id
1816           response.should redirect_to '/users/sign_in'
1817         end
1818       end
1819       context 'json形式' do
1820         it 'ステータスコード401 Unauthorizedを返す' do
1821           get :ground_colors, :id => @other_author.id, :format => :json
1822           response.status.should eq 401
1823         end
1824         it '応答メッセージにUnauthorizedを返す' do
1825           get :ground_colors, :id => @other_author.id, :format => :json
1826           response.message.should match(/Unauthorized/)
1827         end
1828       end
1829     end
1830     context 'ユーザ権限はないが管理者権限があるとき' do
1831       before do
1832         sign_out @user
1833         sign_in @admin
1834       end
1835       it 'ステータスコード200 OKを返す' do
1836         get :ground_colors, :id => @other_author.id
1837         response.should be_success 
1838       end
1839     end
1840     context 'ユーザだが作家登録していないとき' do
1841       before do
1842         @author.destroy
1843       end
1844       it 'ステータスコード200 OKを返す' do
1845         get :ground_colors, :id => @other_author.id
1846         response.should be_success 
1847       end
1848     end
1849   end
1850   
1851   describe '作家数取得に於いて' do
1852     before do
1853       Author.should_receive(:visible_count).and_return(3)
1854 #      sign_in @user
1855     end
1856     context 'つつがなく終わるとき' do
1857       it 'ステータスコード200 OKを返す' do
1858         get :count, :format => :json
1859         response.should be_success 
1860       end
1861       context 'json形式' do
1862         it 'jsonデータを返す' do
1863           get :count, :format => :json
1864           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1865         end
1866         it 'データがHash構造になっていて作家数が3である' do
1867           get :count, :format => :json
1868           json = JSON.parse response.body
1869           json["count"].should == 3
1870         end
1871       end
1872     end
1873   end
1874   
1875   describe '新規作成フォーム表示に於いて' do
1876     before do
1877       @new_user = FactoryGirl.create( :user_yas)
1878       sign_in @new_user
1879     end
1880     context 'つつがなく終わるとき' do
1881       it 'ステータスコード200 OKを返す' do
1882         get :new
1883         response.should be_success 
1884       end
1885       it '@auに新規データを用意している' do
1886         get :new
1887         assigns(:au).should be_a_new(Author)
1888       end
1889       it '作家モデルにデフォルト値補充を依頼している' do
1890         Author.any_instance.should_receive(:supply_default).exactly(1)
1891         get :new
1892       end
1893       context 'html形式' do
1894         it 'newテンプレートを描画する' do
1895           get :new
1896           response.should render_template("new")
1897         end
1898       end
1899       context 'js形式' do
1900         it 'new.jsテンプレートを描画する' do
1901           get :new, :format => :js
1902           response.should render_template("new")
1903         end
1904       end
1905       context 'json形式' do
1906         it 'jsonデータを返す' do
1907           get :new, :format => :json
1908           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1909         end
1910         it '作家モデルにjson単体出力オプションを問い合わせている' do
1911           Author.should_receive(:show_json_opt).exactly(1)
1912           get :new, :format => :json
1913         end
1914       end
1915     end
1916     context 'ユーザ権限がないとき' do
1917       before do
1918         sign_out @new_user
1919       end
1920       context 'html形式' do
1921         it 'ステータスコード302 Foundを返す' do
1922           get :new
1923           response.status.should eq 302
1924         end
1925         it 'サインインページへ遷移する' do
1926           get :new
1927           response.body.should redirect_to '/users/sign_in'
1928         end
1929       end
1930       context 'js形式' do
1931         it 'ステータスコード401 Unauthorizedを返す' do
1932           get :new, :format => :js
1933           response.status.should eq 401
1934         end
1935         it '応答メッセージにUnauthorizedを返す' do
1936           get :new, :format => :js
1937           response.message.should match(/Unauthorized/)
1938         end
1939       end
1940       context 'json形式' do
1941         it 'ステータスコード401 Unauthorizedを返す' do
1942           get :new, :format => :json
1943           response.status.should eq 401
1944         end
1945         it '応答メッセージにUnauthorizedを返す' do
1946           get :new, :format => :json
1947           response.message.should match(/Unauthorized/)
1948         end
1949       end
1950     end
1951     context 'ユーザ権限はないが管理者権限があるとき' do
1952       before do
1953         sign_out @user
1954         sign_in @admin
1955       end
1956       context 'html形式' do
1957         it 'ステータスコード302 Foundを返す' do
1958           get :new
1959           response.status.should eq 302
1960         end
1961         it 'サインインページへ遷移する' do
1962           get :new
1963           response.body.should redirect_to '/users/sign_in'
1964         end
1965       end
1966     end
1967     context 'ユーザだが作家登録していないとき' do
1968       before do
1969         @author.destroy
1970       end
1971       it 'ステータスコード200 OKを返す' do
1972           get :new
1973         response.should be_success 
1974       end
1975     end
1976   end
1977
1978   describe '新規作成に於いて' do
1979     before do
1980       @new_user = FactoryGirl.create( :user_yas)
1981       sign_in @new_user
1982       @attr = FactoryGirl.attributes_for(:author, :user_id => @new_user.id, :name => 'ken')
1983     end
1984     context '事前チェックしておく' do
1985       it '作家モデルにデフォルト値補充を依頼している' do
1986         Author.any_instance.should_receive(:supply_default).exactly(1)
1987         post :create, :author => @attr
1988       end
1989       it '作家モデルにカラム値復元を依頼している' do
1990         Author.any_instance.should_receive(:attributes=).exactly(1)
1991         post :create, :author => @attr
1992       end
1993       it '作家モデルに上書き補充を依頼している' do
1994         Author.any_instance.should_receive(:overwrite).exactly(1)
1995         post :create, :author => @attr
1996       end
1997       it 'モデルに保存依頼する' do
1998         Author.any_instance.should_receive(:save).exactly(1)
1999         post :create, :author => @attr
2000       end
2001     end
2002     context 'つつがなく終わるとき' do
2003       it "@auに作成された作家を保持していて、それがDBにある" do
2004         post :create, :author => @attr
2005         assigns(:au).should be_a(Author)
2006         assigns(:au).should be_persisted
2007       end
2008       context 'html形式' do
2009         it 'ステータスコード302 Foundを返す' do
2010           Author.any_instance.stub(:save).and_return(true)
2011           post :create, :author => @attr
2012           response.status.should eq 302
2013         end
2014         it 'トップページへ遷移する' do
2015 #          Author.any_instance.stub(:save).and_return(true)
2016           post :create, :author => @attr
2017           response.should redirect_to(root_path)
2018         end
2019       end
2020       context 'json形式' do
2021         it 'ステータスコード200 OKを返す' do
2022 #          Author.any_instance.stub(:save).and_return(true)
2023           post :create, :author => @attr, :format => :json
2024           response.should be_success 
2025         end
2026         it '作成された作家をjsonデータで返す' do
2027           post :create, :author => @attr, :format => :json
2028           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2029         end
2030         it '作家モデルにjson単体出力オプションを問い合わせている' do
2031           Author.should_receive(:show_json_opt).exactly(1)
2032           post :create, :author => @attr, :format => :json
2033         end
2034         it 'データがアレになっている' do
2035           post :create, :author => @attr, :format => :json
2036           json = JSON.parse response.body
2037           json["name"].should match(/ken/)
2038         end
2039       end
2040     end
2041     context 'ユーザ権限がないとき' do
2042       before do
2043         sign_out @new_user
2044       end
2045       context 'html形式' do
2046         it 'ステータスコード302 Foundを返す' do
2047           post :create, :author => @attr
2048           response.status.should eq 302
2049         end
2050         it 'サインインページへ遷移する' do
2051           post :create, :author => @attr
2052           response.body.should redirect_to '/users/sign_in'
2053         end
2054       end
2055       context 'json形式' do
2056         it 'ステータスコード401 Unauthorizedを返す' do
2057           post :create, :author => @attr, :format => :json
2058           response.status.should eq 401
2059         end
2060         it '応答メッセージにUnauthorizedを返す' do
2061           post :create, :author => @attr, :format => :json
2062           response.message.should match(/Unauthorized/)
2063         end
2064       end
2065     end
2066     context 'ユーザ権限はないが管理者権限があるとき' do
2067       before do
2068         sign_out @user
2069         sign_in @admin
2070       end
2071       context 'html形式' do
2072         it 'ステータスコード302 Foundを返す' do
2073           post :create, :author => @attr
2074           response.status.should eq 302
2075         end
2076         it 'サインインページへ遷移する' do
2077           post :create, :author => @attr
2078           response.body.should redirect_to '/users/sign_in'
2079         end
2080       end
2081     end
2082     context '検証、保存に失敗した' do
2083       before do
2084         Author.any_instance.stub(:save).and_return(false)
2085       end
2086       it "未保存の作家を保持している" do
2087         post :create, :author => @attr
2088         assigns(:au).should be_a_new(Author)
2089       end
2090       context 'html形式' do
2091         it 'ステータスコード200 OKを返す' do
2092           post :create, :author => @attr
2093           response.status.should eq 200
2094         end
2095         it '新規ページを描画する' do
2096           post :create, :author => @attr
2097           response.should render_template("new")
2098         end
2099       end
2100       context 'json形式' do
2101         it 'ステータスコード422 unprocessable_entity を返す' do
2102           post :create, :author => @attr, :format => :json
2103           response.status.should eq 422
2104         end
2105         it '応答メッセージUnprocessable Entityを返す' do
2106           post :create, :author => @attr, :format => :json
2107           response.message.should match(/Unprocessable/)
2108         end
2109       end
2110     end
2111   end
2112
2113   describe '編集フォーム表示に於いて' do
2114     before do
2115       sign_in @user
2116       Author.stub(:edit).and_return(@author)
2117     end
2118     context 'つつがなく終わるとき' do
2119       it 'ステータスコード200 OKを返す' do
2120         get :edit, :id => @author.id
2121         response.should be_success 
2122       end
2123       it '作家モデルに編集取得を問い合わせている' do
2124         Author.should_receive(:edit).exactly(1)
2125         get :edit, :id => @author.id
2126       end
2127       #@authorだとログイン中のアカウントと干渉してしまう。
2128       it '@auにデータを用意している' do
2129         get :edit, :id => @author.id
2130         assigns(:au).should eq @author
2131       end
2132       context 'html形式' do
2133         it 'editテンプレートを描画する' do
2134           get :edit, :id => @author.id
2135           response.should render_template("edit")
2136         end
2137       end
2138       context 'js形式' do
2139         it 'edit.jsテンプレートを描画する' do
2140           get :edit, :id => @author.id, :format => :js
2141           response.should render_template("edit")
2142         end
2143       end
2144     end
2145     context 'ユーザ権限がないとき' do
2146       before do
2147         sign_out @user
2148       end
2149       context 'html形式' do
2150         it 'ステータスコード302 Foundを返す' do
2151           get :edit, :id => @author.id
2152           response.status.should eq 302
2153         end
2154         it 'サインインページへ遷移する' do
2155           get :edit, :id => @author.id
2156           response.body.should redirect_to '/users/sign_in'
2157         end
2158       end
2159       context 'js形式' do
2160         it 'ステータスコード401 Unauthorizedを返す' do
2161           get :edit, :id => @author.id, :format => :js
2162           response.status.should eq 401
2163         end
2164         it '応答メッセージにUnauthorizedを返す' do
2165           get :edit, :id => @author.id, :format => :js
2166           response.message.should match(/Unauthorized/)
2167         end
2168       end
2169     end
2170     context 'ユーザ権限はないが管理者権限があるとき' do
2171       before do
2172         sign_out @user
2173         sign_in @admin
2174       end
2175       context 'html形式' do
2176         it 'ステータスコード302 Foundを返す' do
2177           get :edit, :id => @author.id
2178           response.status.should eq 302
2179         end
2180         it 'サインインページへ遷移する' do
2181           get :edit, :id => @author.id
2182           response.body.should redirect_to '/users/sign_in'
2183         end
2184       end
2185     end
2186     context 'ユーザだが作家登録していないとき' do
2187       before do
2188         @other_user = FactoryGirl.create( :user_yas)
2189         @other_author = FactoryGirl.create :author, :user_id => @other_user.id
2190         @author.destroy
2191       end
2192       context 'html形式' do
2193         it 'ステータスコード302 Foundを返す' do
2194           get :edit, :id => @other_author.id
2195           response.status.should eq 302
2196         end
2197         it '作家登録ページへ遷移する' do
2198           get :edit, :id => @other_author.id
2199           response.body.should redirect_to new_author_path
2200         end
2201       end
2202     end
2203   end
2204
2205   describe '更新に於いて' do
2206     before do
2207       @attr = @author.attributes
2208       @attr['name'] = 'ryu'
2209       sign_in @user
2210     end
2211     context '事前チェックしておく' do
2212       it '作家モデルに編集取得を問い合わせている' do
2213         Author.stub(:edit).with(any_args()).and_return @author
2214         Author.should_receive(:edit).exactly(1)
2215         put :update, :id => @author.id, :author => @attr
2216       end
2217       it 'モデルにpostデータ転送を依頼する' do
2218         Author.any_instance.stub(:attributes=).with(any_args)
2219         Author.any_instance.should_receive(:attributes=).exactly(1)
2220         put :update, :id => @author.id, :author => @attr
2221       end
2222       it 'モデルに上書き補充を依頼する' do
2223         Author.any_instance.stub(:overwrite).with(any_args)
2224         Author.any_instance.should_receive(:overwrite).exactly(1)
2225         put :update, :id => @author.id, :author => @attr
2226       end
2227       it 'モデルに更新を依頼する' do
2228         Author.any_instance.stub(:save).with(any_args).and_return true
2229         Author.any_instance.should_receive(:save).exactly(1)
2230         put :update, :id => @author.id, :author => @attr
2231       end
2232       it '@auにアレを取得している' do
2233         put :update, :id => @author.id, :author => @attr
2234         assigns(:au).should eq @author
2235       end
2236     end
2237     context 'つつがなく終わるとき' do
2238       it '更新される' do
2239         put :update, :id => @author.id, :author => @attr
2240         Author.find(@author.id).name.should eq 'ryu'
2241       end
2242       context 'html形式' do
2243         it 'ステータスコード302 Foundを返す' do
2244           Author.any_instance.stub(:save).with(any_args()).and_return(true)
2245           put :update, :id => @author.id, :author => @attr
2246           response.status.should eq 302
2247         end
2248         it '設定ページへ遷移する' do
2249           put :update, :id => @author.id, :author => @attr
2250           response.should redirect_to('/home/configure')
2251         end
2252       end
2253       context 'json形式' do
2254         it 'ステータスコード200 OKを返す' do
2255           Author.any_instance.stub(:save).with(any_args()).and_return(true)
2256           put :update, :id => @author.id, :author => @attr, :format => :json
2257           response.should be_success 
2258         end
2259         it 'ページ本体は特に返さない' do
2260           Author.any_instance.stub(:save).with(any_args()).and_return(true)
2261           put :update, :id => @author.id, :author => @attr, :format => :json
2262           response.body.should match /./
2263         end
2264       end
2265     end
2266     context 'ユーザ権限がないとき' do
2267       before do
2268         sign_out @user
2269       end
2270       context 'html形式' do
2271         it 'ステータスコード302 Foundを返す' do
2272           put :update, :id => @author.id, :author => @attr
2273           response.status.should eq 302
2274         end
2275         it 'サインインページへ遷移する' do
2276           put :update, :id => @author.id, :author => @attr
2277           response.body.should redirect_to '/users/sign_in'
2278         end
2279       end
2280       context 'json形式' do
2281         it '応答メッセージにUnauthorizedを返す' do
2282           put :update, :id => @author.id, :author => @attr, :format => :json
2283           response.message.should match(/Unauthorized/)
2284         end
2285       end
2286     end
2287     context 'ユーザ権限はないが管理者権限があるとき' do
2288       before do
2289         sign_out @user
2290         sign_in @admin
2291       end
2292       context 'html形式' do
2293         it 'ステータスコード302 Foundを返す' do
2294           put :update, :id => @author.id, :author => @attr
2295           response.status.should eq 302
2296         end
2297         it 'サインインページへ遷移する' do
2298           put :update, :id => @author.id, :author => @attr
2299           response.body.should redirect_to '/users/sign_in'
2300         end
2301       end
2302     end
2303     context 'ユーザだが作家登録していないとき' do
2304       before do
2305         @other_user = FactoryGirl.create( :user_yas)
2306         @other_author = FactoryGirl.create :author, :user_id => @other_user.id
2307         @author.destroy
2308       end
2309       context 'html形式' do
2310         it 'ステータスコード302 Foundを返す' do
2311           get :update, :id => @other_author.id
2312           response.status.should eq 302
2313         end
2314         it '作家登録ページへ遷移する' do
2315           get :update, :id => @other_author.id
2316           response.body.should redirect_to new_author_path
2317         end
2318       end
2319     end
2320     context '検証、保存に失敗したとき' do
2321       before do
2322         Author.any_instance.stub(:save).and_return(false)
2323       end
2324       context 'html形式' do
2325         it 'ステータスコード200 Okを返す' do
2326           put :update, :id => @author.id, :author => @attr
2327           response.status.should eq 200
2328         end
2329         it '編集ページを描画する' do
2330           put :update, :id => @author.id, :author => @attr
2331           response.should render_template("edit")
2332         end
2333       end
2334       context 'json形式' do
2335         it 'ステータスコード422 unprocessable_entity を返す' do
2336           Author.any_instance.stub(:save).and_return(false)
2337           put :update, :id => @author.id, :author => @attr, :format => :json
2338           response.status.should eq 422
2339         end
2340         it '応答メッセージUnprocessable Entityを返す' do
2341           put :update, :id => @author.id, :author => @attr, :format => :json
2342           response.message.should match(/Unprocessable/)
2343         end
2344       end
2345     end
2346   end
2347
2348 else
2349   describe '一覧表示に於いて' do
2350     before do
2351       Author.stub(:list).and_return([@author, @author, @author])
2352       sign_in @user
2353     end
2354     context 'つつがなく終わるとき' do
2355       it 'ステータスコード200 OKを返す' do
2356         get :index
2357         response.should be_success 
2358       end
2359       context 'html形式' do
2360         it 'indexテンプレートを描画する' do
2361           get :index
2362           response.should render_template("index")
2363         end
2364       end
2365       context 'json形式' do
2366         it 'jsonデータを返す' do
2367           get :index, :format => :json
2368           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2369         end
2370       end
2371     end
2372     context 'ユーザ権限がないとき' do
2373       before do
2374         sign_out @user
2375       end
2376       it 'ステータスコード200 OKを返す' do
2377         get :index
2378         response.should be_success 
2379       end
2380       context 'html形式' do
2381         it 'indexテンプレートを描画する' do
2382           get :index
2383           response.should render_template("index")
2384         end
2385       end
2386       context 'json形式' do
2387         it 'jsonデータを返す' do
2388           get :index, :format => :json
2389           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2390         end
2391       end
2392     end
2393   end
2394   
2395   describe '閲覧に於いて' do
2396     before do
2397       Author.stub(:show).and_return(@author)
2398       sign_in @user
2399     end
2400     context 'つつがなく終わるとき' do
2401       it 'ステータスコード200 OKを返す' do
2402         get :show, :id => @author.id
2403         response.should be_success
2404       end
2405       context 'html形式' do
2406         it 'showテンプレートを描画する' do
2407           get :show, :id => @author.id
2408           response.should render_template("show")
2409         end
2410       end
2411       context 'json形式' do
2412         it 'jsonデータを返す' do
2413           get :show, :id => @author.id, :format => :json
2414           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2415         end
2416       end
2417     end
2418     context 'ユーザ権限がないとき' do
2419       before do
2420         sign_out @user
2421       end
2422       it 'ステータスコード200 OKを返す' do
2423         get :show, :id => @author.id
2424         response.should be_success
2425       end
2426       context 'html形式' do
2427         it 'showテンプレートを描画する' do
2428           get :show, :id => @author.id
2429           response.should render_template("show")
2430         end
2431       end
2432       context 'json形式' do
2433         it 'jsonデータを返す' do
2434           get :show, :id => @author.id, :format => :json
2435           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2436         end
2437       end
2438     end
2439   end
2440   
2441   describe '対象作家のスクロール一覧表示に於いて' do
2442     before do
2443       @other_user = FactoryGirl.create( :user_yas)
2444       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
2445       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
2446       @scroll = FactoryGirl.create :scroll, :author_id => @other_user.author.id
2447       Scroll.stub(:mylist).and_return([@scroll, @scroll, @scroll])
2448       sign_in @user
2449     end
2450     context 'つつがなく終わるとき' do
2451       it 'ステータスコード200 OKを返す' do
2452         get :scrolls, :id => @other_author.id
2453         response.should be_success 
2454       end
2455       context 'html形式' do
2456         it 'scrollテンプレートを描画する' do
2457           get :scrolls, :id => @other_author.id
2458           response.should render_template("scroll")
2459         end
2460       end
2461       context 'json形式' do
2462         it 'jsonデータを返す' do
2463           get :scrolls, :id => @other_author.id, :format => :json
2464           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2465         end
2466       end
2467     end
2468     context 'ユーザ権限がないとき' do
2469       before do
2470         sign_out @user
2471       end
2472       it 'ステータスコード200 OKを返す' do
2473         get :scrolls, :id => @other_author.id
2474         response.should be_success 
2475       end
2476       context 'html形式' do
2477         it 'scrollsテンプレートを描画する' do
2478           get :scrolls, :id => @other_author.id
2479           response.should render_template("scrolls")
2480         end
2481       end
2482       context 'json形式' do
2483         it 'jsonデータを返す' do
2484           get :scrolls, :id => @other_author.id, :format => :json
2485           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2486         end
2487       end
2488     end
2489   end
2490   
2491   describe '対象作家のスクコマ一覧表示に於いて' do
2492     before do
2493       @other_user = FactoryGirl.create( :user_yas)
2494       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
2495       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
2496       @scroll = FactoryGirl.create :scroll, :author_id => @other_user.author.id
2497       @panel = FactoryGirl.create :panel, :author_id => @other_author.id
2498       @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @other_author.id
2499       ScrollPanel.stub(:mylist).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
2500       sign_in @user
2501     end
2502     context 'つつがなく終わるとき' do
2503       it 'ステータスコード200 OKを返す' do
2504         get :scroll_panels, :id => @other_author.id
2505         response.should be_success 
2506       end
2507       context 'html形式' do
2508         it 'scroll_panelsテンプレートを描画する' do
2509           get :scroll_panels, :id => @other_author.id
2510           response.should render_template("scroll_panels")
2511         end
2512       end
2513       context 'json形式' do
2514         it 'jsonデータを返す' do
2515           get :scroll_panels, :id => @other_author.id, :format => :json
2516           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2517         end
2518       end
2519     end
2520     context 'ユーザ権限がないとき' do
2521       before do
2522         sign_out @user
2523       end
2524       it 'ステータスコード200 OKを返す' do
2525         get :scroll_panels, :id => @other_author.id
2526         response.should be_success 
2527       end
2528       context 'html形式' do
2529         it 'scroll_panelsテンプレートを描画する' do
2530           get :scroll_panels, :id => @other_author.id
2531           response.should render_template("scroll_panels")
2532         end
2533       end
2534       context 'json形式' do
2535         it 'jsonデータを返す' do
2536           get :scroll_panels, :id => @other_author.id, :format => :json
2537           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2538         end
2539       end
2540     end
2541   end
2542   
2543   describe '対象作家のコマ一覧表示に於いて' do
2544     before do
2545       @other_user = FactoryGirl.create( :user_yas)
2546       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
2547       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
2548       @panel = FactoryGirl.create :panel, :author_id => @other_author.id
2549       Panel.stub(:mylist).and_return([@panel, @panel, @panel])
2550       sign_in @user
2551     end
2552     context 'つつがなく終わるとき' do
2553       it 'ステータスコード200 OKを返す' do
2554         get :panels, :id => @other_author.id
2555         response.should be_success 
2556       end
2557       context 'html形式' do
2558         it 'panelsテンプレートを描画する' do
2559           get :panels, :id => @other_author.id
2560           response.should render_template("panels")
2561         end
2562       end
2563       context 'json形式' do
2564         it 'jsonデータを返す' do
2565           get :panels, :id => @other_author.id, :format => :json
2566           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2567         end
2568       end
2569     end
2570     context 'ユーザ権限がないとき' do
2571       before do
2572         sign_out @user
2573       end
2574       it 'ステータスコード200 OKを返す' do
2575         get :panels, :id => @other_author.id
2576         response.should be_success 
2577       end
2578       context 'html形式' do
2579         it 'panelsテンプレートを描画する' do
2580           get :panels, :id => @other_author.id
2581           response.should render_template("panels")
2582         end
2583       end
2584       context 'json形式' do
2585         it 'jsonデータを返す' do
2586           get :panels, :id => @other_author.id, :format => :json
2587           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2588         end
2589       end
2590     end
2591   end
2592   
2593   describe '対象作家のコマ絵一覧表示に於いて' do
2594     before do
2595       @other_user = FactoryGirl.create( :user_yas)
2596       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
2597       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
2598       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
2599       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
2600       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
2601       @panel = FactoryGirl.create :panel, :author_id => @author.id
2602       @panel_picture = FactoryGirl.create :panel_picture, :picture_id => @p.id, :panel_id => @panel.id, :width => @p.width, :height => @p.height
2603       PanelPicture.stub(:list).and_return([@panel_picture, @panel_picture, @panel_picture])
2604       sign_in @user
2605     end
2606     context 'つつがなく終わるとき' do
2607       it 'ステータスコード200 OKを返す' do
2608         get :panel_pictures, :id => @other_author.id
2609         response.should be_success 
2610       end
2611       context 'html形式' do
2612         it 'panel_picturesテンプレートを描画する' do
2613           get :panel_pictures, :id => @other_author.id
2614           response.should render_template("panel_pictures")
2615         end
2616       end
2617       context 'json形式' do
2618         it 'jsonデータを返す' do
2619           get :panel_pictures, :id => @other_author.id, :format => :json
2620           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2621         end
2622       end
2623     end
2624     context 'ユーザ権限がないとき' do
2625       before do
2626         sign_out @user
2627       end
2628       it 'ステータスコード200 OKを返す' do
2629         get :panel_pictures, :id => @other_author.id
2630         response.should be_success 
2631       end
2632       context 'html形式' do
2633         it 'panel_picturesテンプレートを描画する' do
2634           get :panel_pictures, :id => @other_author.id
2635           response.should render_template("panel_pictures")
2636         end
2637       end
2638       context 'json形式' do
2639         it 'jsonデータを返す' do
2640           get :panel_pictures, :id => @other_author.id, :format => :json
2641           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2642         end
2643       end
2644     end
2645   end
2646   
2647   describe '対象作家の絵地一覧表示に於いて' do
2648     before do
2649       @other_user = FactoryGirl.create( :user_yas)
2650       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
2651       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
2652       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
2653       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
2654       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
2655       @panel = FactoryGirl.create :panel, :author_id => @author.id
2656       @ground_picture = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
2657       GroundPicture.stub(:himlist).and_return([@ground_picture, @ground_picture, @ground_picture])
2658       sign_in @user
2659     end
2660     context 'つつがなく終わるとき' do
2661       it 'ステータスコード200 OKを返す' do
2662         get :ground_pictures, :id => @other_author.id
2663         response.should be_success 
2664       end
2665       context 'html形式' do
2666         it 'ground_picturesテンプレートを描画する' do
2667           get :ground_pictures, :id => @other_author.id
2668           response.should render_template("ground_pictures")
2669         end
2670       end
2671       context 'json形式' do
2672         it 'jsonデータを返す' do
2673           get :ground_pictures, :id => @other_author.id, :format => :json
2674           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2675         end
2676       end
2677     end
2678     context 'ユーザ権限がないとき' do
2679       before do
2680         sign_out @user
2681       end
2682       context 'html形式' do
2683         it 'ground_picturesテンプレートを描画する' do
2684           get :ground_pictures, :id => @other_author.id
2685           response.should render_template("ground_pictures")
2686         end
2687       end
2688       context 'json形式' do
2689         it 'jsonデータを返す' do
2690           get :ground_pictures, :id => @other_author.id, :format => :json
2691           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2692         end
2693       end
2694     end
2695   end
2696   
2697   describe '対象作家の色地一覧表示に於いて' do
2698     before do
2699       @other_user = FactoryGirl.create( :user_yas)
2700       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
2701       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
2702       @gc = FactoryGirl.create :ground_color
2703       @panel = FactoryGirl.create :panel, :author_id => @author.id
2704       GroundColor.stub(:himlist).and_return([@gc, @gc, @gc])
2705       sign_in @user
2706     end
2707     context 'つつがなく終わるとき' do
2708       it 'ステータスコード200 OKを返す' do
2709         get :ground_colors, :id => @other_author.id
2710         response.should be_success 
2711       end
2712       context 'html形式' do
2713         it 'ground_colorsテンプレートを描画する' do
2714           get :ground_colors, :id => @other_author.id
2715           response.should render_template("ground_colors")
2716         end
2717       end
2718       context 'json形式' do
2719         it 'jsonデータを返す' do
2720           get :ground_colors, :id => @other_author.id, :format => :json
2721           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2722         end
2723       end
2724     end
2725     context 'ユーザ権限がないとき' do
2726       before do
2727         sign_out @user
2728       end
2729       context 'html形式' do
2730         it 'ground_colorsテンプレートを描画する' do
2731           get :ground_colors, :id => @other_author.id
2732           response.should render_template("ground_colors")
2733         end
2734       end
2735       context 'json形式' do
2736         it 'jsonデータを返す' do
2737           get :ground_colors, :id => @other_author.id, :format => :json
2738           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2739         end
2740       end
2741     end
2742   end
2743   
2744   describe '作家数取得に於いて' do
2745     before do
2746       Author.should_receive(:visible_count).and_return(3)
2747 #      sign_in @user
2748     end
2749     context 'つつがなく終わるとき' do
2750       it 'ステータスコード200 OKを返す' do
2751         get :count, :format => :json
2752         response.should be_success 
2753       end
2754       context 'json形式' do
2755         it 'jsonデータを返す' do
2756           get :count, :format => :json
2757           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2758         end
2759       end
2760     end
2761   end
2762   
2763   describe '新規作成フォーム表示に於いて' do
2764     before do
2765       @new_user = FactoryGirl.create( :user_yas)
2766       sign_in @new_user
2767     end
2768     context 'つつがなく終わるとき' do
2769       it 'ステータスコード200 OKを返す' do
2770         get :new
2771         response.should be_success 
2772       end
2773       context 'html形式' do
2774         it 'newテンプレートを描画する' do
2775           get :new
2776           response.should render_template("new")
2777         end
2778       end
2779       context 'js形式' do
2780         it 'new.jsテンプレートを描画する' do
2781           get :new, :format => :js
2782           response.should render_template("new")
2783         end
2784       end
2785       context 'json形式' do
2786         it 'jsonデータを返す' do
2787           get :new, :format => :json
2788           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
2789         end
2790       end
2791     end
2792     context 'ユーザ権限がないとき' do
2793       before do
2794         sign_out @new_user
2795       end
2796       context 'html形式' do
2797         it 'ステータスコード302 Foundを返す' do
2798           get :new
2799           response.status.should eq 302
2800         end
2801         it 'サインインページへ遷移する' do
2802           get :new
2803           response.body.should redirect_to '/users/sign_in'
2804         end
2805       end
2806       context 'js形式' do
2807         it 'ステータスコード401 Unauthorizedを返す' do
2808           get :new, :format => :js
2809           response.status.should eq 401
2810         end
2811         it '応答メッセージにUnauthorizedを返す' do
2812           get :new, :format => :js
2813           response.message.should match(/Unauthorized/)
2814         end
2815       end
2816       context 'json形式' do
2817         it 'ステータスコード401 Unauthorizedを返す' do
2818           get :new, :format => :json
2819           response.status.should eq 401
2820         end
2821         it '応答メッセージにUnauthorizedを返す' do
2822           get :new, :format => :json
2823           response.message.should match(/Unauthorized/)
2824         end
2825       end
2826     end
2827   end
2828
2829   describe '新規作成に於いて' do
2830     before do
2831       @new_user = FactoryGirl.create( :user_yas)
2832       sign_in @new_user
2833       @attr = FactoryGirl.attributes_for(:author, :user_id => @new_user.id, :name => 'ken')
2834     end
2835     context 'つつがなく終わるとき' do
2836       context 'html形式' do
2837         it 'ステータスコード302 Foundを返す' do
2838           Author.any_instance.stub(:save).and_return(true)
2839           post :create, :author => @attr
2840           response.status.should eq 302
2841         end
2842         it 'トップページへ遷移する' do
2843 #          Author.any_instance.stub(:save).and_return(true)
2844           post :create, :author => @attr
2845           response.should redirect_to(root_path)
2846         end
2847       end
2848       context 'json形式' do
2849         it 'ステータスコード200 OKを返す' do
2850 #          Author.any_instance.stub(:save).and_return(true)
2851           post :create, :author => @attr, :format => :json
2852           response.should be_success 
2853         end
2854       end
2855     end
2856     context 'ユーザ権限がないとき' do
2857       before do
2858         sign_out @new_user
2859       end
2860       context 'html形式' do
2861         it 'ステータスコード302 Foundを返す' do
2862           post :create, :author => @attr
2863           response.status.should eq 302
2864         end
2865         it 'サインインページへ遷移する' do
2866           post :create, :author => @attr
2867           response.body.should redirect_to '/users/sign_in'
2868         end
2869       end
2870       context 'json形式' do
2871         it 'ステータスコード401 Unauthorizedを返す' do
2872           post :create, :author => @attr, :format => :json
2873           response.status.should eq 401
2874         end
2875         it '応答メッセージにUnauthorizedを返す' do
2876           post :create, :author => @attr, :format => :json
2877           response.message.should match(/Unauthorized/)
2878         end
2879       end
2880     end
2881   end
2882
2883   describe '編集フォーム表示に於いて' do
2884     before do
2885       sign_in @user
2886       Author.stub(:edit).and_return(@author)
2887     end
2888     context 'つつがなく終わるとき' do
2889       it 'ステータスコード200 OKを返す' do
2890         get :edit, :id => @author.id
2891         response.should be_success 
2892       end
2893       context 'html形式' do
2894         it 'editテンプレートを描画する' do
2895           get :edit, :id => @author.id
2896           response.should render_template("edit")
2897         end
2898       end
2899       context 'js形式' do
2900         it 'edit.jsテンプレートを描画する' do
2901           get :edit, :id => @author.id, :format => :js
2902           response.should render_template("edit")
2903         end
2904       end
2905     end
2906     context 'ユーザ権限がないとき' do
2907       before do
2908         sign_out @user
2909       end
2910       context 'html形式' do
2911         it 'ステータスコード302 Foundを返す' do
2912           get :edit, :id => @author.id
2913           response.status.should eq 302
2914         end
2915         it 'サインインページへ遷移する' do
2916           get :edit, :id => @author.id
2917           response.body.should redirect_to '/users/sign_in'
2918         end
2919       end
2920       context 'js形式' do
2921         it 'ステータスコード401 Unauthorizedを返す' do
2922           get :edit, :id => @author.id, :format => :js
2923           response.status.should eq 401
2924         end
2925         it '応答メッセージにUnauthorizedを返す' do
2926           get :edit, :id => @author.id, :format => :js
2927           response.message.should match(/Unauthorized/)
2928         end
2929       end
2930     end
2931   end
2932
2933   describe '更新に於いて' do
2934     before do
2935       @attr = @author.attributes
2936       @attr['name'] = 'ryu'
2937       sign_in @user
2938     end
2939     context 'つつがなく終わるとき' do
2940       it '更新される' do
2941         put :update, :id => @author.id, :author => @attr
2942         Author.find(@author.id).name.should eq 'ryu'
2943       end
2944       context 'html形式' do
2945         it 'ステータスコード302 Foundを返す' do
2946           Author.any_instance.stub(:save).with(any_args()).and_return(true)
2947           put :update, :id => @author.id, :author => @attr
2948           response.status.should eq 302
2949         end
2950         it '設定ページへ遷移する' do
2951           put :update, :id => @author.id, :author => @attr
2952           response.should redirect_to('/home/configure')
2953         end
2954       end
2955       context 'json形式' do
2956         it 'ステータスコード200 OKを返す' do
2957           Author.any_instance.stub(:save).with(any_args()).and_return(true)
2958           put :update, :id => @author.id, :author => @attr, :format => :json
2959           response.should be_success 
2960         end
2961         it 'ページ本体は特に返さない' do
2962           Author.any_instance.stub(:save).with(any_args()).and_return(true)
2963           put :update, :id => @author.id, :author => @attr, :format => :json
2964           response.body.should match /./
2965         end
2966       end
2967     end
2968     context 'ユーザ権限がないとき' do
2969       before do
2970         sign_out @user
2971       end
2972       it 'ステータスコード302 Foundを返す' do
2973         put :update, :id => @author.id, :author => @attr
2974         response.status.should eq 302
2975       end
2976       context 'html形式' do
2977         it 'サインインページへ遷移する' do
2978           put :update, :id => @author.id, :author => @attr
2979           response.body.should redirect_to '/users/sign_in'
2980         end
2981       end
2982       context 'json形式' do
2983         it '応答メッセージにUnauthorizedを返す' do
2984           put :update, :id => @author.id, :author => @attr, :format => :json
2985           response.message.should match(/Unauthorized/)
2986         end
2987       end
2988     end
2989   end
2990
2991 end
2992 end