OSDN Git Service

fix js manifest
[pettanr/pettanr.git] / spec / controllers / scrolls_controller_spec.rb
index 9a93a82..cb047c0 100644 (file)
@@ -4,71 +4,156 @@ require 'spec_helper'
 describe ScrollsController do
   before do
     @admin =FactoryGirl.create :admin
+    @user_yas = FactoryGirl.create :user_yas_with_owner
+    @user_rom = FactoryGirl.create :user_rom
+    @author_yas =  @user_yas.author
   end
-  
+
 if Manifest.manifest.magic_numbers['run_mode'] == 1
   describe '一覧表示に於いて' do
     before do
-      @author_yas =  FactoryGirl.create :yas_with_scrolls
-      @user_yas = @author_yas.user
+      factory_contents :scroll_hello, @author_yas
     end
     
-    context 'つつがなく終わるとき' do
+    context '正常系の共通処理' do
       before do
         sign_in @user_yas
       end
+      it 'ステータス OKを返して、ファイラーまたはjsonデータを返す。' do
+        list_should_return_filer_or_json :index
+      end
+      it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
+        get :index
+        expect(assigns(:my_model_class)).to be Scroll
+      end
+      it 'リストグループのマニフェストから新着リストの取得処理を@listに取得している' do
+        get :index
+        expect(assigns(:list).item_name).to eq('scroll')
+        expect(assigns(:list).list_name).to eq('public')
+      end
       it '@itemsにリストを取得している' do
         get :index
-        except(assigns(:items).size).to be >= 3
+        expect(assigns(:items).size).to be >= 3
       end
-      it 'ステータスコード200 OKを返す' do
-        list_should_return_filer_or_json :index
+      context 'html形式' do
+        it '@filerにファイラーを取得している' do
+          get :index
+          expect(assigns(:filer).class).to be Locmare::Filer
+        end
+      end
+      context 'json形式' do
+        it '@filerにファイラーをセットしていない' do
+          get :index, format: :json
+          expect(assigns(:filer)).to be nil
+        end
       end
     end
-    context '権限' do
-      it 'ユーザ権限はないが管理者権限があるとき 200 OKを返す' do
+    context '件数取得' do
+      before do
+        sign_in @user_yas
+      end
+      it 'ステータス OKを返す' do
+        return_ok_at_get :count, format: :json
+      end
+      context 'html形式' do
+        it '必要ないので実装していない' do
+          get :count
+          expect(response.status).to eq(406)
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :count, format: :json
+          expect {JSON.parse(response.body)}.not_to raise_error
+        end
+      end
+    end
+    context 'サインインの状態が例外的なとき' do
+      it 'ユーザではなく管理者でも通常通り応答する' do
         sign_in @admin
         return_ok_at_get :index
+        return_ok_at_get :index, format: :json
       end
-      it 'ユーザだが作家登録していないとき 200 OKを返す' do
-        @user_rom = FactoryGirl.create :user_rom
+      it '創作活動してないROM専の読者にも通常通り応答する' do
         sign_in @user_rom
         return_ok_at_get :index
+        return_ok_at_get :index, format: :json
       end
-      it 'sign_inを返す' do
+      it 'ゲスト(サインインしていない)はサインインページに遷移する' do
         announce_sign_in_at_get :index
       end
     end
   end
   describe '作家フィルタ一覧及びカウント' do
     before do
-      @author_yas =  FactoryGirl.create :yas_with_scrolls
-      @user_yas = @author_yas.user
-      @scroll = @author_yas.scrolls.first
+      factory_contents :scroll_hello, @author_yas
     end
-    context 'つつがなく終わるとき' do
+    
+    context '正常系の共通処理' do
       before do
         sign_in @user_yas
       end
+      it 'ステータス OKを返して、ファイラーまたはjsonデータを返す。' do
+        list_should_return_filer_or_json :by_author, id: @author_yas.id
+      end
+      it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
+        get :by_author, id: @author_yas.id
+        expect(assigns(:my_model_class)).to be Scroll
+      end
+      it 'リストグループのマニフェストから新着リストの取得処理を@listに取得している' do
+        get :by_author, id: @author_yas.id
+        expect(assigns(:list).item_name).to eq('scroll')
+        expect(assigns(:list).list_name).to eq('by_author')
+      end
       it '@itemsにリストを取得している' do
-        get :by_author
-        except(assigns(:items).size).to be >= 3
+        get :by_author, id: @author_yas.id
+        expect(assigns(:items).size).to be >= 3
       end
-      it 'ステータスコード200 OKを返す' do
-        list_should_return_filer_or_json :by_author, id: @author_yas.id
+      context 'html形式' do
+        it '@filerにファイラーを取得している' do
+          get :by_author, id: @author_yas.id
+          expect(assigns(:filer).class).to be Locmare::Filer
+        end
+      end
+      context 'json形式' do
+        it '@filerにファイラーをセットしていない' do
+          get :by_author, id: @author_yas.id, format: :json
+          expect(assigns(:filer)).to be nil
+        end
+      end
+    end
+    context '件数取得' do
+      before do
+        sign_in @user_yas
+      end
+      it 'ステータス OKを返す' do
+        return_ok_at_get :count_by_author, id: @author_yas.id, format: :json
+      end
+      context 'html形式' do
+        it '必要ないので実装していない' do
+          get :count_by_author, id: @author_yas.id
+          expect(response.status).to eq(406)
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :count_by_author, id: @author_yas.id, format: :json
+          expect {JSON.parse(response.body)}.not_to raise_error
+        end
       end
     end
