OSDN Git Service

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