This commit is contained in:
songtianlun 2024-12-30 00:09:54 +08:00
parent 7ee9afebe0
commit 22b1e769b2
12 changed files with 184 additions and 8 deletions

View File

@ -54,10 +54,12 @@ end
group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"
gem 'guard', '~> 2.19'
end
group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
gem "minitest-reporters"
end

View File

@ -74,6 +74,7 @@ GEM
uri (>= 0.13.1)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ansi (1.5.0)
ast (2.4.2)
base64 (0.2.0)
bcrypt_pbkdf (1.1.1)
@ -96,6 +97,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
coderay (1.1.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crass (1.0.6)
@ -109,11 +111,29 @@ GEM
erubi (1.13.1)
et-orbi (1.2.11)
tzinfo
ffi (1.17.0-aarch64-linux-gnu)
ffi (1.17.0-aarch64-linux-musl)
ffi (1.17.0-arm-linux-gnu)
ffi (1.17.0-arm-linux-musl)
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86_64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
ffi (1.17.0-x86_64-linux-musl)
formatador (1.1.0)
fugit (1.11.1)
et-orbi (~> 1, >= 1.2.11)
raabro (~> 1.4)
globalid (1.2.1)
activesupport (>= 6.1)
guard (2.19.0)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (>= 1.0.12, < 2.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.13.0)
shellany (~> 0.0)
thor (>= 0.18.1)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
importmap-rails (2.1.0)
@ -140,10 +160,14 @@ GEM
thor (~> 1.3)
zeitwerk (>= 2.6.18, < 3.0)
language_server-protocol (3.17.0.3)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.4)
loofah (2.23.1)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
lumberjack (1.2.10)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
@ -151,9 +175,16 @@ GEM
net-smtp
marcel (1.0.4)
matrix (0.4.2)
method_source (1.1.0)
mini_mime (1.1.5)
minitest (5.25.4)
minitest-reporters (1.7.1)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
msgpack (1.7.5)
nenv (0.3.0)
net-imap (0.5.4)
date
net-protocol
@ -185,6 +216,9 @@ GEM
racc (~> 1.4)
nokogiri (1.18.0-x86_64-linux-musl)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
ostruct (0.6.1)
parallel (1.26.3)
parser (3.3.6.0)
@ -195,6 +229,9 @@ GEM
activesupport (>= 7.0.0)
rack
railties (>= 7.0.0)
pry (0.15.2)
coderay (~> 1.1)
method_source (~> 1.0)
psych (5.2.2)
date
stringio
@ -241,6 +278,9 @@ GEM
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rdoc (6.10.0)
psych (>= 4.0.0)
regexp_parser (2.10.0)
@ -284,6 +324,7 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
shellany (0.0.1)
solid_cable (3.0.5)
actioncable (>= 7.2)
activejob (>= 7.2)
@ -364,9 +405,11 @@ DEPENDENCIES
brakeman
capybara
debug
guard (~> 2.19)
importmap-rails
jbuilder
kamal
minitest-reporters
propshaft
puma (>= 5.0)
rails (~> 8.0.1)

73
Guardfile Normal file
View File

