OSDN Git Service

t#32046:
[pettanr/pettanr.git] / spec / controllers / scrolls_controller_spec.rb
index 8ebf574..041f309 100644 (file)
@@ -1,6 +1,6 @@
 # -*- encoding: utf-8 -*-
 require 'spec_helper'
-#ã\82³ã\83\9fã\83\83ã\82¯
+#ã\82¹ã\82¯ã\83­ã\83¼ã\83«
 describe ScrollsController do
   before do
     @admin =FactoryGirl.create :admin
@@ -49,7 +49,7 @@ if MagicNumber['run_mode'] == 1
         get :index
         response.should be_success 
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに一覧を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに一覧を問い合わせている' do
         Scroll.should_receive(:list).exactly(1)
         get :index
       end
@@ -72,7 +72,7 @@ if MagicNumber['run_mode'] == 1
           get :index, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにjson一覧出力オプションを問い合わせている' do
+        it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルにjson一覧出力オプションを問い合わせている' do
           Scroll.should_receive(:list_json_opt).exactly(1)
           get :index, :format => :json
         end
@@ -81,7 +81,7 @@ if MagicNumber['run_mode'] == 1
           json = JSON.parse response.body
           json.should have_at_least(3).items
         end
-        it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ­ã\81\8fã\82\89ã\81\84ã\81¯ã\82³ã\83\9fã\83\83ã\82¯っぽいものであって欲しい' do
+        it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ­ã\81\8fã\82\89ã\81\84ã\81¯ã\82¹ã\82¯ã\83­ã\83¼ã\83«っぽいものであって欲しい' do
           get :index, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("title").should be_true
@@ -148,7 +148,7 @@ if MagicNumber['run_mode'] == 1
         get :show, :id => @scroll.id
         response.should be_success
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに単体取得を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに単体取得を問い合わせている' do
         Scroll.should_receive(:show).exactly(1)
         get :show
       end
@@ -167,7 +167,7 @@ if MagicNumber['run_mode'] == 1
           get :show, :id => @scroll.id, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにjson単体出力オプションを問い合わせている' do
+        it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルにjson単体出力オプションを問い合わせている' do
           Scroll.should_receive(:show_json_opt).exactly(1)
           get :show, :id => @scroll.id, :format => :json
         end
@@ -226,7 +226,7 @@ if MagicNumber['run_mode'] == 1
       end
     end
 =begin
