OSDN Git Service

t#30169:show, index action create all resource
[pettanr/pettanr.git] / spec / controllers / panel_pictures_controller_spec.rb
index 7fac516..1de3557 100644 (file)
@@ -119,4 +119,74 @@ describe PanelPicturesController do
     end
   end
   
+  describe '単体表示に於いて' do
+    before do
+      sign_in @user
+      @panel_picture = FactoryGirl.create :panel_picture, @attr
+      PanelPicture.stub(:show).and_return(@panel_picture)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @panel_picture.id
+        response.should be_success
+      end
+      it 'コマ絵モデルに単体取得を問い合わせている' do
+        PanelPicture.should_receive(:show).exactly(1)
+        get :show
+      end
+      it '@panel_pictureにアレを取得している' do
+        get :show, :id => @panel_picture.id
+        assigns(:panel_picture).should eq(@panel_picture)
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @panel_picture.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @panel_picture.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'コマ絵モデルにjson単体出力オプションを問い合わせている' do
+          PanelPicture.should_receive(:show_json_opt).exactly(1)
+          get :show, :id => @panel_picture.id, :format => :json
+        end
+        it 'データがアレになっている' do
+          get :show, :id => @panel_picture.id, :format => :json
+          json = JSON.parse response.body
+          json["link"].should_not be_nil
+          json["x"].should_not be_nil
+          json["y"].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 => @panel_picture.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :show, :id => @panel_picture.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :show, :id => @panel_picture.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :show, :id => @panel_picture.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
 end