OSDN Git Service

merge v04
[pettanr/pettanr.git] / spec / controllers / comics_controller_spec.rb
index 20dfcc3..8879610 100644 (file)
@@ -8,646 +8,543 @@ describe ComicsController do
     @lg = Factory :license_group
     @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
     @user = Factory :user_yas\r
-    @author = @user.author    #ユーザ作成時に連動して作成される
-  end
-  
-  describe '一覧表示に於いて' do
-    before do
-      @comic = Factory :normal_comic, :author_id => @user.author.id
-      Comic.stub(:list).and_return([@comic, @comic, @comic])
-      sign_in @user
-    end
-    context '事前チェックする' do
-      it '与えられたpageがセットされている' do
-        get :index, :page => 5
-        assigns(:page).should eq 5
-      end
-      it '省略されると@pageに1値が入る' do
-        get :index
-        assigns(:page).should eq 1
-      end
-      it '与えられたpage_sizeがセットされている' do
-        get :index, :page_size => 15
-        assigns(:page_size).should eq 15
-      end
-      it '省略されると@page_sizeにデフォルト値が入る' do
-        get :index
+    @author = @user.author    #ユーザ作成時に連動して作成される\r
+  end\r
+  \r
+  describe '一覧表示に於いて' do\r
+    before do\r
+      @comic = Factory :comic, :author_id => @user.author.id\r
+      Comic.stub(:list).and_return([@comic, @comic, @comic])\r
+      sign_in @user\r
+    end\r
+    context '事前チェックする' do\r
+      it '与えられたpageがセットされている' do\r
+        get :index, :page => 5\r
+        assigns(:page).should eq 5\r
+      end\r
+      it '省略されると@pageに1値が入る' do\r
+        get :index\r
+        assigns(:page).should eq 1\r
+      end\r
+      it '与えられたpage_sizeがセットされている' do\r
+        get :index, :page_size => 15\r
+        assigns(:page_size).should eq 15\r
+      end\r
+      it '省略されると@page_sizeにデフォルト値が入る' do\r
+        get :index\r
+        assigns(:page_size).should eq Comic.default_page_size\r
+      end\r
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do\r
+        get :index, :page_size => 1500\r
+        assigns(:page_size).should eq Comic.max_page_size\r
+      end\r
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do\r
+        get :index, :page_size => 0\r
         assigns(:page_size).should eq Comic.default_page_size\r
-      end
-      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
-        get :index, :page_size => 1500
-        assigns(:page_size).should eq Comic.max_page_size
-      end
-      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
-        get :index, :page_size => 0
-        assigns(:page_size).should eq Comic.default_page_size
-      end
-    end
-    context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :index
-        response.should be_success 
-      end
-      it 'コミックモデルに一覧を問い合わせている' do
+      end\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :index\r
+        response.should be_success \r
+      end\r
+      it 'コミックモデルに一覧を問い合わせている' do\r
         Comic.should_receive(:list).exactly(1)\r
-        get :index
-      end
-      it '@comicsにリストを取得している' do
-        get :index
-        assigns(:comics).should have_at_least(3).items
-      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
-        it 'データがリスト構造になっている' do
-          get :index, :format => :json
+        get :index\r
+      end\r
+      it '@comicsにリストを取得している' do\r
+        get :index\r
+        assigns(:comics).should have_at_least(3).items\r
+      end\r
+      context 'html形式' do\r
+        it 'indexテンプレートを描画する' do\r
+          get :index\r
+          response.should render_template("index")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :index, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+        it 'データがリスト構造になっている' do\r
+          get :index, :format => :json\r
+          json = JSON.parse response.body\r
+          json.should have_at_least(3).items\r
+        end\r
+        it 'リストの先頭くらいはコミックっぽいものであって欲しい' do\r
+          get :index, :format => :json\r
           json = JSON.parse response.body\r
