discourse/spec/requests/admin/search_logs_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

105 lines
2.5 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-11-15 08:13:50 +08:00
RSpec.describe Admin::SearchLogsController do
fab!(:admin) { Fabricate(:admin) }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:user) { Fabricate(:user) }
2017-11-15 08:13:50 +08:00
before do
SearchLog.log(term: 'ruby', search_type: :header, ip_address: '127.0.0.1')
end
after do
SearchLog.clear_debounce_cache!
end
it "is a subclass of StaffController" do
expect(Admin::SearchLogsController < Admin::StaffController).to eq(true)
end
describe "#index" do
2017-11-15 08:13:50 +08:00
it "raises an error if you aren't logged in" do
get '/admin/logs/search_logs.json'
expect(response.status).to eq(404)
2017-11-15 08:13:50 +08:00
end
it "raises an error if you aren't an admin" do
sign_in(user)
get '/admin/logs/search_logs.json'
expect(response.status).to eq(404)
2017-11-15 08:13:50 +08:00
end
it "should work if you are an admin" do
sign_in(admin)
get '/admin/logs/search_logs.json'
expect(response.status).to eq(200)
2017-11-15 08:13:50 +08:00
json = response.parsed_body
2017-11-15 08:13:50 +08:00
expect(json[0]['term']).to eq('ruby')
expect(json[0]['searches']).to eq(1)
expect(json[0]['ctr']).to eq(0)
2017-11-15 08:13:50 +08:00
end
it "should work if you are a moderator" do
sign_in(moderator)
get "/admin/logs/search_logs.json"
expect(response.status).to eq(200)
json = response.parsed_body
expect(json[0]["term"]).to eq("ruby")
expect(json[0]["searches"]).to eq(1)
expect(json[0]["ctr"]).to eq(0)
end
2017-11-15 08:13:50 +08:00
end
describe "#term" do
it "raises an error if you aren't logged in" do
get '/admin/logs/search_logs/term.json', params: {
term: "ruby"
}
expect(response.status).to eq(404)
end
it "raises an error if you aren't an admin" do
sign_in(user)
get '/admin/logs/search_logs/term.json', params: {
term: "ruby"
}
expect(response.status).to eq(404)
end
it "should work if you are an admin" do
sign_in(admin)
get '/admin/logs/search_logs/term.json', params: {
term: "ruby"
}
expect(response.status).to eq(200)
json = response.parsed_body
expect(json['term']['type']).to eq('search_log_term')
expect(json['term']['search_result']).to be_present
end
it "should work if you are a moderator" do
sign_in(moderator)
get "/admin/logs/search_logs/term.json", params: {
term: "ruby"
}
expect(response.status).to eq(200)
json = response.parsed_body
expect(json["term"]["type"]).to eq("search_log_term")
expect(json["term"]["search_result"]).to be_present
end
end
2017-11-15 08:13:50 +08:00
end