1 # -*- encoding: utf-8 -*-
4 describe ScrollsController do
6 @admin =FactoryGirl.create :admin
7 @user_yas = FactoryGirl.create :user_yas_with_owner
8 @user_rom = FactoryGirl.create :user_rom
9 @author_yas = @user_yas.author
11 @my_model_class = Scroll #操作モデル
14 if Manifest.manifest.magic_numbers['run_mode'] == 1
15 describe '一覧表示に於いて' do
17 factory_contents :scroll_hello, @author_yas
19 @query_format_json = @query.merge(:format => :json)
30 it 'コントローラのマニフェストから操作モデルを導出している' do
31 set_model? @my_model_class
33 it 'コントローラのマニフェストからリスト操作モデルを導出している' do
34 set_list_model? @my_model_class
36 it 'リストグループのマニフェストからリストgetter(新着リスト)を導出している' do
37 set_list? 'scroll', 'public'
39 it '@itemsにリストを取得している' do
40 expect(assigns(:items).size).to be >= 3
47 it 'ステータス OKを返して、ファイラーを描画している' do
51 it '@filerにファイラーを取得している' do
57 get :index, @query_format_json
59 it 'ステータス OKを返して、jsonデータを返している' do
63 it '@filerにファイラーをセットしていない' do
64 expect(assigns(:filer)).to be nil
73 expect(response.status).to eq(406)
77 it 'ステータス OKを返して、jsonデータを返している' do
79 get :count, @query_format_json
84 context 'ゲスト(サインインしていない)' do
86 get :count, @query_format_json
92 context 'サインインの状態が例外的なとき' do
93 it 'ユーザではなく管理者でも通常通り応答している' do
97 get :index, @query_format_json
100 it '創作活動してないROM専の読者にも通常通り応答している' do
104 get :index, @query_format_json
107 it 'ゲスト(サインインしていない)はサインインページに遷移している' do
109 redirect? sign_in_url
110 get :index, @query_format_json
115 describe '作家フィルタ一覧及びカウント' do
117 factory_contents :scroll_hello, @author_yas
118 @query = {:id => @author_yas.id}
119 @query_format_json = @query.merge(:format => :json)
128 get :by_author, @query
130 it 'コントローラのマニフェストから操作モデルを導出している' do
131 set_model? @my_model_class
133 it 'リストグループのマニフェストから新着リストの取得処理を@listに取得している' do
134 set_list? 'scroll', 'by_author'
136 it '@itemsにリストを取得している' do
137 expect(assigns(:items).size).to be >= 3
142 get :by_author, @query
144 it 'ステータス OKを返して、ファイラーを描画している' do
148 it '@filerにファイラーを取得している' do
154 get :by_author, @query_format_json
156 it 'ステータス OKを返して、jsonデータを返している' do
160 it '@filerにファイラーをセットしていない' do
161 expect(assigns(:filer)).to be nil
167 it '必要ないので実装していない' do
169 get :count_by_author, @query
170 expect(response.status).to eq(406)
176 get :count_by_author, @query_format_json
181 context 'ゲスト(サインインしていない)' do
183 get :count_by_author, @query_format_json
189 context 'サインインの状態が例外的なとき' do
190 it 'ユーザではなく管理者でも通常通り応答している' do
192 get :by_author, @query
194 get :by_author, @query_format_json
197 it '創作活動してないROM専の読者にも通常通り応答している' do
200 get :by_author, @query_format_json
203 it 'ゲスト(サインインしていない)はサインインページに遷移している' do
204 get :by_author, @query
205 redirect? sign_in_url
206 get :by_author, @query_format_json
212 describe '単体表示に於いて' do
214 @item = FactoryGirl.create :scroll_hello, author: @author_yas
216 @query = {:id => @item_id}
217 @query_format_json = @query.merge(:format => :json)
218 @query_format_prof = @query.merge(:format => :prof)
224 context '正常系の共通処理' do
228 it 'コントローラのマニフェストから操作モデルを導出している' do
229 set_model? @my_model_class
231 it '@itemにリクエストしたアイテムを取得している' do
232 expect(assigns(:item)).to eq(@item)
239 it 'showテンプレートを描画している' do
241 expect(response).to render_template("show")
243 it 'プロファイラーは必要ないので@profilerに用意していない' do
244 expect(assigns(:profiler)).to be nil
249 get :show, @query_format_json
255 it 'プロファイラーは必要ないので@profilerに用意していない' do
256 expect(assigns(:profiler)).to be nil
261 get :show, @query_format_prof
263 it 'プロファイラーテンプレートを描画している' do
267 it '@profilerにプロファイラーを取得している' do
272 context 'サインインの状態が例外的なとき' do
273 it 'ユーザではなく管理者でも通常通り応答している' do
277 get :show, @query_format_json
280 it '創作活動してないROM専の読者にも通常通り応答している' do
284 get :show, @query_format_json
287 it 'ゲスト(サインインしていない)はサインインページに遷移している' do
289 redirect? sign_in_url
290 get :show, @query_format_json
296 describe 'プレイリストに於いて' do
298 @item = FactoryGirl.create :scroll_hello_with_scroll_panels, author: @author_yas
300 @query = {:id => @item_id}
301 @query_format_json = @query.merge(:format => :json)
311 it 'コントローラのマニフェストから操作モデルを導出している' do
312 set_model? @my_model_class
314 it '@itemにリクエストしたスクロールを取得している' do
315 expect(assigns(:item)).to eq(@item)
317 it 'コントローラのマニフェストからリスト操作モデルを導出している' do
318 # リクエストの対象はスクロールであるが、返されるのはスクコマのリストである。
320 set_list_model? ScrollPanel
322 it 'リストグループのマニフェストからリストgetter(プレイリスト)を導出している' do
323 set_list? 'scroll_panel', 'play'
325 it '@itemsにプレイリストを取得している' do
326 set_play_list? ScrollPanel
333 it 'playテンプレートを描画している' do
335 expect(response).to render_template("play")
340 get :play, @query_format_json
348 context 'サインインの状態が例外的なとき' do
349 it 'ユーザではなく管理者でも通常通り応答している' do
353 get :play, @query_format_json
356 it '創作活動してないROM専の読者にも通常通り応答している' do
360 get :play, @query_format_json
363 it 'ゲスト(サインインしていない)はサインインページに遷移している' do
365 redirect? sign_in_url
366 get :play, @query_format_json
372 describe '新規作成フォーム表示に於いて' do
375 @query_format_json = @query.merge(:format => :json)
385 it 'コントローラのマニフェストから操作モデルを導出している' do
386 set_model? @my_model_class
388 it '@itemに新規データを用意している' do
389 @item = assigns(:item)
390 expect(@item.is_a?(@my_model_class)).to be true
391 expect(@item.new_record?).to be true
398 it 'スクロールモデルにデフォルト値補充を依頼している' do
399 allow_any_instance_of(@my_model_class).to receive(:supply_default)
400 expect_any_instance_of(@my_model_class).to receive(:supply_default)
408 it 'formテンプレートを描画している' do
412 it '@formに入力フォーム(Bucket)を取得している' do
413 set_bucket? assigns(:item)
418 get :new, @query_format_json
424 it '入力フォームは必要ないので@formに用意していない' do
425 expect(assigns(:form)).to be nil
429 context 'サインインの状態が例外的なとき' do
432 it '創作活動してないROM専の読者は作家登録ページへ遷移している, 例外を発生させている' do
435 redirect? new_author_path
436 announce_regist_author_for_json :get, @query_format_json, :new
438 it 'ゲスト(サインインしていない)はサインインページに遷移している' do
440 redirect? sign_in_url
441 get :new, @query_format_json
444 it 'ユーザではなく管理者でもサインインページに遷移している' do
447 redirect? sign_in_url
448 get :new, @query_format_json
454 describe '新規作成に於いて' do
456 @attributes = FactoryGirl.attributes_for(:scroll_hello, author_id: @author_yas.id)
457 @attr = {:scroll => @attributes}
458 @attr_format_json = @attr.merge(:format => :json)
466 allow_save @my_model_class
469 it 'コントローラのマニフェストから操作モデルを導出している' do
470 set_model? @my_model_class
472 it '@itemに新規アイテムを用意している' do
473 @item = assigns(:item)
474 expect(@item.is_a?(@my_model_class)).to be true
481 it '作成されたアイテムの表示ページへ遷移している' do
482 redirect? @my_model_class.last
487 post :create, @attr_format_json
489 it 'ステータスコード200 OKを返して, 作成されたアイテムをjsonデータで返す' do
498 }.to change {@my_model_class.count}.by(1)
502 context '検証、保存に失敗したとき' do
505 reject_save @my_model_class
511 it 'ステータスコード200 OKを返して, formテンプレートを描画している' do
515 it '@formに入力フォーム(Bucket)を取得している' do
516 set_bucket? assigns(:item)
521 post :create, @attr_format_json
524 render_unprocessable?
528 context 'サインインの状態が例外的なとき' do
530 allow_save @my_model_class
532 it '創作活動してないROM専の読者は作家登録ページへ遷移している, 例外を発生させている' do
535 redirect? new_author_path
536 announce_regist_author_for_json :post, @attr_format_json, :create
538 it 'ゲスト(サインインしていない)はサインインページに遷移している' do
540 redirect? sign_in_url
541 post :create, @attr_format_json
544 it 'ユーザではなく管理者でもサインインページに遷移している' do
547 redirect? sign_in_url
548 post :create, @attr_format_json
554 describe '編集フォーム表示に於いて' do
556 @item = FactoryGirl.create :scroll_hello_with_scroll_panels, author: @author_yas
558 @query = {:id => @item_id}
559 @query_format_json = @query.merge(:format => :json)
569 it 'コントローラのマニフェストから操作モデルを導出している' do
570 set_model? @my_model_class
572 it '@itemにリクエストしたアイテムを取得している' do
573 expect(assigns(:item).is_a?(@my_model_class)).to be true
574 expect(assigns(:item)).to eq(@item)
584 it 'formテンプレートを描画している' do
588 it '@formに入力フォーム(Bucket)を取得している' do
589 set_bucket? assigns(:item)
594 get :edit, @query_format_json
600 it '入力フォームは必要ないので@formに用意していない' do
601 expect(assigns(:form)).to be nil
605 context 'サインインの状態が例外的なとき' do
607 allow_save @my_model_class
609 it '創作活動してないROM専の読者は作家登録ページへ遷移している, 例外を発生させている' do
612 redirect? new_author_path
613 announce_regist_author_for_json :get, @query_format_json, :edit
615 it 'ゲスト(サインインしていない)はサインインページに遷移している' do
617 redirect? sign_in_url
618 post :edit, @query_format_json
621 it 'ユーザではなく管理者でもサインインページに遷移している' do
624 redirect? sign_in_url
625 post :edit, @query_format_json
633 @item = FactoryGirl.create :scroll_hello_with_scroll_panels, author: @author_yas
635 @attributes = FactoryGirl.attributes_for(:scroll_hidden, author_id: @author_yas.id)
636 @attr = {:id => @item_id, :scroll => @attributes}
637 @attr_format_json = @attr.merge(:format => :json)
645 allow_save @my_model_class
648 it 'コントローラのマニフェストから操作モデルを導出している' do
649 set_model? @my_model_class
651 it '@itemにリクエストしたアイテムを取得している' do
652 expect(assigns(:item).is_a?(@my_model_class)).to be true
653 expect(assigns(:item)).to eq(@item)
658 allow_save @my_model_class
661 it 'リクエストしたアイテムの表示ページへ遷移している' do
667 allow_save @my_model_class
668 put :update, @attr_format_json
670 it 'ステータスコード200 OKを返して, ページ本体は特に返さない' do
676 it '@itemの件数に変わりはない' do
679 }.to change {@my_model_class.count}.by(0)
684 updated_item = @my_model_class.find @item_id
685 # 変化を確認できるカラムはモデルごとに違うので注意
686 expect(updated_item.visible).to eq(0)
690 context '検証、保存に失敗したとき' do
693 reject_save @my_model_class
699 it 'ステータスコード200 OKを返して, formテンプレートを描画している' do
703 it '@formに入力フォーム(Bucket)を取得している' do
704 set_bucket? assigns(:item)
709 put :update, @attr_format_json
712 render_unprocessable?
714 it '入力フォームは必要ないので@formに用意していない' do
715 expect(assigns(:form)).to be nil
719 context 'サインインの状態が例外的なとき' do
721 allow_save @my_model_class
723 it '創作活動してないROM専の読者は作家登録ページへ遷移している, 例外を発生させている' do
726 redirect? new_author_path
727 announce_regist_author_for_json :put, @attr_format_json, :update
729 it 'ゲスト(サインインしていない)はサインインページに遷移している' do
731 redirect? sign_in_url
732 put :update, @attr_format_json
735 it 'ユーザではなく管理者でもサインインページに遷移している' do
738 redirect? sign_in_url
739 put :update, @attr_format_json
747 @item = FactoryGirl.create :scroll_hello_with_scroll_panels, author: @author_yas
749 @attr = {:id => @item_id}
750 @attr_format_json = @attr.merge(:format => :json)
758 allow_destroy @my_model_class
759 delete :destroy, @attr
761 it 'コントローラのマニフェストから操作モデルを導出している' do
762 set_model? @my_model_class
764 it '@itemにリクエストしたアイテムを取得している' do
765 expect(assigns(:item).is_a?(@my_model_class)).to be true
766 expect(assigns(:item)).to eq(@item)
771 allow_destroy @my_model_class
772 delete :destroy, @attr
774 it 'マイスクロールの一覧ページへ遷移している' do
775 redirect? '/home/scrolls'
780 allow_destroy @my_model_class
781 delete :destroy, @attr_format_json
783 it 'ステータスコード200 OKを返して, ページ本体は特に返さない' do
784 expect(response).to be_success
791 delete :destroy, @attr
792 }.to change {@my_model_class.count}.by(-1)
794 it 'ぶら下がるリーフも削除されている' do
796 delete :destroy, @attr
797 }.to change {ScrollPanel.count}.from(4).to(0)
801 context '検証、保存に失敗したとき' do
804 reject_destroy @my_model_class
808 delete :destroy, @attr
810 it 'リクエストしたアイテムの詳細ページへ遷移している' do
816 delete :destroy, @attr_format_json
819 render_unprocessable?
823 context 'サインインの状態が例外的なとき' do
825 allow_destroy @my_model_class
827 it '創作活動してないROM専の読者は作家登録ページへ遷移している, 例外を発生させている' do
829 delete :destroy, @attr
830 redirect? new_author_path
831 announce_regist_author_for_json :delete, @attr_format_json, :destroy
833 it 'ゲスト(サインインしていない)はサインインページに遷移している' do
834 delete :destroy, @attr
835 redirect? sign_in_url
836 delete :destroy, @attr_format_json
839 it 'ユーザではなく管理者でもサインインページに遷移している' do
841 delete :destroy, @attr
842 redirect? sign_in_url
843 delete :destroy, @attr_format_json
850 describe '一覧表示に於いて' do
852 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
853 Scroll.stub(:list).and_return([@scroll, @scroll, @scroll])
856 context '正常系の共通処理' do
857 it 'ステータスコード200 OKを返す' do
859 response.should be_success
862 it 'indexテンプレートを描画する' do
864 response.should render_template("index")
869 get :index, :format => :json
870 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
874 context 'ユーザ権限がないとき' do
878 it 'ステータスコード200 OKを返す' do
880 response.should be_success
883 it 'indexテンプレートを描画する' do
885 response.should render_template("index")
890 get :index, :format => :json
891 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
897 describe '単体表示に於いて' do
899 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id, :title => 'normal'
900 Scroll.stub(:show).and_return(@scroll)
903 context '正常系の共通処理' do
904 it 'ステータスコード200 OKを返す' do
905 get :show, :id => @scroll.id
906 response.should be_success
909 it 'showテンプレートを描画する' do
910 get :show, :id => @scroll.id
911 response.should render_template("show")
916 get :show, :id => @scroll.id, :format => :json
917 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
921 context 'ユーザ権限がないとき' do
925 it 'ステータスコード200 OKを返す' do
926 get :show, :id => @scroll.id
927 response.should be_success
930 it 'showテンプレートを描画する' do
931 get :show, :id => @scroll.id
932 response.should render_template("show")
937 get :show, :id => @scroll.id, :format => :json
938 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
943 describe 'スクロール数取得に於いて' do
945 Scroll.should_receive(:visible_count).and_return(3)
948 context '正常系の共通処理' do
949 it 'ステータスコード200 OKを返す' do
950 get :count, :format => :json
951 response.should be_success
955 get :count, :format => :json
956 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
962 describe '新規作成フォーム表示に於いて' do
966 context '正常系の共通処理' do
967 it 'ステータスコード200 OKを返す' do
969 response.should be_success
972 it 'newテンプレートを描画する' do
974 response.should render_template("new")
978 it 'new.jsテンプレートを描画する' do
979 get :new, :format => :js
980 response.should render_template("new")
985 get :new, :format => :json
986 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
990 context 'ユーザ権限がないとき' do
995 it 'ステータスコード302 Foundを返す' do
997 response.status.should eq 302
999 it 'サインインページへ遷移する' do
1001 response.body.should redirect_to '/users/sign_in'
1005 it 'ステータスコード401 Unauthorizedを返す' do
1006 get :new, :format => :js
1007 response.status.should eq 401
1009 it '応答メッセージにUnauthorizedを返す' do
1010 get :new, :format => :js
1011 response.message.should match(/Unauthorized/)
1015 it 'ステータスコード401 Unauthorizedを返す' do
1016 get :new, :format => :json
1017 response.status.should eq 401
1019 it '応答メッセージにUnauthorizedを返す' do
1020 get :new, :format => :json
1021 response.message.should match(/Unauthorized/)
1027 describe '新規作成に於いて' do
1030 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
1032 context '正常系の共通処理' do
1034 it 'ステータスコード302 Foundを返す' do
1035 Scroll.any_instance.stub(:save).and_return(true)
1036 post :create, :scroll => @attr
1037 response.status.should eq 302
1039 it '作成されたスクロールの表示ページへ遷移する' do
1040 # Scroll.any_instance.stub(:save).and_return(true)
1041 post :create, :scroll => @attr
1042 response.should redirect_to(Scroll.last)
1046 it 'ステータスコード200 OKを返す' do
1047 # Scroll.any_instance.stub(:save).and_return(true)
1048 post :create, :scroll => @attr, :format => :json
1049 response.should be_success
1051 it '作成されたスクロールをjsonデータで返す' do
1052 post :create, :scroll => @attr, :format => :json
1053 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1057 context 'ユーザ権限がないとき' do
1062 it 'ステータスコード302 Foundを返す' do
1063 post :create, :scroll => @attr
1064 response.status.should eq 302
1066 it 'サインインページへ遷移する' do
1067 post :create, :scroll => @attr
1068 response.body.should redirect_to '/users/sign_in'
1072 it 'ステータスコード401 Unauthorizedを返す' do
1073 post :create, :scroll => @attr, :format => :json
1074 response.status.should eq 401
1076 it '応答メッセージにUnauthorizedを返す' do
1077 post :create, :scroll => @attr, :format => :json
1078 response.message.should match(/Unauthorized/)
1084 describe '編集フォーム表示に於いて' do
1086 @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
1088 Scroll.stub(:edit).and_return(@scroll)
1090 context '正常系の共通処理' do
1091 it 'ステータスコード200 OKを返す' do
1092 get :edit, :id => @scroll.id
1093 response.should be_success
1096 it 'editテンプレートを描画する' do
1097 get :edit, :id => @scroll.id
1098 response.should render_template("edit")
1102 it 'edit.jsテンプレートを描画する' do
1103 get :edit, :id => @scroll.id, :format => :js
1104 response.should render_template("edit")
1108 context 'ユーザ権限がないとき' do
1113 it 'ステータスコード302 Foundを返す' do
1114 get :edit, :id => @scroll.id
1115 response.status.should eq 302
1117 it 'サインインページへ遷移する' do
1118 get :edit, :id => @scroll.id
1119 response.body.should redirect_to '/users/sign_in'
1123 it 'ステータスコード401 Unauthorizedを返す' do
1124 get :edit, :id => @scroll.id, :format => :js
1125 response.status.should eq 401
1127 it '応答メッセージにUnauthorizedを返す' do
1128 get :edit, :id => @scroll.id, :format => :js
1129 response.message.should match(/Unauthorized/)
1135 describe '更新に於いて' do
1137 @scroll = FactoryGirl.create :scroll, :author => @author
1138 @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
1141 context '正常系の共通処理' do
1143 it 'ステータスコード302 Foundを返す' do
1144 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1145 put :update, :id => @scroll.id, :scroll => @attr
1146 response.status.should eq 302
1148 it '更新されたスクロールの表示ページへ遷移する' do
1149 put :update, :id => @scroll.id, :scroll => @attr
1150 response.should redirect_to(@scroll)
1154 it 'ステータスコード200 OKを返す' do
1155 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1156 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
1157 response.should be_success
1159 it 'ページ本体は特に返さない' do
1160 Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
1161 put :update, :id => @scroll.id, :scroll => @attr, :format => :json
1162 response.body.should match /./
1166 context 'ユーザ権限がないとき' do
1170 it 'ステータスコード302 Foundを返す' do
1171 put :update, :id => @scroll.id, :scroll => @attr
1172 response.status.should eq 302
1175 it 'サインインページへ遷移する' do
1176 put :update, :id => @scroll.id, :scroll => @attr
1177 response.body.should redirect_to '/users/sign_in'
1183 describe '削除に於いて' do
1185 @scroll = FactoryGirl.create :scroll, :author => @author
1188 context '正常系の共通処理' do
1191 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
1193 it 'ステータスコード302 Foundを返す' do
1194 delete :destroy, :id => @scroll.id
1195 response.status.should eq 302
1197 it 'マイスクロールの一覧ページへ遷移する' do
1198 delete :destroy, :id => @scroll.id
1199 response.should redirect_to('/home/scroll')
1204 Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
1206 it 'ステータスコード200 OKを返す' do
1207 delete :destroy, :id => @scroll.id, :format => :json
1208 response.should be_success
1210 it 'ページ本体は特に返さない' do
1211 delete :destroy, :id => @scroll.id, :format => :json
1212 response.body.should match /./
1216 context 'ユーザ権限がないとき' do
1220 it 'ステータスコード302 Foundを返す' do
1221 delete :destroy, :id => @scroll.id
1222 response.status.should eq 302
1225 it 'サインインページへ遷移する' do
1226 delete :destroy, :id => @scroll.id
1227 response.body.should redirect_to '/users/sign_in'
1231 it '応答メッセージにUnauthorizedを返す' do
1232 delete :destroy, :id => @scroll.id, :format => :json
1233 response.message.should match(/Unauthorized/)