heartcombo--simple_form/test/support/models.rb

64 lines
1.3 KiB
Ruby
Raw Normal View History

2009-12-08 13:48:31 +00:00
require 'ostruct'
class Column
attr_accessor :name, :type#, :limit, :precision, :scale
def initialize(attrs={})
self.name = attrs[:name]
self.type = attrs[:type]
end
end
2009-12-08 13:48:31 +00:00
class User < OpenStruct
def id
1
end
def new_record?
false
end
def column_for_attribute(attribute)
column_type = case attribute.to_sym
when :name, :status, :password then :string
2009-12-08 13:48:31 +00:00
when :description then :text
when :age then :integer
when :credit_limit then :decimal
when :active then :boolean
when :born_at then :date
when :delivery_time then :time
when :created_at then :datetime
when :updated_at then :timestamp
end
Column.new(:name => attribute, :type => column_type)
2009-12-08 13:48:31 +00:00
end
def human_attribute_name(attribute)
nil
end
2009-12-08 18:38:03 +00:00
def errors
{}
end
2009-12-08 13:48:31 +00:00
end
class SuperUser < User
def human_attribute_name(attribute)
case attribute
when 'name' then 'Super User Name!'
else super
end
end
2009-12-08 18:38:03 +00:00
def errors
@errors ||= {
:name => "can't be blank",
:description => "must be longer than 15 characters",
:age => ["is not a number", "must be greater than 18"],
:credit_limit => ["must be present", "must be greater than 0"]
}
end
2009-12-08 13:48:31 +00:00
end