OSDN Git Service

merge
[pettanr/pettanr.git] / spec / controllers / authors_controller_spec.rb
index 0ad1f83..87587c2 100644 (file)
@@ -8,6 +8,7 @@ describe AuthorsController do
     @sp = FactoryGirl.create :system_picture
     @lg = FactoryGirl.create :license_group
     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+    @speech_balloon_template = FactoryGirl.create :speech_balloon_template
     @user = FactoryGirl.create( :user_yas)
     @author = FactoryGirl.create :author, :user_id => @user.id
     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
@@ -59,6 +60,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:authors).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")
@@ -244,6 +249,7 @@ if MagicNumber['run_mode'] == 1
       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
       @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id
+      Author.stub(:show).and_return(@other_author)
       Comic.stub(:himlist).and_return([@comic, @comic, @comic])
       sign_in @user
     end
@@ -291,6 +297,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:comics).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :comics, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'comicsテンプレートを描画する' do
           get :comics, :id => @other_author.id
           response.should render_template("comics")
@@ -372,6 +382,7 @@ if MagicNumber['run_mode'] == 1
       @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id
       @panel = FactoryGirl.create :panel, :author_id => @other_user.author.id
       @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @other_user.author.id
+      Author.stub(:show).and_return(@other_author)
       Story.stub(:himlist).and_return([@story, @story, @story])
       sign_in @user
     end
@@ -419,6 +430,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:stories).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :stories, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'storiesテンプレートを描画する' do
           get :stories, :id => @other_author.id
           response.should render_template("stories")
@@ -499,6 +514,7 @@ if MagicNumber['run_mode'] == 1
       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
       @panel = FactoryGirl.create :panel, :author_id => @other_author.id
+      Author.stub(:show).and_return(@other_author)
       Panel.stub(:himlist).and_return([@panel, @panel, @panel])
       sign_in @user
     end
@@ -546,6 +562,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:panels).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :panels, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'panelsテンプレートを描画する' do
           get :panels, :id => @other_author.id
           response.should render_template("panels")
@@ -628,6 +648,7 @@ if MagicNumber['run_mode'] == 1
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
       @panel = FactoryGirl.create :panel, :author_id => @author.id
       @panel_picture = FactoryGirl.create :panel_picture, :picture_id => @p.id, :panel_id => @panel.id, :width => @p.width, :height => @p.height
+      Author.stub(:show).and_return(@other_author)
       PanelPicture.stub(:himlist).and_return([@panel_picture, @panel_picture, @panel_picture])
       sign_in @user
     end
@@ -675,6 +696,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:panel_pictures).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :panel_pictures, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'panel_picturesテンプレートを描画する' do
           get :panel_pictures, :id => @other_author.id
           response.should render_template("panel_pictures")
@@ -749,6 +774,139 @@ if MagicNumber['run_mode'] == 1
     end
   end
   
+  describe '対象作家のフキダシ一覧表示に於いて' do
+    before do
+      @other_user = FactoryGirl.create( :user_yas)
+      @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+      @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
+      @panel = FactoryGirl.create :panel, :author_id => @other_author.id
+      @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+      Author.stub(:show).and_return(@other_author)
+      SpeechBalloon.stub(:himlist).and_return([@sb, @sb, @sb])
+      sign_in @user
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :speech_balloons, :id => @other_author.id, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :speech_balloons, :id => @other_author.id
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :speech_balloons, :id => @other_author.id, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :speech_balloons, :id => @other_author.id
+        assigns(:page_size).should eq Author.default_speech_balloon_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :speech_balloons, :id => @other_author.id, :page_size => 1500
+        assigns(:page_size).should eq Author.speech_balloon_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :speech_balloons, :id => @other_author.id, :page_size => 0
+        assigns(:page_size).should eq Author.default_speech_balloon_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :speech_balloons, :id => @other_author.id
+        response.should be_success 
+      end
+      it '作家モデルに単体取得を問い合わせている' do
+        Author.should_receive(:show).exactly(1)
+        get :speech_balloons, :id => @other_author.id
+      end
+      it 'フキダシモデルに他作家のフキダシ一覧を問い合わせている' do
+        SpeechBalloon.should_receive(:himlist).exactly(1)
+        get :speech_balloons, :id => @other_author.id
+      end
+      it '@speech_balloonsにリストを取得している' do
+        get :speech_balloons, :id => @other_author.id
+        assigns(:speech_balloons).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :speech_balloons, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'speech_balloonsテンプレートを描画する' do
+          get :speech_balloons, :id => @other_author.id
+          response.should render_template("speech_balloons")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :speech_balloons, :id => @other_author.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'フキダシモデルにjson一覧出力オプションを問い合わせている' do
+          SpeechBalloon.should_receive(:list_json_opt).exactly(1)
+          get :speech_balloons, :id => @other_author.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :speech_balloons, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはフキダシっぽいものであって欲しい' do
+          get :speech_balloons, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("speech_balloon_template_id").should be_true
+          json.first.has_key?("z").should be_true
+          json.first.has_key?("t").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :speech_balloons, :id => @other_author.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :speech_balloons, :id => @other_author.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :speech_balloons, :id => @other_author.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :speech_balloons, :id => @other_author.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 :speech_balloons, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :speech_balloons, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+  end
+  
   describe '対象作家の絵地一覧表示に於いて' do
     before do
       @other_user = FactoryGirl.create( :user_yas)
@@ -759,6 +917,7 @@ if MagicNumber['run_mode'] == 1
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
       @panel = FactoryGirl.create :panel, :author_id => @author.id
       @ground_picture = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+      Author.stub(:show).and_return(@other_author)
       GroundPicture.stub(:himlist).and_return([@ground_picture, @ground_picture, @ground_picture])
       sign_in @user
     end
@@ -806,6 +965,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:ground_pictures).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :ground_pictures, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'ground_picturesテンプレートを描画する' do
           get :ground_pictures, :id => @other_author.id
           response.should render_template("ground_pictures")
@@ -887,6 +1050,7 @@ if MagicNumber['run_mode'] == 1
       @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
       @gc = FactoryGirl.create :ground_color
       @panel = FactoryGirl.create :panel, :author_id => @author.id
+      Author.stub(:show).and_return(@other_author)
       GroundColor.stub(:himlist).and_return([@gc, @gc, @gc])
       sign_in @user
     end
@@ -934,6 +1098,10 @@ if MagicNumber['run_mode'] == 1
         assigns(:ground_colors).should have_at_least(3).items
       end
       context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :ground_colors, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
         it 'ground_colorsテンプレートを描画する' do
           get :ground_colors, :id => @other_author.id
           response.should render_template("ground_colors")