I have a number of models that store words as a string with each words separated by a space. I have defined model methods to delete and add words to the string and the size or number of words is updated each time accordingly. There is an error somewhere because the size sometimes comes out to be negative. I’m wondering, what is the best way to test a situation like this in rails. I would ideally like to write a test that allows me to add a number of words and remove them while verifying the correct value of size each time. Thanks.
Share
I assume your model looks something like this? I have omitted some code for simplicity since your question isn’t about how to implement the word management piece but on how to test it.
Now you can just write a simple unit test.