OSDN Git Service

t#32246:add sheet
[pettanr/pettanr.git] / spec / controllers / sheets_controller_spec.rb
index 0109ad1..289f3ed 100644 (file)
@@ -267,7 +267,7 @@ if MagicNumber['run_mode'] == 1
   
   describe '閲覧に於いて' do
     before do
-      @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
+      @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id, :caption => 'normal'
       @panel = FactoryGirl.create :panel, :author_id => @author.id
       @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
       Sheet.stub(:show).with(@sheet.id.to_s, [@user, nil]).and_return(@sheet)
@@ -281,16 +281,8 @@ if MagicNumber['run_mode'] == 1
         Sheet.should_receive(:show).with(@sheet.id.to_s, [@user, nil]).exactly(1)
         get :play, :id => @sheet.id
       end
-      it '紙コマモデルにプレイリスト取得を問い合わせている' do
-        SheetPanel.should_receive(:play_list).with(@sheet, @author).exactly(1)
-        get :play, :id => @sheet.id
-      end
     end
     context 'つつがなく終わるとき' do
-      it '@sheet_panelsにリストを取得している' do
-        get :play, :id => @sheet.id
-        assigns(:sheet_panels).should have_at_least(3).items
-      end
       context 'html形式' do
         it 'ステータスコード200 OKを返す' do
           get :play, :id => @sheet.id
@@ -310,21 +302,15 @@ if MagicNumber['run_mode'] == 1
           get :play, :id => @sheet.id, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it '紙コマモデルに紙コマリストのjson出力を問い合わせている' do
-          SheetPanel.should_receive(:list_as_json_text).exactly(1)
-          get :play, :id => @sheet.id, :format => :json
-        end
-        it 'データがリスト構造になっている' do
-          get :play, :id => @sheet.id, :format => :json
-          json = JSON.parse response.body
-          json.should have_at_least(3).items
+        it '用紙モデルにjson単体出力オプションを問い合わせている' do
+          Sheet.should_receive(:show_json_opt).exactly(1)
+          get :show, :id => @sheet.id, :format => :json
         end
-        it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ­ã\81\8fã\82\89ã\81\84ã\81¯ç´\99ã\82³ã\83\9eã\81£ã\81½ã\81\84ã\82\82ã\81®ã\81§ã\81\82ã\81£ã\81¦æ¬²ã\81\97ã\81\84' do
+        it 'ã\83\87ã\83¼ã\82¿ã\81\8cã\82¢ã\83¬ã\81«ã\81ªã\81£ã\81¦ã\81\84ã\82\8b' do
           get :play, :id => @sheet.id, :format => :json
           json = JSON.parse response.body
-          json.first.has_key?("panel_id").should be_true
-          json.first.has_key?("sheet_id").should be_true
-          json.first.has_key?("author_id").should be_true
+          json["caption"].should match(/normal/)
+          json["visible"].should_not be_nil
         end
       end
     end
@@ -512,20 +498,27 @@ if MagicNumber['run_mode'] == 1
       @attr = FactoryGirl.attributes_for(:sheet, :author_id => @author.id, :caption => 'normal')
     end
     context '事前チェックしておく' do
-      it '用紙モデルにデフォルト値補充を依頼している' do
-        Sheet.any_instance.should_receive(:supply_default).exactly(1)
+      it 'sheetがパラメータにあれば、展開する' do
         post :create, :sheet => @attr
+        assigns(:prm)['caption'].should eq 'normal'
       end
-      it '用紙モデルにカラム値復元を依頼している' do
-        Sheet.any_instance.should_receive(:attributes=).exactly(1)
-        post :create, :sheet => @attr
+      it 'jsonがパラメータにあれば、展開する' do
+        post :create, :json => FactoryGirl.attributes_for(:sheet, :caption => 'json prm').to_json
+        assigns(:prm)['caption'].should eq 'json prm'
       end
-      it '用紙モデルに上書き補充を依頼している' do
-        Sheet.any_instance.should_receive(:overwrite).exactly(1)
+      it 'sheet・json両パラメータがあれば、sheetを優先して展開する' do
+        post :create, {
+          :sheet => FactoryGirl.attributes_for(:sheet, :caption => 'normal'), 
+          :json => FactoryGirl.attributes_for(:sheet, :caption => 'json prm').to_json
+        }
+        assigns(:prm)['caption'].should eq 'normal'
+      end
+      it '用紙モデルにデフォルト値補充を依頼している' do
+        Sheet.any_instance.should_receive(:supply_default).exactly(1)
         post :create, :sheet => @attr
       end
       it 'モデルに保存依頼する' do
