add max_exorcism_level to weapons

- migration to add column (nullable integer)
- expose in blueprint
- permit in controller
- add spec for create/update
This commit is contained in:
Justin Edmund 2026-01-04 01:19:48 -08:00
parent 53cb15fa27
commit 2642f0ad08
5 changed files with 133 additions and 3 deletions

View file

@ -12,8 +12,8 @@ module Api
# Primary information
fields :granblue_id, :element, :proficiency,
:max_level, :max_skill_level, :max_awakening_level, :limit, :rarity,
:ax, :ax_type, :gacha, :promotions, :forge_order
:max_level, :max_skill_level, :max_awakening_level, :max_exorcism_level,
:limit, :rarity, :ax, :ax_type, :gacha, :promotions, :forge_order
# Series - returns full object with flags if weapon_series is present, fallback to legacy integer
field :series do |w|

View file

@ -219,7 +219,7 @@ module Api
:flb, :ulb, :transcendence, :extra, :extra_prerequisite, :limit, :ax, :gacha,
:min_hp, :max_hp, :max_hp_flb, :max_hp_ulb,
:min_atk, :max_atk, :max_atk_flb, :max_atk_ulb,
:max_level, :max_skill_level, :max_awakening_level,
:max_level, :max_skill_level, :max_awakening_level, :max_exorcism_level,
:release_date, :flb_date, :ulb_date, :transcendence_date,
:wiki_en, :wiki_ja, :wiki_raw, :gamewith, :kamigame,
:recruits, :forged_from, :forge_chain_id, :forge_order,

View file

@ -0,0 +1,5 @@
class AddMaxExorcismLevelToWeapons < ActiveRecord::Migration[8.0]
def change
add_column :weapons, :max_exorcism_level, :integer, default: nil
end
end

View file

@ -85,5 +85,15 @@ FactoryBot.define do
trait :ax_weapon do
ax { true }
end
trait :odiant do
weapon_series { WeaponSeries.find_by(slug: 'odiant') || create(:weapon_series, :odiant) }
max_exorcism_level { 5 }
end
trait :with_befoulment do
weapon_series { WeaponSeries.find_by(slug: 'odiant') || create(:weapon_series, :odiant) }
max_exorcism_level { 5 }
end
end
end

View file

@ -0,0 +1,115 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Weapons API', type: :request do
let(:editor_user) { create(:user, role: 7) }
let(:regular_user) { create(:user, role: 3) }
let(:editor_token) do
Doorkeeper::AccessToken.create!(resource_owner_id: editor_user.id, expires_in: 30.days, scopes: 'public')
end
let(:regular_token) do
Doorkeeper::AccessToken.create!(resource_owner_id: regular_user.id, expires_in: 30.days, scopes: 'public')
end
let(:editor_headers) do
{ 'Authorization' => "Bearer #{editor_token.token}", 'Content-Type' => 'application/json' }
end
let(:regular_headers) do
{ 'Authorization' => "Bearer #{regular_token.token}", 'Content-Type' => 'application/json' }
end
let!(:weapon_series) { create(:weapon_series, :odiant) }
let!(:weapon) { create(:weapon, weapon_series: weapon_series, max_exorcism_level: 5) }
describe 'GET /api/v1/weapons/:id' do
it 'returns the weapon with max_exorcism_level' do
get "/api/v1/weapons/#{weapon.id}"
expect(response).to have_http_status(:ok)
json = JSON.parse(response.body)
expect(json['maxExorcismLevel']).to eq(5)
end
it 'returns null for max_exorcism_level when not set' do
weapon_without_exorcism = create(:weapon, max_exorcism_level: nil)
get "/api/v1/weapons/#{weapon_without_exorcism.id}"
expect(response).to have_http_status(:ok)
json = JSON.parse(response.body)
expect(json['maxExorcismLevel']).to be_nil
end
end
describe 'POST /api/v1/weapons' do
let(:valid_params) do
{
weapon: {
granblue_id: '1040000001',
name_en: 'Test Weapon',
rarity: 4,
element: 1,
proficiency: 1,
max_exorcism_level: 5
}
}
end
it 'creates a weapon with max_exorcism_level when editor' do
post '/api/v1/weapons', params: valid_params.to_json, headers: editor_headers
expect(response).to have_http_status(:created)
json = JSON.parse(response.body)
expect(json['maxExorcismLevel']).to eq(5)
end
it 'creates a weapon with null max_exorcism_level' do
params = valid_params.deep_dup
params[:weapon][:max_exorcism_level] = nil
params[:weapon][:granblue_id] = '1040000002'
post '/api/v1/weapons', params: params.to_json, headers: editor_headers
expect(response).to have_http_status(:created)
json = JSON.parse(response.body)
expect(json['maxExorcismLevel']).to be_nil
end
it 'rejects creation from non-editor' do
post '/api/v1/weapons', params: valid_params.to_json, headers: regular_headers
expect(response).to have_http_status(:unauthorized)
end
end
describe 'PATCH /api/v1/weapons/:id' do
it 'updates max_exorcism_level' do
patch "/api/v1/weapons/#{weapon.id}",
params: { weapon: { max_exorcism_level: 3 } }.to_json,
headers: editor_headers
expect(response).to have_http_status(:ok)
json = JSON.parse(response.body)
expect(json['maxExorcismLevel']).to eq(3)
end
it 'clears max_exorcism_level when set to null' do
patch "/api/v1/weapons/#{weapon.id}",
params: { weapon: { max_exorcism_level: nil } }.to_json,
headers: editor_headers
expect(response).to have_http_status(:ok)
json = JSON.parse(response.body)
expect(json['maxExorcismLevel']).to be_nil
end
it 'rejects update from non-editor' do
patch "/api/v1/weapons/#{weapon.id}",
params: { weapon: { max_exorcism_level: 3 } }.to_json,
headers: regular_headers
expect(response).to have_http_status(:unauthorized)
end
end
end