-    context '権限' do
-      it 'ユーザ権限はないが管理者権限があるとき 200 OKを返す' do
+    context 'サインインの状態が例外的なとき' do
+      it 'ユーザではなく管理者でも通常通り応答する' do
         sign_in @admin
-        return_ok_at_get :by_author
+        return_ok_at_get :by_author, id: @author_yas.id
+        return_ok_at_get :by_author, id: @author_yas.id, format: :json
       end
-      it 'ユーザだが作家登録していないとき 200 OKを返す' do
-        @user_rom = FactoryGirl.create :user_rom, id: @author_yas.id
+      it '創作活動してないROM専の読者にも通常通り応答する' do
         sign_in @user_rom
-        return_ok_at_get :by_author
+        return_ok_at_get :by_author, id: @author_yas.id
+        return_ok_at_get :by_author, id: @author_yas.id, format: :json
       end
-      it 'sign_inを返す' do
+      it 'ゲスト(サインインしていない)はサインインページに遷移する' do
         announce_sign_in_at_get :by_author, id: @author_yas.id
       end
     end
@@ -76,713 +161,440 @@ if Manifest.manifest.magic_numbers['run_mode'] == 1
   
   describe '単体表示に於いて' do
     before do
-      @author_yas =  FactoryGirl.create :yas_with_scrolls
-      @user_yas = @author_yas.user
-      sign_in @user_yas
-      @scroll = @author_yas.scrolls.first
+      @item =  FactoryGirl.create :scroll_hello, author: @author_yas
+      @item_id = @item.id
     end
-    context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :show, :id => @scroll.id
-        response.should be_success
+    context '正常系の共通処理' do
+      before do
+        sign_in @user_yas
       end
-      it '@itemにアレを取得している' do
-        get :show, :id => @scroll.id
-        assigns(:item).id.should eq(@scroll.id)
+      it '[html, json, prof]でステータスコード200 OKを返す' do
+        return_ok_at_get :show, id: @item_id
+        return_ok_at_get :show, id: @item_id, format: :json
+        return_ok_at_get :show, id: @item_id, format: :prof
+      end
+      it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
+        get :show, id: @item_id
+        expect(assigns(:my_model_class)).to be Scroll
+      end
+      it '@itemにリクエストしたアイテムを取得している' do
+        get :show, id: @item_id
+        expect(assigns(:item)).to eq(@item)
       end
       context 'html形式' do
         it 'showテンプレートを描画する' do
-          get :show, :id => @scroll.id
-          response.should render_template("show")
+          get :show, id: @item_id
+          expect(response).to render_template("show")
         end
       end
       context 'json形式' do
         it 'jsonデータを返す' do
-          get :show, :id => @scroll.id, :format => :json
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+          get :show, id: @item_id, format: :json
+          expect {JSON.parse(response.body)}.not_to raise_error
+        end
+        it 'プロファイラーは必要ないので@profilerに用意していない' do
+          get :show, id: @item_id, format: :json
+          expect(assigns(:profiler)).to be nil
         end
       end
       context 'prof形式' do
-        it 'profilerを描画する' do
-          get :show, :id => @scroll.id, :format => :prof
-          response.should render_template("templates/r/profiler/profiler")
+        it 'プロファイラーテンプレートを描画する' do
+          get :show, id: @item_id, format: :prof
+          expect(response).to render_template("templates/r/profiler/profiler")
         end
       end
     end
-    context 'ユーザ権限がないとき' do
+    context 'サインインの状態が例外的なとき' do
+      it 'ユーザではなく管理者でも通常通り応答する' do
+        sign_in @admin
+        return_ok_at_get :show, id: @item_id
+        return_ok_at_get :show, id: @item_id, format: :json
+      end
+      it '創作活動してないROM専の読者にも通常通り応答する' do
+        sign_in @user_rom
+        return_ok_at_get :show, id: @item_id
+        return_ok_at_get :show, id: @item_id, format: :json
+      end
+      it 'ゲスト(サインインしていない)はサインインページに遷移する' do
+        announce_sign_in_at_get :show, id: @item_id
+      end
+    end
+  end
+  
+  describe 'プレイリストに於いて' do
+    before do
+      @item =  FactoryGirl.create :scroll_hello_with_scroll_panels, author: @author_yas
+      @item_id = @item.id
+    end
+    context '正常系の共通処理' do
       before do