-        Sheet.any_instance.should_receive(:save).exactly(1)
+        Sheet.any_instance.should_receive(:store).exactly(1)
         post :create, :sheet => @attr
       end
     end
@@ -537,19 +530,19 @@ if MagicNumber['run_mode'] == 1
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
-          Sheet.any_instance.stub(:save).and_return(true)
+          Sheet.any_instance.stub(:store).and_return(true)
           post :create, :sheet => @attr
           response.status.should eq 302
         end
         it '作成された用紙の表示ページへ遷移する' do
-#          Sheet.any_instance.stub(:save).and_return(true)
+#          Sheet.any_instance.stub(:store).and_return(true)
           post :create, :sheet => @attr
           response.should redirect_to(Sheet.last)
         end
       end
       context 'json形式' do
         it 'ステータスコード200 OKを返す' do
-#          Sheet.any_instance.stub(:save).and_return(true)
+#          Sheet.any_instance.stub(:store).and_return(true)
           post :create, :sheet => @attr, :format => :json
           response.should be_success 
         end
@@ -749,37 +742,45 @@ if MagicNumber['run_mode'] == 1
       sign_in @user
     end
     context '事前チェックしておく' do
-      it '用紙モデルに編集取得を問い合わせている' do
-        Sheet.stub(:edit).with(any_args()).and_return @sheet
-        Sheet.should_receive(:edit).exactly(1)
+      it 'sheetがパラメータにあれば、展開する' do
         put :update, :id => @sheet.id, :sheet => @attr
+        assigns(:prm)['caption'].should eq 'updated caption'
       end
-      it '用紙モデルにカラム値復元を依頼している' do
-        Sheet.any_instance.should_receive(:attributes=).exactly(1)
-        put :update, :id => @sheet.id, :sheet => @attr
+      it 'jsonがパラメータにあれば、展開する' do
+        put :update, :id => @sheet.id, :json => FactoryGirl.attributes_for(:sheet, :caption => 'json caption').to_json
+        assigns(:prm)['caption'].should eq 'json caption'
+      end
+      it 'sheet・json両パラメータがあれば、sheetを優先して展開する' do
+        put :update, {
+          :id => @sheet.id, 
+          :sheet => FactoryGirl.attributes_for(:sheet, :caption => 'updated caption'), 
+          :json => FactoryGirl.attributes_for(:sheet, :caption => 'json caption').to_json
+        }
+        assigns(:prm)['caption'].should eq 'updated caption'
       end
-      it '用紙モデルに上書き補充を依頼している' do
-        Sheet.any_instance.should_receive(:overwrite).exactly(1)
+    end
+    context 'つつがなく終わるとき' do
+      it '用紙モデルに編集取得を問い合わせている' do
+        Sheet.stub(:edit).with(any_args()).and_return @sheet
+        Sheet.should_receive(:edit).exactly(1)
         put :update, :id => @sheet.id, :sheet => @attr
       end
       it 'モデルに更新を依頼する' do
-        Sheet.any_instance.stub(:save).with(any_args).and_return true
-        Sheet.any_instance.should_receive(:save).exactly(1)
+        Sheet.any_instance.stub(:store).with(any_args).and_return true
+        Sheet.any_instance.should_receive(:store).exactly(1)
         put :update, :id => @sheet.id, :sheet => @attr
       end
       it '@sheetにアレを取得している' do
         put :update, :id => @sheet.id, :sheet => @attr
         assigns(:sheet).id.should eq(@sheet.id)
       end
-    end
-    context 'つつがなく終わるとき' do
       it '更新される' do
         put :update, :id => @sheet.id, :sheet => @attr
         Sheet.find(@sheet.id).visible.should eq 0
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
-          Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
+          Sheet.any_instance.stub(:store).with(any_args()).and_return(true)
           put :update, :id => @sheet.id, :sheet => @attr
           response.status.should eq 302
         end
@@ -790,12 +791,12 @@ if MagicNumber['run_mode'] == 1
       end
       context 'json形式' do
         it 'ステータスコード200 OKを返す' do
-          Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
+          Sheet.any_instance.stub(:store).with(any_args()).and_return(true)
           put :update, :id => @sheet.id, :sheet => @attr, :format => :json
           response.should be_success 
         end
         it 'ページ本体は特に返さない' do
-          Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
+          Sheet.any_instance.stub(:store).with(any_args()).and_return(true)
           put :update, :id => @sheet.id, :sheet => @attr, :format => :json
           response.body.should match /./
         end