style: standardize quotation marks and spacing

- Updated single quotes to double quotes for consistency
- Adjusted spacing in array definitions for better readability
- Ensured consistent use of quotes in flash messages and method parameters

These changes enhance the overall code style without altering any functionality.
This commit is contained in:
songtianlun 2025-01-04 10:21:22 +08:00
parent 5ff05c3dc4
commit 712cd10894
16 changed files with 48 additions and 51 deletions

View File

@ -17,7 +17,7 @@ gem "stimulus-rails"
# Build JSON APIs with ease [https://github.com/rails/jbuilder] # Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder" gem "jbuilder"
gem 'bcrypt', '~> 3.1' gem "bcrypt", "~> 3.1"
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7" # gem "bcrypt", "~> 3.1.7"

View File

@ -22,7 +22,7 @@ guard :minitest, spring: "bin/rails test", all_on_start: false do
watch('config/routes.rb') { interface_tests } watch('config/routes.rb') { interface_tests }
watch(%r{app/views/layouts/*}) { interface_tests } watch(%r{app/views/layouts/*}) { interface_tests }
watch(%r{âpp/models/(.*?)\.rb$}) do |matches| watch(%r{âpp/models/(.*?)\.rb$}) do |matches|
["test/models/#{matches[1]}_test.rb", "test/integration/microposts_interface_test.rb"] [ "test/models/#{matches[1]}_test.rb", "test/integration/microposts_interface_test.rb" ]
end end
watch(%r{^test/fixtures/(.*?)\.yml$}) do |matches| watch(%r{^test/fixtures/(.*?)\.yml$}) do |matches|
"test/models/#{matches[1].singularize}_test.rb" "test/models/#{matches[1].singularize}_test.rb"
@ -37,7 +37,7 @@ guard :minitest, spring: "bin/rails test", all_on_start: false do
resource_tests(matches[1]) resource_tests(matches[1])
end end
watch(%r{âpp/views/([^/]*?)/.*\.html\.erb$}) do |matches| watch(%r{âpp/views/([^/]*?)/.*\.html\.erb$}) do |matches|
["test/controllers/#{matches[1]}_controller_test.rb"] + integration_tests(matches[1]) [ "test/controllers/#{matches[1]}_controller_test.rb" ] + integration_tests(matches[1])
end end
watch(%r{âpp/helpers/(.*?)_helper\.rb$}) do |matches| integration_tests(matches[1]) watch(%r{âpp/helpers/(.*?)_helper\.rb$}) do |matches| integration_tests(matches[1])
end end
@ -45,11 +45,11 @@ guard :minitest, spring: "bin/rails test", all_on_start: false do
end end
watch('app/helpers/sessions_helper.rb') do integration_tests << 'test/helpers/sessions_helper_test.rb' watch('app/helpers/sessions_helper.rb') do integration_tests << 'test/helpers/sessions_helper_test.rb'
end end
watch('app/controllers/sessions_controller.rb') do ['test/controllers/sessions_controller_test.rb', 'test/integration/users_login_test.rb'] watch('app/controllers/sessions_controller.rb') do [ 'test/controllers/sessions_controller_test.rb', 'test/integration/users_login_test.rb' ]
end end
watch('app/controllers/account_activations_controller.rb') do 'test/integration/users_signup_test.rb' watch('app/controllers/account_activations_controller.rb') do 'test/integration/users_signup_test.rb'
end end
watch(%r{app/views/users/*}) do resource_tests('users') + ['test/integration/microposts_interface_test.rb'] watch(%r{app/views/users/*}) do resource_tests('users') + [ 'test/integration/microposts_interface_test.rb' ]
end end
end # Returns the integration tests corresponding to the given resource. end # Returns the integration tests corresponding to the given resource.
@ -70,4 +70,4 @@ def
end # Returns all tests for the given resource. end # Returns all tests for the given resource.
def def
resource_tests(resource) integration_tests(resource) << controller_test(resource) resource_tests(resource) integration_tests(resource) << controller_test(resource)
end end

View File

@ -9,12 +9,12 @@ class SessionsController < ApplicationController
if user&.authenticate(params[:session][:password]) if user&.authenticate(params[:session][:password])
forwarding_url = session[:forwarding_url] forwarding_url = session[:forwarding_url]
reset_session reset_session
params[:session][:remember_me] == '1' ? remember(user) : forget(user) params[:session][:remember_me] == "1" ? remember(user) : forget(user)
log_in user log_in user
redirect_to forwarding_url || user redirect_to forwarding_url || user
else else
flash.now[:danger] = 'Invalid email/password combination' flash.now[:danger] = "Invalid email/password combination"
render 'new' render "new"
end end
end end

View File

@ -1,7 +1,7 @@
class UsersController < ApplicationController class UsersController < ApplicationController
include SessionsHelper include SessionsHelper
before_action :logged_in_user, only: [:edit, :update] before_action :logged_in_user, only: [ :edit, :update ]
before_action :correct_user, only: [:edit, :update] before_action :correct_user, only: [ :edit, :update ]
def show def show
@user = User.find(params[:id]) @user = User.find(params[:id])
# debugger # debugger
@ -20,7 +20,7 @@ class UsersController < ApplicationController
redirect_to @user redirect_to @user
# redirect_to user_url(@user) # redirect_to user_url(@user)
else else
render 'new' render "new"
end end
end end
@ -35,7 +35,7 @@ class UsersController < ApplicationController
redirect_to @user redirect_to @user
# redirect_to user_url(@user) # redirect_to user_url(@user)
else else
render 'edit' render "edit"
end end
end end

View File

@ -1,5 +1,5 @@
module ApplicationHelper module ApplicationHelper
def full_title(page_title = '') def full_title(page_title = "")
base_title = "Ruby on Rails Tutorial Sample App" base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty? if page_title.empty?
base_title base_title

View File

@ -8,4 +8,4 @@ Rails.application.config.assets.version = "1.0"
Rails.application.config.assets.paths << Rails.root.join("node_modules/bootstrap/dist/js") Rails.application.config.assets.paths << Rails.root.join("node_modules/bootstrap/dist/js")
Rails.application.config.assets.paths << Rails.root.join("node_modules/bootstrap-icons/font") Rails.application.config.assets.paths << Rails.root.join("node_modules/bootstrap-icons/font")
Rails.application.config.assets.paths << Rails.root.join("node_modules/bootstrap/dist/js") Rails.application.config.assets.paths << Rails.root.join("node_modules/bootstrap/dist/js")
Rails.application.config.assets.precompile << "bootstrap.min.js" Rails.application.config.assets.precompile << "bootstrap.min.js"

View File

@ -8,14 +8,14 @@ Rails.application.routes.draw do
root "static_pages#home" root "static_pages#home"
get '/help', to: 'static_pages#help' get "/help", to: "static_pages#help"
get '/about', to: 'static_pages#about' get "/about", to: "static_pages#about"
get '/contact', to: 'static_pages#contact' get "/contact", to: "static_pages#contact"
get '/signup', to: 'users#new' get "/signup", to: "users#new"
get '/login', to: 'sessions#new' get "/login", to: "sessions#new"
post '/login', to: 'sessions#create' post "/login", to: "sessions#create"
delete '/logout', to: 'sessions#destroy' delete "/logout", to: "sessions#destroy"
resources :users resources :users

View File

@ -1,7 +1,6 @@
require "test_helper" require "test_helper"
class StaticPagesControllerTest < ActionDispatch::IntegrationTest class StaticPagesControllerTest < ActionDispatch::IntegrationTest
def setup def setup
@base_title = "Ruby on Rails Tutorial Sample App" @base_title = "Ruby on Rails Tutorial Sample App"
end end
@ -30,4 +29,3 @@ class StaticPagesControllerTest < ActionDispatch::IntegrationTest
assert_select "title", full_title("Contact") assert_select "title", full_title("Contact")
end end
end end

View File

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

View File

@ -1,7 +1,6 @@
require 'test_helper' require "test_helper"
class SessionsHelperTest < ActionView::TestCase class SessionsHelperTest < ActionView::TestCase
def setup def setup
@user = users(:michael) @user = users(:michael)
remember(@user) remember(@user)
@ -16,4 +15,4 @@ class SessionsHelperTest < ActionView::TestCase
@user.update_attribute(:remember_digest, User.digest(User.new_token)) @user.update_attribute(:remember_digest, User.digest(User.new_token))
assert_nil current_user assert_nil current_user
end end
end end

View File

@ -6,7 +6,7 @@ class SiteLayoutTest < ActionDispatch::IntegrationTest
# end # end
test "layout links" do test "layout links" do
get root_path get root_path
assert_template 'static_pages/home' assert_template "static_pages/home"
assert_select "a[href=?]", root_url, count: 2 assert_select "a[href=?]", root_url, count: 2
assert_select "a[href=?]", about_url assert_select "a[href=?]", about_url
assert_select "a[href=?]", help_url assert_select "a[href=?]", help_url

View File

@ -19,7 +19,7 @@ class UsersEditTest < ActionDispatch::IntegrationTest
get edit_user_path(@user) get edit_user_path(@user)
log_in_as(@user) log_in_as(@user)
assert_redirected_to edit_user_url(@user) assert_redirected_to edit_user_url(@user)
assert_template 'users/edit' assert_template "users/edit"
name = "Foo Bae" name = "Foo Bae"
email = "foo@bar.com" email = "foo@bar.com"
patch user_path(@user), params: { user: { name: name, patch user_path(@user), params: { user: { name: name,
@ -36,13 +36,13 @@ class UsersEditTest < ActionDispatch::IntegrationTest
test "unsuccessful edit" do test "unsuccessful edit" do
log_in_as(@user) log_in_as(@user)
get edit_user_path(@user) get edit_user_path(@user)
assert_template 'users/edit' assert_template "users/edit"
patch user_path(@user), params: { user: { name: "", patch user_path(@user), params: { user: { name: "",
email: "foo@invalid", email: "foo@invalid",
password: "foo", password: "foo",
password_confirmation: "bar" password_confirmation: "bar"
} } } }
assert_template 'users/edit' assert_template "users/edit"
end end
test "should redirect edit when not logged in" do test "should redirect edit when not logged in" do

View File

@ -7,11 +7,11 @@ class UsersLoginTest < ActionDispatch::IntegrationTest
test "login with valid email/invalid password" do test "login with valid email/invalid password" do
get login_path get login_path
assert_template 'sessions/new' assert_template "sessions/new"
post login_path, params: { session: { email: @user.email, post login_path, params: { session: { email: @user.email,
password: "invalid" } } password: "invalid" } }
assert_not is_logged_in? assert_not is_logged_in?
assert_template 'sessions/new' assert_template "sessions/new"
assert_not flash.empty? assert_not flash.empty?
get root_path get root_path
assert flash.empty? assert flash.empty?
@ -19,10 +19,10 @@ class UsersLoginTest < ActionDispatch::IntegrationTest
test "login with invalid information" do test "login with invalid information" do
get login_path get login_path
assert_template 'sessions/new' assert_template "sessions/new"
post login_path, params: { session: { post login_path, params: { session: {
email: "", password: "" } } email: "", password: "" } }
assert_template 'sessions/new' assert_template "sessions/new"
assert_not flash.empty? assert_not flash.empty?
get root_path get root_path
assert flash.empty? assert flash.empty?
@ -32,11 +32,11 @@ class UsersLoginTest < ActionDispatch::IntegrationTest
get login_path get login_path
post login_path, params: { session: { email: post login_path, params: { session: { email:
@user.email, @user.email,
password: 'password' } } password: "password" } }
assert is_logged_in? assert is_logged_in?
assert_redirected_to @user assert_redirected_to @user
follow_redirect! follow_redirect!
assert_template 'users/show' assert_template "users/show"
assert_select "a[href=?]", login_path, count: 0 assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(@user) assert_select "a[href=?]", user_path(@user)
@ -52,13 +52,13 @@ class UsersLoginTest < ActionDispatch::IntegrationTest
end end
test "login with remembering" do test "login with remembering" do
log_in_as(@user, remember_me: '1') log_in_as(@user, remember_me: "1")
assert_not cookies[:remember_token].blank? assert_not cookies[:remember_token].blank?
end end
test "login without remembering" do test "login without remembering" do
log_in_as(@user, remember_me: '1') log_in_as(@user, remember_me: "1")
log_in_as(@user, remember_me: '0') log_in_as(@user, remember_me: "0")
assert cookies[:remember_token].blank? assert cookies[:remember_token].blank?
end end
end end

View File

@ -3,27 +3,27 @@ require "test_helper"
class UsersSignupTest < ActionDispatch::IntegrationTest class UsersSignupTest < ActionDispatch::IntegrationTest
test "invalid signup information" do test "invalid signup information" do
get signup_path get signup_path
assert_no_difference 'User.count' do assert_no_difference "User.count" do
post users_path, params: { user: { name: "", post users_path, params: { user: { name: "",
email: "user@invalid", email: "user@invalid",
password: "foo", password: "foo",
password_confirmation: "bar" } } password_confirmation: "bar" } }
end end
assert_template 'users/new' assert_template "users/new"
assert_select 'div#error_explanation' assert_select "div#error_explanation"
assert_select 'div.alert-danger' assert_select "div.alert-danger"
end end
test "valid signup information" do test "valid signup information" do
get signup_path get signup_path
assert_difference 'User.count', 1 do assert_difference "User.count", 1 do
post users_path, params: { user: {name: "Example User", post users_path, params: { user: { name: "Example User",
email: "user@example.com", email: "user@example.com",
password: "password", password: "password",
password_confirmation: "password" } } password_confirmation: "password" } }
end end
follow_redirect! follow_redirect!
assert_template 'users/show' assert_template "users/show"
assert_not flash.notice assert_not flash.notice
assert is_logged_in? assert is_logged_in?
end end

View File

@ -75,6 +75,6 @@ class UserTest < ActiveSupport::TestCase
end end
test "authenticated? should return false for a user with nil digest" do test "authenticated? should return false for a user with nil digest" do
assert_not @user.authenticated?('') assert_not @user.authenticated?("")
end end
end end

View File

@ -23,7 +23,7 @@ module ActiveSupport
end end
class ActionDispatch::IntegrationTest class ActionDispatch::IntegrationTest
def log_in_as(user, password: 'password', remember_me: '1') def log_in_as(user, password: "password", remember_me: "1")
post login_path, params: { session: { email: user.email, post login_path, params: { session: { email: user.email,
password: password, password: password,
remember_me: remember_me } } remember_me: remember_me } }