Guys bear with me on this. I would highly appreciate any advise provided.
So lets say I have a controller with the below code:
class PersonController < ApplicationController
serialize_with personSerializer
string: title
int: age
def update
authorize(person, can_update?)
person.update(title:title,age:age)
serialize person
end
end
So in terms of Business Logic we have here:
- check for authorize
- update the object
- return the serializer of the object (it's just a json result)
Now I want to test this piece of code with RSpec, but there is no DB to save or receive an object (well there was one earlier, but I want to remove it when running tests).
So far I have tried using nulldb gem to remove the db dependency. But the problem arrives when the created object cannot be retrieved.
If I want to test the authorize (1). It's a function of another gem that tests if the user can even use this controller.
Do I need to completely mock it? If so, how? Which tool to use?
Same for the update, if I do person.update, how should I check if it works if I don't have access to the active record?
updateand force the response? 🤔safesince you specify exactly the received parameters.