OSDN Git Service

play panel_elements
[pettanr/pettanr.git] / spec / controllers / comics_controller_spec.rb
index 7a11c89..4cb92bf 100644 (file)
 require 'spec_helper'
 
-# This spec was generated by rspec-rails when you ran the scaffold generator.
-# It demonstrates how one might use RSpec to specify the controller code that
-# was generated by Rails when you ran the scaffold generator.
-#
-# It assumes that the implementation code is generated by the rails scaffold
-# generator.  If you are using any extension libraries to generate different
-# controller code, this generated spec may or may not pass.
-#
-# It only uses APIs available in rails and/or rspec-rails.  There are a number
-# of tools you can use to make these specs even more expressive, but we're
-# sticking to rails and rspec-rails APIs to keep things simple and stable.
-#
-# Compared to earlier versions of this generator, there is very limited use of
-# stubs and message expectations in this spec.  Stubs are only used when there
-# is no simpler way to get a handle on the object needed for the example.
-# Message expectations are only used when there is no simpler way to specify
-# that an instance is receiving a specific message.
-
 describe ComicsController do
-
   # This should return the minimal set of attributes required to create a valid
   # Comic. As you add validations to Comic, be sure to
   # update the return value of this method accordingly.
   def valid_attributes
-    {}
+    {:title => 'test comic', :width => 100, :height => 50, :visible => 0, :editable => 0}
   end
 
-  describe "GET index" do
-    it "assigns all comics as @comics" do
-      comic = Comic.create! valid_attributes
-      get :index
-      assigns(:comics).should eq([comic])
+  describe '一覧表示に於いて' do
+    before do
+      Pettanr.run_mode = 1
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      it '@comicsにリストを取得している' do
+        get :index
+        assigns(:comics).should have_at_least(3).items
+      end
+      context 'パラメータが' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      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
+          json = JSON.parse response.body
+          json.should match(/error/)
+        end
+        it 'データがリスト構造になっている' do
+          get :index, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      it 'ステータスコード401 Unauthorizedを返す' do
+        get :index
+        response.status.should eq 401
+      end
+      context 'html形式' do
+        it 'サインインページへ遷移する' do
+          get :index
+          response.should redirect_to '/'
+        end
+      end
+      context 'json形式' do
+        it '文字列errorが含まれたjsonデータを返す' do
+          response.body.should have_tag('json', 'error')
+        end
+      end
+      context 'ただし、公開型のときだけは' do
+        it 'ステータスコード200 OKを返す' do
+          Pettanr.run_mode = 0
+          get :index
+          response.should be_success 
+        end
+      end
     end
   end
-
-  describe "GET show" do
-    it "assigns the requested comic as @comic" do
-      comic = Comic.create! valid_attributes
-      get :show, :id => comic.id
-      assigns(:comic).should eq(comic)
+  
+  describe '単体表示に於いて' do
+    before do
+      Pettanr.run_mode = 1
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => 1
+        response.should be_success 
+      end
+      it '@comicにアレを取得している' do
+        get :show, :id => 1
+        assigns(:comic).should eq(comic)
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => 1
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => 1, :format => :json
+          json = JSON.parse response.body
+          json.should have_tag('json', 'error')
+        end
+        it 'データがアレになっている' do
+          get :show, :id => 1, :format => :json
+          json = JSON.parse response.body
+          json.should have_tag('json', 'error')
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      it 'ステータスコード401 Unauthorizedを返す' do
+        get :show, :id => 1
+        response.should eq 401
+      end
+      context 'html形式' do
+        it 'サインインページへ遷移する' do
+          get :show, :id => 1
+          response.should redirect_to '/'
+        end
+      end
+      context 'json形式' do
+        it '文字列errorが含まれたjsonデータを返す' do
+          
+        end
+      end
+      context 'ただし、公開型のときだけは' do
+        it 'ステータスコード200 OKを返す' do
+          Pettanr.run_mode = 0
+          get :show, :id => 1
+          response.should be_success 
+        end
+      end
+    end
+    context '非公開コミックを見ようとしたとき' do
+      it 'ステータスコード403 forbiddenを返す' do
+        get :show, :id => 1
+        response.status.should eq 403
+      end
+      context 'html形式' do
+        it 'forbiddenページへ遷移する' do
+          get :show, :id => 1
+          response.should redirect_to '/403.html'
+        end
+      end
+      context 'json形式' do
+        it 'エラーメッセージを返す' do
+          
+        end
+      end
     end
   end
 
-  describe "GET new" do
-    it "assigns a new comic as @comic" do
-      get :new
-      assigns(:comic).should be_a_new(Comic)
+  describe 'コミック数取得に於いて' do
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :count, :format => :json
+        response.should be_success 
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :count, :format => :json
+          json = JSON.parse response.body
+          json.should have_tag('json', 'error')
+        end
+        it 'データがリスト構造になっている' do
+          get :count, :format => :json
+          json = JSON.parse response.body
+          json.should have_tag('json', 'error')
+        end
+      end
     end
   end
 
