OSDN Git Service

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