I am new to MiniTest. Most tests are easy to understand, as this is Ruby code, as well as Rspec-style readability. However, I have authentication problems. As with any application, most controllers are hidden behind some kind of authentication, the most common of which is authenticate_userto ensure that the user is logged on.
How can I check user session→? I use authentication from scratch, not developing.
I have this as a link: https://github.com/chriskottom/minitest_cookbook_source/blob/master/minishop/test/support/session_helpers.rb
But not quite sure how to implement it.
Let me use this as an example controller:
class ProductsController < ApplicationController
before_action :authenticate_user
def index
@products = Product.all
end
def show
@product = Product.find(params[:id])
end
end
How will my test look in these basic cases?
test "it should GET products index" do
get :index
assert_response :success
end
test "it should GET products show" do
get :show
assert_response :success
end