-          json.should have_at_least(3).items
-        end
-        it 'リストの先頭くらいはコミックっぽいものであって欲しい' do
-          get :index, :format => :json
-          json = JSON.parse response.body
-          json.first.has_key?("title").should be_true
-        end
-      end
-    end
-    context '作家権限がないとき' do
-      before do
-        sign_out @user
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :index
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          get :index
-          response.should redirect_to '/users/sign_in'
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          get :index, :format => :json
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
+          json.first.has_key?("title").should be_true\r
+        end\r
+      end\r
+    end\r
+    context '作家権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :index\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :index\r
+          response.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
           get :index, :format => :json\r
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-  end
-  
-  describe '単体表示に於いて' do
-    before do
-      @comic = Factory :normal_comic, :author_id => @user.author.id
-      Comic.stub(:show).and_return(@comic)
-      sign_in @user
-    end
-    context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :show, :id => @comic.id
-        response.should be_success
-      end
-      it 'コミックモデルに単体取得を問い合わせている' do
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :index, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe '単体表示に於いて' do\r
+    before do\r
+      @comic = Factory :comic, :author_id => @user.author.id, :title => 'normal'\r
+      Comic.stub(:show).and_return(@comic)\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :show, :id => @comic.id\r
+        response.should be_success\r
+      end\r
+      it 'コミックモデルに単体取得を問い合わせている' do\r
         Comic.should_receive(:show).exactly(1)\r
