OSDN Git Service

fix spec
[pettanr/pettanr.git] / spec / manifests / scroll_spec.rb
index af004e0..b9a8b9e 100644 (file)
@@ -3,6 +3,7 @@ require 'spec_helper'
 #スクロールマニフェスト
 
 describe Scroll do
+  include ManifestsMacros
   before do
     @model = Scroll
   end
@@ -11,11 +12,11 @@ describe Scroll do
     it 'スクコマを閉じるためのバインダーである' do
       expect(@model.ancestors.include?(Peta::Binder)).to eq true
     end
-    it ' 項はない' do
+    it '親モデルは持たない' do
       expect(@model.my_peta.parent_model_name).to be_blank
     end
     describe 'ブーストに於いて' do
-      it 'ブースト特筆すべき注意事項はない' do
+      it '特筆すべき注意事項はない' do
         expect(@model.my_peta.boost.keys).to be_empty
       end
     end
@@ -26,114 +27,142 @@ describe Scroll do
     before do
       @controller = @model.my_controller
     end
-    it 'ã\83¼である' do
+    it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«ã\81®ã\81\9fã\82\81ã\81®ã\82³ã\83³ã\83\88ã\83­ã\83¼ã\83©である' do
       expect(@model.item_name).to eq 'scroll'
     end
     describe 'actionに於いて' do
       before do
         @actions = @controller.actions
+        @actions_names = ['index', 'by_author', 'by_panel', 'play', 'show', 
+          'count', 'count_by_author', 'count_by_panel', 
+          'new', 'edit', 'create', 'update', 'destroy']
       end
-      it 'はない' do
-        expect(@actions.keys.size).to eq 13
-        expect(@actions.keys).to include 'index'
-        expect(@actions.keys).to include 'by_author'
-        expect(@actions.keys).to include 'by_panel'
-        expect(@actions.keys).to include 'play'
-        expect(@actions.keys).to include 'show'
-        expect(@actions.keys).to include 'count'
-        expect(@actions.keys).to include 'count_by_author'
-        expect(@actions.keys).to include 'count_by_panel'
-        expect(@actions.keys).to include 'new'
-        expect(@actions.keys).to include 'edit'
-        expect(@actions.keys).to include 'create'
-        expect(@actions.keys).to include 'update'
-        expect(@actions.keys).to include 'destroy'
+      it 'これらのアクションが定義されている' do
+        set_actions? @actions, @actions_names
       end
-      describe 'index actionに於いて' do
+      describe 'baseに於いて' do
+      end
+      describe 'indexに於いて' do
         before do
           @action = @actions['index']
         end
-        it 'type' do
+        it 'listタイプのアクションである' do
           expect(@action.type).to eq 'list'
         end
-        it 'type' do
-          expect(@action.item_name).to eq 'scroll'
-          expect(@action.list_name).to eq 'public'
+        it 'マニフェストから設定を取り出している' do
+          # スクロールの公開リストを返すように定義している
+          set_list_action? @action, 'scroll', 'public'
         end
       end
-      describe 'by_author actionに於いて' do
+      describe 'by_authorに於いて' do
         before do
           @action = @actions['by_author']
         end
-        it 'type' do
+        it 'listタイプのアクションである' do
           expect(@action.type).to eq 'list'
         end
-        it 'type' do
-          expect(@action.item_name).to eq 'scroll'
-          expect(@action.list_name).to eq 'by_author'
+        it 'マニフェストから設定を取り出している' do
+          # スクロールの作家フィルタリストを返すように定義している
+          set_list_action? @action, 'scroll', 'by_author'
         end
       end
-      describe 'count actionに於いて' do
+      describe 'by_panelに於いて' do
+        before do
+          @action = @actions['by_panel']
+        end
+        it 'listタイプのアクションである' do
+          expect(@action.type).to eq 'list'
+        end
+        it 'マニフェストから設定を取り出している' do
+          #スクロールのコマフィルタリストを返すように定義している
+          set_list_action? @action, 'scroll', 'by_panel'
+        end
+      end
+      describe 'countに於いて' do
         before do
           @action = @actions['count']
         end
