mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Add user_agent
column to search_logs
(#27742)
Add a new column - `user_agent` - to the `SearchLog` table. This column can be null as we are only allowing a the user-agent string to have a max length of 2000 characters. In the case the user-agent string surpasses the max characters allowed, we simply nullify the value, and save/write the log as normal.
This commit is contained in:
@@ -7,26 +7,49 @@ RSpec.describe SearchLog, type: :model do
|
||||
context "with invalid arguments" do
|
||||
it "no search type returns error" do
|
||||
status, _ =
|
||||
SearchLog.log(term: "bounty hunter", search_type: :missing, ip_address: "127.0.0.1")
|
||||
SearchLog.log(
|
||||
term: "bounty hunter",
|
||||
search_type: :missing,
|
||||
ip_address: "127.0.0.1",
|
||||
user_agent: "Mozilla",
|
||||
)
|
||||
expect(status).to eq(:error)
|
||||
end
|
||||
|
||||
it "no IP returns error" do
|
||||
status, _ = SearchLog.log(term: "bounty hunter", search_type: :header, ip_address: nil)
|
||||
status, _ =
|
||||
SearchLog.log(
|
||||
term: "bounty hunter",
|
||||
search_type: :header,
|
||||
ip_address: nil,
|
||||
user_agent: "Mozilla",
|
||||
)
|
||||
expect(status).to eq(:error)
|
||||
end
|
||||
|
||||
it "does not error when no user_agent" do
|
||||
status, _ =
|
||||
SearchLog.log(term: "bounty hunter", search_type: :header, ip_address: "127.0.0.1")
|
||||
expect(status).to eq(:created)
|
||||
end
|
||||
end
|
||||
|
||||
context "when anonymous" do
|
||||
it "logs and updates the search" do
|
||||
freeze_time
|
||||
action, log_id =
|
||||
SearchLog.log(term: "jabba", search_type: :header, ip_address: "192.168.0.33")
|
||||
SearchLog.log(
|
||||
term: "jabba",
|
||||
search_type: :header,
|
||||
ip_address: "192.168.0.33",
|
||||
user_agent: "Mozilla",
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
log = SearchLog.find(log_id)
|
||||
expect(log.term).to eq("jabba")
|
||||
expect(log.search_type).to eq(SearchLog.search_types[:header])
|
||||
expect(log.ip_address).to eq("192.168.0.33")
|
||||
expect(log.user_agent).to eq("Mozilla")
|
||||
|
||||
action, updated_log_id =
|
||||
SearchLog.log(term: "jabba the hut", search_type: :header, ip_address: "192.168.0.33")
|
||||
@@ -63,6 +86,7 @@ RSpec.describe SearchLog, type: :model do
|
||||
term: "hello",
|
||||
search_type: :full_page,
|
||||
ip_address: "192.168.0.1",
|
||||
user_agent: "Mozilla",
|
||||
user_id: user.id,
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
@@ -70,6 +94,7 @@ RSpec.describe SearchLog, type: :model do
|
||||
expect(log.term).to eq("hello")
|
||||
expect(log.search_type).to eq(SearchLog.search_types[:full_page])
|
||||
expect(log.ip_address).to eq(nil)
|
||||
expect(log.user_agent).to eq("Mozilla")
|
||||
expect(log.user_id).to eq(user.id)
|
||||
|
||||
action, updated_log_id =
|
||||
|
Reference in New Issue
Block a user