OSDN Git Service

t30329#:i18n flash message
[pettanr/pettanr.git] / spec / controllers / speech_balloon_templates_controller_spec.rb
index f2e941f..a107f5b 100644 (file)
@@ -9,7 +9,7 @@ describe SpeechBalloonTemplatesController do
     @lg = FactoryGirl.create :license_group
     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
     @user = FactoryGirl.create( :user_yas)
-    @author = @user.author
+    @author = FactoryGirl.create :author, :user_id => @user.id
     @sbt = FactoryGirl.create :speech_balloon_template
   end
 
@@ -19,10 +19,6 @@ describe SpeechBalloonTemplatesController do
       SpeechBalloonTemplate.stub(:list).and_return([@sbt, @sbt, @sbt])
     end
     context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :index
-        response.should be_success 
-      end
       it 'フキダシテンプレートモデルに一覧を問い合わせている' do
         SpeechBalloonTemplate.should_receive(:list).exactly(1)
         get :index
@@ -32,16 +28,28 @@ describe SpeechBalloonTemplatesController do
         assigns(:speech_balloon_templates).should have_at_least(3).items
       end
       context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :index
+          response.should be_success 
+        end
         it 'indexテンプレートを描画する' do
           get :index
           response.should render_template("index")
         end
       end
       context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :index, :format => :json
+          response.should be_success 
+        end
         it 'jsonデータを返す' do
           get :index, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
+        it 'フキダシテンプレートモデルにjson一覧出力オプションを問い合わせている' do
+          SpeechBalloonTemplate.should_receive(:list_json_opt).exactly(1)
+          get :index, :format => :json
+        end
         it 'データがリスト構造になっている' do
           get :index, :format => :json
           json = JSON.parse response.body
@@ -50,7 +58,9 @@ describe SpeechBalloonTemplatesController do
         it 'リストの先頭くらいはフキダシテンプレートっぽいものであって欲しい' do
           get :index, :format => :json
           json = JSON.parse response.body
+          json.first.has_key?("name").should be_true
           json.first.has_key?("classname").should be_true
+          json.first.has_key?("t").should be_true
         end
       end
     end
@@ -84,32 +94,40 @@ describe SpeechBalloonTemplatesController do
   describe '単体表示に於いて' do
     before do
       sign_in @user
-      SpeechBalloonTemplate.stub(:show).and_return(@sbt)
+      SpeechBalloonTemplate.stub(:show).with(@sbt.id.to_s, @author).and_return(@sbt)
     end
     context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :show, :id => @sbt.id
-        response.should be_success
-      end
       it 'フキダシテンプレートモデルに単体取得を問い合わせている' do
         SpeechBalloonTemplate.should_receive(:show).exactly(1)
         get :show
       end
       it '@speech_balloon_templateにアレを取得している' do
         get :show, :id => @sbt.id
-        assigns(:speech_balloon_template).id.should eq(@sbt.id)
+        assigns(:speech_balloon_template).should eq(@sbt)
       end
       context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @sbt.id
+          response.should be_success
+        end
         it 'showテンプレートを描画する' do
           get :show, :id => @sbt.id
           response.should render_template("show")
         end
       end
       context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @sbt.id, :format => :json
+          response.should be_success
+        end
         it 'jsonデータを返す' do
           get :show, :id => @sbt.id, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
+        it 'フキダシテンプレートモデルにjson単体出力オプションを問い合わせている' do
+          SpeechBalloonTemplate.should_receive(:show_json_opt).exactly(1)
+          get :show, :id => @sbt.id, :format => :json
+        end
         it 'データがアレになっている' do
           get :show, :id => @sbt.id, :format => :json
           json = JSON.parse response.body