-        sign_out @user_yas
+        sign_in @user_yas
+      end
+      it '[html, json]でステータス OKを返す' do
+        return_ok_at_get :play, id: @item_id
+        return_ok_at_get :play, id: @item_id, format: :json
+      end
+      it 'コントローラのマニフェストからScrollPanelモデルを@my_model_classに取得している' do
+        # リクエストの対象はスクロールであるが、返されるのはスクコマのリストである。
+        # くれぐれも間違えないように。 
+        get :play, id: @item_id
+        expect(assigns(:my_model_class)).to be ScrollPanel
+      end
+      it '@itemにリクエストしたスクロールを取得している' do
+        get :play, id: @item_id
+        expect(assigns(:item)).to eq(@item)
+      end
+      it 'リストグループのマニフェストからプレイリストの取得処理を@listに取得している' do
+        get :play, id: @item_id
+        expect(assigns(:list).item_name).to eq('scroll_panel')
+        expect(assigns(:list).list_name).to eq('play')
+      end
+      it '@itemsにプレイリストを取得している' do
+        get :play, id: @item_id
+        expect(assigns(:items).size).to be >= 3
+        expect(assigns(:count)).to be >= 3
+        expect(assigns(:pager)).not_to be nil
       end
       context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :show, :id => @scroll.id
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          get :show, :id => @scroll.id
-          response.body.should redirect_to '/users/sign_in'
+        it 'playテンプレートを描画する' do
+          get :play, id: @item_id
+          expect(response).to render_template("play")
         end
       end
       context 'json形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          get :show, :id => @scroll.id, :format => :json
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          get :show, :id => @scroll.id, :format => :json
-          response.message.should match(/Unauthorized/)
+        it 'jsonデータを返す' do
+          get :play, id: @item_id, format: :json
+          expect {JSON.parse(response.body)}.not_to raise_error
         end
       end
     end
-    context 'ユーザ権限はないが管理者権限があるとき' do
-      before do
-        sign_out @user_yas
+    context 'サインインの状態が例外的なとき' do
+      it 'ユーザではなく管理者でも通常通り応答する' do
         sign_in @admin
+        return_ok_at_get :play, id: @item_id
+        return_ok_at_get :play, id: @item_id, format: :json
       end
-      it 'ステータスコード200 OKを返す' do
-        get :show, :id => @scroll.id
-        response.should be_success 
+      it '創作活動してないROM専の読者にも通常通り応答する' do
+        sign_in @user_rom
+        return_ok_at_get :play, id: @item_id
+        return_ok_at_get :play, id: @item_id, format: :json
+      end
+      it 'ゲスト(サインインしていない)はサインインページに遷移する' do
+        announce_sign_in_at_get :play, id: @item_id
       end
     end
-    context 'ユーザだが作家登録していないとき' do
+  end
+  
+  describe '新規作成フォーム表示に於いて' do
+    before do
+    end
+    context '正常系の共通処理' do
       before do
-        sign_out @user_yas
-        @user_ghost = FactoryGirl.create :user_ghost
-        sign_in @user_ghost
+        sign_in @user_yas
       end
-      context 'html形式' do
-        it 'ステータスコード200 OKを返す' do
-          get :show, :id => @scroll.id
-          response.should be_success
-        end
+      it '[html, json]でステータス OKを返す' do
+        return_ok_at_get :new
+        return_ok_at_get :new, format: :json
+      end
+      it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
+        get :new
+        expect(assigns(:my_model_class)).to be Scroll
+      end
+      it '@itemに新規データを用意している' do
+        get :new
+        @item = assigns(:item)
+        expect(@item.is_a?(Scroll)).to be true
+        expect(@item.new_record?).to be true
+      end
+      it '@formに入力フォーム(Bucket)を取得している' do
+        get :new
+        @item = assigns(:item)
+        expect(assigns(:form).item).to eq(@item)
+        expect(assigns(:form).mounted).to eq(true)
+        expect(assigns(:form).submit).to eq(true)
+      end
+      it 'スクロールモデルにデフォルト値補充とブーストを依頼している' do
+        allow_any_instance_of(Scroll).to receive(:supply_default)
+        allow_any_instance_of(Scroll).to receive(:boosts)
+        expect_any_instance_of(Scroll).to receive(:supply_default)
+        expect_any_instance_of(Scroll).to receive(:boosts)
+        get :new
       end
-    end
-=begin
-    context '対象スクロールがないとき' do
       context 'html形式' do
-        it '例外404 not_foundを返す' do
-          lambda{
-            get :show, :id => 0
-          }.should raise_error(ActiveRecord::RecordNotFound)
+        it 'formテンプレートを描画する' do
+          get :new
+          expect(response).to render_template("templates/r/form/form")
         end
       end
       context 'json形式' do
-        it '例外404 not_foundを返す' do
-          lambda{ 
-            get :show, :id => 0, :format => :json
-          }.should raise_error(ActiveRecord::RecordNotFound)
+        it 'jsonデータを返す' do
+          get :new, format: :json
+          expect {JSON.parse(response.body)}.not_to raise_error
         end
       end
     end
