FEATURE: Add modifier to assigned count (#598)
* FEATURE: Add modifier to assigned count * lint: update stree in pending_assigns_reminder_spec
This commit is contained in:
parent
525dbcdc21
commit
7fcde6c1b4
|
@ -56,10 +56,15 @@ class PendingAssignsReminder
|
||||||
end
|
end
|
||||||
|
|
||||||
def assigned_count_for(user)
|
def assigned_count_for(user)
|
||||||
Assignment
|
assignments =
|
||||||
.joins_with_topics
|
Assignment.joins_with_topics.where(
|
||||||
.where(assigned_to_id: user.id, assigned_to_type: "User", active: true)
|
assigned_to_id: user.id,
|
||||||
.count
|
assigned_to_type: "User",
|
||||||
|
active: true,
|
||||||
|
)
|
||||||
|
assignments =
|
||||||
|
DiscoursePluginRegistry.apply_modifier(:assigned_count_for_user_query, assignments, user)
|
||||||
|
assignments.count
|
||||||
end
|
end
|
||||||
|
|
||||||
def assigned_topics(user, order:)
|
def assigned_topics(user, order:)
|
||||||
|
|
|
@ -143,9 +143,9 @@ RSpec.describe PendingAssignsReminder do
|
||||||
expect(topic.title).to eq(I18n.t("pending_assigns_reminder.title", pending_assignments: 3))
|
expect(topic.title).to eq(I18n.t("pending_assigns_reminder.title", pending_assignments: 3))
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with assigns_reminder_assigned_topics_query" do
|
context "with assigns_reminder_assigned_topics_query modifier" do
|
||||||
let(:modifier_block) { Proc.new { |query| query.where.not(id: @post1.topic_id) } }
|
let(:modifier_block) { Proc.new { |query| query.where.not(id: @post1.topic_id) } }
|
||||||
it "doesn't remind if topic is solved" do
|
it "updates the query correctly" do
|
||||||
plugin_instance = Plugin::Instance.new
|
plugin_instance = Plugin::Instance.new
|
||||||
plugin_instance.register_modifier(:assigns_reminder_assigned_topics_query, &modifier_block)
|
plugin_instance.register_modifier(:assigns_reminder_assigned_topics_query, &modifier_block)
|
||||||
topics = reminder.send(:assigned_topics, user, order: :asc)
|
topics = reminder.send(:assigned_topics, user, order: :asc)
|
||||||
|
@ -158,5 +158,22 @@ RSpec.describe PendingAssignsReminder do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with assigned_count_for_user_query modifier" do
|
||||||
|
let(:modifier_block) { Proc.new { |query, user| query.where.not(assigned_to_id: user.id) } }
|
||||||
|
it "updates the query correctly" do
|
||||||
|
expect(reminder.send(:assigned_count_for, user)).to eq(3)
|
||||||
|
|
||||||
|
plugin_instance = Plugin::Instance.new
|
||||||
|
plugin_instance.register_modifier(:assigned_count_for_user_query, &modifier_block)
|
||||||
|
expect(reminder.send(:assigned_count_for, user)).to eq(0)
|
||||||
|
ensure
|
||||||
|
DiscoursePluginRegistry.unregister_modifier(
|
||||||
|
plugin_instance,
|
||||||
|
:assigned_count_for_user_query,
|
||||||
|
&modifier_block
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue