#952 ✓duplicate
Ashley Moran

Since 0.10, Resource#update (formerly Resource#update_attributes) bypasses validations

Reported by Ashley Moran | July 6th, 2009 @ 01:59 PM

Almost entirely courtesy of the eternally meticulous, but equally eternally elusive and mysterious, mrship (who may one day register on LightHouse), here is proof of the bug described in the ticket title:

require 'rubygems'
  
USE_DM_0_9 = true
 
if USE_DM_0_9
  DM_GEMS_VERSION   = "0.9.11"
  DO_GEMS_VERSION   = "0.9.12"
else
  DM_GEMS_VERSION   = "0.10.0"
  DO_GEMS_VERSION   = "0.10.0"
end
 
gem "data_objects",   DO_GEMS_VERSION
gem "do_sqlite3",     DO_GEMS_VERSION # If using another database, replace this
gem "dm-core",        DM_GEMS_VERSION         
gem "dm-aggregates",  DM_GEMS_VERSION   
gem "dm-migrations",  DM_GEMS_VERSION   
gem "dm-timestamps",  DM_GEMS_VERSION   
gem "dm-types",       DM_GEMS_VERSION        
gem "dm-validations", DM_GEMS_VERSION  
gem "dm-serializer",  DM_GEMS_VERSION  

require "data_objects"
require "dm-core"
require "dm-aggregates"
require "dm-migrations"
require "dm-timestamps"
require "dm-types"
require "dm-validations"
require "dm-serializer"

require 'spec'
 
SQLITE_FILE = File.join(`pwd`.chomp, "test.db")
 
DataMapper.setup(:default, "sqlite3:#{SQLITE_FILE}")
DataMapper.setup(:reloaded, "sqlite3:#{SQLITE_FILE}")
 
class Cow
  include DataMapper::Resource

  property :id, Serial
  property :cow_id, Integer
  property :name, String, :nullable => false
end
 
module IdentityMapHelper
  def reload(object)
    object.class.get(object.id)
  end
  
  def with_db_reconnect(&blk)
    original_repository = DataMapper::Repository.context.pop
    repository(:reloaded, &blk)
    DataMapper::Repository.context << original_repository
  end
end
 
Spec::Runner.configure do |config|
  include IdentityMapHelper
  
  config.before(:each) do
    Cow.auto_migrate!
  end
  
  config.before(:each) do    
    DataMapper::Repository.context << repository(:default)
  end
  
  config.after(:each) do
    DataMapper::Repository.context.pop
  end
end
 
describe "Updating with a blank name" do
  before(:each) do
    @cow_1 = Cow.new(:cow_id => 1, :name => "Daisy")
  end
  
  it "should be invalid if :nullable => false properties are blank" do
    @cow_1.save
    @cow_1.name = ""
    @cow_1.should_not be_valid
    if USE_DM_0_9
      @cow_1.update_attributes(:name => "").should be_false
    else
      @cow_1.update(:name => "").should be_false
    end
  end
end

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Referenced by

Pages