-  describe "GET edit" do
-    it "assigns the requested comic as @comic" do
-      comic = Comic.create! valid_attributes
-      get :edit, :id => comic.id
-      assigns(:comic).should eq(comic)
+  describe '新規作成フォーム表示に於いて' do
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :new
+        response.should be_success 
+      end
+      it '@comicに新規データを用意している' do
+        get :new
+        assigns(:comic).should be_a_new(Comic)
+      end
+      it '@comicにデフォルト値editable=0, visible=0がセットされている' do
+        get :new
+      end
+      context 'html形式' do
+      end
+      context 'js形式' do
+        it '部分フォームを返す' do
+          
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      it 'ステータスコード401 Unauthorizedを返す' do
+        
+      end
+      context 'js形式' do
+        it '文字列errorが含まれたjsonデータを返す' do
+          
+        end
+      end
     end
   end
 
-  describe "POST create" do
-    describe "with valid params" do
-      it "creates a new Comic" do
+  describe '新規作成に於いて' do
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        post :create
+        response.should be_success 
+      end
+      it '作成される' do
         expect {
           post :create, :comic => valid_attributes
         }.to change(Comic, :count).by(1)
       end
-
-      it "assigns a newly created comic as @comic" do
+      it "@comicに作成されたコミックを保持している" do
         post :create, :comic => valid_attributes
         assigns(:comic).should be_a(Comic)
         assigns(:comic).should be_persisted
       end
-
-      it "redirects to the created comic" do
-        post :create, :comic => valid_attributes
-        response.should redirect_to(Comic.last)
+      context 'html形式' do
+        it '作成されたコミックの表示ページへ遷移する' do
+          post :create, :comic => valid_attributes
+          response.should redirect_to(Comic.last)
+        end
+      end
+      context 'json形式' do
+        it '作成されたコミックをjsonデータで返す' do
+          
+        end
       end
     end
-
-    describe "with invalid params" do
-      it "assigns a newly created but unsaved comic as @comic" do
-        # Trigger the behavior that occurs when invalid params are submitted
+    context '作家権限がないとき' do
+      context 'html形式' do
+        it 'サインインページへ遷移する' do
+          
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          
+        end
+        it '文字列errorが含まれたjsonデータを返す' do
+          
+        end
+      end
+    end
+    context '検証、保存に失敗した' do
+      it "未保存のコミックを保持している" do
         Comic.any_instance.stub(:save).and_return(false)
         post :create, :comic => {}
         assigns(:comic).should be_a_new(Comic)
       end
+      context 'html形式' do
+        it '新規ページを描画する' do
+          Comic.any_instance.stub(:save).and_return(false)
+          post :create, :comic => {}
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          
+        end
+        it '文字列errorが含まれたjsonデータを返す' do
+          
+        end
+      end
+    end
+  end
 
-      it "re-renders the 'new' template" do
-        # Trigger the behavior that occurs when invalid params are submitted
-        Comic.any_instance.stub(:save).and_return(false)
-        post :create, :comic => {}
-        response.should render_template("new")
+  describe '編集フォーム表示に於いて' do
+    context 'つつがなく終わるとき' do
+      context 'js形式' do
+        it '部分フォームを返す' do
+          
+        end
+        it '指定のデータが入っている' do
+          
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      it 'ステータスコード401 Unauthorizedを返す' do
+        
+      end
+      context 'js形式' do
+        it '文字列errorが含まれたjsonデータを返す' do
+          
+        end
+      end
+    end
+    context '対象コミックがないとき' do
+      it 'ステータスコード404 not_foundを返す' do
+        
+      end
+      context 'html形式' do
+        it '404ページへ遷移する' do
+          
+        end
+      end
+      context 'js形式' do
+        it '文字列errorが含まれたjsonデータを返す' do
+          
+        end
+      end
+    end
+  end
+
+  describe '更新に於いて' do
+    context 'つつがなく終わるとき' do
+      it '更新される' do
+        
+      end
+      context 'html形式' do
+        it '更新されたコミックの表示ページへ遷移する' do
+          
+        end
+      end
+      context 'json形式' do
+        it '更新されたコミックをjsonデータで返す' do
+          
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      it 'ステータスコード401 Unauthorizedを返す' do
+        
+      end
+      context 'html形式' do
+        it 'サインインページへ遷移する' do
+          
+        end
+      end
+      context 'json形式' do
+        it '文字列errorが含まれたjsonデータを返す' do
+          
+        end
+      end
+    end
+    context '他人のコミックを編集しようとしたとき' do
+      it 'ステータスコード403 forbiddenを返す' do
+        
+      end
+      context 'html形式' do
+        it '403ページへ遷移する' do
+          
+        end
+      end
+      context 'json形式' do
+        it '文字列errorが含まれたjsonデータを返す' do
+          
+        end
+      end
+    end
+    context '対象コミックがないとき' do
+      it 'ステータスコード404 not_foundを返す' do
+        
+      end
+      context 'html形式' do
+        it '404ページへ遷移する' do
+          
+        end
+      end
+      context 'json形式' do
+        it '文字列errorが含まれたjsonデータを返す' do
+          
+        end
+      end
+    end
+    context '検証、保存に失敗したとき' do
+      context 'html形式' do
+        it '編集ページを描画する' do
+          
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          
+        end
+        it '文字列errorが含まれたjsonデータを返す' do
+          
+        end
       end
     end
   end