OSDN Git Service

t#30169:show, index action create all resource
[pettanr/pettanr.git] / spec / controllers / panel_colors_controller_spec.rb
index 4fcd560..11b47f8 100644 (file)
@@ -1,6 +1,6 @@
 # -*- encoding: utf-8 -*-
 require 'spec_helper'
-#コマの色背景
+#指定色地
 
 describe PanelColorsController do
   before do
@@ -51,7 +51,7 @@ describe PanelColorsController do
         get :index
         response.should be_success 
       end
-      it '色背景モデルに一覧を問い合わせている' do
+      it '指定色地モデルに一覧を問い合わせている' do
         PanelColor.should_receive(:list).exactly(1)
         get :index
       end
@@ -70,7 +70,7 @@ describe PanelColorsController do
           get :index, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'コマの色背景モデルにjson一覧出力オプションを問い合わせている' do
+        it '指定色地モデルにjson一覧出力オプションを問い合わせている' do
           PanelColor.should_receive(:list_json_opt).exactly(1)
           get :index, :format => :json
         end
@@ -79,7 +79,7 @@ describe PanelColorsController do
           json = JSON.parse response.body
           json.should have_at_least(3).items
         end
-        it 'リストの先頭くらいは色背景っぽいものであって欲しい' do
+        it 'リストの先頭くらいは指定色地っぽいものであって欲しい' do
           get :index, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("panel_id").should be_true
@@ -115,4 +115,74 @@ describe PanelColorsController do
     end
   end
   
+  describe '単体表示に於いて' do
+    before do
+      sign_in @user
+      @pc = FactoryGirl.create :panel_color, :panel_id => @panel.id
+      PanelColor.stub(:show).and_return(@pc)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @pc.id
+        response.should be_success
+      end
+      it '指定色地モデルに単体取得を問い合わせている' do
+        PanelColor.should_receive(:show).exactly(1)
+        get :show
+      end
+      it '@panel_colorにアレを取得している' do
+        get :show, :id => @pc.id
+        assigns(:panel_color).should eq(@pc)
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @pc.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @pc.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '指定色地モデルにjson単体出力オプションを問い合わせている' do
+          PanelColor.should_receive(:show_json_opt).exactly(1)
+          get :show, :id => @pc.id, :format => :json
+        end
+        it 'データがアレになっている' do
+          get :show, :id => @pc.id, :format => :json
+          json = JSON.parse response.body
+          json["panel_id"].should_not be_nil
+          json["z"].should_not be_nil
+          json["code"].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 => @pc.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :show, :id => @pc.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :show, :id => @pc.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :show, :id => @pc.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
 end