Run Rubocop autocorrect on spec/

This commit is contained in:
Manuel Bustillo 2024-12-28 18:07:22 +01:00
parent c15d0806a8
commit 2fc8a6340b
21 changed files with 175 additions and 153 deletions

View File

@ -14,4 +14,8 @@ AllCops:
Layout/LineLength: Layout/LineLength:
Max: 120 Max: 120
RSpec/ExampleLength: RSpec/ExampleLength:
Max: 30 Enabled: false
Metrics/ModuleLength:
Enabled: false
RSpec/MultipleMemoizedHelpers:
Enabled: false

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
# This file is copied to spec/ when you run 'rails generate rspec:install' # This file is copied to spec/ when you run 'rails generate rspec:install'
@ -5,7 +7,7 @@ require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test' ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment' require_relative '../config/environment'
# Prevent database truncation if the environment is production # Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production? abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'rspec/rails' require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point! # Add additional requires below this line. Rails is not loaded until this point!

View File

@ -4,7 +4,7 @@
require 'swagger_helper' require 'swagger_helper'
RSpec.describe 'affinities', type: :request do RSpec.describe 'affinities' do
path '/{slug}/groups/{group_id}/affinities' do path '/{slug}/groups/{group_id}/affinities' do
parameter Swagger::Schema::SLUG parameter Swagger::Schema::SLUG
parameter name: 'group_id', in: :path, type: :string, format: :uuid, description: 'group_id' parameter name: 'group_id', in: :path, type: :string, format: :uuid, description: 'group_id'
@ -46,7 +46,7 @@ RSpec.describe 'affinities', type: :request do
} }
} }
response_empty_200 response_empty200
end end
end end
end end

View File

@ -1,10 +1,11 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'swagger_helper' require 'swagger_helper'
RSpec.describe 'captcha', type: :request do RSpec.describe 'captcha' do
path '/captcha' do path '/captcha' do
post('create a CAPTCHA challenge') do post('create a CAPTCHA challenge') do
tags 'CAPTCHA' tags 'CAPTCHA'
consumes 'application/json' consumes 'application/json'
@ -15,7 +16,7 @@ RSpec.describe 'captcha', type: :request do
required: %i[id], required: %i[id],
properties: { properties: {
id: { type: :string, format: :uuid }, id: { type: :string, format: :uuid },
media_url: { type: :string, format: :uri }, media_url: { type: :string, format: :uri }
} }
xit xit
end end

View File

@ -1,8 +1,10 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'swagger_helper' require 'swagger_helper'
RSpec.describe 'expenses', type: :request do RSpec.describe 'expenses' do
path '/{slug}/expenses' do path '/{slug}/expenses' do
get('list expenses') do get('list expenses') do
tags 'Expenses' tags 'Expenses'
@ -42,8 +44,8 @@ RSpec.describe 'expenses', type: :request do
} }
} }
response_empty_201 response_empty201
response_422 response422
regular_api_responses regular_api_responses
end end
end end
@ -60,9 +62,9 @@ RSpec.describe 'expenses', type: :request do
properties: Swagger::Schema::EXPENSE properties: Swagger::Schema::EXPENSE
} }
response_empty_200 response_empty200
response_422 response422
response_404 response404
regular_api_responses regular_api_responses
end end
@ -71,8 +73,8 @@ RSpec.describe 'expenses', type: :request do
produces 'application/json' produces 'application/json'
parameter Swagger::Schema::SLUG parameter Swagger::Schema::SLUG
parameter Swagger::Schema::ID parameter Swagger::Schema::ID
response_empty_200 response_empty200
response_404 response404
regular_api_responses regular_api_responses
end end
end end

View File