-        get :show
-      end
-      it '@comicにアレを取得している' do
-        get :show, :id => @comic.id
-        assigns(:comic).id.should eq(@comic.id)
-      end
-      context 'html形式' do
-        it 'showテンプレートを描画する' do
-          get :show, :id => @comic.id
-          response.should render_template("show")
-        end
-      end
-      context 'json形式' do
-        it 'jsonデータを返す' do
-          get :show, :id => @comic.id, :format => :json
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
-        end
-        it 'データがアレになっている' do
-          get :show, :id => @comic.id, :format => :json
-          json = JSON.parse response.body
-          json["title"].should match(/normal/)
-        end
-      end
-    end
-    context '作家権限がないとき' do
-      before do
-        sign_out @user
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :show, :id => @comic.id
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          get :show, :id => @comic.id
-          response.body.should redirect_to '/users/sign_in'
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          get :show, :id => @comic.id, :format => :json
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          get :show, :id => @comic.id, :format => :json
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-=begin
-    context '対象コミックがないとき' do
-      context 'html形式' do
-        it '例外404 not_foundを返す' do
+        get :show\r
+      end\r
+      it '@comicにアレを取得している' do\r
+        get :show, :id => @comic.id\r
+        assigns(:comic).id.should eq(@comic.id)\r
+      end\r
+      context 'html形式' do\r
+        it 'showテンプレートを描画する' do\r
+          get :show, :id => @comic.id\r
+          response.should render_template("show")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :show, :id => @comic.id, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+        it 'データがアレになっている' do\r
+          get :show, :id => @comic.id, :format => :json\r
+          json = JSON.parse response.body\r
+          json["title"].should match(/normal/)\r
+        end\r
+      end\r
+    end\r
+    context '作家権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :show, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :show, :id => @comic.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :show, :id => @comic.id, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :show, :id => @comic.id, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+=begin\r
+    context '対象コミックがないとき' do\r
+      context 'html形式' do\r
+        it '例外404 not_foundを返す' do\r
           lambda{\r
-            get :show, :id => 0
-          }.should raise_error(ActiveRecord::RecordNotFound)
-        end
-      end
-      context 'json形式' do
-        it '例外404 not_foundを返す' do
+            get :show, :id => 0\r
+          }.should raise_error(ActiveRecord::RecordNotFound)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it '例外404 not_foundを返す' do\r
           lambda{ \r
-            get :show, :id => 0, :format => :json
-          }.should raise_error(ActiveRecord::RecordNotFound)
-        end
-      end
-    end
-    context '非公開コミックを見ようとしたとき' do
-      context 'html形式' do
-        it '例外403 forbiddenを返す' do
-          Comic.any_instance.stub(:visible?).with(any_args()).and_return(false)
-          hidden = Factory :hidden_comic, :author_id => @author.id
+            get :show, :id => 0, :format => :json\r
+          }.should raise_error(ActiveRecord::RecordNotFound)\r
+        end\r
+      end\r
+    end\r
+    context '非公開コミックを見ようとしたとき' do\r
+      context 'html形式' do\r
+        it '例外403 forbiddenを返す' do\r
+          Comic.any_instance.stub(:visible?).with(any_args()).and_return(false)\r
+          hidden = Factory :hidden_comic, :author_id => @author.id\r
           lambda{\r
-            get :show, :id => hidden
-          }.should raise_error(ActiveRecord::Forbidden)
-        end
-      end
-      context 'json形式' do
-        it '例外403 forbiddenを返す' do
-          Comic.any_instance.stub(:visible?).with(any_args()).and_return(false)
-          hidden = Factory :hidden_comic, :author_id => @author.id
+            get :show, :id => hidden\r
+          }.should raise_error(ActiveRecord::Forbidden)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it '例外403 forbiddenを返す' do\r
+          Comic.any_instance.stub(:visible?).with(any_args()).and_return(false)\r
+          hidden = Factory :hidden_comic, :author_id => @author.id\r
           lambda{\r
-            get :show, :id => hidden, :format => :json
-          }.should raise_error(ActiveRecord::Forbidden)
-        end
-      end
-    end
-=end
-  end
-  describe '閲覧に於いて' do
-    before do
-      @comic = Factory :normal_comic, :author_id => @user.author.id
-      Comic.stub(:show).and_return(@comic)
-      sign_in @user
-    end
-    context '事前チェックする' do
-      before do
-        Panel.stub(:count).and_return(10)
-      end
-      it '与えられたoffsetがセットされている' do
-        get :play, :id => @comic.id, :offset => 7
-        assigns(:offset).should eq 7
-      end
-      it '省略されると@offsetに0値が入る' do
-        get :play, :id => @comic.id
-        assigns(:offset).should eq 0
-      end
-      it 'コマ数以上が与えられるとコマ数-1が入る' do
-        get :play, :id => @comic.id, :offset => 10
-        assigns(:offset).should eq 9
-      end
-      it '負の値が与えられると末尾(コマ数)からさかのぼった値が入る' do
-        get :play, :id => @comic.id, :offset => -3
-        assigns(:offset).should eq 7
-      end
-      it 'コマ数以上の負の値が与えられると計算できないので0値が入る' do
-        get :play, :id => @comic.id, :offset => -13
-        assigns(:offset).should eq 0
-      end
-      it '与えられたcountがセットされている' do
-        get :play, :id => @comic.id, :count => 18
-        assigns(:panel_count).should eq 18
-      end
-      it '省略されると@countにデフォルト値が入る' do
-        get :play, :id => @comic.id
-        assigns(:panel_count).should eq Comic.default_panel_size\r
-      end
-      it '最大を超えると@countにデフォルト最大値が入る' do
-        get :play, :id => @comic.id, :count => 1500
-        assigns(:panel_count).should eq Comic.max_panel_size
-      end
-      it '不正な値が入ると@countにデフォルト最大値が入る' do
-        get :play, :id => @comic.id, :page_size => 0
-        assigns(:panel_count).should eq Comic.default_panel_size
-      end
-    end
-    context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :play, :id => @comic.id
-        response.should be_success
-      end
-      it 'コミックモデルに単体取得を問い合わせている' do
-        Comic.should_receive(:show).exactly(1)\r
-        get :play, :id => @comic.id
-      end
-      it '@comicにアレを取得している' do
-        get :play, :id => @comic.id
-        assigns(:comic).id.should eq(@comic.id)
-      end
-      context 'html形式' do
-        it 'playテンプレートを描画する' do
-          get :play, :id => @comic.id
-          response.should render_template("play")
-        end
-      end
-      context 'json形式' do
-        it 'jsonデータを返す' do
-          get :play, :id => @comic.id, :format => :json
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
-        end
-        it 'データがアレになっている' do
-          get :play, :id => @comic.id, :format => :json
-          json = JSON.parse response.body
-          json["title"].should match(/normal/)
-        end
-      end
-    end
-    context '作家権限がないとき' do
-      before do
-        sign_out @user
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :play, :id => @comic.id
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          get :play, :id => @comic.id
-          response.body.should redirect_to '/users/sign_in'
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          get :play, :id => @comic.id, :format => :json
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          get :play, :id => @comic.id, :format => :json
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-  end
-
-  describe 'コミック数取得に於いて' do
-    before do
-      Comic.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
-        it 'データがHash構造になっていてコミック数が1である' do
-          get :count, :format => :json
-          json = JSON.parse response.body
-          json["count"].should == 3
-        end
-      end
-    end
-  end
-
-  describe '新規作成フォーム表示に於いて' do
-    before do
-      sign_in @user
-    end
-    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 'コミックモデルにデフォルト値補充を依頼している' do
+            get :show, :id => hidden, :format => :json\r
+          }.should raise_error(ActiveRecord::Forbidden)\r
+        end\r
+      end\r
+    end\r
+=end\r
+  end\r
+  describe 'コミック数取得に於いて' do\r
+    before do\r
+      Comic.should_receive(:visible_count).and_return(3)\r
+#      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :count, :format => :json\r
+        response.should be_success \r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :count, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+        it 'データがHash構造になっていてコミック数が1である' do\r
+          get :count, :format => :json\r
+          json = JSON.parse response.body\r
+          json["count"].should == 3\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '新規作成フォーム表示に於いて' do\r
+    before do\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :new\r
+        response.should be_success \r
+      end\r
+      it '@comicに新規データを用意している' do\r
+        get :new\r
+        assigns(:comic).should be_a_new(Comic)\r
+      end\r
+      it 'コミックモデルにデフォルト値補充を依頼している' do\r
         Comic.any_instance.should_receive(:supply_default).exactly(1)\r
