OSDN Git Service

fix: any
[pettanr/pettanr.git] / spec / controllers / stories_controller_spec.rb
index 0268c4e..3f7656a 100644 (file)
@@ -10,14 +10,13 @@ describe StoriesController do
     @user = FactoryGirl.create :user_yas
     @author = FactoryGirl.create :author, :user_id => @user.id
     @comic = FactoryGirl.create :comic, :author_id => @user.author.id
-    @panel = FactoryGirl.create :panel, :author_id => @author.id
   end
   
 if MagicNumber['run_mode'] == 1
   describe '一覧表示に於いて' do
     before do
       sign_in @user
-      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
       Story.stub(:list).and_return([@story, @story, @story])
     end
     context 'パラメータpageについて' do
@@ -60,6 +59,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:stories).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :index
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'indexテンプレートを描画する' do
           get :index
           response.should render_template("index")
@@ -82,7 +85,7 @@ if MagicNumber['run_mode'] == 1
         it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
           get :index, :format => :json
           json = JSON.parse response.body
-          json.first.has_key?("panel_id").should be_true
+          json.first.has_key?("title").should be_true
           json.first.has_key?("comic_id").should be_true
           json.first.has_key?("t").should be_true
         end
@@ -137,11 +140,9 @@ if MagicNumber['run_mode'] == 1
   describe '単体表示に於いて' do
     before do
       sign_in @user
-      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
       Comic.stub(:show).with(@comic.id.to_s, [@user, nil]).and_return(@comic)
       Comic.stub(:show).with(@comic.id.to_s, [nil, @admin]).and_return(@comic)
-      Story.stub(:show).with(@story.id.to_s, [@user, nil]).and_return(@story)
-      Story.stub(:show).with(@story.id.to_s, [nil, @admin]).and_return(@story)
     end
     context 'つつがなく終わるとき' do
       it 'ストーリーモデルに単体取得を問い合わせている' do
@@ -171,16 +172,15 @@ if MagicNumber['run_mode'] == 1
           get :show, :id => @story.id, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ストーリーモデルにストーリーjson出力を問い合わせている' do
-          Story.any_instance.should_receive(:story_as_json).exactly(1)
+        it 'ストーリーモデルにjson単体出力オプションを問い合わせている' do
+          Story.should_receive(:show_json_opt).exactly(1)
           get :show, :id => @story.id, :format => :json
         end
         it 'データがアレになっている' do
           get :show, :id => @story.id, :format => :json
           json = JSON.parse response.body
-          json.has_key?("panel_id").should be_true
+          json.has_key?("title").should be_true
           json.has_key?("comic_id").should be_true
-          json.has_key?("author_id").should be_true
         end
       end
     end
@@ -232,88 +232,75 @@ if MagicNumber['run_mode'] == 1
   
   describe '閲覧に於いて' do
     before do
-      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
-      Comic.stub(:show).with(@comic.id.to_s, [@user, nil]).and_return(@comic)
-      Comic.stub(:show).with(@comic.id.to_s, [nil, @admin]).and_return(@comic)
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
+      @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
+      @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
+      Story.stub(:show).with(@story.id.to_s, [@user, nil]).and_return(@story)
+      Story.stub(:show).with(@story.id.to_s, [nil, @admin]).and_return(@story)
       Story.stub(:count).and_return(10)
-      Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])
+      StorySheet.stub(:play_sheet).with(any_args).and_return(@sheet)
       sign_in @user
     end
-    context 'パラメータチェックする' do
-      it '与えられたoffsetがセットされている' do
-        get :comic, :id => @comic.id, :offset => 5
-        assigns(:offset).should eq 5
-      end
-      it '省略されると@offsetに0値が入る' do
-        get :comic, :id => @comic.id
-        assigns(:offset).should eq 0
-      end
-      it '与えられたcountがセットされている' do
-        get :comic, :id => @comic.id, :count => 4
-        assigns(:panel_count).should eq 4
-      end
-      it '省略されると@panel_countにデフォルト値が入る' do
-        get :comic, :id => @comic.id
-        assigns(:panel_count).should eq Story.default_panel_size
-      end
-      it '最大を超えると@panel_countにデフォルト最大値が入る' do
-        get :comic, :id => @comic.id, :count => 1500
-        assigns(:panel_count).should eq Story.max_panel_size
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :play, :id => @story.id, :page => 5
+        assigns(:page).should eq 5
       end
