1 # -*- encoding: utf-8 -*-
5 describe AuthorsController 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
16 if MagicNumber['run_mode'] == 1
17 describe '一覧表示に於いて' do
19 Author.stub(:list).and_return([@author, @author, @author])
23 it '与えられたpageがセットされている' do
24 get :index, :page => 5
25 assigns(:page).should eq 5
27 it '省略されると@pageに1値が入る' do
29 assigns(:page).should eq 1
31 it '与えられたpage_sizeがセットされている' do
32 get :index, :page_size => 15
33 assigns(:page_size).should eq 15
35 it '省略されると@page_sizeにデフォルト値が入る' do
37 assigns(:page_size).should eq Author.default_page_size
39 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
40 get :index, :page_size => 1500
41 assigns(:page_size).should eq Author.max_page_size
43 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
44 get :index, :page_size => 0
45 assigns(:page_size).should eq Author.default_page_size
48 context 'つつがなく終わるとき' do
49 it 'ステータスコード200 OKを返す' do
51 response.should be_success
53 it '作家モデルに一覧を問い合わせている' do
54 Author.should_receive(:list).exactly(1)
57 it '@authorsにリストを取得している' do
59 assigns(:authors).should have_at_least(3).items
62 it 'indexテンプレートを描画する' do
64 response.should render_template("index")
69 get :index, :format => :json
70 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
72 it '作家モデルにjson一覧出力オプションを問い合わせている' do
73 Author.should_receive(:list_json_opt).exactly(1)
74 get :index, :format => :json
76 it 'データがリスト構造になっている' do
77 get :index, :format => :json
78 json = JSON.parse response.body
79 json.should have_at_least(3).items
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
89 context 'ユーザ権限がないとき' do
94 it 'ステータスコード302 Foundを返す' do
96 response.status.should eq 302
100 response.should redirect_to '/users/sign_in'
104 it 'ステータスコード401 Unauthorizedを返す' do
105 get :index, :format => :json
106 response.status.should eq 401
108 it '応答メッセージにUnauthorizedを返す' do
109 get :index, :format => :json
110 response.message.should match(/Unauthorized/)
114 context 'ユーザ権限はないが管理者権限があるとき' do
119 it 'ステータスコード200 OKを返す' do
121 response.should be_success
124 context 'ユーザだが作家登録していないとき' do
128 it 'ステータスコード200 OKを返す' do
130 response.should be_success
137 Author.stub(:show).and_return(@author)
140 context 'つつがなく終わるとき' do
141 it 'ステータスコード200 OKを返す' do
142 get :show, :id => @author.id
143 response.should be_success
145 it '作家モデルに単体取得を問い合わせている' do
146 Author.should_receive(:show).exactly(1)
149 #@authorだとログイン中のアカウントと干渉してしまう。
150 it '@auにアレを取得している' do
151 get :show, :id => @author.id
152 assigns(:au).should eq(@author)
155 it 'showテンプレートを描画する' do
156 get :show, :id => @author.id
157 response.should render_template("show")
162 get :show, :id => @author.id, :format => :json
163 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
165 it '作家モデルにjson単体出力オプションを問い合わせている' do
166 Author.should_receive(:show_json_opt).exactly(1)
167 get :show, :id => @author.id, :format => :json
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
177 context 'ユーザ権限がないとき' do
182 it 'ステータスコード302 Foundを返す' do
183 get :show, :id => @author.id
184 response.status.should eq 302
186 it 'サインインページへ遷移する' do
187 get :show, :id => @author.id
188 response.body.should redirect_to '/users/sign_in'
192 it 'ステータスコード401 Unauthorizedを返す' do
193 get :show, :id => @author.id, :format => :json
194 response.status.should eq 401
196 it '応答メッセージにUnauthorizedを返す' do
197 get :show, :id => @author.id, :format => :json
198 response.message.should match(/Unauthorized/)
202 context 'ユーザ権限はないが管理者権限があるとき' do
207 it 'ステータスコード200 OKを返す' do
208 get :show, :id => @author.id
209 response.should be_success
212 context 'ユーザだが作家登録していないとき' do
216 it 'ステータスコード200 OKを返す' do
217 get :show, :id => @author.id
218 response.should be_success
222 context '対象作家がないとき' do
224 it '例外404 not_foundを返す' do
227 }.should raise_error(ActiveRecord::RecordNotFound)
231 it '例外404 not_foundを返す' do
233 get :show, :id => 0, :format => :json
234 }.should raise_error(ActiveRecord::RecordNotFound)
241 describe '対象作家のコミック一覧表示に於いて' 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])
250 context 'パラメータpageについて' do
252 get :comics, :id => @other_author.id, :page => 5
253 assigns(:page).should eq 5
255 it '省略されると@pageに1値が入る' do
256 get :comics, :id => @other_author.id
257 assigns(:page).should eq 1
259 it '与えられたpage_sizeがセットされている' do
260 get :comics, :id => @other_author.id, :page_size => 15
261 assigns(:page_size).should eq 15
263 it '省略されると@page_sizeにデフォルト値が入る' do
264 get :comics, :id => @other_author.id
265 assigns(:page_size).should eq Author.default_comic_page_size
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
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
276 context 'つつがなく終わるとき' do
277 it 'ステータスコード200 OKを返す' do
278 get :comics, :id => @other_author.id
279 response.should be_success
281 it '作家モデルに単体取得を問い合わせている' do
282 Author.should_receive(:show).exactly(1)
283 get :comics, :id => @other_author.id
285 it 'コミックモデルに一覧を問い合わせている' do
286 Comic.should_receive(:himlist).exactly(1)
287 get :comics, :id => @other_author.id
289 it '@comicsにリストを取得している' do
290 get :comics, :id => @other_author.id
291 assigns(:comics).should have_at_least(3).items
294 it 'comicsテンプレートを描画する' do
295 get :comics, :id => @other_author.id
296 response.should render_template("comics")
301 get :comics, :id => @other_author.id, :format => :json
302 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
304 it 'コミックモデルにjson一覧出力オプションを問い合わせている' do
305 Comic.should_receive(:list_json_opt).exactly(1)
306 get :comics, :id => @other_author.id, :format => :json
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
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
321 context 'ユーザ権限がないとき' do
326 it 'ステータスコード302 Foundを返す' do
327 get :comics, :id => @other_author.id
328 response.status.should eq 302
330 it 'サインインページへ遷移する' do
331 get :comics, :id => @other_author.id
332 response.should redirect_to '/users/sign_in'
336 it 'ステータスコード401 Unauthorizedを返す' do
337 get :comics, :id => @other_author.id, :format => :json
338 response.status.should eq 401
340 it '応答メッセージにUnauthorizedを返す' do
341 get :comics, :id => @other_author.id, :format => :json
342 response.message.should match(/Unauthorized/)
346 context 'ユーザ権限はないが管理者権限があるとき' do
351 it 'ステータスコード200 OKを返す' do
352 get :comics, :id => @other_author.id
353 response.should be_success
356 context 'ユーザだが作家登録していないとき' do
360 it 'ステータスコード200 OKを返す' do
361 get :comics, :id => @other_author.id
362 response.should be_success
367 describe '対象作家のストーリー一覧表示に於いて' 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])
378 context 'パラメータpageについて' do
380 get :stories, :id => @other_author.id, :page => 5
381 assigns(:page).should eq 5
383 it '省略されると@pageに1値が入る' do
384 get :stories, :id => @other_author.id
385 assigns(:page).should eq 1
387 it '与えられたpage_sizeがセットされている' do
388 get :stories, :id => @other_author.id, :page_size => 15
389 assigns(:page_size).should eq 15
391 it '省略されると@page_sizeにデフォルト値が入る' do
392 get :stories, :id => @other_author.id
393 assigns(:page_size).should eq Author.default_story_page_size
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
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
404 context 'つつがなく終わるとき' do
405 it 'ステータスコード200 OKを返す' do
406 get :stories, :id => @other_author.id
407 response.should be_success
409 it '作家モデルに単体取得を問い合わせている' do
410 Author.should_receive(:show).exactly(1)
411 get :stories, :id => @other_author.id
413 it 'ストーリーモデルに他作家のストーリー一覧を問い合わせている' do
414 Story.should_receive(:himlist).exactly(1)
415 get :stories, :id => @other_author.id
417 it '@storiesにリストを取得している' do
418 get :stories, :id => @other_author.id
419 assigns(:stories).should have_at_least(3).items
422 it 'storiesテンプレートを描画する' do
423 get :stories, :id => @other_author.id
424 response.should render_template("stories")
429 get :stories, :id => @other_author.id, :format => :json
430 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
432 it 'ストーリーモデルにjson一覧出力オプションを問い合わせている' do
433 Story.should_receive(:list_json_opt).exactly(1)
434 get :stories, :id => @other_author.id, :format => :json
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
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
450 context 'ユーザ権限がないとき' do
455 it 'ステータスコード302 Foundを返す' do
456 get :stories, :id => @other_author.id
457 response.status.should eq 302
459 it 'サインインページへ遷移する' do
460 get :stories, :id => @other_author.id
461 response.should redirect_to '/users/sign_in'
465 it 'ステータスコード401 Unauthorizedを返す' do
466 get :stories, :id => @other_author.id, :format => :json
467 response.status.should eq 401
469 it '応答メッセージにUnauthorizedを返す' do
470 get :stories, :id => @other_author.id, :format => :json
471 response.message.should match(/Unauthorized/)
475 context 'ユーザ権限はないが管理者権限があるとき' do
480 it 'ステータスコード200 OKを返す' do
481 get :stories, :id => @other_author.id
482 response.should be_success
485 context 'ユーザだが作家登録していないとき' do
489 it 'ステータスコード200 OKを返す' do
490 get :stories, :id => @other_author.id
491 response.should be_success
496 describe '対象作家のコマ一覧表示に於いて' 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])
505 context 'パラメータpageについて' do
507 get :panels, :id => @other_author.id, :page => 5
508 assigns(:page).should eq 5
510 it '省略されると@pageに1値が入る' do
511 get :panels, :id => @other_author.id
512 assigns(:page).should eq 1
514 it '与えられたpage_sizeがセットされている' do
515 get :panels, :id => @other_author.id, :page_size => 15
516 assigns(:page_size).should eq 15
518 it '省略されると@page_sizeにデフォルト値が入る' do
519 get :panels, :id => @other_author.id
520 assigns(:page_size).should eq Author.default_panel_page_size
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
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
531 context 'つつがなく終わるとき' do
532 it 'ステータスコード200 OKを返す' do
533 get :panels, :id => @other_author.id
534 response.should be_success
536 it '作家モデルに単体取得を問い合わせている' do
537 Author.should_receive(:show).exactly(1)
538 get :panels, :id => @other_author.id
540 it 'コマモデルに他作家のコマ一覧を問い合わせている' do
541 Panel.should_receive(:himlist).exactly(1)
542 get :panels, :id => @other_author.id
544 it '@panelsにリストを取得している' do
545 get :panels, :id => @other_author.id
546 assigns(:panels).should have_at_least(3).items
549 it 'panelsテンプレートを描画する' do
550 get :panels, :id => @other_author.id
551 response.should render_template("panels")
556 get :panels, :id => @other_author.id, :format => :json
557 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
559 it 'コマモデルにコマリストのjson出力を問い合わせている' do
560 Panel.should_receive(:list_as_json_text).exactly(1)
561 get :panels, :id => @other_author.id, :format => :json
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
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
575 context 'ユーザ権限がないとき' do
580 it 'ステータスコード302 Foundを返す' do
581 get :panels, :id => @other_author.id
582 response.status.should eq 302
584 it 'サインインページへ遷移する' do
585 get :panels, :id => @other_author.id
586 response.should redirect_to '/users/sign_in'
590 it 'ステータスコード401 Unauthorizedを返す' do
591 get :panels, :id => @other_author.id, :format => :json
592 response.status.should eq 401
594 it '応答メッセージにUnauthorizedを返す' do
595 get :panels, :id => @other_author.id, :format => :json
596 response.message.should match(/Unauthorized/)
600 context 'ユーザ権限はないが管理者権限があるとき' do
605 it 'ステータスコード200 OKを返す' do
606 get :panels, :id => @other_author.id
607 response.should be_success
610 context 'ユーザだが作家登録していないとき' do
614 it 'ステータスコード200 OKを返す' do
615 get :panels, :id => @other_author.id
616 response.should be_success
621 describe '作家数取得に於いて' do
623 Author.should_receive(:visible_count).and_return(3)
626 context 'つつがなく終わるとき' do
627 it 'ステータスコード200 OKを返す' do
628 get :count, :format => :json
629 response.should be_success
633 get :count, :format => :json
634 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
636 it 'データがHash構造になっていて作家数が3である' do
637 get :count, :format => :json
638 json = JSON.parse response.body
639 json["count"].should == 3
645 describe '新規作成フォーム表示に於いて' do
647 @new_user = FactoryGirl.create( :user_yas)
650 context 'つつがなく終わるとき' do
651 it 'ステータスコード200 OKを返す' do
653 response.should be_success
655 it '@auに新規データを用意している' do
657 assigns(:au).should be_a_new(Author)
659 it '作家モデルにデフォルト値補充を依頼している' do
660 Author.any_instance.should_receive(:supply_default).exactly(1)
664 it 'newテンプレートを描画する' do
666 response.should render_template("new")
670 it 'new.jsテンプレートを描画する' do
671 get :new, :format => :js
672 response.should render_template("new")
677 get :new, :format => :json
678 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
680 it '作家モデルにjson単体出力オプションを問い合わせている' do
681 Author.should_receive(:show_json_opt).exactly(1)
682 get :new, :format => :json
686 context 'ユーザ権限がないとき' do
691 it 'ステータスコード302 Foundを返す' do
693 response.status.should eq 302
695 it 'サインインページへ遷移する' do
697 response.body.should redirect_to '/users/sign_in'
701 it 'ステータスコード401 Unauthorizedを返す' do
702 get :new, :format => :js
703 response.status.should eq 401
705 it '応答メッセージにUnauthorizedを返す' do
706 get :new, :format => :js
707 response.message.should match(/Unauthorized/)
711 it 'ステータスコード401 Unauthorizedを返す' do
712 get :new, :format => :json
713 response.status.should eq 401
715 it '応答メッセージにUnauthorizedを返す' do
716 get :new, :format => :json
717 response.message.should match(/Unauthorized/)
721 context 'ユーザ権限はないが管理者権限があるとき' do
727 it 'ステータスコード302 Foundを返す' do
729 response.status.should eq 302
731 it 'サインインページへ遷移する' do
733 response.body.should redirect_to '/users/sign_in'
737 context 'ユーザだが作家登録していないとき' do
741 it 'ステータスコード200 OKを返す' do
743 response.should be_success
748 describe '新規作成に於いて' do
750 @new_user = FactoryGirl.create( :user_yas)
752 @attr = FactoryGirl.attributes_for(:author, :user_id => @new_user.id, :name => 'ken')
754 context '事前チェックしておく' do
755 it '作家モデルにデフォルト値補充を依頼している' do
756 Author.any_instance.should_receive(:supply_default).exactly(1)
757 post :create, :author => @attr
759 it '作家モデルにカラム値復元を依頼している' do
760 Author.any_instance.should_receive(:attributes=).exactly(1)
761 post :create, :author => @attr
763 it '作家モデルに上書き補充を依頼している' do
764 Author.any_instance.should_receive(:overwrite).exactly(1)
765 post :create, :author => @attr
768 Author.any_instance.should_receive(:save).exactly(1)
769 post :create, :author => @attr
772 context 'つつがなく終わるとき' do
773 it "@auに作成された作家を保持していて、それがDBにある" do
774 post :create, :author => @attr
775 assigns(:au).should be_a(Author)
776 assigns(:au).should be_persisted
779 it 'ステータスコード302 Foundを返す' do
780 Author.any_instance.stub(:save).and_return(true)
781 post :create, :author => @attr
782 response.status.should eq 302
785 # Author.any_instance.stub(:save).and_return(true)
786 post :create, :author => @attr
787 response.should redirect_to(root_path)
791 it 'ステータスコード200 OKを返す' do
792 # Author.any_instance.stub(:save).and_return(true)
793 post :create, :author => @attr, :format => :json
794 response.should be_success
796 it '作成された作家をjsonデータで返す' do
797 post :create, :author => @attr, :format => :json
798 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
800 it '作家モデルにjson単体出力オプションを問い合わせている' do
801 Author.should_receive(:show_json_opt).exactly(1)
802 post :create, :author => @attr, :format => :json
805 post :create, :author => @attr, :format => :json
806 json = JSON.parse response.body
807 json["name"].should match(/ken/)
811 context 'ユーザ権限がないとき' do
816 it 'ステータスコード302 Foundを返す' do
817 post :create, :author => @attr
818 response.status.should eq 302
820 it 'サインインページへ遷移する' do
821 post :create, :author => @attr
822 response.body.should redirect_to '/users/sign_in'
826 it 'ステータスコード401 Unauthorizedを返す' do
827 post :create, :author => @attr, :format => :json
828 response.status.should eq 401
830 it '応答メッセージにUnauthorizedを返す' do
831 post :create, :author => @attr, :format => :json
832 response.message.should match(/Unauthorized/)
836 context 'ユーザ権限はないが管理者権限があるとき' do
842 it 'ステータスコード302 Foundを返す' do
843 post :create, :author => @attr
844 response.status.should eq 302
846 it 'サインインページへ遷移する' do
847 post :create, :author => @attr
848 response.body.should redirect_to '/users/sign_in'
852 context '検証、保存に失敗した' do
854 Author.any_instance.stub(:save).and_return(false)
856 it "未保存の作家を保持している" do
857 post :create, :author => @attr
858 assigns(:au).should be_a_new(Author)
861 it 'ステータスコード200 OKを返す' do
862 post :create, :author => @attr
863 response.status.should eq 200
866 post :create, :author => @attr
867 response.should render_template("new")
871 it 'ステータスコード422 unprocessable_entity を返す' do
872 post :create, :author => @attr, :format => :json
873 response.status.should eq 422
875 it '応答メッセージUnprocessable Entityを返す' do
876 post :create, :author => @attr, :format => :json
877 response.message.should match(/Unprocessable/)
883 describe '編集フォーム表示に於いて' do
886 Author.stub(:edit).and_return(@author)
888 context 'つつがなく終わるとき' do
889 it 'ステータスコード200 OKを返す' do
890 get :edit, :id => @author.id
891 response.should be_success
893 it '作家モデルに編集取得を問い合わせている' do
894 Author.should_receive(:edit).exactly(1)
895 get :edit, :id => @author.id
897 #@authorだとログイン中のアカウントと干渉してしまう。
898 it '@auにデータを用意している' do
899 get :edit, :id => @author.id
900 assigns(:au).should eq @author
903 it 'editテンプレートを描画する' do
904 get :edit, :id => @author.id
905 response.should render_template("edit")
909 it 'edit.jsテンプレートを描画する' do
910 get :edit, :id => @author.id, :format => :js
911 response.should render_template("edit")
915 context 'ユーザ権限がないとき' do
920 it 'ステータスコード302 Foundを返す' do
921 get :edit, :id => @author.id
922 response.status.should eq 302
924 it 'サインインページへ遷移する' do
925 get :edit, :id => @author.id
926 response.body.should redirect_to '/users/sign_in'
930 it 'ステータスコード401 Unauthorizedを返す' do
931 get :edit, :id => @author.id, :format => :js
932 response.status.should eq 401
934 it '応答メッセージにUnauthorizedを返す' do
935 get :edit, :id => @author.id, :format => :js
936 response.message.should match(/Unauthorized/)
940 context 'ユーザ権限はないが管理者権限があるとき' do
946 it 'ステータスコード302 Foundを返す' do
947 get :edit, :id => @author.id
948 response.status.should eq 302
950 it 'サインインページへ遷移する' do
951 get :edit, :id => @author.id
952 response.body.should redirect_to '/users/sign_in'
956 context 'ユーザだが作家登録していないとき' do
958 @other_user = FactoryGirl.create( :user_yas)
959 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
963 it 'ステータスコード302 Foundを返す' do
964 get :edit, :id => @other_author.id
965 response.status.should eq 302
968 get :edit, :id => @other_author.id
969 response.body.should redirect_to new_author_path
977 @attr = @author.attributes
978 @attr['name'] = 'ryu'
981 context '事前チェックしておく' do
982 it '作家モデルに編集取得を問い合わせている' do
983 Author.stub(:edit).with(any_args()).and_return @author
984 Author.should_receive(:edit).exactly(1)
985 put :update, :id => @author.id, :author => @attr
987 it 'モデルにpostデータ転送を依頼する' do
988 Author.any_instance.stub(:attributes=).with(any_args)
989 Author.any_instance.should_receive(:attributes=).exactly(1)
990 put :update, :id => @author.id, :author => @attr
992 it 'モデルに上書き補充を依頼する' do
993 Author.any_instance.stub(:overwrite).with(any_args)
994 Author.any_instance.should_receive(:overwrite).exactly(1)
995 put :update, :id => @author.id, :author => @attr
998 Author.any_instance.stub(:save).with(any_args).and_return true
999 Author.any_instance.should_receive(:save).exactly(1)
1000 put :update, :id => @author.id, :author => @attr
1002 it '@auにアレを取得している' do
1003 put :update, :id => @author.id, :author => @attr
1004 assigns(:au).should eq @author
1007 context 'つつがなく終わるとき' do
1009 put :update, :id => @author.id, :author => @attr
1010 Author.find(@author.id).name.should eq 'ryu'
1013 it 'ステータスコード302 Foundを返す' do
1014 Author.any_instance.stub(:save).with(any_args()).and_return(true)
1015 put :update, :id => @author.id, :author => @attr
1016 response.status.should eq 302
1019 put :update, :id => @author.id, :author => @attr
1020 response.should redirect_to('/home/configure')
1024 it 'ステータスコード200 OKを返す' do
1025 Author.any_instance.stub(:save).with(any_args()).and_return(true)
1026 put :update, :id => @author.id, :author => @attr, :format => :json
1027 response.should be_success
1029 it 'ページ本体は特に返さない' do
1030 Author.any_instance.stub(:save).with(any_args()).and_return(true)
1031 put :update, :id => @author.id, :author => @attr, :format => :json
1032 response.body.should match /./
1036 context 'ユーザ権限がないとき' do
1041 it 'ステータスコード302 Foundを返す' do
1042 put :update, :id => @author.id, :author => @attr
1043 response.status.should eq 302
1045 it 'サインインページへ遷移する' do
1046 put :update, :id => @author.id, :author => @attr
1047 response.body.should redirect_to '/users/sign_in'
1051 it '応答メッセージにUnauthorizedを返す' do
1052 put :update, :id => @author.id, :author => @attr, :format => :json
1053 response.message.should match(/Unauthorized/)
1057 context 'ユーザ権限はないが管理者権限があるとき' do
1063 it 'ステータスコード302 Foundを返す' do
1064 put :update, :id => @author.id, :author => @attr
1065 response.status.should eq 302
1067 it 'サインインページへ遷移する' do
1068 put :update, :id => @author.id, :author => @attr
1069 response.body.should redirect_to '/users/sign_in'
1073 context 'ユーザだが作家登録していないとき' do
1075 @other_user = FactoryGirl.create( :user_yas)
1076 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1080 it 'ステータスコード302 Foundを返す' do
1081 get :update, :id => @other_author.id
1082 response.status.should eq 302
1084 it '作家登録ページへ遷移する' do
1085 get :update, :id => @other_author.id
1086 response.body.should redirect_to new_author_path
1090 context '検証、保存に失敗したとき' do
1092 Author.any_instance.stub(:save).and_return(false)
1095 it 'ステータスコード200 Okを返す' do
1096 put :update, :id => @author.id, :author => @attr
1097 response.status.should eq 200
1100 put :update, :id => @author.id, :author => @attr
1101 response.should render_template("edit")
1105 it 'ステータスコード422 unprocessable_entity を返す' do
1106 Author.any_instance.stub(:save).and_return(false)
1107 put :update, :id => @author.id, :author => @attr, :format => :json
1108 response.status.should eq 422
1110 it '応答メッセージUnprocessable Entityを返す' do
1111 put :update, :id => @author.id, :author => @attr, :format => :json
1112 response.message.should match(/Unprocessable/)
1119 describe '一覧表示に於いて' do
1121 Author.stub(:list).and_return([@author, @author, @author])
1124 context 'つつがなく終わるとき' do
1125 it 'ステータスコード200 OKを返す' do
1127 response.should be_success
1130 it 'indexテンプレートを描画する' do
1132 response.should render_template("index")
1137 get :index, :format => :json
1138 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1142 context 'ユーザ権限がないとき' do
1146 it 'ステータスコード200 OKを返す' do
1148 response.should be_success
1151 it 'indexテンプレートを描画する' do
1153 response.should render_template("index")
1158 get :index, :format => :json
1159 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1165 describe '閲覧に於いて' do
1167 Author.stub(:show).and_return(@author)
1170 context 'つつがなく終わるとき' do
1171 it 'ステータスコード200 OKを返す' do
1172 get :show, :id => @author.id
1173 response.should be_success
1176 it 'showテンプレートを描画する' do
1177 get :show, :id => @author.id
1178 response.should render_template("show")
1183 get :show, :id => @author.id, :format => :json
1184 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1188 context 'ユーザ権限がないとき' do
1192 it 'ステータスコード200 OKを返す' do
1193 get :show, :id => @author.id
1194 response.should be_success
1197 it 'showテンプレートを描画する' do
1198 get :show, :id => @author.id
1199 response.should render_template("show")
1204 get :show, :id => @author.id, :format => :json
1205 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1211 describe '対象作家のコミック一覧表示に於いて' do
1213 @other_user = FactoryGirl.create( :user_yas)
1214 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1215 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1216 @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id
1217 Comic.stub(:mylist).and_return([@comic, @comic, @comic])
1220 context 'つつがなく終わるとき' do
1221 it 'ステータスコード200 OKを返す' do
1222 get :comics, :id => @other_author.id
1223 response.should be_success
1226 it 'comicテンプレートを描画する' do
1227 get :comics, :id => @other_author.id
1228 response.should render_template("comic")
1233 get :comics, :id => @other_author.id, :format => :json
1234 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1238 context 'ユーザ権限がないとき' do
1242 it 'ステータスコード200 OKを返す' do
1243 get :comics, :id => @other_author.id
1244 response.should be_success
1247 it 'comicsテンプレートを描画する' do
1248 get :comics, :id => @other_author.id
1249 response.should render_template("comics")
1254 get :comics, :id => @other_author.id, :format => :json
1255 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1261 describe '対象作家のストーリー一覧表示に於いて' do
1263 @other_user = FactoryGirl.create( :user_yas)
1264 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1265 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1266 @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id
1267 @panel = FactoryGirl.create :panel, :author_id => @other_author.id
1268 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @other_author.id
1269 Story.stub(:mylist).and_return([@story, @story, @story])
1272 context 'つつがなく終わるとき' do
1273 it 'ステータスコード200 OKを返す' do
1274 get :stories, :id => @other_author.id
1275 response.should be_success
1278 it 'storiesテンプレートを描画する' do
1279 get :stories, :id => @other_author.id
1280 response.should render_template("stories")
1285 get :stories, :id => @other_author.id, :format => :json
1286 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1290 context 'ユーザ権限がないとき' do
1294 it 'ステータスコード200 OKを返す' do
1295 get :stories, :id => @other_author.id
1296 response.should be_success
1299 it 'storiesテンプレートを描画する' do
1300 get :stories, :id => @other_author.id
1301 response.should render_template("stories")
1306 get :stories, :id => @other_author.id, :format => :json
1307 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1313 describe '対象作家のコマ一覧表示に於いて' do
1315 @other_user = FactoryGirl.create( :user_yas)
1316 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
1317 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
1318 @panel = FactoryGirl.create :panel, :author_id => @other_author.id
1319 Panel.stub(:mylist).and_return([@panel, @panel, @panel])
1322 context 'つつがなく終わるとき' do
1323 it 'ステータスコード200 OKを返す' do
1324 get :panels, :id => @other_author.id
1325 response.should be_success
1328 it 'panelsテンプレートを描画する' do
1329 get :panels, :id => @other_author.id
1330 response.should render_template("panels")
1335 get :panels, :id => @other_author.id, :format => :json
1336 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1340 context 'ユーザ権限がないとき' do
1344 it 'ステータスコード200 OKを返す' do
1345 get :panels, :id => @other_author.id
1346 response.should be_success
1349 it 'panelsテンプレートを描画する' do
1350 get :panels, :id => @other_author.id
1351 response.should render_template("panels")
1356 get :panels, :id => @other_author.id, :format => :json
1357 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1363 describe '作家数取得に於いて' do
1365 Author.should_receive(:visible_count).and_return(3)
1368 context 'つつがなく終わるとき' do
1369 it 'ステータスコード200 OKを返す' do
1370 get :count, :format => :json
1371 response.should be_success
1375 get :count, :format => :json
1376 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1382 describe '新規作成フォーム表示に於いて' do
1384 @new_user = FactoryGirl.create( :user_yas)
1387 context 'つつがなく終わるとき' do
1388 it 'ステータスコード200 OKを返す' do
1390 response.should be_success
1393 it 'newテンプレートを描画する' do
1395 response.should render_template("new")
1399 it 'new.jsテンプレートを描画する' do
1400 get :new, :format => :js
1401 response.should render_template("new")
1406 get :new, :format => :json
1407 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1411 context 'ユーザ権限がないとき' do
1416 it 'ステータスコード302 Foundを返す' do
1418 response.status.should eq 302
1420 it 'サインインページへ遷移する' do
1422 response.body.should redirect_to '/users/sign_in'
1426 it 'ステータスコード401 Unauthorizedを返す' do
1427 get :new, :format => :js
1428 response.status.should eq 401
1430 it '応答メッセージにUnauthorizedを返す' do
1431 get :new, :format => :js
1432 response.message.should match(/Unauthorized/)
1436 it 'ステータスコード401 Unauthorizedを返す' do
1437 get :new, :format => :json
1438 response.status.should eq 401
1440 it '応答メッセージにUnauthorizedを返す' do
1441 get :new, :format => :json
1442 response.message.should match(/Unauthorized/)
1448 describe '新規作成に於いて' do
1450 @new_user = FactoryGirl.create( :user_yas)
1452 @attr = FactoryGirl.attributes_for(:author, :user_id => @new_user.id, :name => 'ken')
1454 context 'つつがなく終わるとき' do
1456 it 'ステータスコード302 Foundを返す' do
1457 Author.any_instance.stub(:save).and_return(true)
1458 post :create, :author => @attr
1459 response.status.should eq 302
1462 # Author.any_instance.stub(:save).and_return(true)
1463 post :create, :author => @attr
1464 response.should redirect_to(root_path)
1468 it 'ステータスコード200 OKを返す' do
1469 # Author.any_instance.stub(:save).and_return(true)
1470 post :create, :author => @attr, :format => :json
1471 response.should be_success
1475 context 'ユーザ権限がないとき' do
1480 it 'ステータスコード302 Foundを返す' do
1481 post :create, :author => @attr
1482 response.status.should eq 302
1484 it 'サインインページへ遷移する' do
1485 post :create, :author => @attr
1486 response.body.should redirect_to '/users/sign_in'
1490 it 'ステータスコード401 Unauthorizedを返す' do
1491 post :create, :author => @attr, :format => :json
1492 response.status.should eq 401
1494 it '応答メッセージにUnauthorizedを返す' do
1495 post :create, :author => @attr, :format => :json
1496 response.message.should match(/Unauthorized/)
1502 describe '編集フォーム表示に於いて' do
1505 Author.stub(:edit).and_return(@author)
1507 context 'つつがなく終わるとき' do
1508 it 'ステータスコード200 OKを返す' do
1509 get :edit, :id => @author.id
1510 response.should be_success
1513 it 'editテンプレートを描画する' do
1514 get :edit, :id => @author.id
1515 response.should render_template("edit")
1519 it 'edit.jsテンプレートを描画する' do
1520 get :edit, :id => @author.id, :format => :js
1521 response.should render_template("edit")
1525 context 'ユーザ権限がないとき' do
1530 it 'ステータスコード302 Foundを返す' do
1531 get :edit, :id => @author.id
1532 response.status.should eq 302
1534 it 'サインインページへ遷移する' do
1535 get :edit, :id => @author.id
1536 response.body.should redirect_to '/users/sign_in'
1540 it 'ステータスコード401 Unauthorizedを返す' do
1541 get :edit, :id => @author.id, :format => :js
1542 response.status.should eq 401
1544 it '応答メッセージにUnauthorizedを返す' do
1545 get :edit, :id => @author.id, :format => :js
1546 response.message.should match(/Unauthorized/)
1552 describe '更新に於いて' do
1554 @attr = @author.attributes
1555 @attr['name'] = 'ryu'
1558 context 'つつがなく終わるとき' do
1560 put :update, :id => @author.id, :author => @attr
1561 Author.find(@author.id).name.should eq 'ryu'
1564 it 'ステータスコード302 Foundを返す' do
1565 Author.any_instance.stub(:save).with(any_args()).and_return(true)
1566 put :update, :id => @author.id, :author => @attr
1567 response.status.should eq 302
1570 put :update, :id => @author.id, :author => @attr
1571 response.should redirect_to('/home/configure')
1575 it 'ステータスコード200 OKを返す' do
1576 Author.any_instance.stub(:save).with(any_args()).and_return(true)
1577 put :update, :id => @author.id, :author => @attr, :format => :json
1578 response.should be_success
1580 it 'ページ本体は特に返さない' do
1581 Author.any_instance.stub(:save).with(any_args()).and_return(true)
1582 put :update, :id => @author.id, :author => @attr, :format => :json
1583 response.body.should match /./
1587 context 'ユーザ権限がないとき' do
1591 it 'ステータスコード302 Foundを返す' do
1592 put :update, :id => @author.id, :author => @attr
1593 response.status.should eq 302
1596 it 'サインインページへ遷移する' do
1597 put :update, :id => @author.id, :author => @attr
1598 response.body.should redirect_to '/users/sign_in'
1602 it '応答メッセージにUnauthorizedを返す' do
1603 put :update, :id => @author.id, :author => @attr, :format => :json
1604 response.message.should match(/Unauthorized/)