@ -1,8 +1,10 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'swagger_helper' require 'swagger_helper'
RSpec.describe 'groups', type: :request do RSpec.describe 'groups' do
path '/{slug}/groups' do path '/{slug}/groups' do
get('list groups') do get('list groups') do
tags 'Groups' tags 'Groups'
@ -100,7 +102,7 @@ RSpec.describe 'groups', type: :request do
parameter Swagger::Schema::SLUG parameter Swagger::Schema::SLUG
parameter name: :id, in: :path, type: :string, format: :uuid parameter name: :id, in: :path, type: :string, format: :uuid
response_empty_200 response_empty200
regular_api_responses regular_api_responses
end end
end end

View File

@ -1,8 +1,10 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'swagger_helper' require 'swagger_helper'
RSpec.describe 'guests', type: :request do RSpec.describe 'guests' do
path '/{slug}/guests' do path '/{slug}/guests' do
get('list guests') do get('list guests') do
tags 'Guests' tags 'Guests'
@ -51,8 +53,8 @@ RSpec.describe 'guests', type: :request do
} }
} }
response_empty_201 response_empty201
response_422 response422
regular_api_responses regular_api_responses
end end
end end
@ -80,9 +82,9 @@ RSpec.describe 'guests', type: :request do
} }
} }
response_empty_200 response_empty200
response_422 response422
response_404 response404
regular_api_responses regular_api_responses
end end
@ -92,8 +94,8 @@ RSpec.describe 'guests', type: :request do
parameter Swagger::Schema::SLUG parameter Swagger::Schema::SLUG
parameter name: 'id', in: :path, type: :string, format: :uuid parameter name: 'id', in: :path, type: :string, format: :uuid
response_empty_200 response_empty200
response_404 response404
regular_api_responses regular_api_responses
end end
end end

View File

@ -1,8 +1,10 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'swagger_helper' require 'swagger_helper'
RSpec.describe 'summary', type: :request do RSpec.describe 'summary' do
path '/{slug}/summary' do path '/{slug}/summary' do
get('list summaries') do get('list summaries') do
tags 'Summary' tags 'Summary'

View File

@ -1,8 +1,10 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'swagger_helper' require 'swagger_helper'
RSpec.describe 'tables_arrangements', type: :request do RSpec.describe 'tables_arrangements' do
path '/{slug}/tables_arrangements' do path '/{slug}/tables_arrangements' do
get('list tables arrangements') do get('list tables arrangements') do
tags 'Tables Arrangements' tags 'Tables Arrangements'

View File

@ -1,15 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'swagger_helper' require 'swagger_helper'
RSpec.describe 'tokens', type: :request do
path '/token' do
get('get a cookie with CSRF token') do
tags 'CSRF token'
consumes 'application/json'
produces 'application/json'
response_empty_200
end
end
end

View File

@ -1,9 +1,10 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'swagger_helper' require 'swagger_helper'
RSpec.describe 'users/confirmations', type: :request do RSpec.describe 'users/confirmations' do
path '/{slug}/users/confirmation' do path '/{slug}/users/confirmation' do
get('confirm user email') do get('confirm user email') do
tags 'Users' tags 'Users'
@ -17,7 +18,7 @@ RSpec.describe 'users/confirmations', type: :request do
xit xit
end end
response_422 response422
end end
end end
end end

View File