-      it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
-        get :comic, :id => @comic.id, :count => -1
-        assigns(:panel_count).should eq Story.default_panel_size
+      it '省略されると@pageに1値が入る' do
+        get :play, :id => @story.id
+        assigns(:page).should eq 1
       end
     end
     context '事前チェックする' do
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに単体取得を問い合わせている' do
-        Comic.should_receive(:show).with(@comic.id.to_s, [@user, nil]).exactly(1)
-        get :comic, :id => @comic.id
+      it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼モデルに単体取得を問い合わせている' do
+        Story.should_receive(:show).with(@story.id.to_s, [@user, nil]).exactly(1)
+        get :play, :id => @story.id
       end
-      it 'ストーリーモデルにプレイリスト取得を問い合わせている' do
-        Story.should_receive(:play_list).with(@comic, @author, 0, 30).exactly(1)
-        get :comic, :id => @comic.id
+      it 'ストモデルにプレイリスト取得を問い合わせている' do
+        StorySheet.should_receive(:play_sheet).with(@story, @author, 1).exactly(1)
+        get :play, :id => @story.id
       end
     end
     context 'つつがなく終わるとき' do
-      it '@storiesにリストを取得している' do
-        get :comic, :id => @comic.id
-        assigns(:stories).should have_at_least(3).items
+      it '@sheetに用紙を取得している' do
+        get :play, :id => @story.id
+        assigns(:sheet).should eq @sheet
       end
       context 'html形式' do
         it 'ステータスコード200 OKを返す' do
-          get :comic, :id => @comic.id
+          get :play, :id => @story.id
           response.should be_success 
         end
-        it 'comicテンプレートを描画する' do
-          get :comic, :id => @comic.id
-          response.should render_template("comic")
+        it 'playテンプレートを描画する' do
+          get :play, :id => @story.id
+          response.should render_template("play")
         end
       end
       context 'json形式' do
         it 'ステータスコード200 OKを返す' do
-          get :comic, :id => @comic.id, :format => :json
+          get :play, :id => @story.id, :format => :json
           response.should be_success 
         end
         it 'jsonデータを返す' do
-          get :comic, :id => @comic.id, :format => :json
+          get :play, :id => @story.id, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ストーリーモデルにストーリーリストのjson出力を問い合わせている' do
-          Story.should_receive(:list_as_json_text).exactly(1)
-          get :comic, :id => @comic.id, :format => :json
+        it '紙コマモデルに紙コマリストのjson出力を問い合わせている' do
+          SheetPanel.should_receive(:list_as_json_text).exactly(1)
+          get :play, :id => @story.id, :format => :json
         end
         it 'データがリスト構造になっている' do
-          get :comic, :id => @comic.id, :format => :json
+          get :play, :id => @story.id, :format => :json
           json = JSON.parse response.body
-          json.should have_at_least(3).items
+          json.should have_at_least(1).items
         end
-        it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
-          get :comic, :id => @comic.id, :format => :json
+        it 'リストの先頭くらいは紙コマっぽいものであって欲しい' do
+          get :play, :id => @story.id, :format => :json
           json = JSON.parse response.body
+          json.first.has_key?("sheet_id").should be_true
           json.first.has_key?("panel_id").should be_true
-          json.first.has_key?("comic_id").should be_true
-          json.first.has_key?("author_id").should be_true
         end
       end
     end
@@ -323,21 +310,21 @@ if MagicNumber['run_mode'] == 1
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
-          get :comic, :id => @comic.id
+          get :play, :id => @story.id
           response.status.should eq 302
         end
         it 'サインインページへ遷移する' do
-          get :comic, :id => @comic.id
+          get :play, :id => @story.id
           response.should redirect_to '/users/sign_in'
         end
       end
       context 'json形式' do
         it 'ステータスコード401 Unauthorizedを返す' do
