a11yist/test/controllers/links_controller_test.rb

71 lines
1.6 KiB
Ruby
Raw Normal View History

2024-09-05 22:54:38 +02:00
# frozen_string_literal: true
2024-07-26 00:59:00 +02:00
require "test_helper"
class LinksControllerTest < ActionDispatch::IntegrationTest
2024-09-22 22:49:53 +02:00
def login(email, password)
post "/login", params: { email: email, password: password }
assert_redirected_to "/"
end
def logout
post "/logout"
assert_redirected_to "/"
end
teardown do
logout
end
2024-07-26 00:59:00 +02:00
setup do
@link = links(:one)
2024-09-22 22:49:53 +02:00
Account.create(email: "test@example.com", password: "password")
login("test@example.com", "password")
2024-07-26 00:59:00 +02:00
end
test "should get index" do
get links_url
assert_response :success
end
test "should get new" do
get new_link_url
assert_response :success
end
test "should create link" do
assert_difference("Link.count") do
2024-09-05 22:54:38 +02:00
post links_url,
params: { link: { fail_count: @link.fail_count, last_check_at: @link.last_check_at,
link_category_id: @link.link_category_id, text: @link.text, url: @link.url } }
2024-07-26 00:59:00 +02:00
end
assert_redirected_to link_url(Link.last)
end
test "should show link" do
get link_url(@link)
assert_response :success
end
test "should get edit" do
get edit_link_url(@link)
assert_response :success
end
test "should update link" do
2024-09-05 22:54:38 +02:00
patch link_url(@link),
params: { link: { fail_count: @link.fail_count, last_check_at: @link.last_check_at,
link_category_id: @link.link_category_id, text: @link.text, url: @link.url } }
2024-07-26 00:59:00 +02:00
assert_redirected_to link_url(@link)
end
test "should destroy link" do
assert_difference("Link.count", -1) do
delete link_url(@link)
end
assert_redirected_to links_url
end
end