I am working on Ruby 2.2.0, I have a class
class JobOffer
include DataMapper::Resource
property :id, Serial
property :title, String
property :location, String
property :experience, Numeric, :default => 0
property :description, String
property :created_on, Date
property :updated_on, Date
property :is_active, Boolean, :default => true
belongs_to :user
validates_presence_of :title
validates_numericality_of :experience => {
:greater_than_or_equal_to => 0,
:less_than_or_equal_to => 16
}
end
My question is: How I can test values of experience field in rspec tests? It's easy to test title, because I ask for valid? and it returns if title is present or not, but I don't know if is there something like this for numeric fields. Thanks in advance!
Just testing that a an attr can be written for a given model isn't very useful as it's part of the core functionality of the ORM, and likewise with the validators, but if you really want to, you could test creation of a new job offer, something like...
But again, this is pretty much core functionality of the ORM, so it's arguably not a useful test.