2017-11-14 19:13:50 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Admin::SearchLogsController do
|
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
before do
|
2018-01-14 22:51:04 -05:00
|
|
|
SearchLog.clear_debounce_cache!
|
2017-11-14 19:13:50 -05:00
|
|
|
SearchLog.log(term: 'ruby', search_type: :header, ip_address: '127.0.0.1')
|
|
|
|
end
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
|
|
|
expect(response).to be_success
|
|
|
|
|
|
|
|
json = ::JSON.parse(response.body)
|
|
|
|
expect(json[0]['term']).to eq('ruby')
|
|
|
|
end
|
|
|
|
end
|
2017-12-19 21:41:31 -05:00
|
|
|
|
|
|
|
context "#term" 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/term/ruby.json'
|
|
|
|
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)
|
2018-01-11 22:15:10 -05:00
|
|
|
get '/admin/logs/search_logs/term/ruby.json'
|
|
|
|
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)
|
|
|
|
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')
|
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
|