Skip to content

Commit

Permalink
Add controller tests for new and create limerick actions
Browse files Browse the repository at this point in the history
  • Loading branch information
sdflem committed Apr 19, 2023
1 parent 0fd930c commit 72d5f5f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/controllers/limericks_controller_test.rb
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 72d5f5f

Please sign in to comment.