OSDN Git Service

t#29671:fix my panel list as json
[pettanr/pettanr.git] / spec / controllers / home_controller_spec.rb
index 94eb801..f55b22e 100644 (file)
@@ -11,6 +11,7 @@ describe HomeController do
     @user = FactoryGirl.create( :user_yas)
     @author = @user.author
     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
+    @color = FactoryGirl.create :color
     @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
     @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
     @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
@@ -73,6 +74,10 @@ describe HomeController do
           get :comic, :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 :comic, :format => :json
+        end
         it 'データがリスト構造になっている' do
           get :comic, :format => :json
           json = JSON.parse response.body
@@ -82,6 +87,7 @@ describe HomeController do
           get :comic, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("title").should be_true
+          json.first.has_key?("visible").should be_true\r
         end
       end
     end
@@ -145,10 +151,6 @@ describe HomeController do
       end
     end
     context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :panel
-        response.should be_success 
-      end
       it 'コマモデルに一覧を問い合わせている' do
         Panel.should_receive(:mylist).exactly(1)
         get :panel
@@ -158,16 +160,28 @@ describe HomeController do
         assigns(:panels).should have_at_least(3).items
       end
       context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :panel
+          response.should be_success 
+        end
         it 'panelテンプレートを描画する' do
           get :panel
           response.should render_template("panel")
         end
       end
       context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :panel, :format => :json
+          response.should be_success 
+        end
         it 'jsonデータを返す' do
           get :panel, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
+        it 'コマモデルにコマリストのjson出力を問い合わせている' do
+          Panel.should_receive(:list_as_json_text).exactly(1)
+          get :panel, :format => :json
+        end
         it 'データがリスト構造になっている' do
           get :panel, :format => :json
           json = JSON.parse response.body
@@ -264,6 +278,10 @@ describe HomeController do
           get :panel_picture, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
+        it 'コマ絵モデルにjson一覧出力オプションを問い合わせている' do
+          PanelPicture.should_receive(:list_json_opt).exactly(1)
+          get :panel_picture, :format => :json
+        end
         it 'データがリスト構造になっている' do
           get :panel_picture, :format => :json
           json = JSON.parse response.body
@@ -273,6 +291,8 @@ describe HomeController do
           get :panel_picture, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("link").should be_true
+          json.first.has_key?("x").should be_true
+          json.first.has_key?("y").should be_true
         end
       end
     end
@@ -306,7 +326,7 @@ describe HomeController do
   describe '自分の原画一覧表示に於いて' do
     before do
       sign_in @user
-      OriginalPicture.stub(:list).and_return([@op, @op, @op])
+      OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
     end
     context 'パラメータpageについて' do
       it '@pageに値が入る' do
@@ -341,7 +361,7 @@ describe HomeController do
       end
       it '原画モデルに一覧を問い合わせている' do
         #原画は他人が使えないので「自分の」リストはない
-        OriginalPicture.should_receive(:list).exactly(1)
+        OriginalPicture.should_receive(:mylist).exactly(1)
         get :picture
       end
       it '@original_picturesにリストを取得している' do
@@ -359,6 +379,10 @@ describe HomeController do
           get :picture, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
+        it '原画モデルにjson一覧出力オプションを問い合わせている' do
+          OriginalPicture.should_receive(:list_json_opt).exactly(1)
+          get :picture, :format => :json
+        end
         it 'データがリスト構造になっている' do
           get :picture, :format => :json
           json = JSON.parse response.body
@@ -368,6 +392,9 @@ describe HomeController do
           get :picture, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("ext").should be_true
+          json.first.has_key?("md5").should be_true
+          json.first.has_key?("artist_id").should be_true
+          json.first.has_key?("width").should be_true
         end
       end
     end
@@ -420,4 +447,307 @@ describe HomeController do
     end
   end
   