@ -1,9 +1,10 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'swagger_helper' require 'swagger_helper'
RSpec.describe 'users/registrations', type: :request do RSpec.describe 'users/registrations' do
path '/{slug}/users' do path '/{slug}/users' do
post('create registration') do post('create registration') do
tags 'Users Registrations' tags 'Users Registrations'
@ -13,7 +14,7 @@ RSpec.describe 'users/registrations', type: :request do
parameter Swagger::Schema::SLUG parameter Swagger::Schema::SLUG
parameter name: :body, in: :body, schema: { parameter name: :body, in: :body, schema: {
type: :object, type: :object,
required: [:user, :wedding], required: %i[user wedding],
properties: { properties: {
user: { user: {
type: :object, type: :object,

View File

@ -1,11 +1,11 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'swagger_helper' require 'swagger_helper'
RSpec.describe 'users/sessions', type: :request do RSpec.describe 'users/sessions' do
path '/{slug}/users/sign_in' do path '/{slug}/users/sign_in' do
post('create session') do post('create session') do
tags 'Users Sessions' tags 'Users Sessions'
consumes 'application/json' consumes 'application/json'
@ -32,7 +32,7 @@ RSpec.describe 'users/sessions', type: :request do
xit xit
end end
response_401(message: 'Invalid Email or password.') response401(message: 'Invalid Email or password.')
end end
end end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'rails_helper' require 'rails_helper'
@ -12,8 +14,7 @@ module Tables
describe '#calculate' do describe '#calculate' do
before do before do
allow(calculator).to receive(:table_size_penalty).and_return(2) allow(calculator).to receive_messages(table_size_penalty: 2, cohesion_discomfort: 3)
allow(calculator).to receive(:cohesion_discomfort).and_return(3)
end end
let(:table) { Table.new(create_list(:guest, 6)) } let(:table) { Table.new(create_list(:guest, 6)) }
@ -29,6 +30,7 @@ module Tables
table.min_per_table = 5 table.min_per_table = 5
table.max_per_table = 7 table.max_per_table = 7
end end
context 'when the number of guests is in the lower bound' do context 'when the number of guests is in the lower bound' do
let(:table) { Table.new(create_list(:guest, 5)) } let(:table) { Table.new(create_list(:guest, 5)) }
@ -88,6 +90,7 @@ module Tables
allow(AffinityGroupsHierarchy.instance).to receive(:distance).with(friends.id, school.id).and_return(4) allow(AffinityGroupsHierarchy.instance).to receive(:distance).with(friends.id, school.id).and_return(4)
allow(AffinityGroupsHierarchy.instance).to receive(:distance).with(work.id, school.id).and_return(5) allow(AffinityGroupsHierarchy.instance).to receive(:distance).with(work.id, school.id).and_return(5)
end end
context 'when the table contains just two guests' do context 'when the table contains just two guests' do
context 'when they belong to the same group' do context 'when they belong to the same group' do
let(:table) { create_list(:guest, 2, group: family) } let(:table) { create_list(:guest, 2, group: family) }
@ -102,6 +105,7 @@ module Tables
create(:guest, group: friends) create(:guest, group: friends)
] ]
end end
it { expect(calculator.send(:cohesion_discomfort)).to eq(1) } it { expect(calculator.send(:cohesion_discomfort)).to eq(1) }
end end
@ -205,7 +209,7 @@ module Tables
end end
it 'returns the sum of the penalties for each pair of guests' do it 'returns the sum of the penalties for each pair of guests' do
expect(calculator.send(:cohesion_discomfort)).to eq(4 * 1 + 4 * Rational(1, 2) + 4 * Rational(2, 3)) expect(calculator.send(:cohesion_discomfort)).to eq((4 * 1) + (4 * Rational(1, 2)) + (4 * Rational(2, 3)))
end end
end end
@ -219,7 +223,7 @@ module Tables
end end
it 'returns the sum of the penalties for each pair of guests' do it 'returns the sum of the penalties for each pair of guests' do
expect(calculator.send(:cohesion_discomfort)).to eq(6 * 1 + 2 * Rational(1, 2) + 3 * Rational(2, 3)) expect(calculator.send(:cohesion_discomfort)).to eq((6 * 1) + (2 * Rational(1, 2)) + (3 * Rational(2, 3)))
end end
end end
end end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'rails_helper' require 'rails_helper'
@ -5,19 +7,19 @@ require 'rails_helper'
module Tables module Tables
RSpec.describe Distribution do RSpec.describe Distribution do
describe '#random_distribution' do describe '#random_distribution' do
let(:subject) { described_class.new(min_per_table: 5, max_per_table: 10) } subject(:distribution) { described_class.new(min_per_table: 5, max_per_table: 10) }
context 'when there are fewer people than the minimum per table' do context 'when there are fewer people than the minimum per table' do
it 'creates one table' do it 'creates one table' do
subject.random_distribution([1, 2, 3, 4]) distribution.random_distribution([1, 2, 3, 4])
expect(subject.tables.count).to eq(1) expect(distribution.tables.count).to eq(1)
end end
end end
context 'when there are more people than the maximum per table' do context 'when there are more people than the maximum per table' do
it 'creates multiple tables' do it 'creates multiple tables' do
subject.random_distribution([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) distribution.random_distribution([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
expect(subject.tables.count).to be > 1 expect(distribution.tables.count).to be > 1
end end
end end
end end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'rails_helper' require 'rails_helper'
@ -7,7 +9,7 @@ module Tables
describe '#each' do describe '#each' do
let(:shifts) do let(:shifts) do
acc = [] acc = []
described_class.new(initial_solution).each do |solution| described_class.new(initial_solution).each do |solution| # rubocop:disable Style/MapIntoArray -- #map is not implemented
acc << solution.tables.map(&:dup) acc << solution.tables.map(&:dup)
end end
acc acc

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'rails_helper' require 'rails_helper'
@ -7,7 +9,7 @@ module Tables
describe '#each' do describe '#each' do
let(:swaps) do let(:swaps) do
acc = [] acc = []
described_class.new(initial_solution).each do |solution| described_class.new(initial_solution).each do |solution| # rubocop:disable Style/MapIntoArray -- #map is not implemented
acc << solution.tables.map(&:dup) acc << solution.tables.map(&:dup)
end end
acc acc

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
require 'rails_helper' require 'rails_helper'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
# This file was generated by the `rails generate rspec:install` command. Conventionally, all # This file was generated by the `rails generate rspec:install` command. Conventionally, all
@ -48,49 +50,47 @@ RSpec.configure do |config|
# The settings below are suggested to provide a good initial experience # The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content. # with RSpec, but feel free to customize to your heart's content.
=begin # # This allows you to limit a spec run to individual examples or groups
# This allows you to limit a spec run to individual examples or groups # # you care about by tagging them with `:focus` metadata. When nothing
# you care about by tagging them with `:focus` metadata. When nothing # # is tagged with `:focus`, all examples get run. RSpec also provides
# is tagged with `:focus`, all examples get run. RSpec also provides # # aliases for `it`, `describe`, and `context` that include `:focus`
# aliases for `it`, `describe`, and `context` that include `:focus` # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
# metadata: `fit`, `fdescribe` and `fcontext`, respectively. # config.filter_run_when_matching :focus
config.filter_run_when_matching :focus #
# # Allows RSpec to persist some state between runs in order to support
# Allows RSpec to persist some state between runs in order to support # # the `--only-failures` and `--next-failure` CLI options. We recommend
# the `--only-failures` and `--next-failure` CLI options. We recommend # # you configure your source control system to ignore this file.
# you configure your source control system to ignore this file. # config.example_status_persistence_file_path = "spec/examples.txt"
config.example_status_persistence_file_path = "spec/examples.txt" #
# # Limits the available syntax to the non-monkey patched syntax that is
# Limits the available syntax to the non-monkey patched syntax that is # # recommended. For more details, see:
# recommended. For more details, see: # # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
# https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ # config.disable_monkey_patching!
config.disable_monkey_patching! #
# # Many RSpec users commonly either run the entire suite or an individual
# Many RSpec users commonly either run the entire suite or an individual # # file, and it's useful to allow more verbose output when running an
# file, and it's useful to allow more verbose output when running an # # individual spec file.
# individual spec file. # if config.files_to_run.one?
if config.files_to_run.one? # # Use the documentation formatter for detailed output,
# Use the documentation formatter for detailed output, # # unless a formatter has already been configured
# unless a formatter has already been configured # # (e.g. via a command-line flag).
# (e.g. via a command-line flag). # config.default_formatter = "doc"
config.default_formatter = "doc" # end
end #
# # Print the 10 slowest examples and example groups at the
# Print the 10 slowest examples and example groups at the # # end of the spec run, to help surface which specs are running
# end of the spec run, to help surface which specs are running # # particularly slow.
# particularly slow. # config.profile_examples = 10
config.profile_examples = 10 #
# # Run specs in random order to surface order dependencies. If you find an
# Run specs in random order to surface order dependencies. If you find an # # order dependency and want to debug it, you can fix the order by providing
# order dependency and want to debug it, you can fix the order by providing # # the seed, which is printed after each run.
# the seed, which is printed after each run. # # --seed 1234
# --seed 1234 # config.order = :random
config.order = :random #
# # Seed global randomization in this process using the `--seed` CLI option.
# Seed global randomization in this process using the `--seed` CLI option. # # Setting this allows you to use `--seed` to deterministically reproduce
# Setting this allows you to use `--seed` to deterministically reproduce # # test failures related to randomization by passing the same `--seed` value
# test failures related to randomization by passing the same `--seed` value # # as the one that triggered the failure.
# as the one that triggered the failure. # Kernel.srand config.seed
Kernel.srand config.seed
=end
end end

View File

@ -3,10 +3,10 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'rails_helper' require 'rails_helper'
require_relative './swagger_response_helper' require_relative 'swagger_response_helper'
require_relative './requests/schemas.rb' require_relative 'requests/schemas'
include SwaggerResponseHelper include SwaggerResponseHelper # rubocop:disable Style/MixinUsage
RSpec.configure do |config| RSpec.configure do |config|
# Specify a root folder where Swagger JSON files are generated # Specify a root folder where Swagger JSON files are generated

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
module SwaggerResponseHelper module SwaggerResponseHelper
@ -5,14 +7,13 @@ module SwaggerResponseHelper
TIMESTAMP_EXAMPLE = Time.zone.now.iso8601(3) TIMESTAMP_EXAMPLE = Time.zone.now.iso8601(3)
TIMESTAMP = { type: :string, pattern: TIMESTAMP_FORMAT, example: TIMESTAMP_EXAMPLE }.freeze TIMESTAMP = { type: :string, pattern: TIMESTAMP_FORMAT, example: TIMESTAMP_EXAMPLE }.freeze
PASSWORD = { type: :string, minLength: User.password_length.begin, maxLength: User.password_length.end } PASSWORD = { type: :string, minLength: User.password_length.begin, maxLength: User.password_length.end }.freeze
def regular_api_responses def regular_api_responses
response_401 response401
end end
def response_422 def response422
response(422, 'Validation errors in input parameters') do response(422, 'Validation errors in input parameters') do
produces 'application/json' produces 'application/json'
error_schema error_schema
@ -20,7 +21,7 @@ module SwaggerResponseHelper
end end
end end
def response_empty_200 def response_empty200
response(200, 'Success') do response(200, 'Success') do
produces 'application/json' produces 'application/json'
schema type: :object schema type: :object
@ -28,7 +29,7 @@ module SwaggerResponseHelper
end end
end end
def response_empty_201 def response_empty201
response(201, 'Created') do response(201, 'Created') do
produces 'application/json' produces 'application/json'
schema type: :object schema type: :object
@ -36,7 +37,7 @@ module SwaggerResponseHelper
end end
end end
def response_404 def response404
response(404, 'Record not found') do response(404, 'Record not found') do
produces 'application/json' produces 'application/json'
error_schema error_schema
@ -44,7 +45,7 @@ module SwaggerResponseHelper
end end
end end
def response_401(message: nil) def response401(message: nil)
response(401, 'Unauthorized') do response(401, 'Unauthorized') do
produces 'application/json' produces 'application/json'
schema type: :object, schema type: :object,