OSDN Git Service

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