Sha256: 930b3bba182d65ec48fb83b245a60d88eed64daeef2fa34a2612c9f0afedda15
Contents?: true
Size: 1.15 KB
Versions: 1
Compression:
Stored size: 1.15 KB
Contents
module ModelHelpers def build_model(&blk) let(:model) do Class.new(ActiveRecord::Base) do attr_accessor :id def self.name "TestModel" end def self.primary_key "id" end def self.columns @columns ||= [] end def self.attribute_names @columns.map(&:name) end def self.attribute_method?(method) method = method.to_s.sub("=", "") columns.any? {|c| c.name == method } end def self.column(name, sql_type = "varchar(255)", default = nil, null = true) if ActiveRecord::ConnectionAdapters::AbstractAdapter.method_defined?(:lookup_cast_type) cast_type = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(nil, nil, nil).lookup_cast_type(sql_type) columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, cast_type, sql_type.to_s, null) else columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null) end end instance_eval(&blk) if blk end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
warp-1.3.1 | spec/support/model_helpers.rb |