FEATURE: search log term details page (#5445)

This commit is contained in:
Arpit Jalan
2017-12-20 08:11:31 +05:30
committed by Sam
parent bbc606988f
commit eab66065d1
17 changed files with 172 additions and 9 deletions

View File

@@ -156,6 +156,26 @@ RSpec.describe SearchLog, type: :model do
end
end
context "term_details" do
before do
SearchLog.log(term: "ruby", search_type: :header, ip_address: "127.0.0.1")
SearchLog.log(term: 'ruby', search_type: :header, ip_address: '127.0.0.1', user_id: Fabricate(:user).id)
SearchLog.log(term: "ruby", search_type: :full_page, ip_address: "127.0.0.2")
end
it "correctly returns term details" do
term_details = SearchLog.term_details("ruby")
expect(term_details[:data][0][:y]).to eq(3)
term_header_details = SearchLog.term_details("ruby", :all, :header)
expect(term_header_details[:data][0][:y]).to eq(2)
SearchLog.where(term: 'ruby', ip_address: '127.0.0.2').update_all(search_result_id: 24)
term_click_through_details = SearchLog.term_details("ruby", :all, :click_through_only)
expect(term_click_through_details[:data][0][:y]).to eq(1)
end
end
context "trending" do
before do
SearchLog.log(term: 'ruby', search_type: :header, ip_address: '127.0.0.1')

View File

@@ -32,4 +32,29 @@ RSpec.describe Admin::SearchLogsController do
expect(json[0]['term']).to eq('ruby')
end
end
context "#term" do
it "raises an error if you aren't logged in" do
expect do
get '/admin/logs/search_logs/term/ruby.json'
end.to raise_error(ActionController::RoutingError)
end
it "raises an error if you aren't an admin" do
sign_in(user)
expect do
get '/admin/logs/search_logs/term/ruby.json'
end.to raise_error(ActionController::RoutingError)
end
it "should work if you are an admin" do
sign_in(admin)
get '/admin/logs/search_logs/term/ruby.json'
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json['term']['type']).to eq('search_log_term')
end
end
end