FIX: Do not raise an error when in:all search is performed by anon (#9113)
Also improve in:all specs to catch to catch similar failures
This commit is contained in:
parent
4b70719a48
commit
5b3630dba3
|
@ -176,7 +176,7 @@ class Search
|
||||||
@search_context = @guardian.user
|
@search_context = @guardian.user
|
||||||
end
|
end
|
||||||
|
|
||||||
if @search_all_topics
|
if @search_all_topics && @guardian.user
|
||||||
@opts[:type_filter] = "all_topics"
|
@opts[:type_filter] = "all_topics"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -315,56 +315,53 @@ describe Search do
|
||||||
TopicAllowedUser.create!(user_id: u2.id, topic_id: private_topic.id)
|
TopicAllowedUser.create!(user_id: u2.id, topic_id: private_topic.id)
|
||||||
|
|
||||||
# private only
|
# private only
|
||||||
results = Search.execute('cheese',
|
results = Search.execute('in:all cheese',
|
||||||
type_filter: 'all_topics',
|
|
||||||
guardian: Guardian.new(u1))
|
guardian: Guardian.new(u1))
|
||||||
expect(results.posts.length).to eq(1)
|
expect(results.posts.length).to eq(1)
|
||||||
|
|
||||||
# public only
|
# public only
|
||||||
results = Search.execute('eggs',
|
results = Search.execute('in:all eggs',
|
||||||
type_filter: 'all_topics',
|
|
||||||
guardian: Guardian.new(u1))
|
guardian: Guardian.new(u1))
|
||||||
expect(results.posts.length).to eq(1)
|
expect(results.posts.length).to eq(1)
|
||||||
|
|
||||||
# both
|
# both
|
||||||
results = Search.execute('spam',
|
results = Search.execute('in:all spam',
|
||||||
type_filter: 'all_topics',
|
|
||||||
guardian: Guardian.new(u1))
|
guardian: Guardian.new(u1))
|
||||||
expect(results.posts.length).to eq(2)
|
expect(results.posts.length).to eq(2)
|
||||||
|
|
||||||
|
# for anon
|
||||||
|
results = Search.execute('in:all spam',
|
||||||
|
guardian: Guardian.new)
|
||||||
|
expect(results.posts.length).to eq(1)
|
||||||
|
|
||||||
# nonparticipatory user
|
# nonparticipatory user
|
||||||
results = Search.execute('cheese',
|
results = Search.execute('in:all cheese',
|
||||||
type_filter: 'all_topics',
|
|
||||||
guardian: Guardian.new(u3))
|
guardian: Guardian.new(u3))
|
||||||
expect(results.posts.length).to eq(0)
|
expect(results.posts.length).to eq(0)
|
||||||
|
|
||||||
results = Search.execute('eggs',
|
results = Search.execute('in:all eggs',
|
||||||
type_filter: 'all_topics',
|
|
||||||
guardian: Guardian.new(u3))
|
guardian: Guardian.new(u3))
|
||||||
expect(results.posts.length).to eq(1)
|
expect(results.posts.length).to eq(1)
|
||||||
|
|
||||||
results = Search.execute('spam',
|
results = Search.execute('in:all spam',
|
||||||
type_filter: 'all_topics',
|
|
||||||
guardian: Guardian.new(u3))
|
guardian: Guardian.new(u3))
|
||||||
expect(results.posts.length).to eq(1)
|
expect(results.posts.length).to eq(1)
|
||||||
|
|
||||||
# Admin doesn't see private topic
|
# Admin doesn't see private topic
|
||||||
results = Search.execute('spam',
|
results = Search.execute('in:all spam',
|
||||||
type_filter: 'all_topics',
|
|
||||||
guardian: Guardian.new(u4))
|
guardian: Guardian.new(u4))
|
||||||
expect(results.posts.length).to eq(1)
|
expect(results.posts.length).to eq(1)
|
||||||
|
|
||||||
# same keyword for different users
|
# same keyword for different users
|
||||||
results = Search.execute('ham',
|
results = Search.execute('in:all ham',
|
||||||
type_filter: 'all_topics',
|
|
||||||
guardian: Guardian.new(u1))
|
guardian: Guardian.new(u1))
|
||||||
expect(results.posts.length).to eq(2)
|
expect(results.posts.length).to eq(2)
|
||||||
results = Search.execute('ham',
|
|
||||||
type_filter: 'all_topics',
|
results = Search.execute('in:all ham',
|
||||||
guardian: Guardian.new(u2))
|
guardian: Guardian.new(u2))
|
||||||
expect(results.posts.length).to eq(2)
|
expect(results.posts.length).to eq(2)
|
||||||
results = Search.execute('ham',
|
|
||||||
type_filter: 'all_topics',
|
results = Search.execute('in:all ham',
|
||||||
guardian: Guardian.new(u3))
|
guardian: Guardian.new(u3))
|
||||||
expect(results.posts.length).to eq(1)
|
expect(results.posts.length).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue