* 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
145 lines
4.3 KiB
Ruby
145 lines
4.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Api
|
|
module V1
|
|
class PartyBlueprint < ApiBlueprint
|
|
# Base fields that are always needed
|
|
fields :local_id, :description, :shortcode, :visibility,
|
|
:name, :element, :extra, :charge_attack,
|
|
:button_count, :turn_count, :chain_count, :clear_time,
|
|
:full_auto, :auto_guard, :auto_summon,
|
|
:created_at, :updated_at
|
|
|
|
fields :local_id, :description, :charge_attack,
|
|
:button_count, :turn_count, :chain_count,
|
|
:master_level, :ultimate_mastery
|
|
|
|
# Party associations
|
|
association :user,
|
|
blueprint: UserBlueprint,
|
|
view: :minimal
|
|
|
|
association :job,
|
|
blueprint: JobBlueprint
|
|
|
|
association :raid,
|
|
blueprint: RaidBlueprint,
|
|
view: :nested
|
|
|
|
# Metadata associations
|
|
field :favorited do |party, options|
|
|
party.favorited?(options[:current_user])
|
|
end
|
|
|
|
# For collection views
|
|
view :preview do
|
|
include_view :preview_objects # Characters, Weapons, Summons
|
|
include_view :preview_metadata # Object counts
|
|
end
|
|
|
|
# For object views
|
|
view :full do
|
|
# Primary object associations
|
|
include_view :nested_objects # Characters, Weapons, Summons
|
|
include_view :remix_metadata # Remixes, Source party
|
|
include_view :job_metadata # Accessory, Skills, Guidebooks
|
|
end
|
|
|
|
# Primary object associations
|
|
view :preview_objects do
|
|
association :characters,
|
|
blueprint: GridCharacterBlueprint,
|
|
view: :preview
|
|
|
|
association :weapons,
|
|
blueprint: GridWeaponBlueprint,
|
|
view: :preview
|
|
|
|
association :summons,
|
|
blueprint: GridSummonBlueprint,
|
|
view: :preview
|
|
end
|
|
|
|
view :nested_objects do
|
|
association :characters,
|
|
blueprint: GridCharacterBlueprint,
|
|
view: :nested
|
|
|
|
association :weapons,
|
|
blueprint: GridWeaponBlueprint,
|
|
view: :nested
|
|
|
|
association :summons,
|
|
blueprint: GridSummonBlueprint,
|
|
view: :nested
|
|
end
|
|
|
|
# Metadata views
|
|
view :preview_metadata do
|
|
field :counts do |party|
|
|
{
|
|
weapons: party.weapons_count,
|
|
characters: party.characters_count,
|
|
summons: party.summons_count
|
|
}
|
|
end
|
|
end
|
|
|
|
view :source_party do
|
|
association :source_party,
|
|
blueprint: PartyBlueprint,
|
|
view: :preview,
|
|
if: ->(_field_name, party, _options) { party.source_party_id.present? }
|
|
end
|
|
|
|
view :remix_metadata do
|
|
include_view :source_party
|
|
|
|
# Re-added remixes association
|
|
association :remixes,
|
|
blueprint: PartyBlueprint,
|
|
view: :preview
|
|
end
|
|
|
|
# Job-related views
|
|
view :job_metadata do
|
|
field :job_skills, cache: true do |party|
|
|
{
|
|
'0' => party.skill0 ? JobSkillBlueprint.render_as_hash(party.skill0) : nil,
|
|
'1' => party.skill1 ? JobSkillBlueprint.render_as_hash(party.skill1) : nil,
|
|
'2' => party.skill2 ? JobSkillBlueprint.render_as_hash(party.skill2) : nil,
|
|
'3' => party.skill3 ? JobSkillBlueprint.render_as_hash(party.skill3) : nil
|
|
}
|
|
end
|
|
|
|
field :guidebooks, cache: true do |party|
|
|
{
|
|
'1' => party.guidebook1 ? GuidebookBlueprint.render_as_hash(party.guidebook1) : nil,
|
|
'2' => party.guidebook2 ? GuidebookBlueprint.render_as_hash(party.guidebook2) : nil,
|
|
'3' => party.guidebook3 ? GuidebookBlueprint.render_as_hash(party.guidebook3) : nil
|
|
}
|
|
end
|
|
|
|
association :accessory,
|
|
blueprint: JobAccessoryBlueprint,
|
|
if: ->(_field_name, party, _options) { party.accessory_id.present? }
|
|
end
|
|
|
|
# Created view
|
|
view :created do
|
|
include_view :full
|
|
fields :edit_key
|
|
end
|
|
|
|
view :remixed do
|
|
include_view :created
|
|
include_view :source_party
|
|
end
|
|
|
|
# Destroyed view
|
|
view :destroyed do
|
|
fields :name, :description, :created_at, :updated_at
|
|
end
|
|
end
|
|
end
|
|
end
|