Closed jonmchan closed 5 years ago
I generally don't test views. Especially with the default setup that is only one line of code. The test above makes sense for datagrid if you are really concerned.
Perhaps
RSpec.describe "contacts/index", type: :view do
before(:each) do
create_list(:contact, 11)
end
context "admin" do
before(:each) do
allow(view).to receive(:current_user).and_return(create(:admin))
contact_grid = assign(:grid, ContactsGrid.new)
assign(:pagy, pagy(contact_grid.assets)[0])
assign(:records, pagy(contact_grid.assets)[1])
render
end
it "renders a list of users with heading and paginations" do
# do assert
end
end
And my index action
def index
@grid = ContactsGrid.new(params[:contacts_grid])
@pagy, @records = pagy(@grid.assets)
authorize @grid
end
I do a rails scaffold and it generates the standard rspec view tests:
I was thinking about what the best way to do view specs with datagrid. Any best practices?