Skip to content

Instantly share code, notes, and snippets.

@solnic
Created May 26, 2010 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solnic/ebcaecc449ec04cf8e9d to your computer and use it in GitHub Desktop.
Save solnic/ebcaecc449ec04cf8e9d to your computer and use it in GitHub Desktop.
require 'spec'
require 'dm-core'
require 'dm-migrations'
require 'dm-validations'
DataMapper.setup(:default, 'sqlite3::memory:')
class Ad
include DataMapper::Resource
property :id, Serial
property :failure_perc, Decimal, :default => 0.0, :min => 0.0, :max => 100.0
end
Ad.auto_migrate!
describe Ad do
it 'should validate' do
ad = Ad.new(:failure_perc => 75.0)
ad.failure_perc = -1.0
ad.valid?.should be(false)
ad.failure_perc = 150.0
ad.valid?.should be(false)
ad.failure_perc = 50.0
ad.valid?.should be(true)
ad.save.should be(true)
ad.id.should_not be(nil)
ad.failure_perc.should eql(50.0)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment