From 72d5f5f767f9df1a944ee9f849af32d16b1b7859 Mon Sep 17 00:00:00 2001 From: Scott Fleming Date: Wed, 19 Apr 2023 13:34:37 -0500 Subject: [PATCH] Add controller tests for new and create limerick actions --- test/controllers/limericks_controller_test.rb | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/controllers/limericks_controller_test.rb b/test/controllers/limericks_controller_test.rb index c966176..f5d92dc 100644 --- a/test/controllers/limericks_controller_test.rb +++ b/test/controllers/limericks_controller_test.rb @@ -2,6 +2,8 @@ class LimericksControllerTest < ActionDispatch::IntegrationTest + include Devise::Test::IntegrationHelpers + test "should get index" do # Arrange (nothing to do for this test) # Act @@ -10,4 +12,41 @@ class LimericksControllerTest < ActionDispatch::IntegrationTest assert_response :success end + test "should get new" do + # Arrange + user = users(:one) + sign_in user + # Act + get new_limerick_url + # Assert + assert_response :success + end + + test "should not get new if not signed in" do + # Arrange (nothing to do for this test) + # Act + get new_limerick_url + # Assert + assert_response :redirect + assert_redirected_to new_user_session_url + end + + test "should create limerick" do + # Arrange + user = users(:one) + sign_in user + # Act + assert_difference("Limerick.count", +1) do + post limericks_url, params: { + limerick: { + title: "Hello hello hello", + limerick_text: "Hello hello hello\nHello hello hello\nHello hello hello\nHello hello hello\nHello hello hello" + } + } + end + # Assert + assert_response :redirect + assert_redirected_to root_url + end + end