OSDN Git Service

Merge branch 'v05' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v05
[pettanr/pettanr.git] / spec / controllers / authors_controller_spec.rb
index ff4a766..2ef2701 100644 (file)
@@ -13,6 +13,7 @@ describe AuthorsController do
     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
   end
 
+if MagicNumber['run_mode'] == 1
   describe '一覧表示に於いて' do
     before do
       Author.stub(:list).and_return([@author, @author, @author])
@@ -85,7 +86,7 @@ describe AuthorsController do
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
         sign_out @user
       end
@@ -110,6 +111,25 @@ describe AuthorsController do
         end
       end
     end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+    end
   end
   
   describe '閲覧に於いて' do
@@ -154,7 +174,7 @@ describe AuthorsController do
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
         sign_out @user
       end
@@ -179,6 +199,25 @@ describe AuthorsController do
         end
       end
     end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @author.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @author.id
+        response.should be_success 
+      end
+    end
 =begin
     context '対象作家がないとき' do
       context 'html形式' do
@@ -199,6 +238,257 @@ describe AuthorsController do
 =end
   end
   
+  describe '対象作家のコミック一覧表示に於いて' do
+    before do
+      @other_user = FactoryGirl.create( :user_yas)
+      @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+      @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
+      @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id
+      Comic.stub(:mylist).and_return([@comic, @comic, @comic])
+      sign_in @user
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :comics, :id => @other_author.id, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :comics, :id => @other_author.id
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :comics, :id => @other_author.id, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :comics, :id => @other_author.id
+        assigns(:page_size).should eq Author.default_comic_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :comics, :id => @other_author.id, :page_size => 1500
+        assigns(:page_size).should eq Author.comic_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :comics, :id => @other_author.id, :page_size => 0
+        assigns(:page_size).should eq Author.default_comic_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :comics, :id => @other_author.id
+        response.should be_success 
+      end
+      it '作家モデルに単体取得を問い合わせている' do
+        Author.should_receive(:show).exactly(1)
+        get :comics, :id => @other_author.id
+      end
+      it 'コミックモデルに一覧を問い合わせている' do
+        Comic.should_receive(:mylist).exactly(1)
+        get :comics, :id => @other_author.id
+      end
+      it '@comicsにリストを取得している' do
+        get :comics, :id => @other_author.id
+        assigns(:comics).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it 'comicテンプレートを描画する' do
+          get :comics, :id => @other_author.id
+          response.should render_template("comic")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :comics, :id => @other_author.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'コミックモデルにjson一覧出力オプションを問い合わせている' do
+          Comic.should_receive(:list_json_opt).exactly(1)
+          get :comics, :id => @other_author.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :comics, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはコミックっぽいものであって欲しい' do
+          get :comics, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("title").should be_true
+          json.first.has_key?("visible").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :comics, :id => @other_author.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :comics, :id => @other_author.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :comics, :id => @other_author.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :comics, :id => @other_author.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :comics, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :comics, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+  end
+  
+  describe '対象作家のコマ一覧表示に於いて' do
+    before do
+      @other_user = FactoryGirl.create( :user_yas)
+      @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+      @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
+      @panel = FactoryGirl.create :panel, :author_id => @other_author.id
+      Panel.stub(:mylist).and_return([@panel, @panel, @panel])
+      sign_in @user
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :panels, :id => @other_author.id, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :panels, :id => @other_author.id
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :panels, :id => @other_author.id, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :panels, :id => @other_author.id
+        assigns(:page_size).should eq Author.default_panel_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :panels, :id => @other_author.id, :page_size => 1500
+        assigns(:page_size).should eq Author.panel_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :panels, :id => @other_author.id, :page_size => 0
+        assigns(:page_size).should eq Author.default_panel_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :panels, :id => @other_author.id
+        response.should be_success 
+      end
+      it '作家モデルに単体取得を問い合わせている' do
+        Author.should_receive(:show).exactly(1)
+        get :panels, :id => @other_author.id
+      end
+      it 'コマモデルに一覧を問い合わせている' do
+        Panel.should_receive(:mylist).exactly(1)
+        get :panels, :id => @other_author.id
+      end
+      it '@panelsにリストを取得している' do
+        get :panels, :id => @other_author.id
+        assigns(:panels).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it 'comicテンプレートを描画する' do
+          get :panels, :id => @other_author.id
+          response.should render_template("panels")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :panels, :id => @other_author.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'コマモデルにコマリストのjson出力を問い合わせている' do
+          Panel.should_receive(:list_as_json_text).exactly(1)
+          get :panels, :id => @other_author.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :panels, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはコマっぽいものであって欲しい' do
+          get :panels, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("z").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :panels, :id => @other_author.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :panels, :id => @other_author.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :panels, :id => @other_author.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :panels, :id => @other_author.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :panels, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :panels, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+  end
+  
   describe '作家数取得に於いて' do
     before do
       Author.should_receive(:visible_count).and_return(3)
