OSDN Git Service

fix spec
[pettanr/pettanr.git] / spec / support / peta_macros.rb
diff --git a/spec/support/peta_macros.rb b/spec/support/peta_macros.rb
new file mode 100644 (file)
index 0000000..f2b8b79
--- /dev/null
@@ -0,0 +1,240 @@
+module ItemMacros\r
+  # 文字コード検証\r
+  def valid_encode? item, text_column_names\r
+    text_column_names.each do |name|\r
+      expect(item.class.valid_encode_columns).to include name\r
+      item.attributes[name] = "\x83G\x83r\x83]\x83D"\r
+      # バージョンが上がって問題なくなったかもしれない\r
+      #expect { item.valid_encode }.to raise_error(Pettanr::BadRequest)\r
+    end\r
+  end\r
+  \r
+  def define_child_models? model, models\r
+    expect(model.child_models.size).to eq models.size\r
+    models.each do |m|\r
+      expect(model.child_models).to include m\r
+    end\r
+  end\r
+  \r
+  def define_child_element_names? model, item_names\r
+    expect(model.child_models.size).to eq item_names.size\r
+    item_names.each do |m|\r
+      expect(model.child_element_names).to include m\r
+    end\r
+  end\r
+  \r
+  def define_my_manifest? model\r
+    expect(model.my_peta).to eq Manifest.manifest.items[model.item_name]\r
+    expect(model.my_controller).to eq Manifest.manifest.controllers[model.table_name]\r
+    expect(model.my_manifest).to eq Manifest.manifest.models[model.item_name]\r
+  end\r
+  \r
+  # マニフェストを取得するためのショートカット\r
+  def define_my_manifest? model\r
+    expect(model.my_peta).to eq Manifest.manifest.items[model.item_name]\r
+    expect(model.my_controller).to eq Manifest.manifest.controllers[model.table_name]\r
+    expect(model.my_manifest).to eq Manifest.manifest.models[model.item_name]\r
+  end\r
+  \r
+  # 名前の活用が正しく変化していることを確認している\r
+  def set_name? item, subjects\r
+    subjects.each do |name, value|\r
+      expect(item.__send__(name)).to eq value\r
+    end\r
+  end\r
+  \r
+  # 拡張カラムなのかを確認している\r
+  def set_extend_column? model, subjects\r
+    subjects.each do |name, value|\r
+      expect(model.extend_column?(name)).to eq value\r
+    end\r
+  end\r
+  \r
+  # ブースターが用意されているか、名前だけでも確認する\r
+  def set_boosters? item, names\r
+    item.boosts 'post'\r
+    item.boosters.keys.each do |name|\r
+      expect(name).to include names\r
+    end\r
+  end\r
+  \r
+  # 拡張データを畳み込めるか確認する\r
+  def fold_extend_settings? model, attr, extend_column_names\r
+    model.fold_extend_settings attr\r
+    extend_column_names.each do |name|\r
+      expect(attr[name]).to be_kind_of String\r
+    end\r
+  end\r
+  \r
+  def define_test item\r
+    expect {expect(item.dom_id)}.not_to raise_error\r
+    expect {expect(item.editize?)}.not_to raise_error\r
+    expect {expect(item.dom_pool_type)}.not_to raise_error\r
+    expect {expect(item.merge_dom_item_id({}))}.not_to raise_error\r
+    expect {expect(item.tag_attributes)}.not_to raise_error\r
+    expect {expect(item.field_tag_attributes(:hoge))}.not_to raise_error\r
+    expect {expect(item.post_attribute_key)}.not_to raise_error\r
+  end\r
+  \r
+end\r
+\r
+module ContentMacros\r
+  # ぶら下がるそれぞれのリーフを取得\r
+  def define_leaf_items? item, leaf_models\r
+    expect(item.respond_to?(:leaf_items)).to be true\r
+    leaf_models.each do |model|\r
+      expect(item.leaf_items(model)).to_not be_empty\r
+      expect(item.leaf_items(model).first.class).to eq model\r
+    end\r
+  end\r
+  \r
+  def define_leafs_items? item, leaf_models\r
+    expect(item.respond_to?(:leafs_items)).to be true\r
+    expect(item.leafs_items).to_not be_empty\r
+    item.leafs_items.map {|i| i.class }.each do |model|\r
+      expect(leaf_models).to include model\r
+    end\r
+  end\r
+  \r
+end\r
+\r
+module BinderMacros\r
+  # ぶら下がるそれぞれのリーフを取得\r
+  def define_leaf_items? item, leaf_models\r
+    expect(item.respond_to?(:leaf_items)).to be true\r
+    leaf_models.each do |model|\r
+      expect(item.leaf_items(model)).to_not be_empty\r
+      expect(item.leaf_items(model).first.class).to eq model\r
+    end\r
+  end\r
+  \r
+  def define_leafs_items? item, leaf_models\r
+    expect(item.respond_to?(:leafs_items)).to be true\r
+    expect(item.leafs_items).to_not be_empty\r
+    item.leafs_items.map {|i| i.class }.each do |model|\r
+      expect(leaf_models).to include model\r
+    end\r
+  end\r
+  \r
+end\r
+\r
+module LeafMacros\r
+  # ぶら下がるそれぞれのリーフを取得\r
+  def define_leaf_items? item, leaf_models\r
+    expect(item.respond_to?(:leaf_items)).to be true\r
+    leaf_models.each do |model|\r
+      expect(item.leaf_items(model)).to_not be_empty\r
+      expect(item.leaf_items(model).first.class).to eq model\r
+    end\r
+  end\r
+  \r
+  def define_leafs_items? item, leaf_models\r
+    expect(item.respond_to?(:leafs_items)).to be true\r
+    expect(item.leafs_items).to_not be_empty\r
+    item.leafs_items.map {|i| i.class }.each do |model|\r
+      expect(leaf_models).to include model\r
+    end\r
+  end\r
+  \r
+end\r
+\r
+module RootMacros\r
+  # ぶら下がるそれぞれのリーフを取得\r
+  def define_leaf_items? item, leaf_models\r
+    expect(item.respond_to?(:leaf_items)).to be true\r
+    leaf_models.each do |model|\r
+      expect(item.leaf_items(model)).to_not be_empty\r
+      expect(item.leaf_items(model).first.class).to eq model\r
+    end\r
+  end\r
+  \r
+  def define_leafs_items? item, leaf_models\r
+    expect(item.respond_to?(:leafs_items)).to be true\r
+    expect(item.leafs_items).to_not be_empty\r
+    item.leafs_items.map {|i| i.class }.each do |model|\r
+      expect(leaf_models).to include model\r
+    end\r
+  end\r
+  \r
+end\r
+\r
+module ElementMacros\r
+  # ぶら下がるそれぞれのリーフを取得\r
+  def define_leaf_items? item, leaf_models\r
+    expect(item.respond_to?(:leaf_items)).to be true\r
+    leaf_models.each do |model|\r
+      expect(item.leaf_items(model)).to_not be_empty\r
+      expect(item.leaf_items(model).first.class).to eq model\r
+    end\r
+  end\r
+  \r
+  def define_leafs_items? item, leaf_models\r
+    expect(item.respond_to?(:leafs_items)).to be true\r
+    expect(item.leafs_items).to_not be_empty\r
+    item.leafs_items.map {|i| i.class }.each do |model|\r
+      expect(leaf_models).to include model\r
+    end\r
+  end\r
+  \r
+end\r
+\r
+module OwnerMacros\r
+  # ぶら下がるそれぞれのリーフを取得\r
+  def define_leaf_items? item, leaf_models\r
+    expect(item.respond_to?(:leaf_items)).to be true\r
+    leaf_models.each do |model|\r
+      expect(item.leaf_items(model)).to_not be_empty\r
+      expect(item.leaf_items(model).first.class).to eq model\r
+    end\r
+  end\r
+  \r
+  def define_leafs_items? item, leaf_models\r
+    expect(item.respond_to?(:leafs_items)).to be true\r
+    expect(item.leafs_items).to_not be_empty\r
+    item.leafs_items.map {|i| i.class }.each do |model|\r
+      expect(leaf_models).to include model\r
+    end\r
+  end\r
+  \r
+end\r
+\r
+module SystemResourceMacros\r
+  # ぶら下がるそれぞれのリーフを取得\r
+  def define_leaf_items? item, leaf_models\r
+    expect(item.respond_to?(:leaf_items)).to be true\r
+    leaf_models.each do |model|\r
+      expect(item.leaf_items(model)).to_not be_empty\r
+      expect(item.leaf_items(model).first.class).to eq model\r
+    end\r
+  end\r
+  \r
+  def define_leafs_items? item, leaf_models\r
+    expect(item.respond_to?(:leafs_items)).to be true\r
+    expect(item.leafs_items).to_not be_empty\r
+    item.leafs_items.map {|i| i.class }.each do |model|\r
+      expect(leaf_models).to include model\r
+    end\r
+  end\r
+  \r
+end\r
+\r
+module TemplateMacros\r
+  # ぶら下がるそれぞれのリーフを取得\r
+  def define_leaf_items? item, leaf_models\r
+    expect(item.respond_to?(:leaf_items)).to be true\r
+    leaf_models.each do |model|\r
+      expect(item.leaf_items(model)).to_not be_empty\r
+      expect(item.leaf_items(model).first.class).to eq model\r
+    end\r
+  end\r
+  \r
+  def define_leafs_items? item, leaf_models\r
+    expect(item.respond_to?(:leafs_items)).to be true\r
+    expect(item.leafs_items).to_not be_empty\r
+    item.leafs_items.map {|i| i.class }.each do |model|\r
+      expect(leaf_models).to include model\r
+    end\r
+  end\r
+  \r
+end\r
+\r