OSDN Git Service

t#30328:create op import ...and pull
[pettanr/pettanr.git] / spec / controllers / artists_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #絵師
4
5 describe ArtistsController 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       Artist.stub(:list).and_return([@artist, @artist, @artist])
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 Artist.default_page_size
38       end
39       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
40         get :index, :page_size => 1500
41         assigns(:page_size).should eq Artist.max_page_size
42       end
43       it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
44         get :index, :page_size => 0
45         assigns(:page_size).should eq Artist.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         Artist.should_receive(:list).exactly(1)
55         get :index
56       end
57       it '@artistsにリストを取得している' do
58         get :index
59         assigns(:artists).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           Artist.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         end
86       end
87     end
88     context '作家権限がないとき' do
89       before do
90         sign_out @user
91       end
92       context 'html形式' do
93         it 'ステータスコード302 Foundを返す' do
94           get :index
95           response.status.should eq 302
96         end
97         it 'サインインページへ遷移する' do
98           get :index
99           response.should redirect_to '/users/sign_in'
100         end
101       end
102       context 'json形式' do
103         it 'ステータスコード401 Unauthorizedを返す' do
104           get :index, :format => :json
105           response.status.should eq 401
106         end
107         it '応答メッセージにUnauthorizedを返す' do
108           get :index, :format => :json
109           response.message.should match(/Unauthorized/)
110         end
111       end
112     end
113   end
114   
115   describe '閲覧に於いて' do
116     before do
117       Artist.stub(:show).and_return(@artist)
118       sign_in @user
119     end
120     context 'つつがなく終わるとき' do
121       it 'ステータスコード200 OKを返す' do
122         get :show, :id => @artist.id
123         response.should be_success
124       end
125       it '絵師モデルに単体取得を問い合わせている' do
126         Artist.should_receive(:show).exactly(1)
127         get :show
128       end
129       it '@arにアレを取得している' do
130         get :show, :id => @artist.id
131         assigns(:ar).should eq(@artist)
132       end
133       context 'html形式' do
134         it 'showテンプレートを描画する' do
135           get :show, :id => @artist.id
136           response.should render_template("show")
137         end
138       end
139       context 'json形式' do
140         it 'jsonデータを返す' do
141           get :show, :id => @artist.id, :format => :json
142           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
143         end
144         it '絵師モデルにjson単体出力オプションを問い合わせている' do
145           Artist.should_receive(:show_json_opt).exactly(1)
146           get :show, :id => @artist.id, :format => :json
147         end
148         it 'データがアレになっている' do
149           get :show, :id => @artist.id, :format => :json
150           json = JSON.parse response.body
151           json["name"].should match(/yas/)
152         end
153       end
154     end
155     context '作家権限がないとき' do
156       before do
157         sign_out @user
158       end
159       context 'html形式' do
160         it 'ステータスコード302 Foundを返す' do
161           get :show, :id => @artist.id
162           response.status.should eq 302
163         end
164         it 'サインインページへ遷移する' do
165           get :show, :id => @artist.id
166           response.body.should redirect_to '/users/sign_in'
167         end
168       end
169       context 'json形式' do
170         it 'ステータスコード401 Unauthorizedを返す' do
171           get :show, :id => @artist.id, :format => :json
172           response.status.should eq 401
173         end
174         it '応答メッセージにUnauthorizedを返す' do
175           get :show, :id => @artist.id, :format => :json
176           response.message.should match(/Unauthorized/)
177         end
178       end
179     end
180 =begin
181     context '対象作家がないとき' do
182       context 'html形式' do
183         it '例外404 not_foundを返す' do
184           lambda{
185             get :show, :id => 0
186           }.should raise_error(ActiveRecord::RecordNotFound)
187         end
188       end
189       context 'json形式' do
190         it '例外404 not_foundを返す' do
191           lambda{ 
192             get :show, :id => 0, :format => :json
193           }.should raise_error(ActiveRecord::RecordNotFound)
194         end
195       end
196     end
197 =end
198   end
199   
200   describe '絵師数取得に於いて' do
201     before do
202       Artist.should_receive(:visible_count).and_return(3)
203 #      sign_in @user
204     end
205     context 'つつがなく終わるとき' do
206       it 'ステータスコード200 OKを返す' do
207         get :count, :format => :json
208         response.should be_success 
209       end
210       context 'json形式' do
211         it 'jsonデータを返す' do
212           get :count, :format => :json
213           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
214         end
215         it 'データがHash構造になっていて絵師数が3である' do
216           get :count, :format => :json
217           json = JSON.parse response.body
218           json["count"].should == 3
219         end
220       end
221     end
222   end
223
224   describe '新規作成フォーム表示に於いて' do
225     before do
226       sign_in @user
227     end
228     context 'つつがなく終わるとき' do
229       it 'ステータスコード200 OKを返す' do
230         get :new
231         response.should be_success 
232       end
233       it '@artistに新規データを用意している' do
234         get :new
235         assigns(:ar).should be_a_new(Artist)
236       end
237       it '絵師モデルにデフォルト値補充を依頼している' do
238         Artist.any_instance.should_receive(:supply_default).exactly(1)
239         get :new
240       end
241       context 'html形式' do
242         it 'newテンプレートを描画する' do
243           get :new
244           response.should render_template("new")
245         end
246       end
247       context 'js形式' do
248         it 'new.jsテンプレートを描画する' do
249           get :new, :format => :js
250           response.should render_template("new")
251         end
252       end
253       context 'json形式' do
254         it 'jsonデータを返す' do
255           get :new, :format => :json
256           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
257         end
258         it '絵師モデルにjson単体出力オプションを問い合わせている' do
259           Artist.should_receive(:show_json_opt).exactly(1)
260           get :new, :format => :json
261         end
262       end
263     end
264     context '作家権限がないとき' do
265       before do
266         sign_out @user
267       end
268       context 'html形式' do
269         it 'ステータスコード302 Foundを返す' do
270           get :new
271           response.status.should eq 302
272         end
273         it 'サインインページへ遷移する' do
274           get :new
275           response.body.should redirect_to '/users/sign_in'
276         end
277       end
278       context 'js形式' do
279         it 'ステータスコード401 Unauthorizedを返す' do
280           get :new, :format => :js
281           response.status.should eq 401
282         end
283         it '応答メッセージにUnauthorizedを返す' do
284           get :new, :format => :js
285           response.message.should match(/Unauthorized/)
286         end
287       end
288       context 'json形式' do
289         it 'ステータスコード401 Unauthorizedを返す' do
290           get :new, :format => :json
291           response.status.should eq 401
292         end
293         it '応答メッセージにUnauthorizedを返す' do
294           get :new, :format => :json
295           response.message.should match(/Unauthorized/)
296         end
297       end
298     end
299   end
300
301   describe '新規作成に於いて' do
302     before do
303       sign_in @user
304       @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
305     end
306     context '事前チェックしておく' do
307       it '絵師モデルにデフォルト値補充を依頼している' do
308         Artist.any_instance.should_receive(:supply_default).exactly(1)
309         post :create, :artist => @attr
310       end
311       it '絵師モデルにカラム値復元を依頼している' do
312         Artist.any_instance.should_receive(:attributes=).exactly(1)
313         post :create, :artist => @attr
314       end
315       it '絵師モデルに上書き補充を依頼している' do
316         Artist.any_instance.should_receive(:overwrite).exactly(1)
317         post :create, :artist => @attr
318       end
319       it 'モデルに保存依頼する' do
320         Artist.any_instance.should_receive(:save).exactly(1)
321         post :create, :artist => @attr
322       end
323     end
324     context 'つつがなく終わるとき' do
325       it "@arに作成された絵師を保持していて、それがDBにある" do
326         post :create, :artist => @attr
327         assigns(:ar).should be_a(Artist)
328         assigns(:ar).should be_persisted
329       end
330       context 'html形式' do
331         it 'ステータスコード302 Foundを返す' do
332           Artist.any_instance.stub(:save).and_return(true)
333           post :create, :artist => @attr
334           response.status.should eq 302
335         end
336         it 'トップページへ遷移する' do
337 #          Artist.any_instance.stub(:save).and_return(true)
338           post :create, :artist => @attr
339           response.should redirect_to(root_path)
340         end
341       end
342       context 'json形式' do
343         it 'ステータスコード200 OKを返す' do
344 #          Artist.any_instance.stub(:save).and_return(true)
345           post :create, :artist => @attr, :format => :json
346           response.should be_success 
347         end
348         it '作成された絵師をjsonデータで返す' do
349           post :create, :artist => @attr, :format => :json
350           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
351         end
352         it '絵師モデルにjson単体出力オプションを問い合わせている' do
353           Artist.should_receive(:show_json_opt).exactly(1)
354           post :create, :artist => @attr, :format => :json
355         end
356         it 'データがアレになっている' do
357           post :create, :artist => @attr, :format => :json
358           json = JSON.parse response.body
359           json["name"].should match(/ken/)
360         end
361       end
362     end
363     context '作家権限がないとき' do
364       before do
365         sign_out @user
366       end
367       context 'html形式' do
368         it 'ステータスコード302 Foundを返す' do
369           post :create, :artist => @attr
370           response.status.should eq 302
371         end
372         it 'サインインページへ遷移する' do
373           post :create, :artist => @attr
374           response.body.should redirect_to '/users/sign_in'
375         end
376       end
377       context 'json形式' do
378         it 'ステータスコード401 Unauthorizedを返す' do
379           post :create, :artist => @attr, :format => :json
380           response.status.should eq 401
381         end
382         it '応答メッセージにUnauthorizedを返す' do
383           post :create, :artist => @attr, :format => :json
384           response.message.should match(/Unauthorized/)
385         end
386       end
387     end
388     context '検証、保存に失敗した' do
389       before do
390         Artist.any_instance.stub(:save).and_return(false)
391       end
392       it "未保存の絵師を保持している" do
393         post :create, :artist => @attr
394         assigns(:ar).should be_a_new(Artist)
395       end
396       context 'html形式' do
397         it 'ステータスコード200 OKを返す' do
398           post :create, :artist => @attr
399           response.status.should eq 200
400         end
401         it '新規ページを描画する' do
402           post :create, :artist => @attr
403           response.should render_template("new")
404         end
405       end
406       context 'json形式' do
407         it 'ステータスコード422 unprocessable_entity を返す' do
408           post :create, :artist => @attr, :format => :json
409           response.status.should eq 422
410         end
411         it '応答メッセージUnprocessable Entityを返す' do
412           post :create, :artist => @attr, :format => :json
413           response.message.should match(/Unprocessable/)
414         end
415       end
416     end
417   end
418
419   describe '編集フォーム表示に於いて' do
420     before do
421       sign_in @user
422       Artist.stub(:edit).and_return(@artist)
423     end
424     context 'つつがなく終わるとき' do
425       it 'ステータスコード200 OKを返す' do
426         get :edit, :id => @artist.id
427         response.should be_success 
428       end
429       it '絵師モデルに編集取得を問い合わせている' do
430         Artist.should_receive(:edit).exactly(1)
431         get :edit, :id => @artist.id
432       end
433       it '@artistにデータを用意している' do
434         get :edit, :id => @artist.id
435         assigns(:artist).should eq @artist
436       end
437       context 'html形式' do
438         it 'editテンプレートを描画する' do
439           get :edit, :id => @artist.id
440           response.should render_template("edit")
441         end
442       end
443       context 'js形式' do
444         it 'edit.jsテンプレートを描画する' do
445           get :edit, :id => @artist.id, :format => :js
446           response.should render_template("edit")
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 :edit, :id => @artist.id
457           response.status.should eq 302
458         end
459         it 'サインインページへ遷移する' do
460           get :edit, :id => @artist.id
461           response.body.should redirect_to '/users/sign_in'
462         end
463       end
464       context 'js形式' do
465         it 'ステータスコード401 Unauthorizedを返す' do
466           get :edit, :id => @artist.id, :format => :js
467           response.status.should eq 401
468         end
469         it '応答メッセージにUnauthorizedを返す' do
470           get :edit, :id => @artist.id, :format => :js
471           response.message.should match(/Unauthorized/)
472         end
473       end
474     end
475   end
476
477   describe '更新に於いて' do
478     before do
479       @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
480       sign_in @user
481     end
482     context '事前チェックしておく' do
483       it '絵師モデルに編集取得を問い合わせている' do
484         Artist.stub(:edit).with(any_args()).and_return @artist
485         Artist.should_receive(:edit).exactly(1)
486         put :update, :id => @artist.id, :artist => @attr
487       end
488       it '絵師モデルにカラム値復元を依頼している' do
489         Artist.any_instance.should_receive(:attributes=).exactly(1)
490         put :update, :id => @artist.id, :artist => @attr
491       end
492       it '絵師モデルに上書き補充を依頼している' do
493         Artist.any_instance.should_receive(:overwrite).exactly(1)
494         put :update, :id => @artist.id, :artist => @attr
495       end
496       it 'モデルに更新を依頼する' do
497         Artist.any_instance.stub(:save).with(any_args).and_return true
498         Artist.any_instance.should_receive(:save).exactly(1)
499         put :update, :id => @artist.id, :artist => @attr
500       end
501       it '@arにアレを取得している' do
502         put :update, :id => @artist.id, :artist => @attr
503         assigns(:ar).should eq @artist
504       end
505     end
506     context 'つつがなく終わるとき' do
507       it '更新される' do
508         put :update, :id => @artist.id, :artist => @attr
509         Artist.find(@artist.id).name.should eq 'ryu'
510       end
511       context 'html形式' do
512         it 'ステータスコード302 Foundを返す' do
513           Artist.any_instance.stub(:save).with(any_args()).and_return(true)
514           put :update, :id => @artist.id, :artist => @attr
515           response.status.should eq 302
516         end
517         it '設定ページへ遷移する' do
518           put :update, :id => @artist.id, :artist => @attr
519           response.should redirect_to('/home/configure')
520         end
521       end
522       context 'json形式' do
523         it 'ステータスコード200 OKを返す' do
524           Artist.any_instance.stub(:save).with(any_args()).and_return(true)
525           put :update, :id => @artist.id, :artist => @attr, :format => :json
526           response.should be_success 
527         end
528         it 'ページ本体は特に返さない' do
529           Artist.any_instance.stub(:save).with(any_args()).and_return(true)
530           put :update, :id => @artist.id, :artist => @attr, :format => :json
531           response.body.should match /./
532         end
533       end
534     end
535     context '作家権限がないとき' do
536       before do
537         sign_out @user
538       end
539       it 'ステータスコード302 Foundを返す' do
540         put :update, :id => @artist.id, :artist => @attr
541         response.status.should eq 302
542       end
543       context 'html形式' do
544         it 'サインインページへ遷移する' do
545           put :update, :id => @artist.id, :artist => @attr
546           response.body.should redirect_to '/users/sign_in'
547         end
548       end
549       context 'json形式' do
550         it '応答メッセージにUnauthorizedを返す' do
551           put :update, :id => @artist.id, :artist => @attr, :format => :json
552           response.message.should match(/Unauthorized/)
553         end
554       end
555     end
556     context '検証、保存に失敗したとき' do
557       before do
558         Artist.any_instance.stub(:save).and_return(false)
559       end
560       context 'html形式' do
561         it 'ステータスコード200 Okを返す' do
562           put :update, :id => @artist.id, :artist => @attr
563           response.status.should eq 200
564         end
565         it '編集ページを描画する' do
566           put :update, :id => @artist.id, :artist => @attr
567           response.should render_template("edit")
568         end
569       end
570       context 'json形式' do
571         it 'ステータスコード422 unprocessable_entity を返す' do
572           Artist.any_instance.stub(:save).and_return(false)
573           put :update, :id => @artist.id, :artist => @attr, :format => :json
574           response.status.should eq 422
575         end
576         it '応答メッセージUnprocessable Entityを返す' do
577           put :update, :id => @artist.id, :artist => @attr, :format => :json
578           response.message.should match(/Unprocessable/)
579         end
580       end
581     end
582   end
583
584 else
585   describe '一覧表示に於いて' do
586     before do
587       Artist.stub(:list).and_return([@artist, @artist, @artist])
588       sign_in @user
589     end
590     context 'つつがなく終わるとき' do
591       it 'ステータスコード200 OKを返す' do
592         get :index
593         response.should be_success 
594       end
595       context 'html形式' do
596         it 'indexテンプレートを描画する' do
597           get :index
598           response.should render_template("index")
599         end
600       end
601       context 'json形式' do
602         it 'jsonデータを返す' do
603           get :index, :format => :json
604           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
605         end
606       end
607     end
608     context '作家権限がないとき' do
609       before do
610         sign_out @user
611       end
612       it 'ステータスコード200 OKを返す' do
613         get :index
614         response.should be_success 
615       end
616       context 'html形式' do
617         it 'indexテンプレートを描画する' do
618           get :index
619           response.should render_template("index")
620         end
621       end
622       context 'json形式' do
623         it 'jsonデータを返す' do
624           get :index, :format => :json
625           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
626         end
627       end
628     end
629   end
630   
631   describe '閲覧に於いて' do
632     before do
633       Artist.stub(:show).and_return(@artist)
634       sign_in @user
635     end
636     context 'つつがなく終わるとき' do
637       it 'ステータスコード200 OKを返す' do
638         get :show, :id => @artist.id
639         response.should be_success
640       end
641       context 'html形式' do
642         it 'showテンプレートを描画する' do
643           get :show, :id => @artist.id
644           response.should render_template("show")
645         end
646       end
647       context 'json形式' do
648         it 'jsonデータを返す' do
649           get :show, :id => @artist.id, :format => :json
650           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
651         end
652       end
653     end
654     context '作家権限がないとき' do
655       before do
656         sign_out @user
657       end
658       it 'ステータスコード200 OKを返す' do
659         get :show, :id => @artist.id
660         response.should be_success
661       end
662       context 'html形式' do
663         it 'showテンプレートを描画する' do
664           get :show, :id => @artist.id
665           response.should render_template("show")
666         end
667       end
668       context 'json形式' do
669         it 'jsonデータを返す' do
670           get :show, :id => @artist.id, :format => :json
671           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
672         end
673       end
674     end
675   end
676   
677   describe '絵師数取得に於いて' do
678     before do
679       Artist.should_receive(:visible_count).and_return(3)
680 #      sign_in @user
681     end
682     context 'つつがなく終わるとき' do
683       it 'ステータスコード200 OKを返す' do
684         get :count, :format => :json
685         response.should be_success 
686       end
687       context 'json形式' do
688         it 'jsonデータを返す' do
689           get :count, :format => :json
690           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
691         end
692       end
693     end
694   end
695
696   describe '新規作成フォーム表示に於いて' do
697     before do
698       sign_in @user
699     end
700     context 'つつがなく終わるとき' do
701       it 'ステータスコード200 OKを返す' do
702         get :new
703         response.should be_success 
704       end
705       context 'html形式' do
706         it 'newテンプレートを描画する' do
707           get :new
708           response.should render_template("new")
709         end
710       end
711       context 'js形式' do
712         it 'new.jsテンプレートを描画する' do
713           get :new, :format => :js
714           response.should render_template("new")
715         end
716       end
717       context 'json形式' do
718         it 'jsonデータを返す' do
719           get :new, :format => :json
720           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
721         end
722       end
723     end
724     context '作家権限がないとき' do
725       before do
726         sign_out @user
727       end
728       context 'html形式' do
729         it 'ステータスコード302 Foundを返す' do
730           get :new
731           response.status.should eq 302
732         end
733         it 'サインインページへ遷移する' do
734           get :new
735           response.body.should redirect_to '/users/sign_in'
736         end
737       end
738       context 'js形式' do
739         it 'ステータスコード401 Unauthorizedを返す' do
740           get :new, :format => :js
741           response.status.should eq 401
742         end
743         it '応答メッセージにUnauthorizedを返す' do
744           get :new, :format => :js
745           response.message.should match(/Unauthorized/)
746         end
747       end
748       context 'json形式' do
749         it 'ステータスコード401 Unauthorizedを返す' do
750           get :new, :format => :json
751           response.status.should eq 401
752         end
753         it '応答メッセージにUnauthorizedを返す' do
754           get :new, :format => :json
755           response.message.should match(/Unauthorized/)
756         end
757       end
758     end
759   end
760
761   describe '新規作成に於いて' do
762     before do
763       sign_in @user
764       @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ken')
765     end
766     context 'つつがなく終わるとき' do
767       context 'html形式' do
768         it 'ステータスコード302 Foundを返す' do
769           Artist.any_instance.stub(:save).and_return(true)
770           post :create, :artist => @attr
771           response.status.should eq 302
772         end
773         it 'トップページへ遷移する' do
774 #          Artist.any_instance.stub(:save).and_return(true)
775           post :create, :artist => @attr
776           response.should redirect_to(root_path)
777         end
778       end
779       context 'json形式' do
780         it 'ステータスコード200 OKを返す' do
781 #          Artist.any_instance.stub(:save).and_return(true)
782           post :create, :artist => @attr, :format => :json
783           response.should be_success 
784         end
785         it '作成された絵師をjsonデータで返す' do
786           post :create, :artist => @attr, :format => :json
787           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
788         end
789       end
790     end
791     context '作家権限がないとき' do
792       before do
793         sign_out @user
794       end
795       context 'html形式' do
796         it 'ステータスコード302 Foundを返す' do
797           post :create, :artist => @attr
798           response.status.should eq 302
799         end
800         it 'サインインページへ遷移する' do
801           post :create, :artist => @attr
802           response.body.should redirect_to '/users/sign_in'
803         end
804       end
805       context 'json形式' do
806         it 'ステータスコード401 Unauthorizedを返す' do
807           post :create, :artist => @attr, :format => :json
808           response.status.should eq 401
809         end
810         it '応答メッセージにUnauthorizedを返す' do
811           post :create, :artist => @attr, :format => :json
812           response.message.should match(/Unauthorized/)
813         end
814       end
815     end
816   end
817
818   describe '編集フォーム表示に於いて' do
819     before do
820       sign_in @user
821       Artist.stub(:edit).and_return(@artist)
822     end
823     context 'つつがなく終わるとき' do
824       it 'ステータスコード200 OKを返す' do
825         get :edit, :id => @artist.id
826         response.should be_success 
827       end
828       context 'html形式' do
829         it 'editテンプレートを描画する' do
830           get :edit, :id => @artist.id
831           response.should render_template("edit")
832         end
833       end
834       context 'js形式' do
835         it 'edit.jsテンプレートを描画する' do
836           get :edit, :id => @artist.id, :format => :js
837           response.should render_template("edit")
838         end
839       end
840     end
841     context '作家権限がないとき' do
842       before do
843         sign_out @user
844       end
845       context 'html形式' do
846         it 'ステータスコード302 Foundを返す' do
847           get :edit, :id => @artist.id
848           response.status.should eq 302
849         end
850         it 'サインインページへ遷移する' do
851           get :edit, :id => @artist.id
852           response.body.should redirect_to '/users/sign_in'
853         end
854       end
855       context 'js形式' do
856         it 'ステータスコード401 Unauthorizedを返す' do
857           get :edit, :id => @artist.id, :format => :js
858           response.status.should eq 401
859         end
860         it '応答メッセージにUnauthorizedを返す' do
861           get :edit, :id => @artist.id, :format => :js
862           response.message.should match(/Unauthorized/)
863         end
864       end
865     end
866   end
867
868   describe '更新に於いて' do
869     before do
870       @attr = FactoryGirl.attributes_for(:artist, :author_id => @author.id, :name => 'ryu')
871       sign_in @user
872     end
873     context 'つつがなく終わるとき' do
874       context 'html形式' do
875         it 'ステータスコード302 Foundを返す' do
876           Artist.any_instance.stub(:save).with(any_args()).and_return(true)
877           put :update, :id => @artist.id, :artist => @attr
878           response.status.should eq 302
879         end
880         it '設定ページへ遷移する' do
881           put :update, :id => @artist.id, :artist => @attr
882           response.should redirect_to('/home/configure')
883         end
884       end
885       context 'json形式' do
886         it 'ステータスコード200 OKを返す' do
887           Artist.any_instance.stub(:save).with(any_args()).and_return(true)
888           put :update, :id => @artist.id, :artist => @attr, :format => :json
889           response.should be_success 
890         end
891         it 'ページ本体は特に返さない' do
892           Artist.any_instance.stub(:save).with(any_args()).and_return(true)
893           put :update, :id => @artist.id, :artist => @attr, :format => :json
894           response.body.should match /./
895         end
896       end
897     end
898     context '作家権限がないとき' do
899       before do
900         sign_out @user
901       end
902       it 'ステータスコード302 Foundを返す' do
903         put :update, :id => @artist.id, :artist => @attr
904         response.status.should eq 302
905       end
906       context 'html形式' do
907         it 'サインインページへ遷移する' do
908           put :update, :id => @artist.id, :artist => @attr
909           response.body.should redirect_to '/users/sign_in'
910         end
911       end
912       context 'json形式' do
913         it '応答メッセージにUnauthorizedを返す' do
914           put :update, :id => @artist.id, :artist => @attr, :format => :json
915           response.message.should match(/Unauthorized/)
916         end
917       end
918     end
919   end
920
921 end
922 end