Skip to content

Commit

Permalink
Fix: 一部環境でマイグレーションできない問題 (#336)
Browse files Browse the repository at this point in the history
* Fix: 一部環境でマイグレーションできない問題

* Fix

* Fix

* Add settings test
  • Loading branch information
kmycode authored Dec 7, 2023
1 parent 0ed5577 commit 6a680ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
28 changes: 4 additions & 24 deletions db/migrate/20231105225839_add_master_settings_to_accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,8 @@ def up
safety_assured do
add_column :accounts, :master_settings, :jsonb

if Rails.env.test?
Account.transaction do
Account.find_in_batches do |accounts|
accounts.each do |account|
account.update(master_settings: { 'subscription_policy' => account.dissubscribable ? 'block' : 'allow' })
end
end
end
else
Account.where(dissubscribable: true).update_all(master_settings: { 'subscription_policy' => 'block' }) # rubocop:disable Rails/SkipsModelValidations
Account.where(dissubscribable: false).update_all(master_settings: { 'subscription_policy' => 'allow' }) # rubocop:disable Rails/SkipsModelValidations
end
ActiveRecord::Base.connection.execute("UPDATE accounts SET master_settings = json_build_object('subscription_policy', 'block') WHERE accounts.dissubscribable IS TRUE")
ActiveRecord::Base.connection.execute("UPDATE accounts SET master_settings = json_build_object('subscription_policy', 'allow') WHERE accounts.dissubscribable IS FALSE")

remove_column :accounts, :dissubscribable
end
Expand All @@ -34,18 +24,8 @@ def down
safety_assured do
add_column_with_default :accounts, :dissubscribable, :boolean, default: false, allow_null: false

if Rails.env.test?
Account.transaction do
Account.find_in_batches do |accounts|
accounts.each do |account|
account.update(dissubscribable: account.master_settings.present? && account.master_settings['subscription_policy'] != 'allow')
end
end
end
else
Account.where(master_settings: { subscription_policy: 'block' }).update_all(dissubscribable: true) # rubocop:disable Rails/SkipsModelValidations
Account.where(master_settings: { subscription_policy: 'allow' }).update_all(dissubscribable: false) # rubocop:disable Rails/SkipsModelValidations
end
ActiveRecord::Base.connection.execute("UPDATE accounts SET dissubscribable = TRUE WHERE master_settings ->> 'subscription_policy' = 'block'")
ActiveRecord::Base.connection.execute("UPDATE accounts SET dissubscribable = FALSE WHERE master_settings ->> 'subscription_policy' = 'allow'")

remove_column :accounts, :master_settings
end
Expand Down
26 changes: 26 additions & 0 deletions spec/services/activitypub/process_account_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,32 @@
end
end

context 'with other settings' do
let(:payload) do
{
id: 'https://foo.test',
type: 'Actor',
inbox: 'https://foo.test/inbox',
otherSetting: [
{ type: 'PropertyValue', name: 'Pronouns', value: 'They/them' },
{ type: 'PropertyValue', name: 'Occupation', value: 'Unit test' },
],
}.with_indifferent_access
end

before do
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(body: '{}')
end

it 'parses out of attachment' do
account = subject.call('alice', 'example.com', payload)
expect(account.settings).to be_a Hash
expect(account.settings.size).to eq 2
expect(account.settings['Pronouns']).to eq 'They/them'
expect(account.settings['Occupation']).to eq 'Unit test'
end
end

context 'when account is not suspended' do
subject { described_class.new.call('alice', 'example.com', payload) }

Expand Down

0 comments on commit 6a680ba

Please sign in to comment.