OSDN Git Service

t#30200:update i18n devise
[pettanr/pettanr.git] / spec / controllers / speech_balloon_templates_controller_spec.rb
index aac1bd3..a107f5b 100644 (file)
@@ -4,11 +4,13 @@ require 'spec_helper'
 describe SpeechBalloonTemplatesController do
 
   before do
-    @admin = Factory :admin
-    @sbt = Factory :license
-    @user = Factory( :user_yas)
-    @author = @user.author
-    @sbt = Factory :speech_balloon_template
+    @admin = FactoryGirl.create :admin
+    @sp = FactoryGirl.create :system_picture
+    @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 = FactoryGirl.create :author, :user_id => @user.id
+    @sbt = FactoryGirl.create :speech_balloon_template
   end
 
   describe '一覧表示に於いて' do
@@ -17,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
@@ -30,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
@@ -48,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
@@ -82,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