-          get :comic, :id => @comic.id, :format => :json
+          get :play, :id => @story.id, :format => :json
           response.status.should eq 401
         end
         it '応答メッセージにUnauthorizedを返す' do
-          get :comic, :id => @comic.id, :format => :json
+          get :play, :id => @story.id, :format => :json
           response.message.should match(/Unauthorized/)
         end
       end
@@ -348,7 +335,7 @@ if MagicNumber['run_mode'] == 1
         sign_in @admin
       end
       it 'ステータスコード200 OKを返す' do
-        get :comic, :id => @comic.id
+        get :play, :id => @story.id
         response.should be_success 
       end
     end
@@ -357,7 +344,7 @@ if MagicNumber['run_mode'] == 1
         @author.destroy
       end
       it 'ステータスコード200 OKを返す' do
-        get :comic, :id => @comic.id
+        get :play, :id => @story.id
         response.should be_success 
       end
     end
@@ -405,16 +392,15 @@ if MagicNumber['run_mode'] == 1
           get :new, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
-          Story.any_instance.should_receive(:story_as_json).exactly(1)
+        it 'ストーリーモデルのjson単体出力オプションを問い合わせている' do
+          Story.should_receive(:show_json_opt).exactly(1)
           get :new, :format => :json
         end
         it 'データがアレになっている' do
           get :new, :format => :json
           json = JSON.parse response.body
-          json.has_key?("panel_id").should be_true
+          json.has_key?("title").should be_true
           json.has_key?("comic_id").should be_true
-          json.has_key?("author_id").should be_true
         end
       end
     end
@@ -478,7 +464,7 @@ if MagicNumber['run_mode'] == 1
   
   describe '新規作成に於いて' do
     before do
-      @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
+      @attr = FactoryGirl.attributes_for(:story, :t => 0, :comic_id => @comic.id)
       sign_in @user
     end
     context 'つつがなく終わるとき' do
@@ -487,10 +473,9 @@ if MagicNumber['run_mode'] == 1
         post :create, :story => @attr
       end
       it 'POSTデータから、カラム値を復元している' do
-        Story.any_instance.stub(:store).and_return(true)
+#        Story.any_instance.stub(:store).and_return(true)
         post :create, :story => @attr
         assigns(:story).comic_id.should eq @comic.id
-        assigns(:story).panel_id.should eq @panel.id
       end
       it '上書き補充を依頼する' do
         Story.any_instance.should_receive(:overwrite).exactly(1)
@@ -500,29 +485,25 @@ if MagicNumber['run_mode'] == 1
         Comic.should_receive(:edit).with(@comic.id, @author).exactly(1)
         post :create, :story => @attr
       end
-      it 'コマモデルに単体取得を依頼している' do
-        Panel.should_receive(:show).with(@panel.id, @author).exactly(1)
-        post :create, :story => @attr
-      end
       it 'モデルに保存依頼する' do
         Story.any_instance.should_receive(:store).exactly(1)
         post :create, :story => @attr
       end
-      it "@storyã\81«ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9eを保持していて、それがDBにある" do
+      it "@storyã\81«ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\83\88ã\83¼ã\83ªã\83¼を保持していて、それがDBにある" do
         post :create, :story => @attr
         assigns(:story).should be_a(Story)
         assigns(:story).should be_persisted
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
-          Story.any_instance.stub(:store).and_return(true)
+#          Story.any_instance.stub(:store).and_return(true)
           post :create, :story => @attr
           response.status.should eq 302
         end
-        it 'コミックのストーリー表示へ遷移する' do
+        it '作成されたストーリーの表示へページ位置を指定して遷移する' do
 #          Story.any_instance.stub(:store).and_return(true)
           post :create, :story => @attr
-          response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
+          response.should redirect_to(play_story_path(assigns(:story), :page => 1))
         end
       end
       context 'json形式' do
@@ -535,8 +516,8 @@ if MagicNumber['run_mode'] == 1
           post :create, :story => @attr, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
-          Story.any_instance.should_receive(:story_as_json).exactly(1)
+        it 'ストーリーモデルのjson単体出力オプションを問い合わせている' do
+          Story.should_receive(:show_json_opt).exactly(1)
           post :create, :story => @attr, :format => :json
         end
         it 'データがアレになっている' do
