mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Refactor flag types for more customization
This commit is contained in:
46
spec/components/flag_settings_spec.rb
Normal file
46
spec/components/flag_settings_spec.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
require 'rails_helper'
|
||||
require 'flag_settings'
|
||||
|
||||
RSpec.describe FlagSettings do
|
||||
|
||||
let(:settings) { FlagSettings.new }
|
||||
|
||||
describe 'add' do
|
||||
it 'will add a type' do
|
||||
settings.add(3, :off_topic)
|
||||
expect(settings.flag_types).to include(:off_topic)
|
||||
expect(settings.is_flag?(:off_topic)).to eq(true)
|
||||
expect(settings.is_flag?(:vote)).to eq(false)
|
||||
|
||||
expect(settings.topic_flag_types).to be_empty
|
||||
expect(settings.notify_types).to be_empty
|
||||
expect(settings.auto_action_types).to be_empty
|
||||
end
|
||||
|
||||
it 'will add a topic type' do
|
||||
settings.add(4, :inappropriate, topic_type: true)
|
||||
expect(settings.flag_types).to include(:inappropriate)
|
||||
expect(settings.topic_flag_types).to include(:inappropriate)
|
||||
expect(settings.without_custom_types).to include(:inappropriate)
|
||||
end
|
||||
|
||||
it 'will add a notify type' do
|
||||
settings.add(3, :off_topic, notify_type: true)
|
||||
expect(settings.flag_types).to include(:off_topic)
|
||||
expect(settings.notify_types).to include(:off_topic)
|
||||
end
|
||||
|
||||
it 'will add an auto action type' do
|
||||
settings.add(7, :notify_moderators, auto_action_type: true)
|
||||
expect(settings.flag_types).to include(:notify_moderators)
|
||||
expect(settings.auto_action_types).to include(:notify_moderators)
|
||||
end
|
||||
|
||||
it 'will add a custom type' do
|
||||
settings.add(7, :notify_user, custom_type: true)
|
||||
expect(settings.flag_types).to include(:notify_user)
|
||||
expect(settings.custom_types).to include(:notify_user)
|
||||
expect(settings.without_custom_types).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -532,7 +532,7 @@ describe PostAction do
|
||||
|
||||
it "prevents user to act twice at the same time" do
|
||||
# flags are already being tested
|
||||
all_types_except_flags = PostActionType.types.except(PostActionType.flag_types)
|
||||
all_types_except_flags = PostActionType.types.except(PostActionType.flag_types_without_custom)
|
||||
all_types_except_flags.values.each do |action|
|
||||
expect do
|
||||
PostAction.act(eviltrout, post, action)
|
||||
|
||||
@@ -9,8 +9,7 @@ describe PostSerializer do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
let(:acted_ids) {
|
||||
PostActionType.public_types.values
|
||||
.concat([:notify_user, :spam]
|
||||
.map { |k| PostActionType.types[k] })
|
||||
.concat([:notify_user, :spam].map { |k| PostActionType.types[k] })
|
||||
}
|
||||
|
||||
def visible_actions_for(user)
|
||||
|
||||
Reference in New Issue
Block a user