@@ -264,7 +554,7 @@ describe AuthorsController do
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
         sign_out @new_user
       end
@@ -299,6 +589,31 @@ describe AuthorsController do
         end
       end
     end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+          get :new
+        response.should be_success 
+      end
+    end
   end
 
   describe '新規作成に於いて' do
@@ -364,7 +679,7 @@ describe AuthorsController do
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
         sign_out @new_user
       end
@@ -389,6 +704,22 @@ describe AuthorsController do
         end
       end
     end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :author => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :author => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
     context '検証、保存に失敗した' do
       before do
         Author.any_instance.stub(:save).and_return(false)
@@ -452,7 +783,7 @@ describe AuthorsController do
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
         sign_out @user
       end
@@ -477,6 +808,39 @@ describe AuthorsController do
         end
       end
     end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @author.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @author.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @other_user = FactoryGirl.create( :user_yas)
+        @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @other_author.id
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          get :edit, :id => @other_author.id
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
   end
 
   describe '更新に於いて' do
@@ -540,15 +904,15 @@ describe AuthorsController do
         end
       end
     end
-    context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
       before do
         sign_out @user
       end
-      it 'ステータスコード302 Foundを返す' do
-        put :update, :id => @author.id, :author => @attr
-        response.status.should eq 302
-      end
       context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @author.id, :author => @attr
+          response.status.should eq 302
+        end
         it 'サインインページへ遷移する' do
           put :update, :id => @author.id, :author => @attr
           response.body.should redirect_to '/users/sign_in'
@@ -561,12 +925,45 @@ describe AuthorsController do
         end
       end
     end
-    context '検証、保存に失敗したとき' do
+    context 'ユーザ権限はないが管理者権限があるとき' do
       before do
-        Author.any_instance.stub(:save).and_return(false)
+        sign_out @user
+        sign_in @admin
       end
       context 'html形式' do
-        it 'ステータスコード200 Okを返す' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @author.id, :author => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          put :update, :id => @author.id, :author => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @other_user = FactoryGirl.create( :user_yas)
+        @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :update, :id => @other_author.id
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          get :update, :id => @other_author.id
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+    context '検証、保存に失敗したとき' do
+      before do
+        Author.any_instance.stub(:save).and_return(false)
+      end
+      context 'html形式' do
+        it 'ステータスコード200 Okを返す' do
           put :update, :id => @author.id, :author => @attr
           response.status.should eq 200
         end
@@ -589,4 +986,445 @@ describe AuthorsController do
     end
   end
 
