FIX: filter by "nobody" was broken (#176)
Meta ref: https://meta.discourse.org/t/filter-by-nobody-seems-broken/197770/
This commit is contained in:
parent
c572e21493
commit
4024eb078c
|
@ -211,7 +211,8 @@ after_initialize do
|
||||||
|
|
||||||
if user_id || special
|
if user_id || special
|
||||||
if username == "nobody"
|
if username == "nobody"
|
||||||
results = results.joins("LEFT JOIN assignments a ON a.topic_id = topics.id AND a.assigned_to_id IS NULL")
|
results = results.joins("LEFT JOIN assignments a ON a.topic_id = topics.id")
|
||||||
|
.where("a.assigned_to_id IS NULL")
|
||||||
else
|
else
|
||||||
if username == "*"
|
if username == "*"
|
||||||
filter = "a.assigned_to_id IS NOT NULL"
|
filter = "a.assigned_to_id IS NOT NULL"
|
||||||
|
|
|
@ -141,6 +141,19 @@ describe TopicQuery do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'assigned' do
|
||||||
|
it "filters assigned topics correctly" do
|
||||||
|
assigned_topic = Fabricate(:post).topic
|
||||||
|
unassigned_topic = Fabricate(:topic)
|
||||||
|
|
||||||
|
TopicAssigner.new(assigned_topic, user).assign(user)
|
||||||
|
query = TopicQuery.new(user, assigned: 'nobody').list_latest
|
||||||
|
|
||||||
|
expect(query.topics.length).to eq(1)
|
||||||
|
expect(query.topics.first).to eq(unassigned_topic)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def assign_to(topic, user)
|
def assign_to(topic, user)
|
||||||
topic.tap do |t|
|
topic.tap do |t|
|
||||||
t.posts << Fabricate(:post)
|
t.posts << Fabricate(:post)
|
||||||
|
|
Loading…
Reference in New Issue