-        it 'type' do
+        it 'countタイプのアクションである' do
           expect(@action.type).to eq 'count'
         end
-        it 'type' do
-          expect(@action.item_name).to eq 'scroll'
-          expect(@action.list_name).to eq 'public'
+        it 'マニフェストから設定を取り出している' do
+          #スクロールの公開リストのカウントを返すように定義している
+          set_list_action? @action, 'scroll', 'public'
+        end
+      end
+      describe 'count_by_authorに於いて' do
+        before do
+          @action = @actions['count_by_author']
+        end
+        it 'countタイプのアクションである' do
+          expect(@action.type).to eq 'count'
+        end
+        it 'マニフェストから設定を取り出している' do
+          # スクロールの作家フィルタリストのカウントを返すように定義している
+          set_list_action? @action, 'scroll', 'by_author'
+        end
+      end
+      describe 'count_by_panelに於いて' do
+        before do
+          @action = @actions['count_by_panel']
+        end
+        it 'countタイプのアクションである' do
+          expect(@action.type).to eq 'count'
+        end
+        it 'マニフェストから設定を取り出している' do
+          # スクロールのコマフィルタリストのカウントを返すように定義している
+          set_list_action? @action, 'scroll', 'by_panel'
         end
       end
-      describe 'new actionに於いて' do
+      describe 'newに於いて' do
         before do
           @action = @actions['new']
         end
-        it 'type' do
+        it 'newタイプのアクションである' do
           expect(@action.type).to eq 'new'
         end
         it 'type' do
           expect(@action.item_name).to eq 'scroll'
         end
       end
-      describe 'edit actionに於いて' do
+      describe 'editに於いて' do
         before do
           @action = @actions['edit']
         end
-        it 'type' do
+        it 'editタイプのアクションである' do
           expect(@action.type).to eq 'edit'
         end
         it 'type' do
           expect(@action.item_name).to eq 'scroll'
         end
       end
-      describe 'create actionに於いて' do
+      describe 'createに於いて' do
         before do
           @action = @actions['create']
         end
-        it 'type' do
+        it 'createタイプのアクションである' do
           expect(@action.type).to eq 'create'
         end
         it 'type' do
           expect(@action.item_name).to eq 'scroll'
         end
       end
-      describe 'update actionに於いて' do
+      describe 'updateに於いて' do
         before do
           @action = @actions['update']
         end
-        it 'type' do
+        it 'updateタイプのアクションである' do
           expect(@action.type).to eq 'update'
         end
         it 'type' do
           expect(@action.item_name).to eq 'scroll'
         end
       end
-      describe 'destroy actionに於いて' do
+      describe 'destroyに於いて' do
         before do
           @action = @actions['destroy']
         end
-        it 'type' do
+        it 'destroyタイプのアクションである' do
           expect(@action.type).to eq 'destroy'
         end
         it 'type' do
@@ -145,23 +174,35 @@ describe Scroll do
   end
   
   describe 'モデルに於いて' do
+    before do
+      @my_manifest = @model.my_manifest
+    end
+    it 'サポート機能が動作している' do
+      expect(@my_manifest.model_name).to eq 'scroll'
+      expect(@my_manifest.classify).to eq @model
+      expect(@my_manifest.table_name).to eq 'scrolls'
+    end
+    
     describe 'associationsに於いて' do
       describe 'belongs_toに於いて' do
         before do
-          @belongs_to = @model.my_manifest.associations.belongs_to
+          @belongs_to = @my_manifest.associations.belongs_to
+          @names = ['author']
         end
-        it ' である' do
-          expect(@belongs_to.keys).to include 'author'
+        it 'これらのモデルに所属している' do
+          set_associations? @belongs_to, @names
         end
         describe 'authorに於いて' do
           before do
             @mani = @belongs_to['author']
           end
-          it 'type' do
+          it 'マニフェストから設定を取り出している' do
+            # モデル名と外部キーが定義あるいはデフォルト値補充されている
             expect(@mani.model_name).to eq 'author'
             expect(@mani.id_column).to eq 'author_id'
           end
