OSDN Git Service

t#29671:fix my panel list as json
authoryasushiito <yas@pen-chan.jp>
Thu, 27 Sep 2012 23:00:35 +0000 (08:00 +0900)
committeryasushiito <yas@pen-chan.jp>
Thu, 27 Sep 2012 23:00:35 +0000 (08:00 +0900)
app/controllers/home_controller.rb
spec/controllers/home_controller_spec.rb

index 9d296c1..0384ec4 100644 (file)
@@ -86,7 +86,7 @@ class HomeController < ApplicationController
 
     respond_to do |format|
       format.html # index.html.erb
-      format.json { render json: @panels.to_json() }
+      format.json { render text: Panel.list_as_json_text(@panels) }
     end
   end
   
index f42e53f..f55b22e 100644 (file)
@@ -151,10 +151,6 @@ describe HomeController do
       end
     end
     context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :panel
-        response.should be_success 
-      end
       it 'コマモデルに一覧を問い合わせている' do
         Panel.should_receive(:mylist).exactly(1)
         get :panel
@@ -164,16 +160,28 @@ describe HomeController do
         assigns(:panels).should have_at_least(3).items
       end
       context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :panel
+          response.should be_success 
+        end
         it 'panelテンプレートを描画する' do
           get :panel
           response.should render_template("panel")
         end
       end
       context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :panel, :format => :json
+          response.should be_success 
+        end
         it 'jsonデータを返す' do
           get :panel, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
+        it 'コマモデルにコマリストのjson出力を問い合わせている' do
+          Panel.should_receive(:list_as_json_text).exactly(1)
+          get :panel, :format => :json
+        end
         it 'データがリスト構造になっている' do
           get :panel, :format => :json
           json = JSON.parse response.body