OSDN Git Service

fix test
[pettanr/pettanr.git] / spec / controllers / scrolls_controller_spec.rb
index 487548d..e828f7d 100644 (file)
@@ -209,6 +209,103 @@ if Manifest.manifest.magic_numbers['run_mode'] == 1
     end
   end
   
+  describe 'コマフィルタ一覧及びカウント' do
+    before do
+      @panel = FactoryGirl.create :panel_hello_with_scroll_panels, author_id: @author_yas.id
+      @query = {:id => @panel.id}
+      @query_format_json = @query.merge(:format => :json)
+    end
+    
+    context '正常系' do
+      before do
+        sign_in @user_yas
+      end
+      context '共通処理' do
+        before do
+          get :by_panel, @query
+        end
+        it 'コントローラのマニフェストから操作モデルを導出している' do
+          set_model? @my_model_class
+        end
+        it 'リストグループのマニフェストから新着リストの取得処理を@listに取得している' do
+          set_list? 'scroll', 'by_panel'
+        end
+        it '@itemsにリストを取得している' do
+          expect(assigns(:items).size).to be >= 3
+        end
+      end
+      context 'html形式' do
+        before do
+          get :by_panel, @query
+        end
+        it 'ステータス OKを返して、ファイラーを描画している' do
+          return_ok?
+          render_filer?
+        end
+        it '@filerにファイラーを取得している' do
+          let_filer?
+        end
+      end
+      context 'json形式' do
+        before do
+          get :by_panel, @query_format_json
+        end
+        it 'ステータス OKを返して、jsonデータを返している' do
+          return_ok?
+          render_json?
+        end
+        it '@filerにファイラーをセットしていない' do
+          expect(assigns(:filer)).to be nil
+        end
+      end
+    end
+    context '件数取得' do
+      context 'html形式' do
+        it '必要ないので実装していない' do
+          sign_in @user_yas
+          get :count_by_panel, @query
+          expect(response.status).to eq(406)
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          sign_in @user_yas
+          get :count_by_panel, @query_format_json
+          return_ok?
+          render_json?
+        end
+      end
+      context 'ゲスト(サインインしていない)' do
+        it '通常通り応答している' do
+          get :count_by_panel, @query_format_json
+          return_ok?
+          render_json?
+        end
+      end
+    end
+    context 'サインインの状態が例外的なとき' do
+      it 'ユーザではなく管理者でも通常通り応答している' do
+        sign_in @admin
+        get :by_panel, @query
+        return_ok?
+        get :by_panel, @query_format_json
+        render_json?
+      end
+      it '創作活動してないROM専の読者にも通常通り応答している' do
+        sign_in @user_rom
+        return_ok?
+        get :by_panel, @query_format_json
+        render_json?
+      end
+      it 'ゲスト(サインインしていない)はサインインページに遷移している' do
+        get :by_panel, @query
+        redirect? sign_in_url
+        get :by_panel, @query_format_json
+        render_unauthorized?
+      end
+    end
+  end
+  
   describe '単体表示に於いて' do
     before do
       @item =  FactoryGirl.create :scroll_hello, author: @author_yas