-    context '非公開スクロールを見ようとしたとき' do
-      context 'html形式' do
-        it '例外403 forbiddenを返す' do
-          Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
-          hidden = FactoryGirl.create :hidden_scroll, :author_id => @author.id
-          lambda{
-            get :show, :id => hidden
-          }.should raise_error(ActiveRecord::Forbidden)
-        end
+    context 'サインインの状態が例外的なとき' do
+      before do
       end
-      context 'json形式' do
-        it '例外403 forbiddenを返す' do
-          Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
-          hidden = FactoryGirl.create :hidden_scroll, :author_id => @author.id
-          lambda{
-            get :show, :id => hidden, :format => :json
-          }.should raise_error(ActiveRecord::Forbidden)
-        end
+      it '創作活動してないROM専の読者には作家登録ページへ遷移する' do
+        sign_in @user_rom
+        get :new
+        announce_regist_author_for_html
+        announce_regist_author_for_json :get
+      end
+      it 'ゲスト(サインインしていない)はサインインページに遷移する' do
+        announce_sign_in_at_get :new
+      end
+      it 'ユーザではなく管理者でもサインインページに遷移する' do
+        sign_in @admin
+        announce_sign_in_at_get :new
       end
     end
-=end
   end
-  
-  describe '閲覧に於いて' do
+
+  describe '新規作成に於いて' do
     before do
-      @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
-      @panel = FactoryGirl.create :panel, :author_id => @author.id
-      @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
-      Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
-      Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
-      ScrollPanel.stub(:count).and_return(10)
-      ScrollPanel.stub(:play_list).with(any_args).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
-      sign_in @user
+      @attributes = FactoryGirl.attributes_for(:scroll_hello, author_id: @author_yas.id)
+      @attr = {:scroll => @attributes}
     end
-    context 'つつがなく終わるとき' do
-      it '@scroll_panelsにリストを取得している' do
-        get :play, :id => @scroll.id
-        assigns(:scroll_panels).should have_at_least(3).items
+    context '正常系の共通処理' do
+      before do
+        sign_in @user_yas
+      end
+      it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
+        allow_save Scroll
+        post_save @attr
+        expect(assigns(:my_model_class)).to be Scroll
+      end
+      it '@itemに新規アイテムを用意している' do
+        allow_save Scroll
+        post_save @attr
+        @item = assigns(:item)
+        expect(@item.is_a?(Scroll)).to be true
       end
       context 'html形式' do
-        it 'ステータスコード200 OKを返す' do
-          get :play, :id => @scroll.id
-          response.should be_success 
-        end
-        it 'scrollテンプレートを描画する' do
-          get :play, :id => @scroll.id
-          response.should render_template("scroll")
+        it 'ステータスコード302 Foundを返して, 作成されたアイテムの表示ページへ遷移する' do
+          post_save @attr
+          expect(response.status).to eq(302)
+          expect(response).to redirect_to Scroll.last
         end
       end
       context 'json形式' do
-        it 'ステータスコード200 OKを返す' do
-          get :play, :id => @scroll.id, :format => :json
-          response.should be_success 
-        end
-        it 'jsonデータを返す' do
-          get :play, :id => @scroll.id, :format => :json
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        it 'ステータスコード200 OKを返して, 作成されたアイテムをjsonデータで返す' do
+          post_save @attr.merge(:format => :json)
+          expect(response).to be_success
+          expect {JSON.parse(response.body)}.not_to raise_error
         end
       end
     end
-    context 'ユーザ権限がないとき' do
+    context '検証、保存に失敗したとき' do
       before do
-        sign_out @user
+        sign_in @user_yas
+        reject_save Scroll
       end
       context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :play, :id => @scroll.id
-          response.status.should eq 302
+        it 'ステータスコード200 OKを返して, formテンプレートを描画する' do
+          post_save @attr
+          expect(response).to be_success
+          expect(response).to render_template("templates/r/form/form")
         end
-        it 'サインインページへ遷移する' do
-          get :play, :id => @scroll.id
-          response.should redirect_to '/users/sign_in'
+        it '@formに入力フォーム(Bucket)を取得している' do
+          post_save @attr
+          @item = assigns(:item)
+          expect(assigns(:form).item).to eq(@item)
+          expect(assigns(:form).mounted).to eq(true)
+          expect(assigns(:form).submit).to eq(true)
         end
       end
       context 'json形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          get :play, :id => @scroll.id, :format => :json
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          get :play, :id => @scroll.id, :format => :json
-          response.message.should match(/Unauthorized/)
+        it 'ステータスコード422 unprocessable_entityを返して, 応答メッセージUnprocessable Entityを返す' do
+          post_save @attr.merge(:format => :json)
+          expect(response.status).to eq(422)
+          expect(response.message).to match(/Unprocessable/)
         end
       end
     end
-    context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bとき' do
+    context 'ã\82µã\82¤ã\83³ã\82¤ã\83³ã\81®ç\8a¶æ\85\8bã\81\8cä¾\8bå¤\96ç\9a\84ã\81ªとき' do
       before do
-        sign_out @user
-        sign_in @admin
+        allow_save Scroll
       end
