DEV: Switch over category settings to new table - Part 3 (#20657)

In #20135 we prevented invalid inputs from being accepted in category setting form fields on the front-end. We didn't do anything on the back-end at that time, because we were still discussing which path we wanted to take. Eventually we decided we want to move this to a new CategorySetting model.

This PR moves the require_topic_approval and require_reply_approval from custom fields to the new CategorySetting model.

This PR is nearly identical to #20580, which migrated num_auto_bump_daily, but since these are slightly more sensitive, they are moved after the previous one is verified.
This commit is contained in:
Ted Johansson
2023-09-12 09:51:49 +08:00
committed by GitHub
parent 07c29f3066
commit f08c6d2756
13 changed files with 178 additions and 51 deletions

View File

@ -906,22 +906,18 @@ RSpec.describe Category do
describe "require topic/post approval" do
fab!(:category) { Fabricate(:category_with_definition) }
describe "#require_topic_approval?" do
before do
category.custom_fields[Category::REQUIRE_TOPIC_APPROVAL] = true
category.save
end
it "delegates methods to category settings" do
expect(category).to delegate_method(:require_reply_approval).to(:category_setting)
expect(category).to delegate_method(:require_reply_approval=).with_arguments(true).to(
:category_setting,
)
expect(category).to delegate_method(:require_reply_approval?).to(:category_setting)
it { expect(category.reload.require_topic_approval?).to eq(true) }
end
describe "#require_reply_approval?" do
before do
category.custom_fields[Category::REQUIRE_REPLY_APPROVAL] = true
category.save
end
it { expect(category.reload.require_reply_approval?).to eq(true) }
expect(category).to delegate_method(:require_topic_approval).to(:category_setting)
expect(category).to delegate_method(:require_topic_approval=).with_arguments(true).to(
:category_setting,
)
expect(category).to delegate_method(:require_topic_approval?).to(:category_setting)
end
end