@ -0,0 +1,73 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
require 'active_support/core_ext/string' # Defines the matching rules for Guard.
guard :minitest, spring: "bin/rails test", all_on_start: false do
watch(%r{^test/(.*)/?(.*)_test\.rb$})
watch('test/test_helper.rb') { 'test' }
watch('config/routes.rb') { interface_tests }
watch(%r{app/views/layouts/*}) { interface_tests }
watch(%r{âpp/models/(.*?)\.rb$}) do |matches|
["test/models/#{matches[1]}_test.rb", "test/integration/microposts_interface_test.rb"]
end
watch(%r{^test/fixtures/(.*?)\.yml$}) do |matches|
"test/models/#{matches[1].singularize}_test.rb"
end
watch(%r{âpp/mailers/(.*?)\.rb$}) do |matches|
"test/mailers/#{matches[1]}_test.rb"
end
watch(%r{âpp/views/(.*)_mailer/.*$}) do |matches|
"test/mailers/#{matches[1]}_mailer_test.rb"
end
watch(%r{âpp/controllers/(.*?)_controller\.rb$}) do |matches|
resource_tests(matches[1])
end
watch(%r{âpp/views/([^/]*?)/.*\.html\.erb$}) do |matches|
["test/controllers/#{matches[1]}_controller_test.rb"] + integration_tests(matches[1])
end
watch(%r{âpp/helpers/(.*?)_helper\.rb$}) do |matches| integration_tests(matches[1])
end
watch('app/views/layouts/application.html.erb') do 'test/integration/site_layout_test.rb'
end
watch('app/helpers/sessions_helper.rb') do integration_tests << 'test/helpers/sessions_helper_test.rb'
end
watch('app/controllers/sessions_controller.rb') do ['test/controllers/sessions_controller_test.rb', 'test/integration/users_login_test.rb']
end
watch('app/controllers/account_activations_controller.rb') do 'test/integration/users_signup_test.rb'
end
watch(%r{app/views/users/*}) do resource_tests('users') + ['test/integration/microposts_interface_test.rb']
end
end # Returns the integration tests corresponding to the given resource.
def integration_tests(resource = :all)
if resource == :all
Dir["test/integration/*"]
else
Dir["test/integration/#{resource}_*.rb"]
end
end # Returns all tests that hit the interface.
def
interface_tests
integration_tests << "test/controllers"
end # Returns the controller tests corresponding to the given resource.
def
controller_test(resource) "test/controllers/#{resource}_controller_test.rb"
end # Returns all tests for the given resource.
def
resource_tests(resource) integration_tests(resource) << controller_test(resource)
end

View File

@ -7,4 +7,7 @@ class StaticPagesController < ApplicationController
def about
end
def contact
end
end

View File

@ -1,7 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<title><%= content_for(:title) || "Sample App" %></title>
<!-- <title><%#= content_for(:title) || "Sample App" %></title>-->
<title><%= yield(:title) %> | Ruby on Rails Tutorial Sample App</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">

View File

@ -1,2 +1,11 @@
<h1>StaticPages#about</h1>
<p>Find me in app/views/static_pages/about.html.erb</p>
<% provide(:title, "About") %>
<h1>About</h1>
<p>
The <a href="https://www.railstutorial.org/"><em>Ruby on Rails Tutorial</em></a>
, part of the <a href="https://www.learnenough.com/">Learn Enough</a> family of
tutorials, is a <a href="https://www.railstutorial.org/book">book</a> and
<a href="https://screencasts.railstutorial.org/">screencast series</a>
to teach web development with <a href="https://rubyonrails.org/">Ruby on Rails</a>.
This is the sample app for the tutorial.
</p>

View File

@ -0,0 +1,8 @@
<% provide(:title, "Contact") %>
<h1>Contact</h1>
<p>
Contact the Ruby on Rails Tutorial about the sample app at the
<a href="https://www.railstutorial.org/contact">contact page</a>.
</p>

View File

@ -1,2 +1,9 @@
<h1>StaticPages#help</h1>
<p>Find me in app/views/static_pages/help.html.erb</p>
<% provide(:title, "Help") %>
<h1>Help</h1>
<p>
Get help on the Ruby on Rails Tutorial at the
<a href="https://www.railstutorial.org/help">Rails Tutorial help page</a>.
To get help on this sample app, see the
<a href="https://www.railstutorial.org/book"><em>Ruby on Rails Tutorial</em> book</a>.
</p>

View File

@ -1,2 +1,8 @@
<h1>StaticPages#home</h1>
<p>Find me in app/views/static_pages/home.html.erb</p>
<% provide(:title, "Home") %>
<h1>Sample App</h1>
<p>
This is the home page for the
<a href="https://www.railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</p>

View File

@ -2,8 +2,9 @@ Rails.application.routes.draw do
get "static_pages/home"
get "static_pages/help"
get "static_pages/about"
get "static_pages/contact"
root "application#hello"
root "static_pages#home"
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.

View File

@ -1,19 +1,40 @@
require "test_helper"
class StaticPagesControllerTest < ActionDispatch::IntegrationTest
def setup
@base_title = "Ruby on Rails Tutorial Sample App"
end
test "should get root" do
get root_url
assert_response :success
assert_select "title", "Home | #{@base_title}"
end
test "should get home" do
get static_pages_home_url
assert_response :success
assert_select "title", "Home | #{@base_title}"
assert_select "h1", "Sample App"
end
test "should get help" do
get static_pages_help_url
assert_response :success
assert_select "title", "Help | #{@base_title}"
end
test "Should get about" do
get static_pages_about_url
assert_response :success
assert_select "title", "About | #{@base_title}"
end
test "Should get contact" do
get static_pages_contact_url
assert_response :success
assert_select "title", "Contact | #{@base_title}"
end
end

View File

@ -1,6 +1,8 @@
ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"
require "minitest/reporters"
Minitest::Reporters.use!
module ActiveSupport
class TestCase