add some test

This commit is contained in:
songtianlun 2024-12-31 00:37:02 +08:00
parent 2d8a32478c
commit 02b7393ed4
8 changed files with 42 additions and 15 deletions

View File

@ -65,4 +65,5 @@ group :test do
gem "capybara" gem "capybara"
gem "selenium-webdriver" gem "selenium-webdriver"
gem "minitest-reporters" gem "minitest-reporters"
gem "rails-controller-testing"
end end

View File

@ -272,6 +272,10 @@ GEM
activesupport (= 8.0.1) activesupport (= 8.0.1)
bundler (>= 1.15.0) bundler (>= 1.15.0)
railties (= 8.0.1) railties (= 8.0.1)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.2.0) rails-dom-testing (2.2.0)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
minitest minitest
@ -443,6 +447,7 @@ DEPENDENCIES
propshaft propshaft
puma (>= 5.0) puma (>= 5.0)
rails (~> 8.0.1) rails (~> 8.0.1)
rails-controller-testing
rubocop-rails-omakase rubocop-rails-omakase
sassc-rails (>= 2.1.0) sassc-rails (>= 2.1.0)
selenium-webdriver selenium-webdriver

View File

@ -5,8 +5,8 @@
</small> </small>
<nav> <nav>
<ul> <ul>
<li><%= link_to "About", '#' %></li> <li><%= link_to "About", about_url %></li>
<li><%= link_to "Contact", '#' %></li> <li><%= link_to "Contact", contact_url %></li>
<li><a href="https://news.railstutorial.org">News</a></li> <li><a href="https://news.railstutorial.org">News</a></li>
</ul> </ul>
</nav> </nav>

View File

@ -1,10 +1,10 @@
<header class="navbar navbar-fixed-top navbar-inverse"> <header class="navbar navbar-fixed-top navbar-inverse">
<div class="container"> <div class="container">
<%= link_to "sample app", '#', id: "logo" %> <%= link_to "sample app", root_url, id: "logo" %>
<nav> <nav>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li><%= link_to "Home", '#' %></li> <li><%= link_to "Home", root_url %></li>
<li><%= link_to "Help", '#' %></li> <li><%= link_to "Help", help_url %></li>
<li><%= link_to "Login in", '#' %></li> <li><%= link_to "Login in", '#' %></li>
</ul> </ul>
</nav> </nav>

View File

@ -4,6 +4,10 @@ Rails.application.routes.draw do
get "static_pages/about" get "static_pages/about"
get "static_pages/contact" get "static_pages/contact"
get '/help', to: 'static_pages#help'
get '/about', to: 'static_pages#about'
get '/contact', to: 'static_pages#contact'
root "static_pages#home" root "static_pages#home"
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

View File

@ -7,31 +7,25 @@ class StaticPagesControllerTest < ActionDispatch::IntegrationTest
end end
test "should get root" do test "should get root" do
get root_url get root_path
assert_response :success
assert_select "title", "Home | #{@base_title}"
end
test "should get home" do
get static_pages_home_url
assert_response :success assert_response :success
assert_select "title", "Home | #{@base_title}" assert_select "title", "Home | #{@base_title}"
end end
test "should get help" do test "should get help" do
get static_pages_help_url get help_path
assert_response :success assert_response :success
assert_select "title", "Help | #{@base_title}" assert_select "title", "Help | #{@base_title}"
end end
test "Should get about" do test "Should get about" do
get static_pages_about_url get about_path
assert_response :success assert_response :success
assert_select "title", "About | #{@base_title}" assert_select "title", "About | #{@base_title}"
end end
test "Should get contact" do test "Should get contact" do
get static_pages_contact_url get contact_path
assert_response :success assert_response :success
assert_select "title", "Contact | #{@base_title}" assert_select "title", "Contact | #{@base_title}"
end end

View File

@ -0,0 +1,8 @@
require 'test_helper'
class ApplicationHelperTest < ActionView::TestCase
test "full title helper" do
assert_equal full_title, "Ruby on Rails Tutorial Sample App"
assert_equal full_title("Contact"), "Contact | Ruby on Rails Tutorial Sample App"
end
end

View File

@ -0,0 +1,15 @@
require "test_helper"
class SiteLayoutTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
test "layout links" do
get root_path
assert_template 'static_pages/home'
assert_select "a[href=?]", root_url, count: 2
assert_select "a[href=?]", about_url
assert_select "a[href=?]", help_url
assert_select "a[href=?]", contact_url
end
end