mercredi 25 novembre 2020

Rails model test not railing when it should

I am using Ruby 2.6.3 and Rails 6 as an API. :My model Item has fields name and price. My test is to validate that these fields are present. My test reads as follows

test 'Should have name and price ' do
   item = Item.new
   assert_not item.save, "Item saved without a name or price"
 end

This results in a green test which should not be happening because there are no current validations. Even when I add validations the test is still green:

class Item < ApplicationRecord
  belongs_to :order
  validates :name, presence: true
  validates :price, presence: true
end

With and without validations my test comes back green. What the heck is going on?

Aucun commentaire:

Enregistrer un commentaire