Reputation: 377
I have a sample controller with the following action, and am writing a Request spec for it:
def subscribe_user
concept = UsersConcept::Subscribe.new(user_params)
concept.run
respond_to do |format|
format.html { redirect_to users_path, notice: concept.notice_msg }
end
end
private
def user_params
params.require(:user).permit(:id, :channel_id)
end
Am I correct to write tests for the following:
UsersConcept::Subscribe
calls new
run
Or should I just focus on writing test for verifying redirects, error messages, etc. Thanks in advance.
Upvotes: 2
Views: 22
Reputation: 2727
Rails and RSpec teams suggest replacing or removing your app’s controller tests (also known as the functional test layer), in favor of directly testing models (units), or with higher-level integration tests.
Here you can find the article and some example code:
https://everydayrails.com/2016/08/29/replace-rspec-controller-tests.html
For your action you could test the redirection, success or error messages, a change in die DB for your subscription table...
Upvotes: 1