OSDN Git Service

t#30443:add test for open mode
[pettanr/pettanr.git] / spec / controllers / ground_pictures_controller_spec.rb
index 9f1c798..b24c641 100644 (file)
@@ -1,6 +1,6 @@
 # -*- encoding: utf-8 -*-
 require 'spec_helper'
-#コマの画像背景
+#絵地
 
 describe GroundPicturesController do
   before do
@@ -9,7 +9,7 @@ describe GroundPicturesController do
     @sp = FactoryGirl.create :system_picture
     @lg = FactoryGirl.create :license_group, :name => 'peta'
     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
-    @author = @user.author
+    @author = FactoryGirl.create :author, :user_id => @user.id
     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
     @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
@@ -17,6 +17,7 @@ describe GroundPicturesController do
     @panel = FactoryGirl.create :panel, :author_id => @author.id
   end
 
+if MagicNumber['run_mode'] == 1
   describe '一覧表示に於いて' do
     before do
       sign_in @user
@@ -54,7 +55,7 @@ describe GroundPicturesController do
         get :index
         response.should be_success 
       end
-      it 'コマの画像背景モデルに一覧を問い合わせている' do
+      it '絵地モデルに一覧を問い合わせている' do
         GroundPicture.should_receive(:list).exactly(1)
         get :index
       end
@@ -73,7 +74,7 @@ describe GroundPicturesController do
           get :index, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'コマの画像背景モデルにjson一覧出力オプションを問い合わせている' do
+        it '絵地モデルにjson一覧出力オプションを問い合わせている' do
           GroundPicture.should_receive(:list_json_opt).exactly(1)
           get :index, :format => :json
         end
@@ -82,7 +83,7 @@ describe GroundPicturesController do
           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¯ç\94»å\83\8fè\83\8cæ\99¯っぽいものであって欲しい' do
+        it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ­ã\81\8fã\82\89ã\81\84ã\81¯çµµå\9c°っぽいものであって欲しい' do
           get :index, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("panel_id").should be_true
@@ -118,4 +119,170 @@ describe GroundPicturesController do
     end
   end
   
+  describe '単体表示に於いて' do
+    before do
+      sign_in @user
+      @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+      GroundPicture.stub(:show).and_return(@gp)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @gp.id
+        response.should be_success
+      end
+      it '絵地モデルに単体取得を問い合わせている' do
+        GroundPicture.should_receive(:show).exactly(1)
+        get :show
+      end
+      it '@ground_pictureにアレを取得している' do
+        get :show, :id => @gp.id
+        assigns(:ground_picture).should eq(@gp)
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @gp.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @gp.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '絵地モデルにjson単体出力オプションを問い合わせている' do
+          GroundPicture.should_receive(:show_json_opt).exactly(1)
+          get :show, :id => @gp.id, :format => :json
+        end
+        it 'データがアレになっている' do
+          get :show, :id => @gp.id, :format => :json
+          json = JSON.parse response.body
+          json["panel_id"].should_not be_nil
+          json["z"].should_not be_nil
+          json["picture_id"].should_not be_nil
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :show, :id => @gp.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :show, :id => @gp.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :show, :id => @gp.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :show, :id => @gp.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+else
+  describe '一覧表示に於いて' do
+    before do
+      sign_in @user
+      @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+      GroundPicture.stub(:list).and_return([@gp, @gp, @gp])
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '単体表示に於いて' do
+    before do
+      sign_in @user
+      @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
+      GroundPicture.stub(:show).and_return(@gp)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @gp.id
+        response.should be_success
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @gp.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @gp.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @gp.id
+        response.should be_success
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @gp.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @gp.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+end
 end