-      it 'ステータスコード200 OKを返す' do
-        get :play, :id => @scroll.id
-        response.should be_success 
+      it '創作活動してないROM専の読者には作家登録ページへ遷移する' do
+        sign_in @user_rom
+        post_save @attr
+        announce_regist_author_for_html
+        announce_regist_author_for_json :post, @attr
       end
-    end
-    context 'ユーザだが作家登録していないとき' do
-      before do
-        @author.destroy
+      it 'ゲスト(サインインしていない)はサインインページに遷移する' do
+        post_save @attr
+        announce_sign_in_for_html
+        post_save @attr.merge(:format => :json)
+        announce_sign_in_for_json
       end
-      it 'ステータスコード200 OKを返す' do
-        get :play, :id => @scroll.id
-        response.should be_success 
+      it 'ユーザではなく管理者でもサインインページに遷移する' do
+        sign_in @admin
+        post_save @attr
+        announce_sign_in_for_html
+        post_save @attr.merge(:format => :json)
+        announce_sign_in_for_json
       end
     end
   end
 
-  describe 'スクロール数取得に於いて' do
+  describe '編集フォーム表示に於いて' do
     before do
-      Scroll.should_receive(:visible_count).and_return(3)
-#      sign_in @user
+      @item =  FactoryGirl.create :scroll_hello_with_scroll_panels, author: @author_yas
+      @item_id = @item.id
     end
-    context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :count, :format => :json
-        response.should be_success 
+    context '正常系の共通処理' do
+      before do
+        sign_in @user_yas
+      end
+      it '[html, json]でステータス OKを返す' do
+        return_ok_at_get :edit, id: @item_id
+        return_ok_at_get :edit, id: @item_id, format: :json
+      end
+      it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
+        get :edit, id: @item_id
+        expect(assigns(:my_model_class)).to be Scroll
+      end
+      it '@itemにリクエストしたスクロールを取得している' do
+        get :edit, id: @item_id
+        @item = assigns(:item)
+        expect(@item.is_a?(Scroll)).to be true
+        expect(@item.new_record?).not_to be true
+      end
+      it '@formに入力フォーム(Bucket)を取得している' do
+        get :edit, id: @item_id
+        @item = assigns(:item)
+        expect(assigns(:form).item).to eq(@item)
+        expect(assigns(:form).mounted).to eq(true)
+        expect(assigns(:form).submit).to eq(true)
+      end
+      it 'スクロールモデルにデフォルト値補充とブーストを依頼している' do
+        allow_any_instance_of(Scroll).to receive(:boosts)
+        expect_any_instance_of(Scroll).to receive(:boosts)
+        get :edit, id: @item_id
+      end
+      context 'html形式' do
+        it 'formテンプレートを描画する' do
+          get :edit, id: @item_id
+          expect(response).to render_template("templates/r/form/form")
+        end
       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
+          get :edit, id: @item_id, format: :json
+          expect {JSON.parse(response.body)}.not_to raise_error
         end
       end
     end
+    context 'サインインの状態が例外的なとき' do
+      before do
+        allow_save Scroll
+      end
+      it '創作活動してないROM専の読者には作家登録ページへ遷移する' do
+        sign_in @user_rom
+        get :edit, id: @item_id
+        expect(response.status).to eq(302)
+        expect(response).to redirect_to new_author_path
+      end
+      it 'ゲスト(サインインしていない)はサインインページに遷移する' do
+        announce_sign_in_at_get :new
+      end
+      it 'ユーザではなく管理者でもサインインページに遷移する' do
+        sign_in @admin
+        announce_sign_in_at_get :new
+      end
+    end
   end
 
-  describe 'æ\96°è¦\8fä½\9cæ\88\90ã\83\95ã\82©ã\83¼ã\83 è¡¨ç¤ºに於いて' do
+  describe 'æ\9b´æ\96°に於いて' do
     before do
-      sign_in @user
+      @item =  FactoryGirl.create :scroll_hello_with_scroll_panels, author: @author_yas
+      @item_id = @item.id
+      @attributes = FactoryGirl.attributes_for(:scroll_hidden, author_id: @author_yas.id)
+      @attr = {:id => @item_id, :scroll => @attributes}
     end
-    context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :new
-        response.should be_success 
+    context '正常系の共通処理' do
+      before do
+        sign_in @user_yas
       end
-      it '@scrollに新規データを用意している' do
-        get :new
-        assigns(:scroll).should be_a_new(Scroll)
+      it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
+        allow_save Scroll
+        put_save @attr
+        expect(assigns(:my_model_class)).to be Scroll
       end
-      it 'スクロールモデルにデフォルト値補充を依頼している' do
-        Scroll.any_instance.should_receive(:supply_default).exactly(1)
-        get :new
+      it '@itemにリクエストしたアイテムを取得して, 更新している' do
+        allow_save Scroll
+        put_save @attr
+        @item = assigns(:item)
+        expect(@item.is_a?(Scroll)).to be true
+        expect(@item.visible).to eq(0)
       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")