-          it 'type' do
+          it 'サポート機能が動作している' do
+            # モデルを再現できている
             expect(@mani.model).to eq Author
           end
         end
@@ -169,21 +210,23 @@ describe Scroll do
       describe 'has_manyに於いて' do
         before do
           @has_many = @model.my_manifest.associations.has_many
+          @names = ['scroll_panels', 'panels']
         end
-        it ' である' do
-          expect(@has_many.keys).to include 'scroll_panels'
-          expect(@has_many.keys).to include 'panels'
+        it 'これらのモデルを所持している' do
+          set_associations? @has_many, @names
         end
         describe 'scroll_panelsに於いて' do
           before do
             @mani = @has_many['scroll_panels']
           end
-          it 'type' do
+          it 'マニフェストから設定を取り出している' do
+            # モデル名, 外部キーと中間モデルが定義あるいはデフォルト値補充されている
             expect(@mani.model_name).to eq 'scroll_panel'
             expect(@mani.foreign_key).to eq 'scroll_id'
             expect(@mani.through).to be nil
           end
-          it 'type' do
+          it 'サポート機能が動作している' do
+            # モデルを再現できている, 中間モデルフラグ
             expect(@mani.through?).to be false
             expect(@mani.model).to eq ScrollPanel
           end
@@ -192,12 +235,14 @@ describe Scroll do
           before do
             @mani = @has_many['panels']
           end
-          it 'type' do
+          it 'マニフェストから設定を取り出している' do
+            # モデル名, 外部キーと中間モデルが定義あるいはデフォルト値補充されている
             expect(@mani.model_name).to eq 'panel'
             expect(@mani.foreign_key).to eq 'scroll_id'
             expect(@mani.through).to eq 'scroll_panels'
           end
-          it 'type' do
+          it 'サポート機能が動作している' do
+            # モデルを再現できている, 中間モデルフラグ
             expect(@mani.through?).to be true
             expect(@mani.model).to eq Panel
           end
@@ -209,20 +254,16 @@ describe Scroll do
       before do
         @attributes = @model.my_manifest.attributes
       end
-      it ' である' do
-        expect(@attributes.keys).to include 'id'
-        expect(@attributes.keys).to include 'title'
-        expect(@attributes.keys).to include 'description'
-        expect(@attributes.keys).to include 'visible'
-        expect(@attributes.keys).to include 'author_id'
-        expect(@attributes.keys).to include 'created_at'
-        expect(@attributes.keys).to include 'updated_at'
+      it 'これらのカラムを定義している' do
+        set_attributes? @attributes, 
+          ['id', 'title', 'description', 'visible', 'author_id', 
+          'created_at', 'updated_at']
       end
       describe 'titleに於いて' do
         before do
           @attribute = @attributes['title']
         end
-        it 'type' do
+        it 'textタイプである' do
           expect(@attribute.type).to eq 'text'
         end
       end
@@ -230,7 +271,7 @@ describe Scroll do
         before do
           @attribute = @attributes['description']
         end
-        it 'type' do
+        it 'textタイプである' do
           expect(@attribute.type).to eq 'text'
         end
       end
@@ -238,10 +279,10 @@ describe Scroll do
         before do
           @attribute = @attributes['visible']
         end
-        it 'type' do
+        it 'numberタイプである' do
           expect(@attribute.type).to eq 'number'
         end
-        it 'source' do
+        it '選択肢を定数から取得できるように定義している' do
           expect(@attribute.source.type).to eq 'magic_number'
           expect(@attribute.source.select_item_name).to eq 'scroll_visible_items'
         end
@@ -250,23 +291,12 @@ describe Scroll do
         before do
           @attribute = @attributes['author_id']
         end
-        it 'type' do
+        it 'numberタイプである' do
           expect(@attribute.type).to eq 'number'
         end
       end
     end
     
-    describe 'shortcutに於いて' do
-      before do
-        @my_manifest = @model.my_manifest
-      end
-      it 'type' do
-        expect(@my_manifest.model_name).to eq 'scroll'
-        expect(@my_manifest.classify).to eq @model
-        expect(@my_manifest.table_name).to eq 'scrolls'
-      end
-    end
-    
   end
   
 end