OSDN Git Service

t#29034:create overwrite
[pettanr/pettanr.git] / spec / controllers / stories_controller_spec.rb
index 33e15b0..13985d9 100644 (file)
@@ -39,7 +39,7 @@ describe StoriesController do
         get :new
         assigns(:story).should be_a_new(Story)
       end
-      it 'ã\82³ã\83\9eã\83¢ã\83\87ã\83«ã\81«ã\83\87ã\83\95ã\82©ã\83«ã\83\88å\80¤è£\9cå\85\85ã\82\92ä¾\9dé ¼ã\81\97ã\81¦ã\81\84ã\82\8b' do
+      it 'モデルにデフォルト値補充を依頼している' do
         Story.any_instance.should_receive(:supply_default).exactly(1)
         get :new
       end
@@ -89,6 +89,19 @@ describe StoriesController do
       sign_in @user
     end
     context 'つつがなく終わるとき' do
+      it 'デフォルト値補充を依頼する' do
+        Story.any_instance.should_receive(:supply_default).exactly(1)
+        post :create, :story => @attr
+      end
+      it 'POSTデータから、カラム値を復元している' do
+        Story.any_instance.stub(:store).and_return(true)
+        Story.any_instance.should_receive(:attributes=).exactly(1)
+        post :create, :story => @attr
+      end
+      it '上書き補充を依頼する' do
+        Story.any_instance.should_receive(:overwrite).exactly(1)
+        post :create, :story => @attr
+      end
       it 'モデルに保存依頼する' do
         Story.any_instance.should_receive(:store).exactly(1)
         post :create, :story => @attr
@@ -110,18 +123,6 @@ describe StoriesController do
           response.should redirect_to(:action => :show, :id => @attr[:comic_id])
         end
       end
-      context 'js形式' do
-        it 'ステータスコード302 Foundを返す' do
-          Story.any_instance.stub(:store).and_return(true)
-          post :create, :story => @attr, :format => :js
-          response.status.should eq 302
-        end
-        it 'コミックのストーリー表示へ遷移する' do
-#          Story.any_instance.stub(:store).and_return(true)
-          post :create, :story => @attr, :format => :js
-          response.should redirect_to(:action => :show, :id => @attr[:comic_id])
-        end
-      end
       context 'json形式' do
         it 'ステータスコード200 OKを返す' do
 #          Story.any_instance.stub(:store).and_return(true)
@@ -135,7 +136,7 @@ describe StoriesController do
         it 'データがアレになっている' do
           post :create, :story => @attr, :format => :json
           json = JSON.parse response.body
-          json["t"].should eq @story.t
+          json["t"].should eq 0
         end
       end
     end
@@ -266,6 +267,15 @@ describe StoriesController do
         Story.should_receive(:show).exactly(1)
         put :update, :id => @story.id, :story => @attr
       end
+      it 'POSTデータから、カラム値を復元している' do
+        Story.any_instance.stub(:store).and_return(true)
+        Story.any_instance.should_receive(:attributes=).exactly(1)
+        put :update, :id => @story.id, :story => @attr
+      end
+      it '上書き補充を依頼する' do
+        Story.any_instance.should_receive(:overwrite).exactly(1)
+        put :update, :id => @story.id, :story => @attr
+      end
       it 'モデルに保存依頼する' do
         Story.any_instance.should_receive(:store).exactly(1)
         put :update, :id => @story.id, :story => @attr