OSDN Git Service

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