+        it 'ステータスコード302 Foundを返して, 作成されたアイテムの表示ページへ遷移する' do
+          put_save @attr
+          expect(response.status).to eq(302)
+          expect(response).to redirect_to @item
         end
       end
       context 'json形式' do
-        it 'jsonデータを返す' do
-          get :new, :format => :json
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
-        end
-        it 'スクロールモデルにjson単体出力オプションを問い合わせている' do
-          Scroll.should_receive(:show_json_opt).exactly(1)
-          get :new, :format => :json
+        it 'ステータスコード200 OKを返して, ページ本体は特に返さない' do
+          put_save @attr.merge(:format => :json)
+          expect(response).to be_success
+          expect(response.message).to match /./
         end
       end
     end
-    context 'ユーザ権限がないとき' do
+    context '検証、保存に失敗したとき' do
       before do
-        sign_out @user
+        sign_in @user_yas
+        reject_save Scroll
       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'
+        it 'ステータスコード200 OKを返して, formテンプレートを描画する' do
+          put_save @attr
+          expect(response).to be_success
+          expect(response).to render_template("templates/r/form/form")
         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/)
+        it '@formに入力フォーム(Bucket)を取得している' do
+          put_save @attr
+          @item = assigns(:item)
+          expect(assigns(:form).item).to eq(@item)
+          expect(assigns(:form).mounted).to eq(true)
+          expect(assigns(:form).submit).to eq(true)
         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/)
