OSDN Git Service

t#30169:show, index action create all resource
[pettanr/pettanr.git] / spec / controllers / colors_controller_spec.rb
index 92375fd..7ad3e50 100644 (file)
@@ -1,6 +1,6 @@
 # -*- encoding: utf-8 -*-
 require 'spec_helper'
-#色マスター
+#色
 
 describe ColorsController do
   before do
@@ -68,7 +68,7 @@ describe ColorsController do
           get :index, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'è\89²ã\83\9eã\82¹ã\82¿ã\83¼ã\83¢ã\83\87ã\83«ã\81«jsonä¸\80覧å\87ºå\8a\9bã\82ªã\83\97ã\82·ã\83§ã\83³ã\82\92å\95\8fã\81\84å\90\88ã\82\8fã\81\9bã\81¦ã\81\84ã\82\8b' do
+        it '色モデルにjson一覧出力オプションを問い合わせている' do
           Color.should_receive(:list_json_opt).exactly(1)
           get :index, :format => :json
         end
@@ -97,4 +97,58 @@ describe ColorsController do
     end
   end
   
+  describe '単体表示に於いて' do
+    before do
+      sign_in @user
+      @color = FactoryGirl.create :color
+      Color.stub(:show).and_return(@color)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @color.id
+        response.should be_success
+      end
+      it '色モデルに単体取得を問い合わせている' do
+        Color.should_receive(:show).exactly(1)
+        get :show
+      end
+      it '@colorにアレを取得している' do
+        get :show, :id => @color.id
+        assigns(:color).id.should eq(@color.id)
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @color.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @color.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '色モデルにjson単体出力オプションを問い合わせている' do
+          Color.should_receive(:show_json_opt).exactly(1)
+          get :show, :id => @color.id, :format => :json
+        end
+        it 'データがアレになっている' do
+          get :show, :id => @color.id, :format => :json
+          json = JSON.parse response.body
+          json["name"].should_not be_nil
+          json["code"].should_not be_nil
+          json["t"].should_not be_nil
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード200 okを返す' do
+        get :show, :id => @color.id
+        response.status.should eq 200
+      end
+    end
+  end
+  
 end