mit habe ich das Auftragsmodell mit der Linie für den Gesamtgesamtpreis der Produkte Berechnung der Benutzershoulda-matches Fehler beim Modell Etter vor validarion
before_validation :set_total!
validates :total, presence: true, numericality: { greater_than_or_equal_to: 0 }
set_total diese
sieht aus wie befehlendef set_total!
self.total = products.map(&price).sum
end
Nach meinen Angaben versuche ich zu überprüfen, ob die Gesamtvalidierungen implementiert sind. TDD
it { should validate_presence_of(:total) }
it { should validate_numericality_of(:total).is_greater_than_or_equal_to(0) }
Leider erhalte ich die folgenden Fehler
Failure/Error: it { should validate_presence_of(:total) }
Order did not properly validate that :total cannot be empty/falsy. After setting :total to ‹nil› -- which was read back as ‹#<BigDecimal:5634b8b81008,'0.0',9(27)>› -- the matcher expected the Order to be invalid, but it was valid instead. As indicated in the message above, :total seems to be changing certain values as they are set, and this could have something to do with why this test is failing. If you've overridden the writer method for this attribute, then you may need to change it to make this test pass, or do something else entirely.
Wie ich dieses Problem beheben?