+        it 'ステータスコード422 unprocessable_entityを返して, 応答メッセージUnprocessable Entityを返す' do
+          put_save @attr.merge(:format => :json)
+          expect(response.status).to eq(422)
+          expect(response.message).to match(/Unprocessable/)
         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
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :new, @attr
-          response.status.should eq 302
-        end
-        it '作家登録ページへ遷移する' do
-          get :new, @attr
-          response.body.should redirect_to new_author_path
-        end
-      end
-    end
-  end
-
-  describe '新規作成に於いて' do
-    before do
-      sign_in @user
-      @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
-    end
-    context '事前チェックしておく' do
-      it 'スクロールモデルにデフォルト値補充を依頼している' do
-        Scroll.any_instance.should_receive(:supply_default).exactly(1)
-        post :create, :scroll => @attr
-      end
-      it 'スクロールモデルにカラム値復元を依頼している' do
-        Scroll.any_instance.should_receive(:attributes=).exactly(1)
-        post :create, :scroll => @attr
-      end
-      it 'スクロールモデルに上書き補充を依頼している' do
-        Scroll.any_instance.should_receive(:overwrite).exactly(1)
-        post :create, :scroll => @attr
-      end
-      it 'モデルに保存依頼する' do
-        Scroll.any_instance.should_receive(:save).exactly(1)
-        post :create, :scroll => @attr
-      end
-    end
-    context 'つつがなく終わるとき' do
-      it "@scrollに作成されたスクロールを保持していて、それがDBにある" do
-        post :create, :scroll => @attr
-        assigns(:scroll).should be_a(Scroll)
-        assigns(:scroll).should be_persisted
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          Scroll.any_instance.stub(:save).and_return(true)
-          post :create, :scroll => @attr
-          response.status.should eq 302
-        end
-        it '作成されたスクロールの表示ページへ遷移する' do
-#          Scroll.any_instance.stub(:save).and_return(true)
-          post :create, :scroll => @attr
-          response.should redirect_to(Scroll.last)
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード200 OKを返す' do
-#          Scroll.any_instance.stub(:save).and_return(true)
-          post :create, :scroll => @attr, :format => :json
-          response.should be_success 
-        end
-        it '作成されたスクロールをjsonデータで返す' do
-          post :create, :scroll => @attr, :format => :json
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
-        end
-        it 'データがアレになっている' do
-          post :create, :scroll => @attr, :format => :json
-          json = JSON.parse response.body
-          json["title"].should match(/normal/)
-          json["visible"].should_not be_nil
-        end
-      end
-    end
-    context 'ユーザ権限がないとき' do
-      before do
-        sign_out @user
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          post :create, :scroll => @attr
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          post :create, :scroll => @attr
-          response.body.should redirect_to '/users/sign_in'
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          post :create, :scroll => @attr, :format => :json
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          post :create, :scroll => @attr, :format => :json
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-    context 'ユーザ権限はないが管理者権限があるとき' do
-      before do
-        sign_out @user
-        sign_in @admin
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          post :create, :scroll => @attr
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          post :create, :scroll => @attr
-          response.body.should redirect_to '/users/sign_in'
-        end
-      end
-    end
-    context 'ユーザだが作家登録していないとき' do
-      before do
-        @author.destroy
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          post :create, :scroll => @attr
-          response.status.should eq 302
-        end
-        it '作家登録ページへ遷移する' do
-          post :create, :scroll => @attr
-          response.body.should redirect_to new_author_path
-        end
-      end
-    end
-    context '検証、保存に失敗した' do
-      before do
-        Scroll.any_instance.stub(:save).and_return(false)
-      end
-      it "未保存のスクロールを保持している" do
-        post :create, :scroll => @attr
-        assigns(:scroll).should be_a_new(Scroll)
-      end
-      context 'html形式' do
-        it 'ステータスコード200 OKを返す' do
-          post :create, :scroll => @attr
-          response.status.should eq 200
-        end
-        it '新規ページを描画する' do
-          post :create, :scroll => @attr
-          response.should render_template("new")
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード422 unprocessable_entity を返す' do
-          post :create, :scroll => @attr, :format => :json
-          response.status.should eq 422
-        end
-        it '応答メッセージUnprocessable Entityを返す' do
-          post :create, :scroll => @attr, :format => :json
-          response.message.should match(/Unprocessable/)
-        end
-      end
-    end
-  end
-
-  describe '編集フォーム表示に於いて' do
-    before do
-      @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
-      sign_in @user
-      Scroll.stub(:edit).and_return(@scroll)
-    end
-    context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :edit, :id => @scroll.id
-        response.should be_success 
-      end
-      it 'スクロールモデルに編集取得を問い合わせている' do
-        Scroll.should_receive(:edit).exactly(1)
-        get :edit, :id => @scroll.id
-      end
-      it '@scrollにデータを用意している' do
-        get :edit, :id => @scroll.id
-        assigns(:scroll).should eq @scroll
-      end
-      context 'html形式' do
-        it 'editテンプレートを描画する' do
-          get :edit, :id => @scroll.id
-          response.should render_template("edit")
-        end
-      end
-      context 'js形式' do
-        it 'edit.jsテンプレートを描画する' do
-          get :edit, :id => @scroll.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 => @scroll.id
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          get :edit, :id => @scroll.id
-          response.body.should redirect_to '/users/sign_in'
-        end
-      end
-      context 'js形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          get :edit, :id => @scroll.id, :format => :js
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          get :edit, :id => @scroll.id, :format => :js
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-    context 'ユーザ権限はないが管理者権限があるとき' do
-      before do
-        sign_out @user
-        sign_in @admin
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :edit, :id => @scroll.id
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          get :edit, :id => @scroll.id
-          response.body.should redirect_to '/users/sign_in'
-        end
-      end
-    end
-    context 'ユーザだが作家登録していないとき' do
-      before do
-        @author.destroy
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :edit, :id => @scroll.id
-          response.status.should eq 302
-        end
-        it '作家登録ページへ遷移する' do
-          get :edit, :id => @scroll.id
-          response.body.should redirect_to new_author_path
-        end
-      end
-    end
-  end
-
-  describe '更新に於いて' do
-    before do
-      @scroll = FactoryGirl.create :scroll, :author => @author
-      @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
-      sign_in @user
-    end
-    context '事前チェックしておく' do
-      it 'スクロールモデルに編集取得を問い合わせている' do
-        Scroll.stub(:edit).with(any_args()).and_return @scroll
-        Scroll.should_receive(:edit).exactly(1)
-        put :update, :id => @scroll.id, :scroll => @attr
-      end
-      it 'スクロールモデルにカラム値復元を依頼している' do
-        Scroll.any_instance.should_receive(:attributes=).exactly(1)
-        put :update, :id => @scroll.id, :scroll => @attr
-      end
-      it 'スクロールモデルに上書き補充を依頼している' do
-        Scroll.any_instance.should_receive(:overwrite).exactly(1)
-        put :update, :id => @scroll.id, :scroll => @attr
-      end
-      it 'モデルに更新を依頼する' do
-        Scroll.any_instance.stub(:save).with(any_args).and_return true
-        Scroll.any_instance.should_receive(:save).exactly(1)
-        put :update, :id => @scroll.id, :scroll => @attr
-      end
-      it '@scrollにアレを取得している' do
-        put :update, :id => @scroll.id, :scroll => @attr
-        assigns(:scroll).id.should eq(@scroll.id)
-      end
-    end
-    context 'つつがなく終わるとき' do
-      it '更新される' do
-        put :update, :id => @scroll.id, :scroll => @attr
-        Scroll.find(@scroll.id).visible.should eq 0
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
-          put :update, :id => @scroll.id, :scroll => @attr
-          response.status.should eq 302
-        end
-        it '更新されたスクロールの表示ページへ遷移する' do
-          put :update, :id => @scroll.id, :scroll => @attr
-          response.should redirect_to(@scroll)
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード200 OKを返す' do
-          Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
-          put :update, :id => @scroll.id, :scroll => @attr, :format => :json
-          response.should be_success 
-        end
-        it 'ページ本体は特に返さない' do
-          Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
-          put :update, :id => @scroll.id, :scroll => @attr, :format => :json
-          response.body.should match /./
-        end
-      end
-    end
-    context 'ユーザ権限がないとき' do
+    context 'サインインの状態が例外的なとき' do
       before do
-        sign_out @user
+        allow_save Scroll
       end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          put :update, :id => @scroll.id, :scroll => @attr
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          put :update, :id => @scroll.id, :scroll => @attr
-          response.body.should redirect_to '/users/sign_in'
-        end
+      it '創作活動してないROM専の読者には作家登録ページへ遷移する' do
+        sign_in @user_rom
+        put_save @attr
+        announce_regist_author_for_html
+        announce_regist_author_for_json :put, @attr
       end