-        get :new
-      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
-    end
-    context '作家権限がないとき' do
-      before do
-        sign_out @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
-    end
-  end
-
-  describe '新規作成に於いて' do
-    before do
-      sign_in @user
-    end
-    context 'つつがなく終わるとき' do
-      it 'モデルに保存依頼する' do
-        Comic.any_instance.should_receive(:save).exactly(1)
-        post :create, :comic => Factory.attributes_for(:normal_comic)
-      end
-      it "@comicに作成されたコミックを保持していて、それがDBにある" do
-        post :create, :comic => Factory.attributes_for(:normal_comic)
-        assigns(:comic).should be_a(Comic)
-        assigns(:comic).should be_persisted
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          Comic.any_instance.stub(:save).and_return(true)
-          post :create, :comic => Factory.attributes_for(:normal_comic)
-          response.status.should eq 302
-        end
-        it '作成されたコミックの表示ページへ遷移する' do
-#          Comic.any_instance.stub(:save).and_return(true)
-          post :create, :comic => Factory.attributes_for(:normal_comic)
-          response.should redirect_to(Comic.last)
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード200 OKを返す' do
-#          Comic.any_instance.stub(:save).and_return(true)
-          post :create, :comic => Factory.attributes_for(:normal_comic), :format => :json
-          response.should be_success 
-        end
-        it '作成されたコミックをjsonデータで返す' do
-          post :create, :comic => Factory.attributes_for(:normal_comic), :format => :json
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
-        end
-        it 'データがアレになっている' do
-          post :create, :comic => Factory.attributes_for(:normal_comic), :format => :json
-          json = JSON.parse response.body
-          json["title"].should match(/normal/)
-        end
-      end
-    end
-    context '作家権限がないとき' do
-      before do
-        sign_out @user
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          post :create, :comic => Factory.attributes_for(:normal_comic)
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          post :create, :comic => Factory.attributes_for(:normal_comic)
-          response.body.should redirect_to '/users/sign_in'
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          post :create, :comic => Factory.attributes_for(:normal_comic), :format => :json
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          post :create, :comic => Factory.attributes_for(:normal_comic), :format => :json
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-    context '検証、保存に失敗した' do
-      before do
-        Comic.any_instance.stub(:save).and_return(false)
-      end
-      it "未保存のコミックを保持している" do
-        post :create, :comic => {}
-        assigns(:comic).should be_a_new(Comic)
-      end
-      context 'html形式' do
-        it 'ステータスコード200 OKを返す' do
-          post :create, :comic => {}
-          response.status.should eq 200
-        end
-        it '新規ページを描画する' do
-          post :create, :comic => {}
-          response.should render_template("new")
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード422 unprocessable_entity を返す' do
-          post :create, :comic => {}, :format => :json
-          response.status.should eq 422
-        end
-        it '応答メッセージUnprocessable Entityを返す' do
-          post :create, :comic => {}, :format => :json
-          response.message.should match(/Unprocessable/)
-        end
-      end
-    end
-  end
-
-  describe '編集フォーム表示に於いて' do
-    before do
-      @comic = Factory :normal_comic, :author_id => @user.author.id
-      sign_in @user
-      Comic.stub(:show).and_return(@comic)
-    end
-    context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :edit, :id => @comic.id
-        response.should be_success 
-      end
-      it 'コミックモデルに単体取得を問い合わせている' do
+        get :new\r
+      end\r
+      context 'html形式' do\r
+        it 'newテンプレートを描画する' do\r
+          get :new\r
+          response.should render_template("new")\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'new.jsテンプレートを描画する' do\r
+          get :new, :format => :js\r
+          response.should render_template("new")\r
+        end\r
+      end\r
+    end\r
+    context '作家権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :new\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :new\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :new, :format => :js\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :new, :format => :js\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '新規作成に於いて' do\r
+    before do\r
+      sign_in @user\r
+      @attr = Factory.attributes_for(:comic, :author_id => @author.id, :title => 'normal')\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'モデルに保存依頼する' do\r
+        Comic.any_instance.should_receive(:save).exactly(1)\r
+        post :create, :comic => @attr\r
+      end\r
+      it "@comicに作成されたコミックを保持していて、それがDBにある" do\r
+        post :create, :comic => @attr\r
+        assigns(:comic).should be_a(Comic)\r
+        assigns(:comic).should be_persisted\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '作成されたコミックの表示ページへ遷移する' do\r
+#          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr\r
+          response.should redirect_to(Comic.last)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+#          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr, :format => :json\r
+          response.should be_success \r
+        end\r
+        it '作成されたコミックをjsonデータで返す' do\r
+          post :create, :comic => @attr, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+        it 'データがアレになっている' do\r
+          post :create, :comic => @attr, :format => :json\r
+          json = JSON.parse response.body\r
+          json["title"].should match(/normal/)\r
+        end\r
+      end\r
+    end\r
+    context '作家権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          post :create, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          post :create, :comic => @attr\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          post :create, :comic => @attr, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          post :create, :comic => @attr, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+    context '検証、保存に失敗した' do\r
+      before do\r
+        Comic.any_instance.stub(:save).and_return(false)\r
+      end\r
+      it "未保存のコミックを保持している" do\r
+        post :create, :comic => {}\r
+        assigns(:comic).should be_a_new(Comic)\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          post :create, :comic => {}\r
+          response.status.should eq 200\r
+        end\r
+        it '新規ページを描画する' do\r
+          post :create, :comic => {}\r
+          response.should render_template("new")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード422 unprocessable_entity を返す' do\r
+          post :create, :comic => {}, :format => :json\r
+          response.status.should eq 422\r
+        end\r
+        it '応答メッセージUnprocessable Entityを返す' do\r
+          post :create, :comic => {}, :format => :json\r
+          response.message.should match(/Unprocessable/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '編集フォーム表示に於いて' do\r
+    before do\r
+      @comic = Factory :comic, :author_id => @user.author.id\r
+      sign_in @user\r
+      Comic.stub(:show).and_return(@comic)\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :edit, :id => @comic.id\r
+        response.should be_success \r
+      end\r
+      it 'コミックモデルに単体取得を問い合わせている' do\r
         Comic.should_receive(:show).exactly(1)\r
-        get :edit, :id => @comic.id
-      end
-      it '@comicにデータを用意している' do
-        get :edit, :id => @comic.id
-        assigns(:comic).should eq @comic
-      end
-      context 'html形式' do
-        it 'editテンプレートを描画する' do
-          get :edit, :id => @comic.id
-          response.should render_template("edit")
-        end
-      end
-      context 'js形式' do
-        it 'edit.jsテンプレートを描画する' do
-          get :edit, :id => @comic.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 => @comic.id
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          get :edit, :id => @comic.id
-          response.body.should redirect_to '/users/sign_in'
-        end
-      end
-      context 'js形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          get :edit, :id => @comic.id, :format => :js
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          get :edit, :id => @comic.id, :format => :js
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-  end
-
-  describe '更新に於いて' do
+        get :edit, :id => @comic.id\r
+      end\r
+      it '@comicにデータを用意している' do\r
+        get :edit, :id => @comic.id\r
+        assigns(:comic).should eq @comic\r
+      end\r
+      context 'html形式' do\r
+        it 'editテンプレートを描画する' do\r
+          get :edit, :id => @comic.id\r
+          response.should render_template("edit")\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'edit.jsテンプレートを描画する' do\r
+          get :edit, :id => @comic.id, :format => :js\r
+          response.should render_template("edit")\r
+        end\r
+      end\r
+    end\r
+    context '作家権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :edit, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :edit, :id => @comic.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :edit, :id => @comic.id, :format => :js\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :edit, :id => @comic.id, :format => :js\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '更新に於いて' do\r
     before do\r
-      @comic = Factory :normal_comic, :author => @author
-      sign_in @user
-    end
-    context '事前チェックしておく' do
-      it 'コミックモデルに単体取得を問い合わせている' do
+      @comic = Factory :comic, :author => @author\r
+      @attr = Factory.attributes_for(:comic, :author_id => @author.id, :title => 'updated title', :visible => 0)\r
+      sign_in @user\r
+    end\r
+    context '事前チェックしておく' do\r
+      it 'コミックモデルに単体取得を問い合わせている' do\r
         Comic.stub(:show).with(any_args()).and_return @comic\r
         Comic.should_receive(:show).exactly(1)\r
-        put :update, :id => @comic.id, :comic => Factory.attributes_for(:normal_comic)
-      end
-      it 'モデルに更新を依頼する' do
-        Comic.any_instance.should_receive(:update_attributes).with(any_args)
-        put :update, :id => @comic.id, :comic => Factory.attributes_for(:normal_comic)
-      end
-      it '@comicにアレを取得している' do
-        put :update, :id => @comic.id, :comic => Factory.attributes_for(:normal_comic)
-        assigns(:comic).id.should eq(@comic.id)
-      end
-    end
-    context 'つつがなく終わるとき' do
+        put :update, :id => @comic.id, :comic => @attr\r
+      end\r
+      it 'モデルに更新を依頼する' do\r
+        Comic.any_instance.should_receive(:update_attributes).with(any_args)\r
+        put :update, :id => @comic.id, :comic => @attr\r
+      end\r
+      it '@comicにアレを取得している' do\r
+        put :update, :id => @comic.id, :comic => @attr\r
+        assigns(:comic).id.should eq(@comic.id)\r
+      end\r
+    end\r
+    context 'つつがなく終わるとき' do\r
       it '更新される' do\r
-        put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic)\r
-        Comic.find(@comic.id).visible.should eq 0
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          Comic.any_instance.stub(:update_attributes).with(any_args()).and_return(true)
-          put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic)
-          response.status.should eq 302
-        end
-        it '更新されたコミックの表示ページへ遷移する' do
-          put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic)
-          response.should redirect_to(@comic)
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード200 OKを返す' do
-          Comic.any_instance.stub(:update_attributes).with(any_args()).and_return(true)
-          put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic), :format => :json
-          response.should be_success 
-        end
-        it 'ページ本体は特に返さない' do
-          Comic.any_instance.stub(:update_attributes).with(any_args()).and_return(true)
-          put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic), :format => :json
-          response.body.should match /./
-        end
-      end
-    end
-    context '作家権限がないとき' do
-      before do
-        sign_out @user
-      end
-      it 'ステータスコード302 Foundを返す' do
-        put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic)
-        response.status.should eq 302
-      end
-      context 'html形式' do
-        it 'サインインページへ遷移する' do
-          put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic)
-          response.body.should redirect_to '/users/sign_in'
-        end
-      end
-      context 'json形式' do
-        it '応答メッセージにUnauthorizedを返す' do
-          put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic), :format => :json
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-    context '検証、保存に失敗したとき' do
-      before do
-        Comic.any_instance.stub(:update_attributes).and_return(false)
-      end
-      context 'html形式' do
-        it 'ステータスコード200 Okを返す' do
-          put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic)
-          response.status.should eq 200
-        end
-        it '編集ページを描画する' do
-          put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic)
-          response.should render_template("edit")
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード422 unprocessable_entity を返す' do
-          Comic.any_instance.stub(:update_attributes).and_return(false)
-          put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic), :format => :json
-          response.status.should eq 422
-        end
-        it '応答メッセージUnprocessable Entityを返す' do
-          put :update, :id => @comic.id, :comic => Factory.attributes_for(:hidden_comic), :format => :json
-          response.message.should match(/Unprocessable/)
-        end
-      end
-    end
-  end
-
-
-end
+        put :update, :id => @comic.id, :comic => @attr\r
+        Comic.find(@comic.id).visible.should eq 0\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          Comic.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '更新されたコミックの表示ページへ遷移する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.should redirect_to(@comic)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          Comic.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.should be_success \r
+        end\r
+        it 'ページ本体は特に返さない' do\r
+          Comic.any_instance.stub(:update_attributes).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.body.should match /./\r
+        end\r
+      end\r
+    end\r
+    context '作家権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      it 'ステータスコード302 Foundを返す' do\r
+        put :update, :id => @comic.id, :comic => @attr\r
+        response.status.should eq 302\r
+      end\r
+      context 'html形式' do\r
+        it 'サインインページへ遷移する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+    context '検証、保存に失敗したとき' do\r
+      before do\r
+        Comic.any_instance.stub(:update_attributes).and_return(false)\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード200 Okを返す' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.status.should eq 200\r
+        end\r
+        it '編集ページを描画する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.should render_template("edit")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード422 unprocessable_entity を返す' do\r
+          Comic.any_instance.stub(:update_attributes).and_return(false)\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.status.should eq 422\r
+        end\r
+        it '応答メッセージUnprocessable Entityを返す' do\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.message.should match(/Unprocessable/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+\r
+end\r