From 712cd10894590004a19f479381553bae6db94b72 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Sat, 4 Jan 2025 10:21:22 +0800 Subject: [PATCH] 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. --- Gemfile | 2 +- Guardfile | 10 +++++----- app/controllers/sessions_controller.rb | 6 +++--- app/controllers/users_controller.rb | 8 ++++---- app/helpers/application_helper.rb | 2 +- config/initializers/assets.rb | 2 +- config/routes.rb | 14 +++++++------- .../static_pages_controller_test.rb | 2 -- test/helpers/application_helper_test.rb | 4 ++-- test/helpers/sessions_helper_test.rb | 5 ++--- test/integration/site_layout_test.rb | 2 +- test/integration/users_edit_test.rb | 6 +++--- test/integration/users_login_test.rb | 18 +++++++++--------- test/integration/users_signup_test.rb | 14 +++++++------- test/models/user_test.rb | 2 +- test/test_helper.rb | 2 +- 16 files changed, 48 insertions(+), 51 deletions(-) diff --git a/Gemfile b/Gemfile index 3abddd4..b0a18fc 100644 --- a/Gemfile +++ b/Gemfile @@ -17,7 +17,7 @@ gem "stimulus-rails" # Build JSON APIs with ease [https://github.com/rails/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] # gem "bcrypt", "~> 3.1.7" diff --git a/Guardfile b/Guardfile index 2bd369a..5a41d27 100644 --- a/Guardfile +++ b/Guardfile @@ -22,7 +22,7 @@ guard :minitest, spring: "bin/rails test", all_on_start: false do 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"] + [ "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" @@ -37,7 +37,7 @@ guard :minitest, spring: "bin/rails test", all_on_start: false do resource_tests(matches[1]) end 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 watch(%r{âpp/helpers/(.*?)_helper\.rb$}) do |matches| integration_tests(matches[1]) end @@ -45,11 +45,11 @@ guard :minitest, spring: "bin/rails test", all_on_start: false do 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'] + 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'] + 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. @@ -70,4 +70,4 @@ def end # Returns all tests for the given resource. def resource_tests(resource) integration_tests(resource) << controller_test(resource) -end \ No newline at end of file +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index f951c73..768a8f0 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -9,12 +9,12 @@ class SessionsController < ApplicationController if user&.authenticate(params[:session][:password]) forwarding_url = session[:forwarding_url] reset_session - params[:session][:remember_me] == '1' ? remember(user) : forget(user) + params[:session][:remember_me] == "1" ? remember(user) : forget(user) log_in user redirect_to forwarding_url || user else - flash.now[:danger] = 'Invalid email/password combination' - render 'new' + flash.now[:danger] = "Invalid email/password combination" + render "new" end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 30ca851..35b0c4b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,7 +1,7 @@ class UsersController < ApplicationController include SessionsHelper - before_action :logged_in_user, only: [:edit, :update] - before_action :correct_user, only: [:edit, :update] + before_action :logged_in_user, only: [ :edit, :update ] + before_action :correct_user, only: [ :edit, :update ] def show @user = User.find(params[:id]) # debugger @@ -20,7 +20,7 @@ class UsersController < ApplicationController redirect_to @user # redirect_to user_url(@user) else - render 'new' + render "new" end end @@ -35,7 +35,7 @@ class UsersController < ApplicationController redirect_to @user # redirect_to user_url(@user) else - render 'edit' + render "edit" end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 648da92..2a92931 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,5 @@ module ApplicationHelper - def full_title(page_title = '') + def full_title(page_title = "") base_title = "Ruby on Rails Tutorial Sample App" if page_title.empty? base_title diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index da93bfb..e6eaff8 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -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-icons/font") Rails.application.config.assets.paths << Rails.root.join("node_modules/bootstrap/dist/js") -Rails.application.config.assets.precompile << "bootstrap.min.js" \ No newline at end of file +Rails.application.config.assets.precompile << "bootstrap.min.js" diff --git a/config/routes.rb b/config/routes.rb index 3a35d24..6448878 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,14 +8,14 @@ Rails.application.routes.draw do root "static_pages#home" - get '/help', to: 'static_pages#help' - get '/about', to: 'static_pages#about' - get '/contact', to: 'static_pages#contact' - get '/signup', to: 'users#new' + get "/help", to: "static_pages#help" + get "/about", to: "static_pages#about" + get "/contact", to: "static_pages#contact" + get "/signup", to: "users#new" - get '/login', to: 'sessions#new' - post '/login', to: 'sessions#create' - delete '/logout', to: 'sessions#destroy' + get "/login", to: "sessions#new" + post "/login", to: "sessions#create" + delete "/logout", to: "sessions#destroy" resources :users diff --git a/test/controllers/static_pages_controller_test.rb b/test/controllers/static_pages_controller_test.rb index 54aa596..affca83 100644 --- a/test/controllers/static_pages_controller_test.rb +++ b/test/controllers/static_pages_controller_test.rb @@ -1,7 +1,6 @@ require "test_helper" class StaticPagesControllerTest < ActionDispatch::IntegrationTest - def setup @base_title = "Ruby on Rails Tutorial Sample App" end @@ -30,4 +29,3 @@ class StaticPagesControllerTest < ActionDispatch::IntegrationTest assert_select "title", full_title("Contact") end end - diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 0b718a2..fa97ea5 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -1,8 +1,8 @@ -require 'test_helper' +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 \ No newline at end of file +end diff --git a/test/helpers/sessions_helper_test.rb b/test/helpers/sessions_helper_test.rb index 500b3b8..06391f6 100644 --- a/test/helpers/sessions_helper_test.rb +++ b/test/helpers/sessions_helper_test.rb @@ -1,7 +1,6 @@ -require 'test_helper' +require "test_helper" class SessionsHelperTest < ActionView::TestCase - def setup @user = users(:michael) remember(@user) @@ -16,4 +15,4 @@ class SessionsHelperTest < ActionView::TestCase @user.update_attribute(:remember_digest, User.digest(User.new_token)) assert_nil current_user end -end \ No newline at end of file +end diff --git a/test/integration/site_layout_test.rb b/test/integration/site_layout_test.rb index b416fb0..878a459 100644 --- a/test/integration/site_layout_test.rb +++ b/test/integration/site_layout_test.rb @@ -6,7 +6,7 @@ class SiteLayoutTest < ActionDispatch::IntegrationTest # end test "layout links" do 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=?]", about_url assert_select "a[href=?]", help_url diff --git a/test/integration/users_edit_test.rb b/test/integration/users_edit_test.rb index 87a5ce5..67dcf79 100644 --- a/test/integration/users_edit_test.rb +++ b/test/integration/users_edit_test.rb @@ -19,7 +19,7 @@ class UsersEditTest < ActionDispatch::IntegrationTest get edit_user_path(@user) log_in_as(@user) assert_redirected_to edit_user_url(@user) - assert_template 'users/edit' + assert_template "users/edit" name = "Foo Bae" email = "foo@bar.com" patch user_path(@user), params: { user: { name: name, @@ -36,13 +36,13 @@ class UsersEditTest < ActionDispatch::IntegrationTest test "unsuccessful edit" do log_in_as(@user) get edit_user_path(@user) - assert_template 'users/edit' + assert_template "users/edit" patch user_path(@user), params: { user: { name: "", email: "foo@invalid", password: "foo", password_confirmation: "bar" } } - assert_template 'users/edit' + assert_template "users/edit" end test "should redirect edit when not logged in" do diff --git a/test/integration/users_login_test.rb b/test/integration/users_login_test.rb index 46cfb8b..fab2475 100644 --- a/test/integration/users_login_test.rb +++ b/test/integration/users_login_test.rb @@ -7,11 +7,11 @@ class UsersLoginTest < ActionDispatch::IntegrationTest test "login with valid email/invalid password" do get login_path - assert_template 'sessions/new' + assert_template "sessions/new" post login_path, params: { session: { email: @user.email, password: "invalid" } } assert_not is_logged_in? - assert_template 'sessions/new' + assert_template "sessions/new" assert_not flash.empty? get root_path assert flash.empty? @@ -19,10 +19,10 @@ class UsersLoginTest < ActionDispatch::IntegrationTest test "login with invalid information" do get login_path - assert_template 'sessions/new' + assert_template "sessions/new" post login_path, params: { session: { email: "", password: "" } } - assert_template 'sessions/new' + assert_template "sessions/new" assert_not flash.empty? get root_path assert flash.empty? @@ -32,11 +32,11 @@ class UsersLoginTest < ActionDispatch::IntegrationTest get login_path post login_path, params: { session: { email: @user.email, - password: 'password' } } + password: "password" } } assert is_logged_in? assert_redirected_to @user follow_redirect! - assert_template 'users/show' + assert_template "users/show" assert_select "a[href=?]", login_path, count: 0 assert_select "a[href=?]", logout_path assert_select "a[href=?]", user_path(@user) @@ -52,13 +52,13 @@ class UsersLoginTest < ActionDispatch::IntegrationTest end 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? end test "login without remembering" do - log_in_as(@user, remember_me: '1') - log_in_as(@user, remember_me: '0') + log_in_as(@user, remember_me: "1") + log_in_as(@user, remember_me: "0") assert cookies[:remember_token].blank? end end diff --git a/test/integration/users_signup_test.rb b/test/integration/users_signup_test.rb index 159e452..a22ba93 100644 --- a/test/integration/users_signup_test.rb +++ b/test/integration/users_signup_test.rb @@ -3,27 +3,27 @@ require "test_helper" class UsersSignupTest < ActionDispatch::IntegrationTest test "invalid signup information" do get signup_path - assert_no_difference 'User.count' do + assert_no_difference "User.count" do post users_path, params: { user: { name: "", email: "user@invalid", password: "foo", password_confirmation: "bar" } } end - assert_template 'users/new' - assert_select 'div#error_explanation' - assert_select 'div.alert-danger' + assert_template "users/new" + assert_select "div#error_explanation" + assert_select "div.alert-danger" end test "valid signup information" do get signup_path - assert_difference 'User.count', 1 do - post users_path, params: { user: {name: "Example User", + assert_difference "User.count", 1 do + post users_path, params: { user: { name: "Example User", email: "user@example.com", password: "password", password_confirmation: "password" } } end follow_redirect! - assert_template 'users/show' + assert_template "users/show" assert_not flash.notice assert is_logged_in? end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 54014d5..4c34345 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -75,6 +75,6 @@ class UserTest < ActiveSupport::TestCase end test "authenticated? should return false for a user with nil digest" do - assert_not @user.authenticated?('') + assert_not @user.authenticated?("") end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 93c8556..07b4884 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -23,7 +23,7 @@ module ActiveSupport end 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, password: password, remember_me: remember_me } }