How come my DataMapper validations aren't working?

This example doesn't validate the presence of the title for me:

require 'rubygems'
require 'dm-core'
require 'dm-migrations'
require 'dm-validations'

db_name = 'rvtest.sqlite'

DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'sqlite://' + Dir.pwd + '/' + db_name)

class Task
  include DataMapper::Resource
  property :id,         Serial
  property :title,      String

  validates_presence_of :title
end

DataMapper.finalize
DataMapper.auto_upgrade!

However, this one does:

require 'rubygems'
require 'dm-core'
require 'dm-migrations'
require 'dm-validations'

db_name = 'rvtest.sqlite'

DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'sqlite://' + Dir.pwd + '/' + db_name)

class Task
  include DataMapper::Resource
  property :id,         Serial
  property :title,      String, :required => true

end

DataMapper.finalize
DataMapper.auto_upgrade!

Why do these work differently? If I go into irb, require this file and type Task.new.save! the first one returns true and the second false.

Answers


save! doesn't call any callbacks, which means it doesn't call validations. try with save


Need Your Help

How to embed an asp.net site in a windows service (or vice versa)

asp.net windows service tcp self-hosting

I'm building a windows service but I would like to get some web pages to control some settings, get diagnostics, etc...

Django include can not find template

python django

I am trying to include 'comment.html' into store.html and store.html extend base.html.