-    context '対象ã\82³ã\83\9fã\83\83ã\82¯がないとき' do
+    context '対象ã\82¹ã\82¯ã\83­ã\83¼ã\83«がないとき' do
       context 'html形式' do
         it '例外404 not_foundを返す' do
           lambda{
@@ -242,7 +242,7 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'é\9d\9eå\85¬é\96\8bã\82³ã\83\9fã\83\83ã\82¯を見ようとしたとき' do
+    context 'é\9d\9eå\85¬é\96\8bã\82¹ã\82¯ã\83­ã\83¼ã\83«を見ようとしたとき' do
       context 'html形式' do
         it '例外403 forbiddenを返す' do
           Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
@@ -264,7 +264,143 @@ if MagicNumber['run_mode'] == 1
     end
 =end
   end
-  describe 'コミック数取得に於いて' do
+  
+  describe '閲覧に於いて' do
+    before do
+      @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
+      @panel = FactoryGirl.create :panel, :author_id => @author.id
+      @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+      Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
+      Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
+      ScrollPanel.stub(:count).and_return(10)
+      ScrollPanel.stub(:play_list).with(any_args).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
+      sign_in @user
+    end
+    context 'パラメータチェックする' do
+      it '与えられたoffsetがセットされている' do
+        get :play, :id => @scroll.id, :offset => 5
+        assigns(:offset).should eq 5
+      end
+      it '省略されると@offsetに0値が入る' do
+        get :play, :id => @scroll.id
+        assigns(:offset).should eq 0
+      end
+      it '与えられたcountがセットされている' do
+        get :play, :id => @scroll.id, :count => 4
+        assigns(:panel_count).should eq 4
+      end
+      it '省略されると@panel_countにデフォルト値が入る' do
+        get :play, :id => @scroll.id
+        assigns(:panel_count).should eq ScrollPanel.default_panel_size
+      end
+      it '最大を超えると@panel_countにデフォルト最大値が入る' do
+        get :play, :id => @scroll.id, :count => 1500
+        assigns(:panel_count).should eq ScrollPanel.max_panel_size
+      end
+      it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
+        get :play, :id => @scroll.id, :count => -1
+        assigns(:panel_count).should eq ScrollPanel.default_panel_size
+      end
+    end
+    context '事前チェックする' do
+      it 'スクロールモデルに単体取得を問い合わせている' do
+        Scroll.should_receive(:show).with(@scroll.id.to_s, [@user, nil]).exactly(1)
+        get :play, :id => @scroll.id
+      end
+      it 'スクコマモデルにプレイリスト取得を問い合わせている' do
+        ScrollPanel.should_receive(:play_list).with(@scroll, @author, 0, 30).exactly(1)
+        get :play, :id => @scroll.id
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it '@scroll_panelsにリストを取得している' do
+        get :play, :id => @scroll.id
+        assigns(:scroll_panels).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :play, :id => @scroll.id
+          response.should be_success 
+        end
+        it 'scrollテンプレートを描画する' do
+          get :play, :id => @scroll.id
+          response.should render_template("scroll")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :play, :id => @scroll.id, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :play, :id => @scroll.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'スクコマモデルにスクコマリストのjson出力を問い合わせている' do
+          ScrollPanel.should_receive(:list_as_json_text).exactly(1)
+          get :play, :id => @scroll.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :play, :id => @scroll.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはスクコマっぽいものであって欲しい' do
+          get :play, :id => @scroll.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("panel_id").should be_true
+          json.first.has_key?("scroll_id").should be_true
+          json.first.has_key?("author_id").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :play, :id => @scroll.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :play, :id => @scroll.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :play, :id => @scroll.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :play, :id => @scroll.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :play, :id => @scroll.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :play, :id => @scroll.id
+        response.should be_success 
+      end
+    end
+  end
+
+  describe 'スクロール数取得に於いて' do
     before do
       Scroll.should_receive(:visible_count).and_return(3)
 #      sign_in @user
@@ -279,7 +415,7 @@ if MagicNumber['run_mode'] == 1
           get :count, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ã\83\87ã\83¼ã\82¿ã\81\8cHashæ§\8bé\80 ã\81«ã\81ªã\81£ã\81¦ã\81\84ã\81¦ã\82³ã\83\9fã\83\83ã\82¯数が1である' do
+        it 'ã\83\87ã\83¼ã\82¿ã\81\8cHashæ§\8bé\80 ã\81«ã\81ªã\81£ã\81¦ã\81\84ã\81¦ã\82¹ã\82¯ã\83­ã\83¼ã\83«数が1である' do
           get :count, :format => :json
           json = JSON.parse response.body
           json["count"].should == 3
@@ -301,7 +437,7 @@ if MagicNumber['run_mode'] == 1
         get :new
         assigns(:scroll).should be_a_new(Scroll)
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにデフォルト値補充を依頼している' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルにデフォルト値補充を依頼している' do
         Scroll.any_instance.should_receive(:supply_default).exactly(1)
         get :new
       end
@@ -322,7 +458,7 @@ if MagicNumber['run_mode'] == 1
           get :new, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにjson単体出力オプションを問い合わせている' do
+        it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルにjson単体出力オプションを問い合わせている' do
           Scroll.should_receive(:show_json_opt).exactly(1)
           get :new, :format => :json
         end
@@ -402,15 +538,15 @@ if MagicNumber['run_mode'] == 1
       @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
     end
     context '事前チェックしておく' do
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにデフォルト値補充を依頼している' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルにデフォルト値補充を依頼している' do
         Scroll.any_instance.should_receive(:supply_default).exactly(1)
         post :create, :scroll => @attr
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにカラム値復元を依頼している' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルにカラム値復元を依頼している' do
         Scroll.any_instance.should_receive(:attributes=).exactly(1)
         post :create, :scroll => @attr
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに上書き補充を依頼している' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに上書き補充を依頼している' do
         Scroll.any_instance.should_receive(:overwrite).exactly(1)
         post :create, :scroll => @attr
       end
@@ -420,7 +556,7 @@ if MagicNumber['run_mode'] == 1
       end
     end
     context 'つつがなく終わるとき' do
-      it "@scrollã\81«ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯を保持していて、それがDBにある" do
+      it "@scrollã\81«ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«を保持していて、それがDBにある" do
         post :create, :scroll => @attr
         assigns(:scroll).should be_a(Scroll)
         assigns(:scroll).should be_persisted
@@ -431,7 +567,7 @@ if MagicNumber['run_mode'] == 1
           post :create, :scroll => @attr
           response.status.should eq 302
         end
-        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯の表示ページへ遷移する' do
+        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«の表示ページへ遷移する' do
 #          Scroll.any_instance.stub(:save).and_return(true)
           post :create, :scroll => @attr
           response.should redirect_to(Scroll.last)
@@ -443,7 +579,7 @@ if MagicNumber['run_mode'] == 1
           post :create, :scroll => @attr, :format => :json
           response.should be_success 
         end
-        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯をjsonデータで返す' do
+        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«をjsonデータで返す' do
           post :create, :scroll => @attr, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
@@ -515,7 +651,7 @@ if MagicNumber['run_mode'] == 1
       before do
         Scroll.any_instance.stub(:save).and_return(false)
       end
-      it "æ\9cªä¿\9då­\98ã\81®ã\82³ã\83\9fã\83\83ã\82¯を保持している" do
+      it "æ\9cªä¿\9då­\98ã\81®ã\82¹ã\82¯ã\83­ã\83¼ã\83«を保持している" do
         post :create, :scroll => @attr
         assigns(:scroll).should be_a_new(Scroll)
       end
@@ -553,7 +689,7 @@ if MagicNumber['run_mode'] == 1
         get :edit, :id => @scroll.id
         response.should be_success 
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに編集取得を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに編集取得を問い合わせている' do
         Scroll.should_receive(:edit).exactly(1)
         get :edit, :id => @scroll.id
       end
@@ -639,16 +775,16 @@ if MagicNumber['run_mode'] == 1
       sign_in @user
     end
     context '事前チェックしておく' do
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに編集取得を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに編集取得を問い合わせている' do
         Scroll.stub(:edit).with(any_args()).and_return @scroll
         Scroll.should_receive(:edit).exactly(1)
         put :update, :id => @scroll.id, :scroll => @attr
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにカラム値復元を依頼している' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルにカラム値復元を依頼している' do
         Scroll.any_instance.should_receive(:attributes=).exactly(1)
         put :update, :id => @scroll.id, :scroll => @attr
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに上書き補充を依頼している' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに上書き補充を依頼している' do
         Scroll.any_instance.should_receive(:overwrite).exactly(1)
         put :update, :id => @scroll.id, :scroll => @attr
       end
@@ -673,7 +809,7 @@ if MagicNumber['run_mode'] == 1
           put :update, :id => @scroll.id, :scroll => @attr
           response.status.should eq 302
         end
-        it 'æ\9b´æ\96°ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯の表示ページへ遷移する' do
+        it 'æ\9b´æ\96°ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«の表示ページへ遷移する' do
           put :update, :id => @scroll.id, :scroll => @attr
           response.should redirect_to(@scroll)
         end
@@ -781,7 +917,7 @@ if MagicNumber['run_mode'] == 1
         Scroll.stub(:edit).with(any_args()).and_return @scroll
         Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに編集取得を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに編集取得を問い合わせている' do
         Scroll.should_receive(:edit).exactly(1)
         delete :destroy, :id => @scroll.id
       end
@@ -808,7 +944,7 @@ if MagicNumber['run_mode'] == 1
           delete :destroy, :id => @scroll.id
           response.status.should eq 302
         end
-        it 'ã\83\9eã\82¤ã\82³ã\83\9fã\83\83ã\82¯の一覧ページへ遷移する' do
+        it 'ã\83\9eã\82¤ã\82¹ã\82¯ã\83­ã\83¼ã\83«の一覧ページへ遷移する' do
           delete :destroy, :id => @scroll.id
           response.should redirect_to('/home/scrolls')
         end
@@ -888,7 +1024,7 @@ if MagicNumber['run_mode'] == 1
           delete :destroy, :id => @scroll.id
           response.status.should eq 302
         end
-        it 'ã\81\9dã\81®ã\82³ã\83\9fã\83\83ã\82¯の詳細ページへ遷移する' do
+        it 'ã\81\9dã\81®ã\82¹ã\82¯ã\83­ã\83¼ã\83«の詳細ページへ遷移する' do
           delete :destroy, :id => @scroll.id
           response.should redirect_to(scroll_path(@scroll))
         end
@@ -1000,7 +1136,7 @@ else
       end
     end
   end
-  describe 'ã\82³ã\83\9fã\83\83ã\82¯数取得に於いて' do
+  describe 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«数取得に於いて' do
     before do
       Scroll.should_receive(:visible_count).and_return(3)
       sign_out @user
@@ -1096,7 +1232,7 @@ else
           post :create, :scroll => @attr
           response.status.should eq 302
         end
-        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯の表示ページへ遷移する' do
+        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«の表示ページへ遷移する' do
 #          Scroll.any_instance.stub(:save).and_return(true)
           post :create, :scroll => @attr
           response.should redirect_to(Scroll.last)
@@ -1108,7 +1244,7 @@ else
           post :create, :scroll => @attr, :format => :json
           response.should be_success 
         end
-        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯をjsonデータで返す' do
+        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«をjsonデータで返す' do
           post :create, :scroll => @attr, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
@@ -1205,7 +1341,7 @@ else
           put :update, :id => @scroll.id, :scroll => @attr
           response.status.should eq 302
         end
-        it 'æ\9b´æ\96°ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯の表示ページへ遷移する' do
+        it 'æ\9b´æ\96°ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«の表示ページへ遷移する' do
           put :update, :id => @scroll.id, :scroll => @attr
           response.should redirect_to(@scroll)
         end
@@ -1254,7 +1390,7 @@ else
           delete :destroy, :id => @scroll.id
           response.status.should eq 302
         end
-        it 'ã\83\9eã\82¤ã\82³ã\83\9fã\83\83ã\82¯の一覧ページへ遷移する' do
+        it 'ã\83\9eã\82¤ã\82¹ã\82¯ã\83­ã\83¼ã\83«の一覧ページへ遷移する' do
           delete :destroy, :id => @scroll.id
           response.should redirect_to('/home/scroll')
         end