+else
+  describe '一覧表示に於いて' do
+    before do
+      Author.stub(:list).and_return([@author, @author, @author])
+      sign_in @user
+    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
+      Author.stub(:show).and_return(@author)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @author.id
+        response.should be_success
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @author.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @author.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 => @author.id
+        response.should be_success
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @author.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @author.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '対象作家のコミック一覧表示に於いて' do
+    before do
+      @other_user = FactoryGirl.create( :user_yas)
+      @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+      @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
+      @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id
+      Comic.stub(:mylist).and_return([@comic, @comic, @comic])
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :comics, :id => @other_author.id
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'comicテンプレートを描画する' do
+          get :comics, :id => @other_author.id
+          response.should render_template("comic")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :comics, :id => @other_author.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 :comics, :id => @other_author.id
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'comicテンプレートを描画する' do
+          get :comics, :id => @other_author.id
+          response.should render_template("comic")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :comics, :id => @other_author.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '対象作家のコマ一覧表示に於いて' do
+    before do
+      @other_user = FactoryGirl.create( :user_yas)
+      @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+      @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
+      @panel = FactoryGirl.create :panel, :author_id => @other_author.id
+      Panel.stub(:mylist).and_return([@panel, @panel, @panel])
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :panels, :id => @other_author.id
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'comicテンプレートを描画する' do
+          get :panels, :id => @other_author.id
+          response.should render_template("panels")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :panels, :id => @other_author.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 :panels, :id => @other_author.id
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'comicテンプレートを描画する' do
+          get :panels, :id => @other_author.id
+          response.should render_template("panels")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :panels, :id => @other_author.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '作家数取得に於いて' do
+    before do
+      Author.should_receive(:visible_count).and_return(3)
+#      sign_in @user
+    end
+    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
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '新規作成フォーム表示に於いて' do
+    before do
+      @new_user = FactoryGirl.create( :user_yas)
+      sign_in @new_user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :new
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'newテンプレートを描画する' do
+          get :new
+          response.should render_template("new")
+        end
+      end
+      context 'js形式' do
+        it 'new.jsテンプレートを描画する' do
+          get :new, :format => :js
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :new, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @new_user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '新規作成に於いて' do
+    before do
+      @new_user = FactoryGirl.create( :user_yas)
+      sign_in @new_user
+      @attr = FactoryGirl.attributes_for(:author, :user_id => @new_user.id, :name => 'ken')
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          Author.any_instance.stub(:save).and_return(true)
+          post :create, :author => @attr
+          response.status.should eq 302
+        end
+        it 'トップページへ遷移する' do
+#          Author.any_instance.stub(:save).and_return(true)
+          post :create, :author => @attr
+          response.should redirect_to(root_path)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          Author.any_instance.stub(:save).and_return(true)
+          post :create, :author => @attr, :format => :json
+          response.should be_success 
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @new_user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :author => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :author => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          post :create, :author => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          post :create, :author => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '編集フォーム表示に於いて' do
+    before do
+      sign_in @user
+      Author.stub(:edit).and_return(@author)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :edit, :id => @author.id
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'editテンプレートを描画する' do
+          get :edit, :id => @author.id
+          response.should render_template("edit")
+        end
+      end
+      context 'js形式' do
+        it 'edit.jsテンプレートを描画する' do
+          get :edit, :id => @author.id, :format => :js
+          response.should render_template("edit")
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @author.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @author.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :edit, :id => @author.id, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :edit, :id => @author.id, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '更新に於いて' do
+    before do
+      @attr = @author.attributes
+      @attr['name'] = 'ryu'
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it '更新される' do
+        put :update, :id => @author.id, :author => @attr
+        Author.find(@author.id).name.should eq 'ryu'
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          Author.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @author.id, :author => @attr
+          response.status.should eq 302
+        end
+        it '設定ページへ遷移する' do
+          put :update, :id => @author.id, :author => @attr
+          response.should redirect_to('/home/configure')
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          Author.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @author.id, :author => @attr, :format => :json
+          response.should be_success 
+        end
+        it 'ページ本体は特に返さない' do
+          Author.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @author.id, :author => @attr, :format => :json
+          response.body.should match /./
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード302 Foundを返す' do
+        put :update, :id => @author.id, :author => @attr
+        response.status.should eq 302
+      end
+      context 'html形式' do
+        it 'サインインページへ遷移する' do
+          put :update, :id => @author.id, :author => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it '応答メッセージにUnauthorizedを返す' do
+          put :update, :id => @author.id, :author => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+end
 end