Project

General

Profile

« Previous | Next » 

Revision b33f4404

Added by Tomáš Strachota over 11 years ago

  • ID b33f440434244fff5af7d036b43b6068c1b74e08

ptables - validation for OS families

View differences:

app/models/ptable.rb
validates_uniqueness_of :name
validates_presence_of :layout
validates_format_of :name, :with => /\A(\S+\s?)+\Z/, :message => "can't be blank or contain trailing white spaces."
validates_inclusion_of :os_family, :in => Operatingsystem.families, :allow_nil => true
default_scope :order => 'LOWER(ptables.name)'
scoped_search :on => :name, :complete_value => true, :default_order => true
......
super({:only => [:name, :id]}.merge(options))
end
def os_family=(value)
super(value.blank? ? nil : value)
end
end
test/unit/ptable_test.rb
assert !partition_table.save
end
test "os family can be one of defined os families" do
partition_table = Ptable.new :name => "Archlinux default", :layout => "any layout", :os_family => Operatingsystem.families[0]
assert partition_table.save
end
test "os family can't be anything else than defined os families" do
partition_table = Ptable.new :name => "Archlinux default", :layout => "any layout", :os_family => "unknown"
assert !partition_table.save
end
test "os family can be nil" do
partition_table = Ptable.new :name => "Archlinux default", :layout => "any layout", :os_family => nil
assert partition_table.save
end
test "blank os family is converted to nil" do
partition_table = Ptable.new :name => "Archlinux default", :layout => "any layout", :os_family => ""
assert partition_table.save
assert partition_table.os_family.nil?
end
# I'm commenting this one out for now, as I'm not sure that its actully needed
# besides, it breaks the inital db migration
# test "layout can't contain trailing white spaces" do

Also available in: Unified diff