OSDN Git Service

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