From 915ee553daa231b565ac12bac54d68adcdf0177b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KMY=EF=BC=88=E9=9B=AA=E3=81=82=E3=81=99=E3=81=8B=EF=BC=89?= Date: Fri, 31 Jan 2025 12:04:26 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20#950=20=E6=96=B0=E8=A6=8F=E3=82=A2?= =?UTF-8?q?=E3=83=B3=E3=83=86=E3=83=8A=E4=BD=9C=E6=88=90=E6=99=82=E3=81=AB?= =?UTF-8?q?=E3=83=AA=E3=82=B9=E3=83=88=E3=81=B8=E6=8C=BF=E5=85=A5=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=92=E8=A8=AD=E5=AE=9A=E3=81=97=E3=81=A6=E3=82=82?= =?UTF-8?q?=E3=80=81=E3=83=9B=E3=83=BC=E3=83=A0=E6=8C=BF=E5=85=A5=E3=81=AB?= =?UTF-8?q?=E3=81=AA=E3=82=8B=20(#975)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: #950 新規アンテナ作成時にリストへ挿入するを設定しても、ホーム挿入になる * Fix test --- app/controllers/api/v1/antennas_controller.rb | 2 +- app/javascript/mastodon/features/antennas/new.tsx | 2 +- app/models/antenna.rb | 2 +- ...0130232529_set_antenna_list_id_default_value.rb | 7 +++++++ db/schema.rb | 4 ++-- lib/tasks/dangerous.rake | 1 + spec/requests/api/v1/antennas_spec.rb | 14 ++++++++++++++ 7 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20250130232529_set_antenna_list_id_default_value.rb diff --git a/app/controllers/api/v1/antennas_controller.rb b/app/controllers/api/v1/antennas_controller.rb index 11610e42c4..4040263c00 100644 --- a/app/controllers/api/v1/antennas_controller.rb +++ b/app/controllers/api/v1/antennas_controller.rb @@ -21,7 +21,7 @@ class Api::V1::AntennasController < Api::BaseController end def create - @antenna = Antenna.create!(antenna_params.merge(account: current_account, list_id: 0)) + @antenna = Antenna.create!(antenna_params.merge(account: current_account)) render json: @antenna, serializer: REST::AntennaSerializer end diff --git a/app/javascript/mastodon/features/antennas/new.tsx b/app/javascript/mastodon/features/antennas/new.tsx index 9a933453d6..56373bb60c 100644 --- a/app/javascript/mastodon/features/antennas/new.tsx +++ b/app/javascript/mastodon/features/antennas/new.tsx @@ -57,7 +57,7 @@ const NewAntenna: React.FC<{ const [stl, setStl] = useState(false); const [ltl, setLtl] = useState(false); const [insertFeeds, setInsertFeeds] = useState(false); - const [listId, setListId] = useState(''); + const [listId, setListId] = useState('0'); const [withMediaOnly, setWithMediaOnly] = useState(false); const [ignoreReblog, setIgnoreReblog] = useState(false); const [mode, setMode] = useState('filtering'); diff --git a/app/models/antenna.rb b/app/models/antenna.rb index 0913d7bfd1..44f9073e17 100644 --- a/app/models/antenna.rb +++ b/app/models/antenna.rb @@ -26,7 +26,7 @@ # created_at :datetime not null # updated_at :datetime not null # account_id :bigint(8) not null -# list_id :bigint(8) not null +# list_id :bigint(8) default(0), not null # class Antenna < ApplicationRecord include Expireable diff --git a/db/migrate/20250130232529_set_antenna_list_id_default_value.rb b/db/migrate/20250130232529_set_antenna_list_id_default_value.rb new file mode 100644 index 0000000000..67b5e7ebd2 --- /dev/null +++ b/db/migrate/20250130232529_set_antenna_list_id_default_value.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class SetAntennaListIdDefaultValue < ActiveRecord::Migration[8.0] + def change + change_column_default :antennas, :list_id, from: nil, to: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 467018a3ad..e353c6a8fb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_01_23_091137) do +ActiveRecord::Schema[8.0].define(version: 2025_01_30_232529) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -309,7 +309,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_23_091137) do create_table "antennas", force: :cascade do |t| t.bigint "account_id", null: false - t.bigint "list_id", null: false + t.bigint "list_id", default: 0, null: false t.string "title", default: "", null: false t.jsonb "keywords" t.jsonb "exclude_keywords" diff --git a/lib/tasks/dangerous.rake b/lib/tasks/dangerous.rake index 23a7e51121..62d000166b 100644 --- a/lib/tasks/dangerous.rake +++ b/lib/tasks/dangerous.rake @@ -14,6 +14,7 @@ namespace :dangerous do end target_migrations = %w( + 20250130232529 20250123091137 20241208232829 20240828123604 diff --git a/spec/requests/api/v1/antennas_spec.rb b/spec/requests/api/v1/antennas_spec.rb index c15aa10ac0..102aabcaa7 100644 --- a/spec/requests/api/v1/antennas_spec.rb +++ b/spec/requests/api/v1/antennas_spec.rb @@ -123,6 +123,20 @@ RSpec.describe 'Antennas' do expect(Antenna.where(account: user.account).count).to eq(1) end + context 'when specify a list when create new' do + let(:list) { Fabricate(:list, account: user.account, title: 'ohagi') } + let(:params) { { title: 'my antenna', list_id: list.id.to_s, insert_feeds: 'true' } } + + it 'returns the new antenna with list', :aggregate_failures do + subject + + expect(response).to have_http_status(200) + expect(response.parsed_body).to match(a_hash_including(title: 'my antenna', insert_feeds: true)) + expect(response.parsed_body['list']).to match(a_hash_including(id: list.id.to_s, title: list.title)) + expect(Antenna.where(account: user.account).count).to eq(1) + end + end + context 'when a title is not given' do let(:params) { { title: '' } }