FEATURE: Log Search Queries

This commit is contained in:
Robin Ward
2017-07-13 13:34:31 -04:00
parent 951fd1219d
commit 97e211f837
8 changed files with 256 additions and 10 deletions

View File

@ -3,7 +3,6 @@ require 'rails_helper'
describe SearchController do
context "integration" do
before do
SearchIndexer.enable
end
@ -20,10 +19,42 @@ describe SearchController do
end
end
context "#query" do
it "logs the search term" do
SiteSetting.log_search_queries = true
xhr :get, :query, term: 'wookie'
expect(response).to be_success
expect(SearchLog.where(term: 'wookie')).to be_present
end
it "doesn't log when disabled" do
SiteSetting.log_search_queries = false
xhr :get, :query, term: 'wookie'
expect(response).to be_success
expect(SearchLog.where(term: 'wookie')).to be_blank
end
end
context "#show" do
it "logs the search term" do
SiteSetting.log_search_queries = true
xhr :get, :show, q: 'bantha'
expect(response).to be_success
expect(SearchLog.where(term: 'bantha')).to be_present
end
it "doesn't log when disabled" do
SiteSetting.log_search_queries = false
xhr :get, :show, q: 'bantha'
expect(response).to be_success
expect(SearchLog.where(term: 'bantha')).to be_blank
end
end
let(:search_context) { {type: 'user', id: 'eviltrout'} }
context "basics" do
pending "basics" do
let(:guardian) { Guardian.new }
let(:search) { mock() }
@ -61,7 +92,7 @@ describe SearchController do
end
context "search context" do
pending "search context" do
it "raises an error with an invalid context type" do
expect {
@ -76,7 +107,6 @@ describe SearchController do
end
context "with a user" do
let(:user) { Fabricate(:user) }
it "raises an error if the user can't see the context" do
@ -85,7 +115,6 @@ describe SearchController do
expect(response).not_to be_success
end
it 'performs the query with a search context' do
guardian = Guardian.new
Guardian.stubs(:new).returns(guardian)
@ -96,10 +125,7 @@ describe SearchController do
xhr :get, :query, term: 'test', search_context: {type: 'user', id: user.username}
end
end
end