+  describe '自分のコマの色背景一覧表示に於いて' do
+    before do
+      @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
+      sign_in @user
+      PanelColor.stub(:mylist).and_return([@pc, @pc, @pc])
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :panel_color, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :panel_color
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :panel_color, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :panel_color
+        assigns(:page_size).should eq PanelColor.default_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :panel_color, :page_size => 1500
+        assigns(:page_size).should eq PanelColor.max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :panel_color, :page_size => 0
+        assigns(:page_size).should eq PanelColor.default_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :panel_color
+        response.should be_success 
+      end
+      it 'コマの色背景モデルに一覧を問い合わせている' do
+        PanelColor.should_receive(:mylist).exactly(1)
+        get :panel_color
+      end
+      it '@panel_colorsにリストを取得している' do
+        get :panel_color
+        assigns(:panel_colors).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it 'panel_colorテンプレートを描画する' do
+          get :panel_color
+          response.should render_template("panel_color")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :panel_color, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'コマの色背景モデルにjson一覧出力オプションを問い合わせている' do
+          PanelColor.should_receive(:list_json_opt).exactly(1)
+          get :panel_color, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :panel_color, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはコマの色背景っぽいものであって欲しい' do
+          get :panel_color, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("panel_id").should be_true
+          json.first.has_key?("code").should be_true
+          json.first.has_key?("z").should be_true
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :panel_color
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :panel_color
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :panel_color, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :panel_color, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '自分のコマの画像背景一覧表示に於いて' do
+    before do
+      @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+      sign_in @user
+      GroundPicture.stub(:mylist).and_return([@gp, @gp, @gp])
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :ground_picture, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :ground_picture
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :ground_picture, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :ground_picture
+        assigns(:page_size).should eq GroundPicture.default_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :ground_picture, :page_size => 1500
+        assigns(:page_size).should eq GroundPicture.max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :ground_picture, :page_size => 0
+        assigns(:page_size).should eq GroundPicture.default_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :ground_picture
+        response.should be_success 
+      end
+      it 'コマの画像背景モデルに一覧を問い合わせている' do
+        GroundPicture.should_receive(:mylist).exactly(1)
+        get :ground_picture
+      end
+      it '@ground_picturesにリストを取得している' do
+        get :ground_picture
+        assigns(:ground_pictures).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it 'ground_pictureテンプレートを描画する' do
+          get :ground_picture
+          response.should render_template("ground_picture")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :ground_picture, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'コマの画像背景モデルにjson一覧出力オプションを問い合わせている' do
+          GroundPicture.should_receive(:list_json_opt).exactly(1)
+          get :ground_picture, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :ground_picture, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはコマの画像背景っぽいものであって欲しい' do
+          get :ground_picture, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("panel_id").should be_true
+          json.first.has_key?("picture_id").should be_true
+          json.first.has_key?("z").should be_true
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :ground_picture
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :ground_picture
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :ground_picture, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :ground_picture, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '自分の間接背景一覧表示に於いて' do
+    before do
+      @gc = FactoryGirl.create :ground_color
+      sign_in @user
+      GroundColor.stub(:mylist).and_return([@gc, @gc, @gc])
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :ground_color, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :ground_color
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :ground_color, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :ground_color
+        assigns(:page_size).should eq GroundColor.default_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :ground_color, :page_size => 1500
+        assigns(:page_size).should eq GroundColor.max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :ground_color, :page_size => 0
+        assigns(:page_size).should eq GroundColor.default_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :ground_color
+        response.should be_success 
+      end
+      it '間接背景モデルに一覧を問い合わせている' do
+        GroundColor.should_receive(:mylist).exactly(1)
+        get :ground_color
+      end
+      it '@ground_colorsにリストを取得している' do
+        get :ground_color
+        assigns(:ground_colors).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it 'ground_colorテンプレートを描画する' do
+          get :ground_color
+          response.should render_template("ground_color")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :ground_color, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '間接背景モデルにjson一覧出力オプションを問い合わせている' do
+          GroundColor.should_receive(:list_json_opt).exactly(1)
+          get :ground_color, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :ground_color, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいは間接背景っぽいものであって欲しい' do
+          get :ground_color, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("panel_id").should be_true
+          json.first.has_key?("color_id").should be_true
+          json.first.has_key?("z").should be_true
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :ground_color
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :ground_color
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :ground_color, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :ground_color, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
 end