Guys bear with me on this. I have been asked by my management team to do something like below and I would highly appreciate any advise provided.
So lets say I have a controller with the below code:
class ListsController < ApplicationController
def show
@list = List.create(slug: params[:slug], something: params[:something])
render 'home/index'
end
end
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 we have been asked to remove it when running tests).
So my question:
- First Is it at all possible to test this without a db?
- If yes then how?
So far I have tried using nulldb gem to remove the db dependency. But the problem arrives when the created object cannot be retrieved. I have tried stubbing and mocking the created object but it hasn't worked so far. Even if it does it would take ages to follow this and test the complete application.
Edit:
I have tried factory_bot as well. But that only helps instantiate an object. But how can I retrieve them later?
Let me know if there is anything you need to understand it better or if I have missed something. Guys any help appreciated.