OSDN Git Service

add test
[pettanr/pettanr.git] / spec / local_manifests / writing_format_spec.rb
diff --git a/spec/local_manifests/writing_format_spec.rb b/spec/local_manifests/writing_format_spec.rb
new file mode 100644 (file)
index 0000000..8bbc6fc
--- /dev/null
@@ -0,0 +1,529 @@
+# -*- encoding: utf-8 -*-
+require 'spec_helper'
+#スクロールマニフェスト
+
+describe WritingFormat do
+  include LocalManifestsMacros
+  before do
+    @model = WritingFormat
+  end
+  
+  describe 'ファイラーに於いて' do
+    before do
+      @my_local_manifest = LocalManifest.manifest.filers[@model.item_name]
+    end
+    it 'サポート機能が動作している' do
+      expect(@my_local_manifest.item_class).to eq @model
+      expect(@my_local_manifest.item_name).to eq @model.item_name
+      expect(@my_local_manifest.filer_name).to eq @model.item_name
+    end
+    describe 'symbolに於いて' do
+      before do
+        @symbol = @my_local_manifest.symbol
+      end
+      it 'defaultタイプのsymbolである' do
+        expect(@symbol.type).to eq 'default'
+      end
+      it 'サポート機能が動作している' do
+        expect(@symbol.visible?).to be true
+      end
+      describe 'faceに於いて' do
+        before do
+          @face = @symbol.face
+        end
+        it 'imageタイプのfaceである' do
+          expect(@face.type).to eq 'image'
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@face.url).to eq '/images/scroll.gif'
+        end
+      end
+      describe 'linkに於いて' do
+        before do
+          @link = @symbol.link
+        end
+        it 'actionタイプのlinkである' do
+          expect(@link.type).to eq 'action'
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@link.action_name).to eq 'show'
+        end
+        it 'サポート機能が動作している' do
+          expect(@link.action_path).to eq '/scrolls/'
+        end
+      end
+    end
+    describe 'captionに於いて' do
+      before do
+        @caption = @my_local_manifest.caption
+      end
+      it 'defaultタイプのsymbolである' do
+        expect(@caption.type).to eq 'default'
+      end
+      it 'サポート機能が動作している' do
+        expect(@caption.visible?).to be true
+      end
+      describe 'faceに於いて' do
+        before do
+          @face = @caption.face
+        end
+        it 'columnタイプのfaceである' do
+          expect(@face.type).to eq 'column'
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@face.column_name).to eq 'title'
+        end
+      end
+      describe 'linkに於いて' do
+        before do
+          @link = @caption.link
+        end
+        it 'actionタイプのlinkである' do
+          expect(@link.type).to eq 'action'
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@link.action_name).to eq 'play'
+        end
+        it 'サポート機能が動作している' do
+          expect(@link.action_path).to eq '/scrolls/play/'
+        end
+      end
+    end
+    describe 'summaryに於いて' do
+      before do
+        @summary = @my_local_manifest.summary
+      end
+      it 'templateタイプのsymbolである' do
+        expect(@summary.type).to eq 'template'
+      end
+      it 'マニフェストから設定を取り出している' do
+        expect(@summary.template_name).to eq 'summary'
+      end
+    end
+    describe 'iconに於いて' do
+      before do
+        @icon = @my_local_manifest.icon
+      end
+      it 'defaultタイプのsymbolである' do
+        expect(@icon.type).to eq 'default'
+      end
+      it 'サポート機能が動作している' do
+        expect(@icon.visible?).to be true
+      end
+    end
+    describe 'dateに於いて' do
+      before do
+        @date = @my_local_manifest.date
+      end
+      it 'defaultタイプのsymbolである' do
+        expect(@date.type).to eq 'default'
+      end
+      it 'サポート機能が動作している' do
+        expect(@date.visible?).to be true
+      end
+    end
+    describe 'editに於いて' do
+      before do
+        @edit = @my_local_manifest.edit
+      end
+      it 'defaultタイプのsymbolである' do
+        expect(@edit.type).to eq 'default'
+      end
+      it 'サポート機能が動作している' do
+        expect(@edit.visible?).to be true
+      end
+    end
+  end
+  
+  describe 'プロファイラーに於いて' do
+    before do
+      @my_local_manifest = LocalManifest.manifest.profilers[@model.item_name]
+    end
+    it 'マニフェストから設定を取り出している' do
+      expect(@my_local_manifest.item_name).to eq @model.item_name
+    end
+    describe 'columnsに於いて' do
+      before do
+        @columns = @my_local_manifest.columns
+        @names = ['id', 'title', 'description', 'visible', 'author_id', 'created_at', 'updated_at']
+      end
+      it 'これらのカラムが定義されている' do
+        set_columns? @columns, @names
+      end
+      describe 'titleに於いて' do
+        before do
+          @column = @columns['title']
+        end
+        it 'defaultタイプのcolumnである' do
+          expect(@column.type).to eq 'default'
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@column.item_name).to eq 'scroll'
+        end
+      end
+      describe 'descriptionに於いて' do
+        before do
+          @column = @columns['description']
+        end
+        it 'defaultタイプのcolumnである' do
+          expect(@column.type).to eq 'default'
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@column.item_name).to eq 'scroll'
+        end
+      end
+      describe 'visibleに於いて' do
+        before do
+          @column = @columns['visible']
+        end
+        it 'sourceタイプのcolumnである' do
+          expect(@column.type).to eq 'source'
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@column.item_name).to eq 'scroll'
+        end
+      end
+      describe 'author_idに於いて' do
+        before do
+          @column = @columns['author_id']
+        end
+        it 'defaultタイプのcolumnである' do
+          expect(@column.type).to eq 'default'
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@column.item_name).to eq 'scroll'
+        end
+      end
+    end
+    describe 'column_namesに於いて' do
+      before do
+        @column_names = @my_local_manifest.column_names
+      end
+      it '数量が守られている' do
+        expect(@column_names.size).to eq 4 + 3
+      end
+      it '順序が守られている' do
+        expect(@column_names).to eq ['id', 'title', 'description', 'visible', 'author_id', 'created_at', 'updated_at']
+      end
+    end
+    describe 'extend_settingsに於いて' do
+      before do
+        @extend_settings = @my_local_manifest.extend_settings
+      end
+      it '拡張カラムは無い' do
+        expect(@extend_settings).to be_empty
+      end
+    end
+    describe 'listsに於いて' do
+      before do
+        @lists = @my_local_manifest.lists
+      end
+      it '無い' do
+        expect(@lists).to be_empty
+      end
+    end
+    describe 'associationsに於いて' do
+      before do
+        @associations = @my_local_manifest.associations
+      end
+      describe 'belongs_toに於いて' do
+        before do
+          @belongs_to = @associations.belongs_to
+        end
+        it 'これらの所属モデルを取り扱う' do
+          expect(@belongs_to.map {|a| a.name}).to eq ['author']
+        end
+        describe 'authorに於いて' do
+          before do
+            @mani = @belongs_to[0]
+          end
+          it 'マニフェストから設定を取り出している' do
+            expect(@mani.name).to eq 'author'
+            expect(@mani.model_name).to eq 'author'
+          end
+          it 'サポート機能が動作している' do
+            expect(@mani.model).to eq Author
+          end
+        end
+      end
+      describe 'has_manyに於いて' do
+        before do
+          @has_many = @associations.has_many
+        end
+        it 'これらの所持モデルを取り扱う' do
+          expect(@has_many.map {|a| a.table_name}).to eq ['scroll_panels', 'panels']
+        end
+        describe 'scroll_panelsに於いて' do
+          before do
+            @mani = @has_many[0]
+          end
+          it 'マニフェストから設定を取り出している' do
+            expect(@mani.name).to eq 'scroll_panels.by_scroll'
+            expect(@mani.model_name).to eq 'scroll_panel'
+            expect(@mani.list_name).to eq 'by_scroll'
+          end
+          it 'サポート機能が動作している' do
+            expect(@mani.model).to eq ScrollPanel
+          end
+        end
+        describe 'panels.by_scrollに於いて' do
+          before do
+            @mani = @has_many[1]
+          end
+          it 'マニフェストから設定を取り出している' do
+            expect(@mani.name).to eq 'panels.by_scroll'
+            expect(@mani.model_name).to eq 'panel'
+            expect(@mani.list_name).to eq 'by_scroll'
+          end
+          it 'サポート機能が動作している' do
+            expect(@mani.model).to eq Panel
+          end
+        end
+      end
+    end
+  end
+  
+  describe 'リストグループに於いて' do
+    before do
+      @my_local_manifest = LocalManifest.manifest.list_groups[@model.item_name]
+    end
+    it 'マニフェストから設定を取り出している' do
+      expect(@my_local_manifest.item_name).to eq @model.item_name
+    end
+    describe 'listsに於いて' do
+      before do
+        @lists = @my_local_manifest.lists
+      end
+      it 'これらのリストを定義している' do
+        set_lists? @lists, ['public', 'private', 'by_author', 'by_panel']
+      end
+      describe 'publicに於いて' do
+        before do
+          @mani = @lists['public']
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@mani.type).to eq 'public'
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@mani.model).to eq Scroll
+        end
+        it 'サポート機能が動作している' do
+          expect(@mani.has_id?).to be nil
+          expect(@mani.pre_id?).to be true
+          expect(@mani.item_name).to eq @model.item_name
+        end
+        describe 'whereに於いて' do
+          before do
+            @where = @mani.where
+          end
+          it 'autoタイプである' do
+            expect(@where.type).to eq 'auto'
+          end
+          it 'サポート機能が動作している' do
+            expect(@where.item_name).to eq @model.item_name
+            expect(@where.list_name).to eq 'public'
+            expect(@where.model).to eq Scroll
+          end
+          it 'method_name' do
+            expect(@where.method_name).to eq 'public_list_where'
+          end
+        end
+        describe 'includesに於いて' do
+          before do
+            @includes = @mani.includes
+          end
+          it 'autoタイプである' do
+            expect(@includes.type).to eq 'auto'
+          end
+          it 'サポート機能が動作している' do
+            expect(@includes.item_name).to eq @model.item_name
+            expect(@includes.list_name).to eq 'public'
+            expect(@includes.model).to eq Scroll
+          end
+          it 'includes' do
+            expect(@includes.includes).to be_empty
+          end
+        end
+        describe 'orderに於いて' do
+          before do
+            @order = @mani.order
+          end
+          it 'autoタイプである' do
+            expect(@order.type).to eq 'auto'
+          end
+          it 'サポート機能が動作している' do
+            expect(@order.item_name).to eq @model.item_name
+            expect(@order.list_name).to eq 'public'
+            expect(@order.model).to eq Scroll
+          end
+          it 'order' do
+            expect(@order.order).to eq 'list_order'
+          end
+        end
+      end
+    end
+  end
+  
+  describe '入力フォームに於いて' do
+    before do
+      @my_local_manifest = LocalManifest.manifest.forms[@model.item_name]
+    end
+    it 'マニフェストから設定を取り出している' do
+      expect(@my_local_manifest.name).to eq @model.item_name
+    end
+    describe 'fieldsに於いて' do
+      before do
+        @fields = @my_local_manifest.fields
+      end
+      # 細かいチェックは後でやるので、大雑把に数量だけチェックしておく。
+      it '数量が守られている' do
+        expect(@fields.size).to eq 5
+      end
+    end
+    describe 'field_namesに於いて' do
+      before do
+        @field_names = @my_local_manifest.field_names
+      end
+      it '数量が守られている' do
+        expect(@field_names.size).to eq 5
+      end
+      it '順序が守られている' do
+        expect(@field_names).to eq ['title', 'description', 'visible', 'id', 'author_id']
+      end
+    end
+    # 処理順に並べられたフィールドのこと
+    # 本来fieldsでテストするべき内容だが、並び替えもテストしたいのでこちらで行う。
+    describe 'ordered_fieldsに於いて' do
+      before do
+        @ordered_fields = @my_local_manifest.ordered_fields
+        @names = ['title', 'description', 'visible', 'id', 'author_id']
+      end
+      it 'これらのフィールドを取り扱う' do
+        expect(@ordered_fields.map {|f| f.name }).to eq @names
+      end
+      describe 'titleに於いて' do
+        before do
+          @field = @ordered_fields[0]
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@field.name).to eq 'title'
+          expect(@field.row_break).to be true
+        end
+        it 'サポート機能が動作している' do
+          expect(@field.part?).to be false
+          expect(@field.form_name).to eq @model.item_name
+          expect(@field.column_name).to eq 'title'
+          expect(@field.model_name).to eq @model.item_name
+        end
+        describe 'labelに於いて' do
+          before do
+            @label = @field.label
+          end
+          it 'defaultタイプである' do
+            expect(@label.type).to eq 'default'
+          end
+          it 'マニフェストから設定を取り出している' do
+            expect(@label.row_break).to be true
+          end
+          it 'サポート機能が動作している' do
+            expect(@label.form_name).to eq @model.item_name
+            expect(@label.field_name).to eq 'title'
+            expect(@label.model_name).to eq @model.item_name
+            expect(@label.column_name).to eq 'title'
+          end
+        end
+        describe 'tagに於いて' do
+          before do
+            @tag = @field.tag
+          end
+          it 'textタイプである' do
+            expect(@tag.type).to eq 'text'
+          end
+          it 'マニフェストから設定を取り出している' do
+            expect(@tag.options).to_not be_empty
+            expect(@tag.options['size']).to eq 20
+          end
+          it 'サポート機能が動作している' do
+            expect(@tag.form_name).to eq @model.item_name
+            expect(@tag.field_name).to eq 'title'
+          end
+        end
+      end
+      describe 'descriptionに於いて' do
+        before do
+          @field = @ordered_fields[1]
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@field.name).to eq 'description'
+          expect(@field.row_break).to be true
+        end
+        it 'サポート機能が動作している' do
+          expect(@field.part?).to be false
+          expect(@field.form_name).to eq @model.item_name
+          expect(@field.column_name).to eq 'description'
+          expect(@field.model_name).to eq @model.item_name
+        end
+      end
+      describe 'visibleに於いて' do
+        before do
+          @field = @ordered_fields[2]
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@field.name).to eq 'visible'
+          expect(@field.row_break).to be true
+        end
+        it 'サポート機能が動作している' do
+          expect(@field.part?).to be false
+          expect(@field.form_name).to eq @model.item_name
+          expect(@field.column_name).to eq 'visible'
+          expect(@field.model_name).to eq @model.item_name
+        end
+      end
+      describe 'idに於いて' do
+        before do
+          @field = @ordered_fields[3]
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@field.name).to eq 'id'
+          expect(@field.row_break).to be true
+        end
+        it 'サポート機能が動作している' do
+          expect(@field.part?).to be false
+          expect(@field.form_name).to eq @model.item_name
+          expect(@field.column_name).to eq 'id'
+          expect(@field.model_name).to eq @model.item_name
+        end
+      end
+      describe 'author_idに於いて' do
+        before do
+          @field = @ordered_fields[4]
+        end
+        it 'マニフェストから設定を取り出している' do
+          expect(@field.name).to eq 'author_id'
+          expect(@field.row_break).to be true
+        end
+        it 'サポート機能が動作している' do
+          expect(@field.part?).to be false
+          expect(@field.form_name).to eq @model.item_name
+          expect(@field.column_name).to eq 'author_id'
+          expect(@field.model_name).to eq @model.item_name
+        end
+      end
+    end
+  end
+  
+  describe 'bucketに於いて' do
+    before do
+      @my_local_manifest = LocalManifest.manifest.buckets[@model.item_name]
+    end
+    it 'マニフェストから設定を取り出している' do
+      expect(@my_local_manifest.members).to be_empty
+      expect(@my_local_manifest.form_field_names).to be_empty
+    end
+    it 'サポート機能が動作している' do
+      expect(@my_local_manifest.has_member?).to be false
+      expect(@my_local_manifest.item_name).to eq @model.item_name
+    end
+  end
+  
+end