OSDN Git Service

t#32046:add sheet
[pettanr/pettanr.git] / spec / controllers / authors_controller_spec.rb
index 8908447..950361c 100644 (file)
@@ -245,7 +245,7 @@ if MagicNumber['run_mode'] == 1
 =end
   end
   
-  describe '対象ä½\9c家ã\81®ã\82³ã\83\9fã\83\83ã\82¯一覧表示に於いて' do
+  describe '対象ä½\9c家ã\81®ã\82¹ã\82¯ã\83­ã\83¼ã\83«一覧表示に於いて' do
     before do
       @other_user = FactoryGirl.create( :user_yas)
       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
@@ -290,7 +290,7 @@ if MagicNumber['run_mode'] == 1
         Author.should_receive(:show).exactly(1)
         get :scrolls, :id => @other_author.id
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに一覧を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに一覧を問い合わせている' do
         Scroll.should_receive(:himlist).exactly(1)
         get :scrolls, :id => @other_author.id
       end
@@ -313,7 +313,7 @@ if MagicNumber['run_mode'] == 1
           get :scrolls, :id => @other_author.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(:list_json_opt).exactly(1)
           get :scrolls, :id => @other_author.id, :format => :json
         end
@@ -322,7 +322,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 :scrolls, :id => @other_author.id, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("title").should be_true
@@ -376,7 +376,7 @@ if MagicNumber['run_mode'] == 1
     end
   end
   
-  describe '対象ä½\9c家ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼一覧表示に於いて' do
+  describe '対象ä½\9c家ã\81®ã\82¹ã\82¯ã\82³ã\83\9e一覧表示に於いて' do
     before do
       @other_user = FactoryGirl.create( :user_yas)
       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
@@ -423,7 +423,7 @@ if MagicNumber['run_mode'] == 1
         Author.should_receive(:show).exactly(1)
         get :scroll_panels, :id => @other_author.id
       end
-      it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼ã\83¢ã\83\87ã\83«ã\81«ä»\96ä½\9c家ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼一覧を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\82³ã\83\9eã\83¢ã\83\87ã\83«ã\81«ä»\96ä½\9c家ã\81®ã\82¹ã\82¯ã\82³ã\83\9e一覧を問い合わせている' do
         ScrollPanel.should_receive(:himlist).exactly(1)
         get :scroll_panels, :id => @other_author.id
       end
@@ -446,7 +446,7 @@ if MagicNumber['run_mode'] == 1
           get :scroll_panels, :id => @other_author.id, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼モデルにjson一覧出力オプションを問い合わせている' do
+        it 'ã\82¹ã\82¯ã\82³ã\83\9eモデルにjson一覧出力オプションを問い合わせている' do
           ScrollPanel.should_receive(:list_json_opt).exactly(1)
           get :scroll_panels, :id => @other_author.id, :format => :json
         end
@@ -455,7 +455,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\88ã\83¼ã\83ªã\83¼っぽいものであって欲しい' do
+        it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ­ã\81\8fã\82\89ã\81\84ã\81¯ã\82¹ã\82¯ã\82³ã\83\9eっぽいものであって欲しい' do
           get :scroll_panels, :id => @other_author.id, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("panel_id").should be_true
