0
@@ -11,31 +11,40 @@ Make sure, in your spec_helper.rb file, you add an include as follows:
0
Test @validates_presence_of :name@
0
Model.should need(:name).using(@valid_attributes)
0
Test @validates_uniqueness_of :name@
0
Model.should need(:name).to_be_unique.using(@valid_attributes)
0
Test presence of at least one field being required
0
Model.should need.one_of(:first_name, :last_name).using(@valid_attributes)
0
Test @validates_length_of :name matches@ database field length
0
Model.should limit_length_of(:name).using(@valid_attributes)
0
Test @validates_length_of :name, :maximum => 255@
0
Model.should limit_length_of(:name).to(255).using(@valid_attributes)
0
Test @validates_length_of :name, :minimum => 3@@
0
Model.should limit_length_of(:name).from(3).using(@valid_attributes)
0
Test @validates_length_of :name, :within => 3..40@
0
Model.should limit_length_of(:name).from(3).to(4).using(@valid_attributes)
0
Test @validates_numericality_of :age@
0
Model.should need_numeric(:age).using(@valid_attributes)
0
You can group multiple validation checks together like so:
0
using(@valid_attributes) do
0
Model.should need(:name)
0
Model.should limit_length_of(:name).to(255)
0
@@ -45,16 +54,20 @@ You can group multiple validation checks together like so:
0
Also allows confirmation of the presence of associations
0
Test @belongs_to :parent@
0
Model.should belong_to(:parent)
0
Test @belongs_to :parent, :class_name => "CustomClass", :foreign_key => "some_id"@
0
Model.should belong_to(:parent).with_options(
0
:class_name => "CustomClass", :foreign_key => "some_id")
0
Model.should have_many(:items)
0
Test @has_many :items, :class_name => "CustomClass", :foreign_key => "some_id"@
0
Model.should have_many(:items).with_options(
0
:class_name => "CustomClass", :foreign_key => "some_id")
Comments
No one has commented yet.