-      context 'json形式' do
-        it '応答メッセージにUnauthorizedを返す' do
-          put :update, :id => @scroll.id, :scroll => @attr, :format => :json
-          response.message.should match(/Unauthorized/)
-        end
+      it 'ゲスト(サインインしていない)はサインインページに遷移する' do
+        put_save @attr
+        announce_sign_in_for_html
+        put_save @attr.merge(:format => :json)
+        announce_sign_in_for_json
       end
-    end
-    context 'ユーザ権限はないが管理者権限があるとき' do
-      before do
-        sign_out @user
+      it 'ユーザではなく管理者でもサインインページに遷移する' do
         sign_in @admin
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          put :update, :id => @scroll.id, :scroll => @attr
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          put :update, :id => @scroll.id, :scroll => @attr
-          response.body.should redirect_to '/users/sign_in'
-        end
-      end
-    end
-    context 'ユーザだが作家登録していないとき' do
-      before do
-        @author.destroy
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          put :update, :id => @scroll.id, :scroll => @attr
-          response.status.should eq 302
-        end
-        it '作家登録ページへ遷移する' do
-          put :update, :id => @scroll.id, :scroll => @attr
-          response.body.should redirect_to new_author_path
-        end
-      end
-    end
-    context '検証、保存に失敗したとき' do
-      before do
-        Scroll.any_instance.stub(:save).and_return(false)
-      end
-      context 'html形式' do
-        it 'ステータスコード200 Okを返す' do
-          put :update, :id => @scroll.id, :scroll => @attr
-          response.status.should eq 200
-        end
-        it '編集ページを描画する' do
-          put :update, :id => @scroll.id, :scroll => @attr
-          response.should render_template("edit")
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード422 unprocessable_entity を返す' do
-          Scroll.any_instance.stub(:save).and_return(false)
-          put :update, :id => @scroll.id, :scroll => @attr, :format => :json
-          response.status.should eq 422
-        end
-        it '応答メッセージUnprocessable Entityを返す' do
-          put :update, :id => @scroll.id, :scroll => @attr, :format => :json
-          response.message.should match(/Unprocessable/)
-        end
+        put_save @attr
+        announce_sign_in_for_html
+        put_save @attr.merge(:format => :json)
+        announce_sign_in_for_json
       end
     end
   end
@@ -810,7 +622,7 @@ if Manifest.manifest.magic_numbers['run_mode'] == 1
         assigns(:scroll).id.should eq(@scroll.id)
       end
     end
-    context 'つつがなく終わるとき' do
+    context '正常系の共通処理' do
       it '削除される' do
         lambda {
           delete :destroy, :id => @scroll.id
@@ -929,7 +741,7 @@ else
       Scroll.stub(:list).and_return([@scroll, @scroll, @scroll])
       sign_in @user
     end
-    context 'つつがなく終わるとき' do
+    context '正常系の共通処理' do
       it 'ステータスコード200 OKを返す' do
         get :index
         response.should be_success 
@@ -976,7 +788,7 @@ else
       Scroll.stub(:show).and_return(@scroll)
       sign_in @user
     end
-    context 'つつがなく終わるとき' do
+    context '正常系の共通処理' do
       it 'ステータスコード200 OKを返す' do
         get :show, :id => @scroll.id
         response.should be_success
@@ -1021,7 +833,7 @@ else
       Scroll.should_receive(:visible_count).and_return(3)
       sign_out @user
     end
-    context 'つつがなく終わるとき' do
+    context '正常系の共通処理' do
       it 'ステータスコード200 OKを返す' do
         get :count, :format => :json
         response.should be_success 
@@ -1039,7 +851,7 @@ else
     before do
       sign_in @user
     end
-    context 'つつがなく終わるとき' do
+    context '正常系の共通処理' do
       it 'ステータスコード200 OKを返す' do
         get :new
         response.should be_success 
@@ -1105,7 +917,7 @@ else
       sign_in @user
       @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
     end
-    context 'つつがなく終わるとき' do
+    context '正常系の共通処理' do
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
           Scroll.any_instance.stub(:save).and_return(true)
@@ -1163,7 +975,7 @@ else
       sign_in @user
       Scroll.stub(:edit).and_return(@scroll)
     end
-    context 'つつがなく終わるとき' do
+    context '正常系の共通処理' do
       it 'ステータスコード200 OKを返す' do
         get :edit, :id => @scroll.id
         response.should be_success 
@@ -1214,7 +1026,7 @@ else
       @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
       sign_in @user
     end
-    context 'つつがなく終わるとき' do
+    context '正常系の共通処理' do
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
           Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
@@ -1261,7 +1073,7 @@ else
       @scroll = FactoryGirl.create :scroll, :author => @author
       sign_in @user
     end
-    context 'つつがなく終わるとき' do
+    context '正常系の共通処理' do
       context 'html形式' do
         before do
           Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)