hensei-api/spec/rails_helper.rb
Justin Edmund d6300f7aeb
Add first round of tests (#178)
* Install Rspec

* Create .aidigestignore

* Update rails_helper

- Added sections and comments
- Add support for loading via canonical.rb
- Add FactoryBot syntax methods
- Disable SQL logging in test environment

* Move gems around

* Add canonical.rb and test env CSVs

We load these CSVs via canonical.rb when we run tests as a data source for canonical objects.

* Remove RBS for now

This is too much and we need to find the right solution

* Refactor GridSummonsController and add tests

* Create GridSummon factory

* Refactor GridSummon and add documentation and tests

* Create have_error_on.rb

* Update .aidigestignore

* Fix warnings

* Add GridWeapons and Parties factories

* Refactor GridWeapon and add documentation and tests

* Create .rubocop.yml

* Create no_weapon_provided_error.rb

* Refactor GridWeaponsController

- Refactors controller
- Adds YARD documentation
- Adds Rspec tests

* Refactor GridSummonsController

- Refactors controller
- Adds YARD documentation
- Adds Rspec tests

* Enable shoulda/matchers

* Update User factory

* Update party.rb

We moved updating the party's element and extra flag to inside the party. We use an after_commit hook to minimize the amount of queries we're running to do this.

* Update party.rb

We change setting the edit key to use the conditional assignment operator so that it doesn't get overridden when we're running tests. This shouldn't have an effect in production.

* Update api_controller.rb

Change render_unprocessable_entity_response to render the errors hash instead of the exception so that we get more helpful errors.

* Add new errors

Added NoCharacterProvidedError and NoSummonProvidedError

* Add tests and docs to GridCharacter

We added a factory, spec and documentation to the GridCharacter model

* Ensure numericality

* Move enums into GranblueEnums

We don't use these yet, but it gives us a structured place to pull them from.

* Refactor GridCharactersController

- Refactors controller
- Adds YARD documentation
- Adds Rspec tests

* Add debug hook and other small changes

* Update grid_characters_controller.rb

Removes logs

* Update .gitignore

* Update .aidigestignore

* Refactored PartiesController

- Split PartiesController into three concerns
- Implemented testing for PartiesController and two concerns
- Implemented fixes across other files to ensure PartiesController tests pass
- Added Favorites factory

* Implement SimpleCov

* Refactor Party model

- Refactors Party model
- Adds tests
- Adds documentation

* Update granblue_enums.rb

Remove included block
2025-02-12 02:42:30 -08:00

84 lines
3.4 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
# Prevent database truncation if the environment is production
abort('The Rails environment is running in production mode!') if Rails.env.production?
# Load Rails and RSpec Rails Rails is not loaded until after the environment is set.
require 'rspec/rails'
# -----------------------------------------------------------------------------
# Additional Requires:
#
# Add any additional requires below this line. For example, if you need to load
# custom libraries or support files that are not automatically required.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Require Support Files:
#
# All files in the spec/support directory and its subdirectories (except those
# ending in _spec.rb) are automatically required here. This is useful for custom
# matchers, macros, and shared contexts.
# -----------------------------------------------------------------------------
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
# -----------------------------------------------------------------------------
# Check for Pending Migrations:
#
# This will check for any pending migrations before tests are run.
# -----------------------------------------------------------------------------
begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
abort e.to_s.strip
end
RSpec.configure do |config|
# Disable ActiveRecord logging during tests for a cleaner test output.
ActiveRecord::Base.logger = nil if Rails.env.test?
# -----------------------------------------------------------------------------
# Shoulda Matchers:
#
# If you use shoulda-matchers, you can configure them here. (Make sure you have
# the shoulda-matchers gem installed and configured in your Gemfile.)
# -----------------------------------------------------------------------------
require 'shoulda/matchers'
Shoulda::Matchers.configure do |matcher_config|
matcher_config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
# -----------------------------------------------------------------------------
# FactoryBot Syntax Methods:
#
# This makes methods like create and build available without needing to prefix
# them with FactoryBot.
# -----------------------------------------------------------------------------
config.include FactoryBot::Syntax::Methods
# -----------------------------------------------------------------------------
# Load canonical seed data for test environment:
#
# This ensures that your canonical CSV data is loaded before your tests run.
# -----------------------------------------------------------------------------
config.before(:suite) do
load Rails.root.join('db', 'seed', 'canonical.rb')
end
# -----------------------------------------------------------------------------
# Backtrace Filtering:
#
# Filter out lines from Rails gems in backtraces for clarity.
# -----------------------------------------------------------------------------
config.filter_rails_from_backtrace!
# You can add additional filters here if needed:
# config.filter_gems_from_backtrace("gem name")
end