@@ -510,6 +510,403 @@ 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
+      @comic = FactoryGirl.create :comic, :author_id => @author.id
+      Author.stub(:show).and_return(@other_author)
+      Comic.stub(:himlist).and_return([@comic, @comic, @comic])
+      sign_in @user
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :comics, :id => @other_author.id, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :comics, :id => @other_author.id
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :comics, :id => @other_author.id, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :comics, :id => @other_author.id
+        assigns(:page_size).should eq Author.default_comic_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :comics, :id => @other_author.id, :page_size => 1500
+        assigns(:page_size).should eq Author.comic_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :comics, :id => @other_author.id, :page_size => 0
+        assigns(:page_size).should eq Author.default_comic_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :comics, :id => @other_author.id
+        response.should be_success 
+      end
+      it '作家モデルに単体取得を問い合わせている' do
+        Author.should_receive(:show).exactly(1)
+        get :comics, :id => @other_author.id
+      end
+      it 'コミックモデルに一覧を問い合わせている' do
+        Comic.should_receive(:himlist).exactly(1)
+        get :comics, :id => @other_author.id
+      end
+      it '@comicsにリストを取得している' do
+        get :comics, :id => @other_author.id
+        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")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :comics, :id => @other_author.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'コミックモデルにjson一覧出力オプションを問い合わせている' do
+          Comic.should_receive(:list_json_opt).exactly(1)
+          get :comics, :id => @other_author.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :comics, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはコミックっぽいものであって欲しい' do
+          get :comics, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("title").should be_true
+          json.first.has_key?("visible").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :comics, :id => @other_author.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :comics, :id => @other_author.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :comics, :id => @other_author.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :comics, :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 :comics, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :comics, :id => @other_author.id
+        response.should be_success 
+      end
+    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
+      @comic = FactoryGirl.create :comic, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
+      Author.stub(:show).and_return(@other_author)
+      Story.stub(:himlist).and_return([@story, @story, @story])
+      sign_in @user
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :stories, :id => @other_author.id, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :stories, :id => @other_author.id
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :stories, :id => @other_author.id, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :stories, :id => @other_author.id
+        assigns(:page_size).should eq Author.default_story_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :stories, :id => @other_author.id, :page_size => 1500
+        assigns(:page_size).should eq Author.story_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :stories, :id => @other_author.id, :page_size => 0
+        assigns(:page_size).should eq Author.default_story_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :stories, :id => @other_author.id
+        response.should be_success 
+      end
+      it '作家モデルに単体取得を問い合わせている' do
+        Author.should_receive(:show).exactly(1)
+        get :stories, :id => @other_author.id
+      end
+      it 'ストーリーモデルに他作家のストーリー一覧を問い合わせている' do
+        Story.should_receive(:himlist).exactly(1)
+        get :stories, :id => @other_author.id
+      end
+      it '@storiesにリストを取得している' do
+        get :stories, :id => @other_author.id
+        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")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :stories, :id => @other_author.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'ストーリーモデルにjson一覧出力オプションを問い合わせている' do
+          Story.should_receive(:list_json_opt).exactly(1)
+          get :stories, :id => @other_author.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :stories, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
+          get :stories, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("comic_id").should be_true
+          json.first.has_key?("title").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :stories, :id => @other_author.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :stories, :id => @other_author.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :stories, :id => @other_author.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :stories, :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 :stories, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :stories, :id => @other_author.id
+        response.should be_success 
+      end
+    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
+      @comic = FactoryGirl.create :comic, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
+      @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
+      Author.stub(:show).and_return(@other_author)
+      StorySheet.stub(:himlist).and_return([@story_sheet, @story_sheet, @story_sheet])
+      sign_in @user
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :story_sheets, :id => @other_author.id, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :story_sheets, :id => @other_author.id
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :story_sheets, :id => @other_author.id, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :story_sheets, :id => @other_author.id
+        assigns(:page_size).should eq Author.default_story_sheet_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :story_sheets, :id => @other_author.id, :page_size => 1500
+        assigns(:page_size).should eq Author.story_sheet_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :story_sheets, :id => @other_author.id, :page_size => 0
+        assigns(:page_size).should eq Author.default_story_sheet_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :story_sheets, :id => @other_author.id
+        response.should be_success 
+      end
+      it '作家モデルに単体取得を問い合わせている' do
+        Author.should_receive(:show).exactly(1)
+        get :story_sheets, :id => @other_author.id
+      end
+      it 'スト紙モデルに他作家のスト紙一覧を問い合わせている' do
+        StorySheet.should_receive(:himlist).exactly(1)
+        get :story_sheets, :id => @other_author.id
+      end
+      it '@story_sheetsにリストを取得している' do
+        get :story_sheets, :id => @other_author.id
+        assigns(:story_sheets).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :story_sheets, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'story_sheetsテンプレートを描画する' do
+          get :story_sheets, :id => @other_author.id
+          response.should render_template("story_sheets")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :story_sheets, :id => @other_author.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'スト紙モデルにjson一覧出力オプションを問い合わせている' do
+          StorySheet.should_receive(:list_json_opt).exactly(1)
+          get :story_sheets, :id => @other_author.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :story_sheets, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはスト紙っぽいものであって欲しい' do
+          get :story_sheets, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("story_id").should be_true
+          json.first.has_key?("sheet_id").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :story_sheets, :id => @other_author.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :story_sheets, :id => @other_author.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :story_sheets, :id => @other_author.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :story_sheets, :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 :story_sheets, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :story_sheets, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+  end
+  
   describe '対象作家の用紙一覧表示に於いて' do
     before do
       @other_user = FactoryGirl.create( :user_yas)
@@ -2041,7 +2438,7 @@ else
     end
   end
   
-  describe '対象ä½\9c家ã\81®ã\82³ã\83\9fã\83\83ã\82¯一覧表示に於いて' do
+  describe '対象ä½\9c家ã\81®ã\82¹ã\82¯ã\83­ã\83¼ã\83«一覧表示に於いて' do
     before do
       @other_user = FactoryGirl.create( :user_yas)
       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
@@ -2091,7 +2488,7 @@ else
     end
   end
   
-  describe '対象ä½\9c家ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼一覧表示に於いて' do
+  describe '対象ä½\9c家ã\81®ã\82¹ã\82¯ã\82³ã\83\9e一覧表示に於いて' do
     before do
       @other_user = FactoryGirl.create( :user_yas)
       @other_author = FactoryGirl.create :author, :user_id => @other_user.id