Mon modèle a une méthode qui mettra à jour plusieurs attributs dans un modèle à partir d'une ressource distante. Je veux tester cela avec Rspec, mais je ne trouve pas comment tester si un champ a été créé ou mis à jour.Test Rspec si un attribut a été mis à jour
Certains pseudo-code pour expliquer la question
def update_from_remote
attributes = {}
fields.each_key do |field_name|
attributes[field_name] = scrape_from_remote field_name
end
update_attributes(attributes)
end
En réalité, ce code est beaucoup plus complexe, mais qui n'encombrent ma question. Un create_from_remote
est plutôt similaire, seulement qu'il n'appelle pas update_attributes
mais les définit simplement, puis enregistre l'objet.
Je voudrais tester cela. Ce que je veux, est une spécification qui permet de déterminer si les champs ont été mis à jour ou remplis:
it 'should fill or set all local attributes on a new profile' do
#how to test if a list of fields were updated in the Database?
end
it 'should update all local attributes on an existing profile' do
#how to test if a list of fields were created in the Database?
end
J'utilise MongoId, mais autant que je sache cela ne devrait pas faire beaucoup de différence.