mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 21:10:17 +08:00
586454bcf1
* DEV: Add a dedicated Admin::StaffController base controller The current parent(Admin:AdminController) for all admin-related controllers uses a filter that allows only staff(admin, moderator) users. This refactor makes Admin::AdminController filter for only admins as the name suggests and introduces a base controller dedicated for staff-related endpoints. * DEV: Set staff-only controllers parent to Admin::StaffController Refactor staff-only controllers to inherit newly introduced Admin::StaffController abstract controller. This conveys the purpose of the parent controller better unlike the previously used parent controller.
105 lines
2.5 KiB
Ruby
105 lines
2.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Admin::SearchLogsController do
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
fab!(:moderator) { Fabricate(:moderator) }
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
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
|
|
it "raises an error if you aren't logged in" do
|
|
get '/admin/logs/search_logs.json'
|
|
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.json'
|
|
expect(response.status).to eq(404)
|
|
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)
|
|
|
|
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
|
|
|
|
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
|
|
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
|
|
end
|