-
-
Save solnic/ebcaecc449ec04cf8e9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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