@@ -635,7 +616,7 @@ if MagicNumber['run_mode'] == 1
 
   describe '編集フォーム表示に於いて' do
     before do
-      @story = FactoryGirl.create :story, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
       sign_in @user
       Story.stub(:show).and_return(@story)
     end
@@ -729,8 +710,8 @@ if MagicNumber['run_mode'] == 1
 
   describe '更新に於いて' do
     before do
-      @story = FactoryGirl.create :story, :author_id => @user.author.id
-      @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
+      @attr = FactoryGirl.attributes_for(:story, :t => 0)
       sign_in @user
     end
     context 'つつがなく終わるとき' do
@@ -763,10 +744,10 @@ if MagicNumber['run_mode'] == 1
           put :update, :id => @story.id, :story => @attr
           response.status.should eq 302
         end
-        it 'ストーリー表示へ遷移する' do
+        it '更新されたストーリーの表示へページ位置を指定して遷移する' do
 #          Story.any_instance.stub(:store).and_return(true)
           put :update, :id => @story.id, :story => @attr
-          response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
+          response.should redirect_to(play_story_path(@story, :page => 1))
         end
       end
       context 'json形式' do
@@ -866,7 +847,7 @@ if MagicNumber['run_mode'] == 1
 
   describe '削除に於いて' do
     before do
-      @story = FactoryGirl.create :story, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
       sign_in @user
       Story.stub(:edit).and_return(@story)
     end
@@ -897,9 +878,9 @@ if MagicNumber['run_mode'] == 1
           delete :destroy, :id => @story.id
           response.status.should eq 302
         end
-        it '閲覧ページへ遷移する' do
+        it 'コミック単体表示ページへ遷移する' do
           delete :destroy, :id => @story.id
-          response.should redirect_to(:controller => 'stories', :action => :comic, :id => @story.comic_id)
+          response.should redirect_to(comic_path(@comic))
         end
       end
       context 'json形式' do
@@ -1002,7 +983,7 @@ else
   describe '一覧表示に於いて' do
     before do
       sign_in @user
-      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
       Story.stub(:list).and_return([@story, @story, @story])
     end
     context 'つつがなく終わるとき' do
@@ -1049,7 +1030,7 @@ else
   describe '単体表示に於いて' do
     before do
       sign_in @user
-      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
       Comic.stub(:show).with(@comic.id.to_s, [nil, nil]).and_return(@comic)
       Comic.stub(:show).with(@comic.id.to_s, [@user, nil]).and_return(@comic)
       Comic.stub(:show).with(@comic.id.to_s, [nil, @admin]).and_return(@comic)
@@ -1108,7 +1089,7 @@ else
   
   describe '閲覧に於いて' do
     before do
-      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
       Comic.stub(:show).with(@comic.id.to_s, [nil, nil]).and_return(@comic)
       Comic.stub(:show).with(@comic.id.to_s, [@user, nil]).and_return(@comic)
       Comic.stub(:show).with(@comic.id.to_s, [nil, @admin]).and_return(@comic)
@@ -1230,7 +1211,7 @@ else
   
   describe '新規作成に於いて' do
     before do
-      @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
+      @attr = FactoryGirl.attributes_for :story, :t => nil, :comic_id => @comic.id
       sign_in @user
     end
     context 'つつがなく終わるとき' do
@@ -1287,7 +1268,7 @@ else
 
   describe '編集フォーム表示に於いて' do
     before do
-      @story = FactoryGirl.create :story, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
       sign_in @user
       Story.stub(:show).and_return(@story)
     end
@@ -1342,8 +1323,8 @@ else
 
   describe '更新に於いて' do
     before do
-      @story = FactoryGirl.create :story, :author_id => @user.author.id
-      @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
+      @attr = FactoryGirl.attributes_for(:story)
       sign_in @user
     end
     context 'つつがなく終わるとき' do
@@ -1396,7 +1377,7 @@ else
 
   describe '削除に於いて' do
     before do
-      @story = FactoryGirl.create :story, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
       sign_in @user
       Story.stub(:edit).and_return(@story)
     end