From 7d0c57ff889283c55f99de5e0e6bb2c21aad6ed8 Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Tue, 3 Jan 2023 21:42:05 -0300 Subject: [PATCH 1/6] fix article pagination info logic --- app/controllers/articles_controller.rb | 2 +- spec/requests/articles_spec.rb | 28 ++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index f1bc985..cdca90c 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -84,7 +84,7 @@ def user_is_article_author? def setup_pagination_info total = @articles.size total_pages = (total / per_page).floor - + total_pages = 1 if total_pages.zero? @pagination_info = { page: page, perPage: per_page, diff --git a/spec/requests/articles_spec.rb b/spec/requests/articles_spec.rb index a35fb0b..7c1228e 100644 --- a/spec/requests/articles_spec.rb +++ b/spec/requests/articles_spec.rb @@ -70,7 +70,12 @@ } } ], - 'articlesCount' => 2 + 'paginationInfo' => { + 'page' => 1, + 'perPage' => 10, + 'total' => 2, + 'totalPages' => 1 + } } end @@ -119,7 +124,12 @@ } } ], - 'articlesCount' => 1 + 'paginationInfo' => { + 'page' => 1, + 'perPage' => 10, + 'total' => 1, + 'totalPages' => 1 + } } end @@ -158,7 +168,12 @@ } } ], - 'articlesCount' => 1 + 'paginationInfo' => { + 'page' => 1, + 'perPage' => 10, + 'total' => 1, + 'totalPages' => 1 + } } end @@ -231,7 +246,12 @@ } } ], - 'articlesCount' => 2 + 'paginationInfo' => { + 'page' => 1, + 'perPage' => 10, + 'total' => 2, + 'totalPages' => 1 + } } end let(:token) { user.generate_jwt } From d22250478270512572071236f4e285fcba9f8001 Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Tue, 3 Jan 2023 21:42:19 -0300 Subject: [PATCH 2/6] rubocop warnings --- .rubocop.yml | 34 +++++++++++++++++-- Gemfile | 16 ++++++--- Gemfile.lock | 9 +++++ Rakefile | 4 ++- app/controllers/comments_controller.rb | 2 ++ app/models/comment.rb | 2 ++ config.ru | 4 ++- config/boot.rb | 8 +++-- config/environment.rb | 4 ++- config/environments/development.rb | 2 +- config/environments/production.rb | 14 ++++---- config/initializers/cors.rb | 10 +++--- .../initializers/filter_parameter_logging.rb | 6 ++-- config/initializers/inflections.rb | 1 + .../initializers/json_param_key_transform.rb | 2 +- config/initializers/rswag-ui.rb | 3 +- config/initializers/rswag_api.rb | 7 ++-- config/initializers/sentry.rb | 10 +++--- config/puma.rb | 14 ++++---- .../20220909022750_devise_create_users.rb | 4 +-- ...20909204735_add_profile_fields_to_users.rb | 2 ++ db/migrate/20220928231633_create_articles.rb | 2 ++ db/migrate/20221012140339_create_favorites.rb | 2 ++ ...2151001_add_favorites_count_to_articles.rb | 2 ++ ...221017135842_acts_as_follower_migration.rb | 14 ++++---- db/migrate/20221116221520_create_comments.rb | 2 ++ db/seeds.rb | 1 + spec/factories/comments.rb | 2 ++ spec/requests/comments_spec.rb | 2 ++ 29 files changed, 136 insertions(+), 49 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 58ff8ba..27399ce 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,3 @@ -# See https://docs.rubocop.org/rubocop/configuration require: - rubocop-rails @@ -27,7 +26,38 @@ RSpec/NestedGroups: Max: 4 RSpec/MultipleMemoizedHelpers: - Max: 7 + Max: 8 Style/Documentation: Enabled: false + + +Metrics/CyclomaticComplexity: + Max: 8 + +Naming/FileName: + Exclude: + - 'config/initializers/rswag-ui.rb' + +RSpec/LetSetup: + Exclude: + - 'spec/requests/tags_spec.rb' + +Rails/BulkChangeTable: + Exclude: + - 'db/migrate/20220909204735_add_profile_fields_to_users.rb' + +Style/GuardClause: + Exclude: + - 'db/migrate/20220929000432_change_collation_for_tag_names.acts_as_taggable_on_engine.rb' + +Style/IfUnlessModifier: + Exclude: + - 'db/migrate/20220929000433_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb' + +Layout/LineLength: + Max: 154 + +Rails/ApplicationRecord: + Exclude: + - 'app/models/user.rb' diff --git a/Gemfile b/Gemfile index c2c5520..5c395f4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } @@ -22,11 +24,11 @@ gem 'jwt', '~> 2.5' group :development, :test do gem 'debug', platforms: %i[mri mingw x64_mingw] + gem 'dotenv-rails', '~> 2.8.1' gem 'factory_bot_rails', '~> 6.2.0' gem 'faker', '~> 2.21.0' gem 'pry', '~> 0.14.1' gem 'rspec-rails', '~> 5.1' - gem 'dotenv-rails', '~> 2.8.1' gem 'rdoc' gem 'rswag-specs', '~> 2.5' @@ -37,12 +39,16 @@ group :development, :test do gem 'shoulda-matchers', '~> 5.1' gem 'simplecov', '~> 0.21.2' gem 'super_diff', '~> 0.9.0' + + gem 'brakeman', '~> 5.4.0' + gem 'bundler-audit', '~> 0.9.1' + gem 'ruby_audit', '~> 2.1.0' end -gem 'acts-as-taggable-on', '~> 9.0' gem 'acts_as_follower', '~> 0.2.1' +gem 'acts-as-taggable-on', '~> 9.0' -gem "rack-cors", "~> 1.1" +gem 'rack-cors', '~> 1.1' -gem "sentry-ruby", "~> 5.7" -gem "sentry-rails", "~> 5.7" +gem 'sentry-rails', '~> 5.7' +gem 'sentry-ruby', '~> 5.7' diff --git a/Gemfile.lock b/Gemfile.lock index 6677ec5..205748d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,7 +76,11 @@ GEM bcrypt (3.1.18) bootsnap (1.12.0) msgpack (~> 1.2) + brakeman (5.4.0) builder (3.2.4) + bundler-audit (0.9.1) + bundler (>= 1.2.0, < 3) + thor (~> 1.0) coderay (1.1.3) concurrent-ruby (1.1.10) crass (1.0.6) @@ -252,6 +256,8 @@ GEM rubocop-rspec (2.12.1) rubocop (~> 1.31) ruby-progressbar (1.11.0) + ruby_audit (2.1.0) + bundler-audit (~> 0.9.0) sentry-rails (5.7.0) railties (>= 5.0) sentry-ruby (~> 5.7.0) @@ -290,6 +296,8 @@ DEPENDENCIES acts-as-taggable-on (~> 9.0) acts_as_follower (~> 0.2.1) bootsnap + brakeman (~> 5.4.0) + bundler-audit (~> 0.9.1) debug devise (~> 4.8) dotenv-rails (~> 2.8.1) @@ -311,6 +319,7 @@ DEPENDENCIES rubocop-performance (~> 1.14) rubocop-rails (~> 2.14) rubocop-rspec (~> 2.11) + ruby_audit (~> 2.1.0) sentry-rails (~> 5.7) sentry-ruby (~> 5.7) shoulda-matchers (~> 5.1) diff --git a/Rakefile b/Rakefile index 9a5ea73..488c551 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require_relative "config/application" +require_relative 'config/application' Rails.application.load_tasks diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 308bde8..1944459 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CommentsController < ApplicationController before_action :find_article! before_action :authenticate_user!, only: %i[create destroy] diff --git a/app/models/comment.rb b/app/models/comment.rb index 0057499..d3627db 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Comment < ApplicationRecord belongs_to :user belongs_to :article diff --git a/config.ru b/config.ru index 4a3c09a..6dc8321 100644 --- a/config.ru +++ b/config.ru @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. -require_relative "config/environment" +require_relative 'config/environment' run Rails.application Rails.application.load_server diff --git a/config/boot.rb b/config/boot.rb index 988a5dd..c04863f 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,4 +1,6 @@ -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) +# frozen_string_literal: true -require "bundler/setup" # Set up gems listed in the Gemfile. -require "bootsnap/setup" # Speed up boot time by caching expensive operations. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations. diff --git a/config/environment.rb b/config/environment.rb index cac5315..d5abe55 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + # Load the Rails application. -require_relative "application" +require_relative 'application' # Initialize the Rails application. Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index 37306cc..a7fcdef 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -14,7 +14,7 @@ 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else - #config.action_controller.perform_caching = false + # config.action_controller.perform_caching = false config.cache_store = :null_store end diff --git a/config/environments/production.rb b/config/environments/production.rb index 57f0296..a823d70 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,4 +1,6 @@ -require "active_support/core_ext/integer/time" +# frozen_string_literal: true + +require 'active_support/core_ext/integer/time' Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -13,7 +15,7 @@ config.eager_load = true # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false + config.consider_all_requests_local = false # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). @@ -21,7 +23,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.asset_host = "http://assets.example.com" @@ -46,7 +48,7 @@ config.log_level = :info # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -75,8 +77,8 @@ # require "syslog/logger" # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") - if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) + if ENV['RAILS_LOG_TO_STDOUT'].present? + logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb index 38fdfd8..e2442d7 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Avoid CORS issues when API is called from the frontend app. @@ -7,10 +9,10 @@ Rails.application.config.middleware.insert_before 0, Rack::Cors do allow do - origins "*" + origins '*' - resource "*", - headers: :any, - methods: [:get, :post, :put, :patch, :delete, :options, :head] + resource '*', + headers: :any, + methods: %i[get post put patch delete options head] end end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index adc6568..3df77c5 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure parameters to be filtered from the log file. Use this to limit dissemination of # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported # notations and behaviors. -Rails.application.config.filter_parameters += [ - :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +Rails.application.config.filter_parameters += %i[ + passw secret token _key crypt salt certificate otp ssn ] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 3860f65..6c78420 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/config/initializers/json_param_key_transform.rb b/config/initializers/json_param_key_transform.rb index 4224850..0af184d 100644 --- a/config/initializers/json_param_key_transform.rb +++ b/config/initializers/json_param_key_transform.rb @@ -2,7 +2,7 @@ # Transform JSON request param keys from JSON-conventional camelCase to # Rails-conventional snake_case: -ActionDispatch::Request.parameter_parsers[:json] = ->(raw_post) { +ActionDispatch::Request.parameter_parsers[:json] = lambda { |raw_post| # Modified from action_dispatch/http/parameters.rb data = ActiveSupport::JSON.decode(raw_post) data = { _json: data } unless data.is_a?(Hash) diff --git a/config/initializers/rswag-ui.rb b/config/initializers/rswag-ui.rb index 0b9a4ab..ad0fa34 100644 --- a/config/initializers/rswag-ui.rb +++ b/config/initializers/rswag-ui.rb @@ -1,5 +1,6 @@ -Rswag::Ui.configure do |c| +# frozen_string_literal: true +Rswag::Ui.configure do |c| # List the Swagger endpoints that you want to be documented through the swagger-ui # The first parameter is the path (absolute or relative to the UI host) to the corresponding # endpoint and the second is a title that will be displayed in the document selector diff --git a/config/initializers/rswag_api.rb b/config/initializers/rswag_api.rb index 5f3ddc4..4ee8fd3 100644 --- a/config/initializers/rswag_api.rb +++ b/config/initializers/rswag_api.rb @@ -1,14 +1,15 @@ -Rswag::Api.configure do |c| +# frozen_string_literal: true +Rswag::Api.configure do |c| # Specify a root folder where Swagger JSON files are located # This is used by the Swagger middleware to serve requests for API descriptions # NOTE: If you're using rswag-specs to generate Swagger, you'll need to ensure # that it's configured to generate files in the same folder - c.swagger_root = Rails.root.to_s + '/swagger' + c.swagger_root = Rails.root.join('swagger') # Inject a lamda function to alter the returned Swagger prior to serialization # The function will have access to the rack env for the current request # For example, you could leverage this to dynamically assign the "host" property # - #c.swagger_filter = lambda { |swagger, env| swagger['host'] = env['HTTP_HOST'] } + # c.swagger_filter = lambda { |swagger, env| swagger['host'] = env['HTTP_HOST'] } end diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb index e2134db..426c2cc 100644 --- a/config/initializers/sentry.rb +++ b/config/initializers/sentry.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + Sentry.init do |config| - config.dsn = ENV['SENTRY_DSN'] - config.breadcrumbs_logger = [:active_support_logger, :http_logger] - config.environment = ENV['APP_ENV'] + config.dsn = ENV.fetch('SENTRY_DSN', nil) + config.breadcrumbs_logger = %i[active_support_logger http_logger] + config.environment = ENV.fetch('APP_ENV', nil) # Set traces_sample_rate to 1.0 to capture 100% # of transactions for performance monitoring. # We recommend adjusting this value in production. config.traces_sample_rate = 1.0 # or - config.traces_sampler = lambda do |context| + config.traces_sampler = lambda do |_context| true end end diff --git a/config/puma.rb b/config/puma.rb index daaf036..1713441 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,28 +1,30 @@ +# frozen_string_literal: true + # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } -min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5) +min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `worker_timeout` threshold that Puma will use to wait before # terminating a worker in development environments. # -worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" +worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development' # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT', 3000) # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV', 'development') # Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } +pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid') # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together diff --git a/db/migrate/20220909022750_devise_create_users.rb b/db/migrate/20220909022750_devise_create_users.rb index c7e8cfa..3345612 100644 --- a/db/migrate/20220909022750_devise_create_users.rb +++ b/db/migrate/20220909022750_devise_create_users.rb @@ -4,8 +4,8 @@ class DeviseCreateUsers < ActiveRecord::Migration[7.0] def change create_table :users do |t| ## Database authenticatable - t.string :email, null: false, default: "" - t.string :encrypted_password, null: false, default: "" + t.string :email, null: false, default: '' + t.string :encrypted_password, null: false, default: '' ## Recoverable t.string :reset_password_token diff --git a/db/migrate/20220909204735_add_profile_fields_to_users.rb b/db/migrate/20220909204735_add_profile_fields_to_users.rb index ef837b1..3a36f66 100644 --- a/db/migrate/20220909204735_add_profile_fields_to_users.rb +++ b/db/migrate/20220909204735_add_profile_fields_to_users.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddProfileFieldsToUsers < ActiveRecord::Migration[7.0] def change add_column :users, :username, :string diff --git a/db/migrate/20220928231633_create_articles.rb b/db/migrate/20220928231633_create_articles.rb index 50bb831..d85226c 100644 --- a/db/migrate/20220928231633_create_articles.rb +++ b/db/migrate/20220928231633_create_articles.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateArticles < ActiveRecord::Migration[7.0] def change create_table :articles do |t| diff --git a/db/migrate/20221012140339_create_favorites.rb b/db/migrate/20221012140339_create_favorites.rb index 9889b92..47980da 100644 --- a/db/migrate/20221012140339_create_favorites.rb +++ b/db/migrate/20221012140339_create_favorites.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateFavorites < ActiveRecord::Migration[7.0] def change create_table :favorites do |t| diff --git a/db/migrate/20221012151001_add_favorites_count_to_articles.rb b/db/migrate/20221012151001_add_favorites_count_to_articles.rb index ed83325..a7352ad 100644 --- a/db/migrate/20221012151001_add_favorites_count_to_articles.rb +++ b/db/migrate/20221012151001_add_favorites_count_to_articles.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddFavoritesCountToArticles < ActiveRecord::Migration[7.0] def change add_column :articles, :favorites_count, :integer diff --git a/db/migrate/20221017135842_acts_as_follower_migration.rb b/db/migrate/20221017135842_acts_as_follower_migration.rb index 1da541a..cdb2b1a 100644 --- a/db/migrate/20221017135842_acts_as_follower_migration.rb +++ b/db/migrate/20221017135842_acts_as_follower_migration.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + class ActsAsFollowerMigration < ActiveRecord::Migration[7.0] def self.up - create_table :follows, :force => true do |t| - t.references :followable, :polymorphic => true, :null => false - t.references :follower, :polymorphic => true, :null => false - t.boolean :blocked, :default => false, :null => false + create_table :follows, force: true do |t| + t.references :followable, polymorphic: true, null: false + t.references :follower, polymorphic: true, null: false + t.boolean :blocked, default: false, null: false t.timestamps end - add_index :follows, ["follower_id", "follower_type"], :name => "fk_follows" - add_index :follows, ["followable_id", "followable_type"], :name => "fk_followables" + add_index :follows, %w[follower_id follower_type], name: 'fk_follows' + add_index :follows, %w[followable_id followable_type], name: 'fk_followables' end def self.down diff --git a/db/migrate/20221116221520_create_comments.rb b/db/migrate/20221116221520_create_comments.rb index 0d76e3b..097f24f 100644 --- a/db/migrate/20221116221520_create_comments.rb +++ b/db/migrate/20221116221520_create_comments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateComments < ActiveRecord::Migration[7.0] def change create_table :comments do |t| diff --git a/db/seeds.rb b/db/seeds.rb index bc25fce..0664d1b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). # diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb index 5682297..fcdecce 100644 --- a/spec/factories/comments.rb +++ b/spec/factories/comments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :comment do body { Faker::Lorem.paragraphs.join(' ') } diff --git a/spec/requests/comments_spec.rb b/spec/requests/comments_spec.rb index 98cd681..a8b2752 100644 --- a/spec/requests/comments_spec.rb +++ b/spec/requests/comments_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'Comments', type: :request do From 48e13e0aa4a8a88ab3fba77c57cdebe10a65cd9b Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Tue, 3 Jan 2023 21:54:35 -0300 Subject: [PATCH 3/6] fix vulnerabilities --- Gemfile.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 205748d..e8e1aa4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -122,7 +122,7 @@ GEM json-schema (2.8.1) addressable (>= 2.4) jwt (2.5.0) - loofah (2.18.0) + loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -147,7 +147,7 @@ GEM net-protocol timeout nio4r (2.5.8) - nokogiri (1.13.7-x86_64-linux) + nokogiri (1.13.10-x86_64-linux) racc (~> 1.4) optimist (3.0.1) orm_adapter (0.5.0) @@ -165,7 +165,7 @@ GEM public_suffix (4.0.7) puma (5.6.4) nio4r (~> 2.0) - racc (1.6.0) + racc (1.6.2) rack (2.2.4) rack-cors (1.1.1) rack (>= 2.0.0) @@ -188,8 +188,8 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.4.3) - loofah (~> 2.3) + rails-html-sanitizer (1.4.4) + loofah (~> 2.19, >= 2.19.1) railties (7.0.3.1) actionpack (= 7.0.3.1) activesupport (= 7.0.3.1) From 85f0be8585e6f87c560a0069aa4bf1d9bcf3394c Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Tue, 3 Jan 2023 21:56:26 -0300 Subject: [PATCH 4/6] run rspec on test --- .github/workflows/rubyonrails.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml index 0e82a80..e9df864 100644 --- a/.github/workflows/rubyonrails.yml +++ b/.github/workflows/rubyonrails.yml @@ -38,7 +38,7 @@ jobs: run: bin/rails db:schema:load # Add or replace test runners here - name: Run tests - run: bin/rake + run: bundle exec rspec lint: runs-on: ubuntu-latest From 13c19390e419c54a3a18776c9429a21b5e8914aa Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Tue, 3 Jan 2023 22:05:41 -0300 Subject: [PATCH 5/6] configure rspec on CI From ff4034c90d74d9a19560814d126a542867af87c6 Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Tue, 3 Jan 2023 22:18:30 -0300 Subject: [PATCH 6/6] fix rspec CI problem --- .github/workflows/rubyonrails.yml | 14 +++++--------- app/models/article.rb | 5 +++++ config/application.rb | 1 + spec/requests/articles_spec.rb | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml index e9df864..7ac9cb3 100644 --- a/.github/workflows/rubyonrails.yml +++ b/.github/workflows/rubyonrails.yml @@ -1,9 +1,3 @@ -# This workflow uses actions that are not certified by GitHub. They are -# provided by a third-party and are governed by separate terms of service, -# privacy policy, and support documentation. -# -# This workflow will install a prebuilt Ruby version, install dependencies, and -# run tests and linters. name: "Ruby on Rails CI" on: push: @@ -11,7 +5,8 @@ on: pull_request: branches: [ "*" ] jobs: - test: + rspec: + name: RSpec runs-on: ubuntu-latest services: postgres: @@ -38,9 +33,10 @@ jobs: run: bin/rails db:schema:load # Add or replace test runners here - name: Run tests - run: bundle exec rspec + run: bundle exec rspec spec - lint: + rubocop: + name: Rubocop runs-on: ubuntu-latest steps: - name: Checkout code diff --git a/app/models/article.rb b/app/models/article.rb index 0545915..eaf87be 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -23,6 +23,11 @@ class Article < ApplicationRecord acts_as_taggable_on :tags + def tag_list + list = super + list.sort + end + private def set_slug diff --git a/config/application.rb b/config/application.rb index acd31e3..3f7f721 100644 --- a/config/application.rb +++ b/config/application.rb @@ -7,6 +7,7 @@ require 'active_record/railtie' require 'action_controller/railtie' require 'action_view/railtie' +require 'action_mailer/railtie' Bundler.require(*Rails.groups) diff --git a/spec/requests/articles_spec.rb b/spec/requests/articles_spec.rb index 7c1228e..1bf0179 100644 --- a/spec/requests/articles_spec.rb +++ b/spec/requests/articles_spec.rb @@ -550,7 +550,7 @@ 'title' => 'How to improve your dragon', 'description' => 'Ever wonder how?', 'body' => 'It takes a Jacobian', - 'tagList' => %w[dragons training improve], + 'tagList' => %w[dragons improve training], 'favorited' => false, 'favoritesCount' => 0, 'createdAt' => String,