2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-14 19:13:50 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Admin::SearchLogsController do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
2017-11-14 19:13:50 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
SearchLog.log(term: 'ruby', search_type: :header, ip_address: '127.0.0.1')
|
|
|
|
end
|
|
|
|
|
2018-04-22 22:00:37 -04:00
|
|
|
after do
|
|
|
|
SearchLog.clear_debounce_cache!
|
|
|
|
end
|
|
|
|
|
2017-11-14 19:13:50 -05:00
|
|
|
context "#index" do
|
|
|
|
it "raises an error if you aren't logged in" do
|
2018-01-11 22:15:10 -05:00
|
|
|
get '/admin/logs/search_logs.json'
|
|
|
|
expect(response.status).to eq(404)
|
2017-11-14 19:13:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an error if you aren't an admin" do
|
|
|
|
sign_in(user)
|
2018-01-11 22:15:10 -05:00
|
|
|
get '/admin/logs/search_logs.json'
|
|
|
|
expect(response.status).to eq(404)
|
2017-11-14 19:13:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should work if you are an admin" do
|
|
|
|
sign_in(admin)
|
|
|
|
get '/admin/logs/search_logs.json'
|
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2017-11-14 19:13:50 -05:00
|
|
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
expect(json[0]['term']).to eq('ruby')
|
2018-12-18 08:43:46 -05:00
|
|
|
expect(json[0]['searches']).to eq(1)
|
|
|
|
expect(json[0]['ctr']).to eq(0)
|
2017-11-14 19:13:50 -05:00
|
|
|
end
|
|
|
|
end
|
2017-12-19 21:41:31 -05:00
|
|
|
|
|
|
|
context "#term" do
|
|
|
|
it "raises an error if you aren't logged in" do
|
2019-03-28 21:48:20 -04:00
|
|
|
get '/admin/logs/search_logs/term.json', params: {
|
|
|
|
term: "ruby"
|
|
|
|
}
|
|
|
|
|
2018-01-11 22:15:10 -05:00
|
|
|
expect(response.status).to eq(404)
|
2017-12-19 21:41:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an error if you aren't an admin" do
|
|
|
|
sign_in(user)
|
2019-03-28 21:48:20 -04:00
|
|
|
|
|
|
|
get '/admin/logs/search_logs/term.json', params: {
|
|
|
|
term: "ruby"
|
|
|
|
}
|
|
|
|
|
2018-01-11 22:15:10 -05:00
|
|
|
expect(response.status).to eq(404)
|
2017-12-19 21:41:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should work if you are an admin" do
|
|
|
|
sign_in(admin)
|
2019-03-28 21:48:20 -04:00
|
|
|
|
|
|
|
get '/admin/logs/search_logs/term.json', params: {
|
|
|
|
term: "ruby"
|
|
|
|
}
|
2017-12-19 21:41:31 -05:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2017-12-19 21:41:31 -05:00
|
|
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
expect(json['term']['type']).to eq('search_log_term')
|
2018-01-16 05:29:22 -05:00
|
|
|
expect(json['term']['search_result']).to be_present
|
2017-12-19 21:41:31 -05:00
|
|
|
end
|
|
|
|
end
|
2017-11-14 19:13:50 -05:00
|
|
|
end
|