From: yasushiito Date: Thu, 27 Sep 2012 23:00:35 +0000 (+0900) Subject: t#29671:fix my panel list as json X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=1ec9dfad4844a29ff6031560f5ed21b5137faf97;hp=4abd6a3257c60de06d07584012a396f759842a38;p=pettanr%2Fpettanr.git t#29671:fix my panel list as json --- diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 9d296c1f..0384ec45 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -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 diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index f42e53f5..f55b22ea 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -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