<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -2,6 +2,7 @@ class PartType &lt; ActiveRecord::Base
   has_many :template_parts
   
   validates_presence_of :name
-  validates_inclusion_of :field_type, :in =&gt; %w{text_area text_field radio_button hidden predefined}
+  validates_uniqueness_of :name
+  validates_inclusion_of :field_type, :in =&gt; %w{text_area text_field check_box radio_button hidden predefined}
 
 end</diff>
      <filename>app/models/part_type.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,14 +1,23 @@
 class CreateDefaultPartTypes &lt; ActiveRecord::Migration
-  def self.up
+  def self.defaults
     [
       {:name =&gt; &quot;One-line&quot;, :field_type =&gt; &quot;text_field&quot;, :field_class =&gt; &quot;text&quot;},
       {:name =&gt; &quot;Plain textarea&quot;, :field_type =&gt; &quot;text_area&quot;, :field_class =&gt; &quot;textarea&quot;},
       {:name =&gt; &quot;Boolean&quot;, :field_type =&gt; &quot;check_box&quot;},
       {:name =&gt; &quot;Predefined&quot;, :field_type =&gt; &quot;predefined&quot;}
-    ].each {|a| PartType.create(a) }
+    ]
+  end
+
+  def self.up
+    self.defaults.each do |a|
+      PartType.create(a)
+    end
   end
-  
+
   def self.down
-    PartType.destroy_all
+    self.defaults.each do |a|
+      pt = PartType.find_by_name(a[:name])
+      pt.destroy unless pt.nil?
+    end
   end
-end
\ No newline at end of file
+end</diff>
      <filename>db/migrate/009_create_default_part_types.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,20 +4,25 @@ describe PartType do
   before :each do
     @part_type = PartType.new :name =&gt; &quot;Test type&quot;, :field_type =&gt; 'text_area'
   end
-  
+
   it &quot;should require a name&quot; do
     @part_type.name = nil
     @part_type.should_not be_valid
     @part_type.should have(1).error_on(:name)
   end
-  
+
   it &quot;should require a valid field type&quot; do
     @part_type.field_type = 'foobar'
     @part_type.should_not be_valid
     @part_type.should have(1).error_on(:field_type)
   end
-  
+
   it &quot;should be valid with correct parameters&quot; do
     @part_type.should be_valid
   end
-end
\ No newline at end of file
+
+  it &quot;should not allow creation of a new part type with a duplicate name&quot; do
+    @new_part_type = PartType.create :name =&gt; @part_type.name
+    @new_part_type.id.should be_nil
+  end
+end</diff>
      <filename>spec/models/part_type_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>04d2ede76e99eb6e28038c888a30c3e4f186af49</id>
    </parent>
  </parents>
  <author>
    <name>Andrew vonderLuft</name>
    <email>avonderluft@avlux.net</email>
  </author>
  <url>http://github.com/seancribbs/radiant-templates-extension/commit/624d43ddc31e4c04e6f28feec5a10d79bc83125f</url>
  <id>624d43ddc31e4c04e6f28feec5a10d79bc83125f</id>
  <committed-date>2009-04-30T11:27:28-07:00</committed-date>
  <authored-date>2009-04-30T11:27:28-07:00</authored-date>
  <message>require template part type name to be unique; fix migrations so that duplicate part types are not created, and only default part types are removed with rollback; update model spec to test for invalidity of duplicate names.</message>
  <tree>f36edc23d72f3c74c235f0a52db46b1696546d06</tree>
  <committer>
    <name>Andrew vonderLuft</name>
    <email>avonderluft@avlux.net</email>
  </committer>
</commit>
