OSDN Git Service

1abf51bccd2f78bfecca4c4785f0beae4dc7d337
[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     @user = FactoryGirl.create( :user_yas)
12     @author = FactoryGirl.create :author, :user_id => @user.id
13     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
14   end
15
16 if MagicNumber['run_mode'] == 1
17   describe '一覧表示に於いて' do
18     before do
19       Author.stub(:list).and_return([@author, @author, @author])
20       sign_in @user
21     end
22     context '事前チェックする' do
23       it '与えられたpageがセットされている' do
24         get :index, :page => 5
25         assigns(:page).should eq 5
26       end
27       it '省略されると@pageに1値が入る' do
28         get :index
29         assigns(:page).should eq 1
30       end
31       it '与えられたpage_sizeがセットされている' do
32         get :index, :page_size => 15
33         assigns(:page_size).should eq 15
34       end
35       it '省略されると@page_sizeにデフォルト値が入る' do
36         get :index
37         assigns(:page_size).should eq Author.default_page_size
38       end
39       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
40         get :index, :page_size => 1500
41         assigns(:page_size).should eq Author.max_page_size
42       end
43       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
44         get :index, :page_size => 0
45         assigns(:page_size).should eq Author.default_page_size
46       end
47     end
48     context 'つつがなく終わるとき' do
49       it 'ステータスコード200 OKを返す' do
50         get :index
51         response.should be_success 
52       end
53       it '作家モデルに一覧を問い合わせている' do
54         Author.should_receive(:list).exactly(1)
55         get :index
56       end
57       it '@authorsにリストを取得している' do
58         get :index
59         assigns(:authors).should have_at_least(3).items
60       end
61       context 'html形式' do
62         it 'indexテンプレートを描画する' do
63           get :index
64           response.should render_template("index")
65         end
66       end
67       context 'json形式' do
68         it 'jsonデータを返す' do
69           get :index, :format => :json
70           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
71         end
72         it '作家モデルにjson一覧出力オプションを問い合わせている' do
73           Author.should_receive(:list_json_opt).exactly(1)
74           get :index, :format => :json
75         end
76         it 'データがリスト構造になっている' do
77           get :index, :format => :json
78           json = JSON.parse response.body
79           json.should have_at_least(3).items
80         end
81         it 'リストの先頭くらいは作家っぽいものであって欲しい' do
82           get :index, :format => :json
83           json = JSON.parse response.body
84           json.first.has_key?("name").should be_true
85           json.first.has_key?("user_id").should be_true
86         end
87       end
88     end
89     context 'ユーザ権限がないとき' do
90       before do
91         sign_out @user
92       end
93       context 'html形式' do
94         it 'ステータスコード302 Foundを返す' do
95           get :index
96           response.status.should eq 302
97         end
98         it 'サインインページへ遷移する' do
99           get :index
100           response.should redirect_to '/users/sign_in'
101         end
102       end
103       context 'json形式' do
104         it 'ステータスコード401 Unauthorizedを返す' do
105           get :index, :format => :json
106           response.status.should eq 401
107         end
108         it '応答メッセージにUnauthorizedを返す' do
109           get :index, :format => :json
110           response.message.should match(/Unauthorized/)
111         end
112       end
113     end
114     context 'ユーザ権限はないが管理者権限があるとき' do
115       before do
116         sign_out @user
117         sign_in @admin
118       end
119       it 'ステータスコード200 OKを返す' do
120         get :index
121         response.should be_success 
122       end
123     end
124     context 'ユーザだが作家登録していないとき' do
125       before do
126         @author.destroy
127       end
128       it 'ステータスコード200 OKを返す' do
129         get :index
130         response.should be_success 
131       end
132     end
133   end
134   
135   describe '閲覧に於いて' do
136     before do
137       Author.stub(:show).and_return(@author)
138       sign_in @user
139     end
140     context 'つつがなく終わるとき' do
141       it 'ステータスコード200 OKを返す' do
142         get :show, :id => @author.id
143         response.should be_success
144       end
145       it '作家モデルに単体取得を問い合わせている' do
146         Author.should_receive(:show).exactly(1)
147         get :show
148       end
149       #@authorだとログイン中のアカウントと干渉してしまう。
150       it '@auにアレを取得している' do
151         get :show, :id => @author.id
152         assigns(:au).should eq(@author)
153       end
154       context 'html形式' do
155         it 'showテンプレートを描画する' do
156           get :show, :id => @author.id
157           response.should render_template("show")
158         end
159       end
160       context 'json形式' do
161         it 'jsonデータを返す' do
162           get :show, :id => @author.id, :format => :json
163           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
164         end
165         it '作家モデルにjson単体出力オプションを問い合わせている' do
166           Author.should_receive(:show_json_opt).exactly(1)
167           get :show, :id => @author.id, :format => :json
168         end
169         it 'データがアレになっている' do
170           get :show, :id => @author.id, :format => :json
171           json = JSON.parse response.body
172           json["name"].should match(/test/)
173           json["user_id"].should eq @author.user_id
174         end
175       end
176     end
177     context 'ユーザ権限がないとき' do
178       before do
179         sign_out @user
180       end
181       context 'html形式' do
182         it 'ステータスコード302 Foundを返す' do
183           get :show, :id => @author.id
184           response.status.should eq 302
185         end
186         it 'サインインページへ遷移する' do
187           get :show, :id => @author.id
188           response.body.should redirect_to '/users/sign_in'
189         end
190       end
191       context 'json形式' do
192         it 'ステータスコード401 Unauthorizedを返す' do
193           get :show, :id => @author.id, :format => :json
194           response.status.should eq 401
195         end
196         it '応答メッセージにUnauthorizedを返す' do
197           get :show, :id => @author.id, :format => :json
198           response.message.should match(/Unauthorized/)
199         end
200       end
201     end
202     context 'ユーザ権限はないが管理者権限があるとき' do
203       before do
204         sign_out @user
205         sign_in @admin
206       end
207       it 'ステータスコード200 OKを返す' do
208         get :show, :id => @author.id
209         response.should be_success 
210       end
211     end
212     context 'ユーザだが作家登録していないとき' do
213       before do
214         @author.destroy
215       end
216       it 'ステータスコード200 OKを返す' do
217         get :show, :id => @author.id
218         response.should be_success 
219       end
220     end
221 =begin
222     context '対象作家がないとき' do
223       context 'html形式' do
224         it '例外404 not_foundを返す' do
225           lambda{
226             get :show, :id => 0
227           }.should raise_error(ActiveRecord::RecordNotFound)
228         end
229       end
230       context 'json形式' do
231         it '例外404 not_foundを返す' do
232           lambda{ 
233             get :show, :id => 0, :format => :json
234           }.should raise_error(ActiveRecord::RecordNotFound)
235         end
236       end
237     end
238 =end
239   end
240   
241   describe '対象作家のコミック一覧表示に於いて' do
242     before do
243       @other_user = FactoryGirl.create( :user_yas)
244       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
245       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
246       @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id
247       Comic.stub(:himlist).and_return([@comic, @comic, @comic])
248       sign_in @user
249     end
250     context 'パラメータpageについて' do
251       it '@pageに値が入る' do
252         get :comics, :id => @other_author.id, :page => 5
253         assigns(:page).should eq 5
254       end
255       it '省略されると@pageに1値が入る' do
256         get :comics, :id => @other_author.id
257         assigns(:page).should eq 1
258       end
259       it '与えられたpage_sizeがセットされている' do
260         get :comics, :id => @other_author.id, :page_size => 15
261         assigns(:page_size).should eq 15
262       end
263       it '省略されると@page_sizeにデフォルト値が入る' do
264         get :comics, :id => @other_author.id
265         assigns(:page_size).should eq Author.default_comic_page_size
266       end
267       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
268         get :comics, :id => @other_author.id, :page_size => 1500
269         assigns(:page_size).should eq Author.comic_max_page_size
270       end
271       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
272         get :comics, :id => @other_author.id, :page_size => 0
273         assigns(:page_size).should eq Author.default_comic_page_size
274       end
275     end
276     context 'つつがなく終わるとき' do
277       it 'ステータスコード200 OKを返す' do
278         get :comics, :id => @other_author.id
279         response.should be_success 
280       end
281       it '作家モデルに単体取得を問い合わせている' do
282         Author.should_receive(:show).exactly(1)
283         get :comics, :id => @other_author.id
284       end
285       it 'コミックモデルに一覧を問い合わせている' do
286         Comic.should_receive(:himlist).exactly(1)
287         get :comics, :id => @other_author.id
288       end
289       it '@comicsにリストを取得している' do
290         get :comics, :id => @other_author.id
291         assigns(:comics).should have_at_least(3).items
292       end
293       context 'html形式' do
294         it 'comicsテンプレートを描画する' do
295           get :comics, :id => @other_author.id
296           response.should render_template("comics")
297         end
298       end
299       context 'json形式' do
300         it 'jsonデータを返す' do
301           get :comics, :id => @other_author.id, :format => :json
302           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
303         end
304         it 'コミックモデルにjson一覧出力オプションを問い合わせている' do
305           Comic.should_receive(:list_json_opt).exactly(1)
306           get :comics, :id => @other_author.id, :format => :json
307         end
308         it 'データがリスト構造になっている' do
309           get :comics, :id => @other_author.id, :format => :json
310           json = JSON.parse response.body
311           json.should have_at_least(3).items
312         end
313         it 'リストの先頭くらいはコミックっぽいものであって欲しい' do
314           get :comics, :id => @other_author.id, :format => :json
315           json = JSON.parse response.body
316           json.first.has_key?("title").should be_true
317           json.first.has_key?("visible").should be_true
318         end
319       end
320     end
321     context 'ユーザ権限がないとき' do
322       before do
323         sign_out @user
324       end
325       context 'html形式' do
326         it 'ステータスコード302 Foundを返す' do
327           get :comics, :id => @other_author.id
328           response.status.should eq 302
329         end
330         it 'サインインページへ遷移する' do
331           get :comics, :id => @other_author.id
332           response.should redirect_to '/users/sign_in'
333         end
334       end
335       context 'json形式' do
336         it 'ステータスコード401 Unauthorizedを返す' do
337           get :comics, :id => @other_author.id, :format => :json
338           response.status.should eq 401
339         end
340         it '応答メッセージにUnauthorizedを返す' do
341           get :comics, :id => @other_author.id, :format => :json
342           response.message.should match(/Unauthorized/)
343         end
344       end
345     end
346     context 'ユーザ権限はないが管理者権限があるとき' do
347       before do
348         sign_out @user
349         sign_in @admin
350       end
351       it 'ステータスコード200 OKを返す' do
352         get :comics, :id => @other_author.id
353         response.should be_success 
354       end
355     end
356     context 'ユーザだが作家登録していないとき' do
357       before do
358         @author.destroy
359       end
360       it 'ステータスコード200 OKを返す' do
361         get :comics, :id => @other_author.id
362         response.should be_success 
363       end
364     end
365   end
366   
367   describe '対象作家のストーリー一覧表示に於いて' do
368     before do
369       @other_user = FactoryGirl.create( :user_yas)
370       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
371       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
372       @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id
373       @panel = FactoryGirl.create :panel, :author_id => @other_user.author.id
374       @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @other_user.author.id
375       Story.stub(:himlist).and_return([@story, @story, @story])
376       sign_in @user
377     end
378     context 'パラメータpageについて' do
379       it '@pageに値が入る' do
380         get :stories, :id => @other_author.id, :page => 5
381         assigns(:page).should eq 5
382       end
383       it '省略されると@pageに1値が入る' do
384         get :stories, :id => @other_author.id
385         assigns(:page).should eq 1
386       end
387       it '与えられたpage_sizeがセットされている' do
388         get :stories, :id => @other_author.id, :page_size => 15
389         assigns(:page_size).should eq 15
390       end
391       it '省略されると@page_sizeにデフォルト値が入る' do
392         get :stories, :id => @other_author.id
393         assigns(:page_size).should eq Author.default_story_page_size
394       end
395       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
396         get :stories, :id => @other_author.id, :page_size => 1500
397         assigns(:page_size).should eq Author.story_max_page_size
398       end
399       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
400         get :stories, :id => @other_author.id, :page_size => 0
401         assigns(:page_size).should eq Author.default_story_page_size
402       end
403     end
404     context 'つつがなく終わるとき' do
405       it 'ステータスコード200 OKを返す' do
406         get :stories, :id => @other_author.id
407         response.should be_success 
408       end
409       it '作家モデルに単体取得を問い合わせている' do
410         Author.should_receive(:show).exactly(1)
411         get :stories, :id => @other_author.id
412       end
413       it 'ストーリーモデルに他作家のストーリー一覧を問い合わせている' do
414         Story.should_receive(:himlist).exactly(1)
415         get :stories, :id => @other_author.id
416       end
417       it '@storiesにリストを取得している' do
418         get :stories, :id => @other_author.id
419         assigns(:stories).should have_at_least(3).items
420       end
421       context 'html形式' do
422         it 'storiesテンプレートを描画する' do
423           get :stories, :id => @other_author.id
424           response.should render_template("stories")
425         end
426       end
427       context 'json形式' do
428         it 'jsonデータを返す' do
429           get :stories, :id => @other_author.id, :format => :json
430           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
431         end
432         it 'ストーリーモデルにjson一覧出力オプションを問い合わせている' do
433           Story.should_receive(:list_json_opt).exactly(1)
434           get :stories, :id => @other_author.id, :format => :json
435         end
436         it 'データがリスト構造になっている' do
437           get :stories, :id => @other_author.id, :format => :json
438           json = JSON.parse response.body
439           json.should have_at_least(3).items
440         end
441         it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
442           get :stories, :id => @other_author.id, :format => :json
443           json = JSON.parse response.body
444           json.first.has_key?("panel_id").should be_true
445           json.first.has_key?("comic_id").should be_true
446           json.first.has_key?("t").should be_true
447         end
448       end
449     end
450     context 'ユーザ権限がないとき' do
451       before do
452         sign_out @user
453       end
454       context 'html形式' do
455         it 'ステータスコード302 Foundを返す' do
456           get :stories, :id => @other_author.id
457           response.status.should eq 302
458         end
459         it 'サインインページへ遷移する' do
460           get :stories, :id => @other_author.id
461           response.should redirect_to '/users/sign_in'
462         end
463       end
464       context 'json形式' do
465         it 'ステータスコード401 Unauthorizedを返す' do
466           get :stories, :id => @other_author.id, :format => :json
467           response.status.should eq 401
468         end
469         it '応答メッセージにUnauthorizedを返す' do
470           get :stories, :id => @other_author.id, :format => :json
471           response.message.should match(/Unauthorized/)
472         end
473       end
474     end
475     context 'ユーザ権限はないが管理者権限があるとき' do
476       before do
477         sign_out @user
478         sign_in @admin
479       end
480       it 'ステータスコード200 OKを返す' do
481         get :stories, :id => @other_author.id
482         response.should be_success 
483       end
484     end
485     context 'ユーザだが作家登録していないとき' do
486       before do
487         @author.destroy
488       end
489       it 'ステータスコード200 OKを返す' do
490         get :stories, :id => @other_author.id
491         response.should be_success 
492       end
493     end
494   end
495   
496   describe '対象作家のコマ一覧表示に於いて' do
497     before do
498       @other_user = FactoryGirl.create( :user_yas)
499       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
500       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
501       @panel = FactoryGirl.create :panel, :author_id => @other_author.id
502       Panel.stub(:himlist).and_return([@panel, @panel, @panel])
503       sign_in @user
504     end
505     context 'パラメータpageについて' do
506       it '@pageに値が入る' do
507         get :panels, :id => @other_author.id, :page => 5
508         assigns(:page).should eq 5
509       end
510       it '省略されると@pageに1値が入る' do
511         get :panels, :id => @other_author.id
512         assigns(:page).should eq 1
513       end
514       it '与えられたpage_sizeがセットされている' do
515         get :panels, :id => @other_author.id, :page_size => 15
516         assigns(:page_size).should eq 15
517       end
518       it '省略されると@page_sizeにデフォルト値が入る' do
519         get :panels, :id => @other_author.id
520         assigns(:page_size).should eq Author.default_panel_page_size
521       end
522       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
523         get :panels, :id => @other_author.id, :page_size => 1500
524         assigns(:page_size).should eq Author.panel_max_page_size
525       end
526       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
527         get :panels, :id => @other_author.id, :page_size => 0
528         assigns(:page_size).should eq Author.default_panel_page_size
529       end
530     end
531     context 'つつがなく終わるとき' do
532       it 'ステータスコード200 OKを返す' do
533         get :panels, :id => @other_author.id
534         response.should be_success 
535       end
536       it '作家モデルに単体取得を問い合わせている' do
537         Author.should_receive(:show).exactly(1)
538         get :panels, :id => @other_author.id
539       end
540       it 'コマモデルに他作家のコマ一覧を問い合わせている' do
541         Panel.should_receive(:himlist).exactly(1)
542         get :panels, :id => @other_author.id
543       end
544       it '@panelsにリストを取得している' do
545         get :panels, :id => @other_author.id
546         assigns(:panels).should have_at_least(3).items
547       end
548       context 'html形式' do
549         it 'panelsテンプレートを描画する' do
550           get :panels, :id => @other_author.id
551           response.should render_template("panels")
552         end
553       end
554       context 'json形式' do
555         it 'jsonデータを返す' do
556           get :panels, :id => @other_author.id, :format => :json
557           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
558         end
559         it 'コマモデルにコマリストのjson出力を問い合わせている' do
560           Panel.should_receive(:list_as_json_text).exactly(1)
561           get :panels, :id => @other_author.id, :format => :json
562         end
563         it 'データがリスト構造になっている' do
564           get :panels, :id => @other_author.id, :format => :json
565           json = JSON.parse response.body
566           json.should have_at_least(3).items
567         end
568         it 'リストの先頭くらいはコマっぽいものであって欲しい' do
569           get :panels, :id => @other_author.id, :format => :json
570           json = JSON.parse response.body
571           json.first.has_key?("z").should be_true
572         end
573       end
574     end
575     context 'ユーザ権限がないとき' do
576       before do
577         sign_out @user
578       end
579       context 'html形式' do
580         it 'ステータスコード302 Foundを返す' do
581           get :panels, :id => @other_author.id
582           response.status.should eq 302
583         end
584         it 'サインインページへ遷移する' do
585           get :panels, :id => @other_author.id
586           response.should redirect_to '/users/sign_in'
587         end
588       end
589       context 'json形式' do
590         it 'ステータスコード401 Unauthorizedを返す' do
591           get :panels, :id => @other_author.id, :format => :json
592           response.status.should eq 401
593         end
594         it '応答メッセージにUnauthorizedを返す' do
595           get :panels, :id => @other_author.id, :format => :json
596           response.message.should match(/Unauthorized/)
597         end
598       end
599     end
600     context 'ユーザ権限はないが管理者権限があるとき' do
601       before do
602         sign_out @user
603         sign_in @admin
604       end
605       it 'ステータスコード200 OKを返す' do
606         get :panels, :id => @other_author.id
607         response.should be_success 
608       end
609     end
610     context 'ユーザだが作家登録していないとき' do
611       before do
612         @author.destroy
613       end
614       it 'ステータスコード200 OKを返す' do
615         get :panels, :id => @other_author.id
616         response.should be_success 
617       end
618     end
619   end
620   
621   describe '作家数取得に於いて' do
622     before do
623       Author.should_receive(:visible_count).and_return(3)
624 #      sign_in @user
625     end
626     context 'つつがなく終わるとき' do
627       it 'ステータスコード200 OKを返す' do
628         get :count, :format => :json
629         response.should be_success 
630       end
631       context 'json形式' do
632         it 'jsonデータを返す' do
633           get :count, :format => :json
634           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
635         end
636         it 'データがHash構造になっていて作家数が3である' do
637           get :count, :format => :json
638           json = JSON.parse response.body
639           json["count"].should == 3
640         end
641       end
642     end
643   end
644   
645   describe '新規作成フォーム表示に於いて' do
646     before do
647       @new_user = FactoryGirl.create( :user_yas)
648       sign_in @new_user
649     end
650     context 'つつがなく終わるとき' do
651       it 'ステータスコード200 OKを返す' do
652         get :new
653         response.should be_success 
654       end
655       it '@auに新規データを用意している' do
656         get :new
657         assigns(:au).should be_a_new(Author)
658       end
659       it '作家モデルにデフォルト値補充を依頼している' do
660         Author.any_instance.should_receive(:supply_default).exactly(1)
661         get :new
662       end
663       context 'html形式' do
664         it 'newテンプレートを描画する' do
665           get :new
666           response.should render_template("new")
667         end
668       end
669       context 'js形式' do
670         it 'new.jsテンプレートを描画する' do
671           get :new, :format => :js
672           response.should render_template("new")
673         end
674       end
675       context 'json形式' do
676         it 'jsonデータを返す' do
677           get :new, :format => :json
678           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
679         end
680         it '作家モデルにjson単体出力オプションを問い合わせている' do
681           Author.should_receive(:show_json_opt).exactly(1)
682           get :new, :format => :json
683         end
684       end
685     end
686     context 'ユーザ権限がないとき' do
687       before do
688         sign_out @new_user
689       end
690       context 'html形式' do
691         it 'ステータスコード302 Foundを返す' do
692           get :new
693           response.status.should eq 302
694         end
695         it 'サインインページへ遷移する' do
696           get :new
697           response.body.should redirect_to '/users/sign_in'
698         end
699       end
700       context 'js形式' do
701         it 'ステータスコード401 Unauthorizedを返す' do
702           get :new, :format => :js
703           response.status.should eq 401
704         end
705         it '応答メッセージにUnauthorizedを返す' do
706           get :new, :format => :js
707           response.message.should match(/Unauthorized/)
708         end
709       end
710       context 'json形式' do
711         it 'ステータスコード401 Unauthorizedを返す' do
712           get :new, :format => :json
713           response.status.should eq 401
714         end
715         it '応答メッセージにUnauthorizedを返す' do
716           get :new, :format => :json
717           response.message.should match(/Unauthorized/)
718         end
719       end
720     end
721     context 'ユーザ権限はないが管理者権限があるとき' do
722       before do
723         sign_out @user
724         sign_in @admin
725       end
726       context 'html形式' do
727         it 'ステータスコード302 Foundを返す' do
728           get :new
729           response.status.should eq 302
730         end
731         it 'サインインページへ遷移する' do
732           get :new
733           response.body.should redirect_to '/users/sign_in'
734         end
735       end
736     end
737     context 'ユーザだが作家登録していないとき' do
738       before do
739         @author.destroy
740       end
741       it 'ステータスコード200 OKを返す' do
742           get :new
743         response.should be_success 
744       end
745     end
746   end
747
748   describe '新規作成に於いて' do
749     before do
750       @new_user = FactoryGirl.create( :user_yas)
751       sign_in @new_user
752       @attr = FactoryGirl.attributes_for(:author, :user_id => @new_user.id, :name => 'ken')
753     end
754     context '事前チェックしておく' do
755       it '作家モデルにデフォルト値補充を依頼している' do
756         Author.any_instance.should_receive(:supply_default).exactly(1)
757         post :create, :author => @attr
758       end
759       it '作家モデルにカラム値復元を依頼している' do
760         Author.any_instance.should_receive(:attributes=).exactly(1)
761         post :create, :author => @attr
762       end
763       it '作家モデルに上書き補充を依頼している' do
764         Author.any_instance.should_receive(:overwrite).exactly(1)
765         post :create, :author => @attr
766       end
767       it 'モデルに保存依頼する' do
768         Author.any_instance.should_receive(:save).exactly(1)
769         post :create, :author => @attr
770       end
771     end
772     context 'つつがなく終わるとき' do
773       it "@auに作成された作家を保持していて、それがDBにある" do
774         post :create, :author => @attr
775         assigns(:au).should be_a(Author)
776         assigns(:au).should be_persisted
777       end
778       context 'html形式' do
779         it 'ステータスコード302 Foundを返す' do
780           Author.any_instance.stub(:save).and_return(true)
781           post :create, :author => @attr
782           response.status.should eq 302
783         end
784         it 'トップページへ遷移する' do
785 #          Author.any_instance.stub(:save).and_return(true)
786           post :create, :author => @attr
787           response.should redirect_to(root_path)
788         end
789       end
790       context 'json形式' do
791         it 'ステータスコード200 OKを返す' do
792 #          Author.any_instance.stub(:save).and_return(true)
793           post :create, :author => @attr, :format => :json
794           response.should be_success 
795         end
796         it '作成された作家をjsonデータで返す' do
797           post :create, :author => @attr, :format => :json
798           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
799         end
800         it '作家モデルにjson単体出力オプションを問い合わせている' do
801           Author.should_receive(:show_json_opt).exactly(1)
802           post :create, :author => @attr, :format => :json
803         end
804         it 'データがアレになっている' do
805           post :create, :author => @attr, :format => :json
806           json = JSON.parse response.body
807           json["name"].should match(/ken/)
808         end
809       end
810     end
811     context 'ユーザ権限がないとき' do
812       before do
813         sign_out @new_user
814       end
815       context 'html形式' do
816         it 'ステータスコード302 Foundを返す' do
817           post :create, :author => @attr
818           response.status.should eq 302
819         end
820         it 'サインインページへ遷移する' do
821           post :create, :author => @attr
822           response.body.should redirect_to '/users/sign_in'
823         end
824       end
825       context 'json形式' do
826         it 'ステータスコード401 Unauthorizedを返す' do
827           post :create, :author => @attr, :format => :json
828           response.status.should eq 401
829         end
830         it '応答メッセージにUnauthorizedを返す' do
831           post :create, :author => @attr, :format => :json
832           response.message.should match(/Unauthorized/)
833         end
834       end
835     end
836     context 'ユーザ権限はないが管理者権限があるとき' do
837       before do
838         sign_out @user
839         sign_in @admin
840       end
841       context 'html形式' do
842         it 'ステータスコード302 Foundを返す' do
843           post :create, :author => @attr
844           response.status.should eq 302
845         end
846         it 'サインインページへ遷移する' do
847           post :create, :author => @attr
848           response.body.should redirect_to '/users/sign_in'
849         end
850       end
851     end
852     context '検証、保存に失敗した' do
853       before do
854         Author.any_instance.stub(:save).and_return(false)
855       end
856       it "未保存の作家を保持している" do
857         post :create, :author => @attr
858         assigns(:au).should be_a_new(Author)
859       end
860       context 'html形式' do
861         it 'ステータスコード200 OKを返す' do
862           post :create, :author => @attr
863           response.status.should eq 200
864         end
865         it '新規ページを描画する' do
866           post :create, :author => @attr
867           response.should render_template("new")
868         end
869       end
870       context 'json形式' do
871         it 'ステータスコード422 unprocessable_entity を返す' do
872           post :create, :author => @attr, :format => :json
873           response.status.should eq 422
874         end
875         it '応答メッセージUnprocessable Entityを返す' do
876           post :create, :author => @attr, :format => :json
877           response.message.should match(/Unprocessable/)
878         end
879       end
880     end
881   end
882
883   describe '編集フォーム表示に於いて' do
884     before do
885       sign_in @user
886       Author.stub(:edit).and_return(@author)
887     end
888     context 'つつがなく終わるとき' do
889       it 'ステータスコード200 OKを返す' do
890         get :edit, :id => @author.id
891         response.should be_success 
892       end
893       it '作家モデルに編集取得を問い合わせている' do
894         Author.should_receive(:edit).exactly(1)
895         get :edit, :id => @author.id
896       end
897       #@authorだとログイン中のアカウントと干渉してしまう。
898       it '@auにデータを用意している' do
899         get :edit, :id => @author.id
900         assigns(:au).should eq @author
901       end
902       context 'html形式' do
903         it 'editテンプレートを描画する' do
904           get :edit, :id => @author.id
905           response.should render_template("edit")
906         end
907       end
908       context 'js形式' do
909         it 'edit.jsテンプレートを描画する' do
910           get :edit, :id => @author.id, :format => :js
911           response.should render_template("edit")
912         end
913       end
914     end
915     context 'ユーザ権限がないとき' do
916       before do
917         sign_out @user
918       end
919       context 'html形式' do
920         it 'ステータスコード302 Foundを返す' do
921           get :edit, :id => @author.id
922           response.status.should eq 302
923         end
924         it 'サインインページへ遷移する' do
925           get :edit, :id => @author.id
926           response.body.should redirect_to '/users/sign_in'
927         end
928       end
929       context 'js形式' do
930         it 'ステータスコード401 Unauthorizedを返す' do
931           get :edit, :id => @author.id, :format => :js
932           response.status.should eq 401
933         end
934         it '応答メッセージにUnauthorizedを返す' do
935           get :edit, :id => @author.id, :format => :js
936           response.message.should match(/Unauthorized/)
937         end
938       end
939     end
940     context 'ユーザ権限はないが管理者権限があるとき' do
941       before do
942         sign_out @user
943         sign_in @admin
944       end
945       context 'html形式' do
946         it 'ステータスコード302 Foundを返す' do
947           get :edit, :id => @author.id
948           response.status.should eq 302
949         end
950         it 'サインインページへ遷移する' do
951           get :edit, :id => @author.id
952           response.body.should redirect_to '/users/sign_in'
953         end
954       end
955     end
956     context 'ユーザだが作家登録していないとき' do
957       before do
958         @other_user = FactoryGirl.create( :user_yas)
959         @other_author = FactoryGirl.create :author, :user_id => @other_user.id
960         @author.destroy
961       end
962       context 'html形式' do
963         it 'ステータスコード302 Foundを返す' do
964           get :edit, :id => @other_author.id
965           response.status.should eq 302
966         end
967         it '作家登録ページへ遷移する' do
968           get :edit, :id => @other_author.id
969           response.body.should redirect_to new_author_path
970         end
971       end
972     end
973   end
974
975   describe '更新に於いて' do
976     before do
977       @attr = @author.attributes
978       @attr['name'] = 'ryu'
979       sign_in @user
980     end
981     context '事前チェックしておく' do
982       it '作家モデルに編集取得を問い合わせている' do
983         Author.stub(:edit).with(any_args()).and_return @author
984         Author.should_receive(:edit).exactly(1)
985         put :update, :id => @author.id, :author => @attr
986       end
987       it 'モデルにpostデータ転送を依頼する' do
988         Author.any_instance.stub(:attributes=).with(any_args)
989         Author.any_instance.should_receive(:attributes=).exactly(1)
990         put :update, :id => @author.id, :author => @attr
991       end
992       it 'モデルに上書き補充を依頼する' do
993         Author.any_instance.stub(:overwrite).with(any_args)
994         Author.any_instance.should_receive(:overwrite).exactly(1)
995         put :update, :id => @author.id, :author => @attr
996       end
997       it 'モデルに更新を依頼する' do
998         Author.any_instance.stub(:save).with(any_args).and_return true
999         Author.any_instance.should_receive(:save).exactly(1)
1000         put :update, :id => @author.id, :author => @attr
1001       end
1002       it '@auにアレを取得している' do
1003         put :update, :id => @author.id, :author => @attr
1004         assigns(:au).should eq @author
1005       end
1006     end
1007     context 'つつがなく終わるとき' do
1008       it '更新される' do
1009         put :update, :id => @author.id, :author => @attr
1010         Author.find(@author.id).name.should eq 'ryu'
1011       end
1012       context 'html形式' do
1013         it 'ステータスコード302 Foundを返す' do
1014           Author.any_instance.stub(:save).with(any_args()).and_return(true)
1015           put :update, :id => @author.id, :author => @attr
1016           response.status.should eq 302
1017         end
1018         it '設定ページへ遷移する' do
1019           put :update, :id => @author.id, :author => @attr
1020           response.should redirect_to('/home/configure')
1021         end
1022       end
1023       context 'json形式' do
1024         it 'ステータスコード200 OKを返す' do
1025           Author.any_instance.stub(:save).with(any_args()).and_return(true)
1026           put :update, :id => @author.id, :author => @attr, :format => :json
1027           response.should be_success 
1028         end
1029         it 'ページ本体は特に返さない' do
1030           Author.any_instance.stub(:save).with(any_args()).and_return(true)
1031           put :update, :id => @author.id, :author => @attr, :format => :json
1032           response.body.should match /./
1033         end
1034       end
1035     end
1036     context 'ユーザ権限がないとき' do
1037       before do
1038         sign_out @user
1039       end
1040       context 'html形式' do
1041         it 'ステータスコード302 Foundを返す' do
1042           put :update, :id => @author.id, :author => @attr
1043           response.status.should eq 302
1044         end
1045         it 'サインインページへ遷移する' do
1046           put :update, :id => @author.id, :author => @attr
1047           response.body.should redirect_to '/users/sign_in'
1048         end
1049       end
1050       context 'json形式' do
1051         it '応答メッセージにUnauthorizedを返す' do
1052           put :update, :id => @author.id, :author => @attr, :format => :json
1053           response.message.should match(/Unauthorized/)
1054         end
1055       end
1056     end
1057     context 'ユーザ権限はないが管理者権限があるとき' do
1058       before do
1059         sign_out @user
1060         sign_in @admin
1061       end
1062       context 'html形式' do
1063         it 'ステータスコード302 Foundを返す' do
1064           put :update, :id => @author.id, :author => @attr
1065           response.status.should eq 302
1066         end
1067         it 'サインインページへ遷移する' do
1068           put :update, :id => @author.id, :author => @attr
1069           response.body.should redirect_to '/users/sign_in'
1070         end
1071       end
1072     end
1073     context 'ユーザだが作家登録していないとき' do
1074       before do
1075         @other_user = FactoryGirl.create( :user_yas)
1076         @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1077         @author.destroy
1078       end
1079       context 'html形式' do
1080         it 'ステータスコード302 Foundを返す' do
1081           get :update, :id => @other_author.id
1082           response.status.should eq 302
1083         end
1084         it '作家登録ページへ遷移する' do
1085           get :update, :id => @other_author.id
1086           response.body.should redirect_to new_author_path
1087         end
1088       end
1089     end
1090     context '検証、保存に失敗したとき' do
1091       before do
1092         Author.any_instance.stub(:save).and_return(false)
1093       end
1094       context 'html形式' do
1095         it 'ステータスコード200 Okを返す' do
1096           put :update, :id => @author.id, :author => @attr
1097           response.status.should eq 200
1098         end
1099         it '編集ページを描画する' do
1100           put :update, :id => @author.id, :author => @attr
1101           response.should render_template("edit")
1102         end
1103       end
1104       context 'json形式' do
1105         it 'ステータスコード422 unprocessable_entity を返す' do
1106           Author.any_instance.stub(:save).and_return(false)
1107           put :update, :id => @author.id, :author => @attr, :format => :json
1108           response.status.should eq 422
1109         end
1110         it '応答メッセージUnprocessable Entityを返す' do
1111           put :update, :id => @author.id, :author => @attr, :format => :json
1112           response.message.should match(/Unprocessable/)
1113         end
1114       end
1115     end
1116   end
1117
1118 else
1119   describe '一覧表示に於いて' do
1120     before do
1121       Author.stub(:list).and_return([@author, @author, @author])
1122       sign_in @user
1123     end
1124     context 'つつがなく終わるとき' do
1125       it 'ステータスコード200 OKを返す' do
1126         get :index
1127         response.should be_success 
1128       end
1129       context 'html形式' do
1130         it 'indexテンプレートを描画する' do
1131           get :index
1132           response.should render_template("index")
1133         end
1134       end
1135       context 'json形式' do
1136         it 'jsonデータを返す' do
1137           get :index, :format => :json
1138           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1139         end
1140       end
1141     end
1142     context 'ユーザ権限がないとき' do
1143       before do
1144         sign_out @user
1145       end
1146       it 'ステータスコード200 OKを返す' do
1147         get :index
1148         response.should be_success 
1149       end
1150       context 'html形式' do
1151         it 'indexテンプレートを描画する' do
1152           get :index
1153           response.should render_template("index")
1154         end
1155       end
1156       context 'json形式' do
1157         it 'jsonデータを返す' do
1158           get :index, :format => :json
1159           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1160         end
1161       end
1162     end
1163   end
1164   
1165   describe '閲覧に於いて' do
1166     before do
1167       Author.stub(:show).and_return(@author)
1168       sign_in @user
1169     end
1170     context 'つつがなく終わるとき' do
1171       it 'ステータスコード200 OKを返す' do
1172         get :show, :id => @author.id
1173         response.should be_success
1174       end
1175       context 'html形式' do
1176         it 'showテンプレートを描画する' do
1177           get :show, :id => @author.id
1178           response.should render_template("show")
1179         end
1180       end
1181       context 'json形式' do
1182         it 'jsonデータを返す' do
1183           get :show, :id => @author.id, :format => :json
1184           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1185         end
1186       end
1187     end
1188     context 'ユーザ権限がないとき' do
1189       before do
1190         sign_out @user
1191       end
1192       it 'ステータスコード200 OKを返す' do
1193         get :show, :id => @author.id
1194         response.should be_success
1195       end
1196       context 'html形式' do
1197         it 'showテンプレートを描画する' do
1198           get :show, :id => @author.id
1199           response.should render_template("show")
1200         end
1201       end
1202       context 'json形式' do
1203         it 'jsonデータを返す' do
1204           get :show, :id => @author.id, :format => :json
1205           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1206         end
1207       end
1208     end
1209   end
1210   
1211   describe '対象作家のコミック一覧表示に於いて' do
1212     before do
1213       @other_user = FactoryGirl.create( :user_yas)
1214       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1215       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1216       @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id
1217       Comic.stub(:mylist).and_return([@comic, @comic, @comic])
1218       sign_in @user
1219     end
1220     context 'つつがなく終わるとき' do
1221       it 'ステータスコード200 OKを返す' do
1222         get :comics, :id => @other_author.id
1223         response.should be_success 
1224       end
1225       context 'html形式' do
1226         it 'comicテンプレートを描画する' do
1227           get :comics, :id => @other_author.id
1228           response.should render_template("comic")
1229         end
1230       end
1231       context 'json形式' do
1232         it 'jsonデータを返す' do
1233           get :comics, :id => @other_author.id, :format => :json
1234           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1235         end
1236       end
1237     end
1238     context 'ユーザ権限がないとき' do
1239       before do
1240         sign_out @user
1241       end
1242       it 'ステータスコード200 OKを返す' do
1243         get :comics, :id => @other_author.id
1244         response.should be_success 
1245       end
1246       context 'html形式' do
1247         it 'comicsテンプレートを描画する' do
1248           get :comics, :id => @other_author.id
1249           response.should render_template("comics")
1250         end
1251       end
1252       context 'json形式' do
1253         it 'jsonデータを返す' do
1254           get :comics, :id => @other_author.id, :format => :json
1255           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1256         end
1257       end
1258     end
1259   end
1260   
1261   describe '対象作家のストーリー一覧表示に於いて' do
1262     before do
1263       @other_user = FactoryGirl.create( :user_yas)
1264       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1265       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1266       @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id
1267       @panel = FactoryGirl.create :panel, :author_id => @other_author.id
1268       @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @other_author.id
1269       Story.stub(:mylist).and_return([@story, @story, @story])
1270       sign_in @user
1271     end
1272     context 'つつがなく終わるとき' do
1273       it 'ステータスコード200 OKを返す' do
1274         get :stories, :id => @other_author.id
1275         response.should be_success 
1276       end
1277       context 'html形式' do
1278         it 'storiesテンプレートを描画する' do
1279           get :stories, :id => @other_author.id
1280           response.should render_template("stories")
1281         end
1282       end
1283       context 'json形式' do
1284         it 'jsonデータを返す' do
1285           get :stories, :id => @other_author.id, :format => :json
1286           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1287         end
1288       end
1289     end
1290     context 'ユーザ権限がないとき' do
1291       before do
1292         sign_out @user
1293       end
1294       it 'ステータスコード200 OKを返す' do
1295         get :stories, :id => @other_author.id
1296         response.should be_success 
1297       end
1298       context 'html形式' do
1299         it 'storiesテンプレートを描画する' do
1300           get :stories, :id => @other_author.id
1301           response.should render_template("stories")
1302         end
1303       end
1304       context 'json形式' do
1305         it 'jsonデータを返す' do
1306           get :stories, :id => @other_author.id, :format => :json
1307           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1308         end
1309       end
1310     end
1311   end
1312   
1313   describe '対象作家のコマ一覧表示に於いて' do
1314     before do
1315       @other_user = FactoryGirl.create( :user_yas)
1316       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1317       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1318       @panel = FactoryGirl.create :panel, :author_id => @other_author.id
1319       Panel.stub(:mylist).and_return([@panel, @panel, @panel])
1320       sign_in @user
1321     end
1322     context 'つつがなく終わるとき' do
1323       it 'ステータスコード200 OKを返す' do
1324         get :panels, :id => @other_author.id
1325         response.should be_success 
1326       end
1327       context 'html形式' do
1328         it 'panelsテンプレートを描画する' do
1329           get :panels, :id => @other_author.id
1330           response.should render_template("panels")
1331         end
1332       end
1333       context 'json形式' do
1334         it 'jsonデータを返す' do
1335           get :panels, :id => @other_author.id, :format => :json
1336           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1337         end
1338       end
1339     end
1340     context 'ユーザ権限がないとき' do
1341       before do
1342         sign_out @user
1343       end
1344       it 'ステータスコード200 OKを返す' do
1345         get :panels, :id => @other_author.id
1346         response.should be_success 
1347       end
1348       context 'html形式' do
1349         it 'panelsテンプレートを描画する' do
1350           get :panels, :id => @other_author.id
1351           response.should render_template("panels")
1352         end
1353       end
1354       context 'json形式' do
1355         it 'jsonデータを返す' do
1356           get :panels, :id => @other_author.id, :format => :json
1357           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1358         end
1359       end
1360     end
1361   end
1362   
1363   describe '作家数取得に於いて' do
1364     before do
1365       Author.should_receive(:visible_count).and_return(3)
1366 #      sign_in @user
1367     end
1368     context 'つつがなく終わるとき' do
1369       it 'ステータスコード200 OKを返す' do
1370         get :count, :format => :json
1371         response.should be_success 
1372       end
1373       context 'json形式' do
1374         it 'jsonデータを返す' do
1375           get :count, :format => :json
1376           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1377         end
1378       end
1379     end
1380   end
1381   
1382   describe '新規作成フォーム表示に於いて' do
1383     before do
1384       @new_user = FactoryGirl.create( :user_yas)
1385       sign_in @new_user
1386     end
1387     context 'つつがなく終わるとき' do
1388       it 'ステータスコード200 OKを返す' do
1389         get :new
1390         response.should be_success 
1391       end
1392       context 'html形式' do
1393         it 'newテンプレートを描画する' do
1394           get :new
1395           response.should render_template("new")
1396         end
1397       end
1398       context 'js形式' do
1399         it 'new.jsテンプレートを描画する' do
1400           get :new, :format => :js
1401           response.should render_template("new")
1402         end
1403       end
1404       context 'json形式' do
1405         it 'jsonデータを返す' do
1406           get :new, :format => :json
1407           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1408         end
1409       end
1410     end
1411     context 'ユーザ権限がないとき' do
1412       before do
1413         sign_out @new_user
1414       end
1415       context 'html形式' do
1416         it 'ステータスコード302 Foundを返す' do
1417           get :new
1418           response.status.should eq 302
1419         end
1420         it 'サインインページへ遷移する' do
1421           get :new
1422           response.body.should redirect_to '/users/sign_in'
1423         end
1424       end
1425       context 'js形式' do
1426         it 'ステータスコード401 Unauthorizedを返す' do
1427           get :new, :format => :js
1428           response.status.should eq 401
1429         end
1430         it '応答メッセージにUnauthorizedを返す' do
1431           get :new, :format => :js
1432           response.message.should match(/Unauthorized/)
1433         end
1434       end
1435       context 'json形式' do
1436         it 'ステータスコード401 Unauthorizedを返す' do
1437           get :new, :format => :json
1438           response.status.should eq 401
1439         end
1440         it '応答メッセージにUnauthorizedを返す' do
1441           get :new, :format => :json
1442           response.message.should match(/Unauthorized/)
1443         end
1444       end
1445     end
1446   end
1447
1448   describe '新規作成に於いて' do
1449     before do
1450       @new_user = FactoryGirl.create( :user_yas)
1451       sign_in @new_user
1452       @attr = FactoryGirl.attributes_for(:author, :user_id => @new_user.id, :name => 'ken')
1453     end
1454     context 'つつがなく終わるとき' do
1455       context 'html形式' do
1456         it 'ステータスコード302 Foundを返す' do
1457           Author.any_instance.stub(:save).and_return(true)
1458           post :create, :author => @attr
1459           response.status.should eq 302
1460         end
1461         it 'トップページへ遷移する' do
1462 #          Author.any_instance.stub(:save).and_return(true)
1463           post :create, :author => @attr
1464           response.should redirect_to(root_path)
1465         end
1466       end
1467       context 'json形式' do
1468         it 'ステータスコード200 OKを返す' do
1469 #          Author.any_instance.stub(:save).and_return(true)
1470           post :create, :author => @attr, :format => :json
1471           response.should be_success 
1472         end
1473       end
1474     end
1475     context 'ユーザ権限がないとき' do
1476       before do
1477         sign_out @new_user
1478       end
1479       context 'html形式' do
1480         it 'ステータスコード302 Foundを返す' do
1481           post :create, :author => @attr
1482           response.status.should eq 302
1483         end
1484         it 'サインインページへ遷移する' do
1485           post :create, :author => @attr
1486           response.body.should redirect_to '/users/sign_in'
1487         end
1488       end
1489       context 'json形式' do
1490         it 'ステータスコード401 Unauthorizedを返す' do
1491           post :create, :author => @attr, :format => :json
1492           response.status.should eq 401
1493         end
1494         it '応答メッセージにUnauthorizedを返す' do
1495           post :create, :author => @attr, :format => :json
1496           response.message.should match(/Unauthorized/)
1497         end
1498       end
1499     end
1500   end
1501
1502   describe '編集フォーム表示に於いて' do
1503     before do
1504       sign_in @user
1505       Author.stub(:edit).and_return(@author)
1506     end
1507     context 'つつがなく終わるとき' do
1508       it 'ステータスコード200 OKを返す' do
1509         get :edit, :id => @author.id
1510         response.should be_success 
1511       end
1512       context 'html形式' do
1513         it 'editテンプレートを描画する' do
1514           get :edit, :id => @author.id
1515           response.should render_template("edit")
1516         end
1517       end
1518       context 'js形式' do
1519         it 'edit.jsテンプレートを描画する' do
1520           get :edit, :id => @author.id, :format => :js
1521           response.should render_template("edit")
1522         end
1523       end
1524     end
1525     context 'ユーザ権限がないとき' do
1526       before do
1527         sign_out @user
1528       end
1529       context 'html形式' do
1530         it 'ステータスコード302 Foundを返す' do
1531           get :edit, :id => @author.id
1532           response.status.should eq 302
1533         end
1534         it 'サインインページへ遷移する' do
1535           get :edit, :id => @author.id
1536           response.body.should redirect_to '/users/sign_in'
1537         end
1538       end
1539       context 'js形式' do
1540         it 'ステータスコード401 Unauthorizedを返す' do
1541           get :edit, :id => @author.id, :format => :js
1542           response.status.should eq 401
1543         end
1544         it '応答メッセージにUnauthorizedを返す' do
1545           get :edit, :id => @author.id, :format => :js
1546           response.message.should match(/Unauthorized/)
1547         end
1548       end
1549     end
1550   end
1551
1552   describe '更新に於いて' do
1553     before do
1554       @attr = @author.attributes
1555       @attr['name'] = 'ryu'
1556       sign_in @user
1557     end
1558     context 'つつがなく終わるとき' do
1559       it '更新される' do
1560         put :update, :id => @author.id, :author => @attr
1561         Author.find(@author.id).name.should eq 'ryu'
1562       end
1563       context 'html形式' do
1564         it 'ステータスコード302 Foundを返す' do
1565           Author.any_instance.stub(:save).with(any_args()).and_return(true)
1566           put :update, :id => @author.id, :author => @attr
1567           response.status.should eq 302
1568         end
1569         it '設定ページへ遷移する' do
1570           put :update, :id => @author.id, :author => @attr
1571           response.should redirect_to('/home/configure')
1572         end
1573       end
1574       context 'json形式' do
1575         it 'ステータスコード200 OKを返す' do
1576           Author.any_instance.stub(:save).with(any_args()).and_return(true)
1577           put :update, :id => @author.id, :author => @attr, :format => :json
1578           response.should be_success 
1579         end
1580         it 'ページ本体は特に返さない' do
1581           Author.any_instance.stub(:save).with(any_args()).and_return(true)
1582           put :update, :id => @author.id, :author => @attr, :format => :json
1583           response.body.should match /./
1584         end
1585       end
1586     end
1587     context 'ユーザ権限がないとき' do
1588       before do
1589         sign_out @user
1590       end
1591       it 'ステータスコード302 Foundを返す' do
1592         put :update, :id => @author.id, :author => @attr
1593         response.status.should eq 302
1594       end
1595       context 'html形式' do
1596         it 'サインインページへ遷移する' do
1597           put :update, :id => @author.id, :author => @attr
1598           response.body.should redirect_to '/users/sign_in'
1599         end
1600       end
1601       context 'json形式' do
1602         it '応答メッセージにUnauthorizedを返す' do
1603           put :update, :id => @author.id, :author => @attr, :format => :json
1604           response.message.should match(/Unauthorized/)
1605         end
1606       end
1607     end
1608   end
1609
1610 end
1611 end