Fix randomly failing specs due to SearchLog cache.
This commit is contained in:
parent
ded84a4b58
commit
9eabf7c02c
|
@ -47,22 +47,25 @@ class SearchLog < ActiveRecord::Base
|
|||
|
||||
if existing = $redis.get(key)
|
||||
id, old_term = existing.split(",", 2)
|
||||
|
||||
if term.start_with?(old_term)
|
||||
where(id: id.to_i).update_all(
|
||||
created_at: Time.zone.now,
|
||||
term: term
|
||||
)
|
||||
|
||||
result = [:updated, id.to_i]
|
||||
end
|
||||
end
|
||||
|
||||
if !result
|
||||
log = create(
|
||||
log = self.create!(
|
||||
term: term,
|
||||
search_type: search_type,
|
||||
ip_address: ip_address,
|
||||
user_id: user_id
|
||||
)
|
||||
|
||||
result = [:created, log.id]
|
||||
end
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ describe SearchController do
|
|||
end
|
||||
|
||||
context "#click" do
|
||||
before do
|
||||
after do
|
||||
SearchLog.clear_debounce_cache!
|
||||
end
|
||||
|
||||
|
|
|
@ -296,16 +296,18 @@ describe Report do
|
|||
SearchLog.log(term: 'php', search_type: :header, ip_address: '127.0.0.1')
|
||||
end
|
||||
|
||||
after do
|
||||
SearchLog.clear_debounce_cache!
|
||||
end
|
||||
|
||||
it "returns a report with data" do
|
||||
expect(report.data).to be_present
|
||||
expect(report.data[0][0]).to eq("ruby")
|
||||
expect(report.data[0][1]).to eq(3)
|
||||
expect(report.data[0][2]).to eq(2)
|
||||
|
||||
expect(report.data[0][0]).to eq "ruby"
|
||||
expect(report.data[0][1]).to eq 3
|
||||
expect(report.data[0][2]).to eq 2
|
||||
|
||||
expect(report.data[1][0]).to eq "php"
|
||||
expect(report.data[1][1]).to eq 1
|
||||
expect(report.data[1][2]).to eq 1
|
||||
expect(report.data[1][0]).to eq("php")
|
||||
expect(report.data[1][1]).to eq(1)
|
||||
expect(report.data[1][2]).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe SearchLog, type: :model do
|
||||
|
||||
before do
|
||||
after do
|
||||
SearchLog.clear_debounce_cache!
|
||||
end
|
||||
|
||||
|
|
|
@ -5,10 +5,13 @@ RSpec.describe Admin::SearchLogsController do
|
|||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
SearchLog.clear_debounce_cache!
|
||||
SearchLog.log(term: 'ruby', search_type: :header, ip_address: '127.0.0.1')
|
||||
end
|
||||
|
||||
after do
|
||||
SearchLog.clear_debounce_cache!
|
||||
end
|
||||
|
||||
context "#index" do
|
||||
it "raises an error if you aren't logged in" do
|
||||
get '/admin/logs/search_logs.json'
|
||||
|
|
|
@ -503,17 +503,23 @@ describe UserMerger do
|
|||
expect(post3.reload.rejected_by).to eq(target_user)
|
||||
end
|
||||
|
||||
it "updates search log entries" do
|
||||
SearchLog.log(term: 'hello', search_type: :full_page, ip_address: '192.168.0.1', user_id: source_user.id)
|
||||
SearchLog.log(term: 'world', search_type: :full_page, ip_address: '192.168.0.1', user_id: source_user.id)
|
||||
SearchLog.log(term: 'star trek', search_type: :full_page, ip_address: '192.168.0.2', user_id: target_user.id)
|
||||
SearchLog.log(term: 'bad', search_type: :full_page, ip_address: '192.168.0.3', user_id: walter.id)
|
||||
describe 'search logs' do
|
||||
after do
|
||||
SearchLog.clear_debounce_cache!
|
||||
end
|
||||
|
||||
merge_users!
|
||||
it "updates search log entries" do
|
||||
SearchLog.log(term: 'hello', search_type: :full_page, ip_address: '192.168.0.1', user_id: source_user.id)
|
||||
SearchLog.log(term: 'world', search_type: :full_page, ip_address: '192.168.0.1', user_id: source_user.id)
|
||||
SearchLog.log(term: 'star trek', search_type: :full_page, ip_address: '192.168.0.2', user_id: target_user.id)
|
||||
SearchLog.log(term: 'bad', search_type: :full_page, ip_address: '192.168.0.3', user_id: walter.id)
|
||||
|
||||
expect(SearchLog.where(user_id: target_user.id).count).to eq(3)
|
||||
expect(SearchLog.where(user_id: source_user.id).count).to eq(0)
|
||||
expect(SearchLog.where(user_id: walter.id).count).to eq(1)
|
||||
merge_users!
|
||||
|
||||
expect(SearchLog.where(user_id: target_user.id).count).to eq(3)
|
||||
expect(SearchLog.where(user_id: source_user.id).count).to eq(0)
|
||||
expect(SearchLog.where(user_id: walter.id).count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
it "merges tag notification settings" do
|
||||
|
|
Loading…
Reference in New Issue