The Gemara mentions in passing that we can be certain that God would not allow a tzaddik – a righteous person – to sin by eating forbidden foods, since He even prevents the animals of such people from doing so. In explanation of this statement, the Gemara relates the following story:
Once, Rabbi Pineḥas ben Ya’ir was on his way to redeem captives, and came to the river Ginai. ‘O Ginai,’ said he, ‘divide thy waters for me, that I may pass through thee.’ It replied, ‘Thou art about to do the will of thy Maker; I, too, am doing the will of my Maker. Thou mayest or mayest not accomplish thy purpose; I am sure of accomplishing mine.’ He said: ‘If thou wilt not divide thyself, I will decree that no waters ever pass through thee.’ It, thereupon, divided itself for him.
There was also present a certain man who was carrying wheat for the Passover, and so Rabbi Pineḥas ben Ya’ir once again addressed the river: ‘Divide thyself for this man, too, for he is engaged in a religious duty.’ It, thereupon, divided itself for him too.
There was also an Arab who had joined them on the journey, and so Rabbi Pineḥas ben Ya’ir once again addressed the river, ‘Divide thyself for this one, too, that he may not say “Is this the treatment of a fellow traveler?”’ It, thereupon, divided itself for him too.
Rabbi Pineḥas ben Ya’ir happened to come to a certain inn. They placed barley before his ass, but it would not eat. It was sifted, but the ass would not eat it. It was carefully picked; still the ass would not eat it.
‘Perhaps,’ suggested Rabbi Pineḥas ben Ya’ir, ‘it is not tithed?’ It was at once tithed, and the ass ate it. He, thereupon, exclaimed, ‘This poor creature is about to do the will of the Creator, and you would feed it with untithed produce!’
Ultimately the Gemara explains that although food for animals need not be tithed, if the food was first purchased to be used as human food, even if it was then used to feed animals, it still must be tithed.