mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: remove the timecop gem
We should only have one way of mocking time, misuse of timecop was causing build stability issues
This commit is contained in:
@@ -26,62 +26,59 @@ RSpec.describe SearchLog, type: :model do
|
||||
|
||||
context "when anonymous" do
|
||||
it "logs and updates the search" do
|
||||
Timecop.freeze do
|
||||
action, log_id = SearchLog.log(
|
||||
term: 'jabba',
|
||||
search_type: :header,
|
||||
ip_address: '192.168.0.33'
|
||||
)
|
||||
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')
|
||||
freeze_time
|
||||
action, log_id = SearchLog.log(
|
||||
term: 'jabba',
|
||||
search_type: :header,
|
||||
ip_address: '192.168.0.33'
|
||||
)
|
||||
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')
|
||||
|
||||
action, updated_log_id = SearchLog.log(
|
||||
term: 'jabba the hut',
|
||||
search_type: :header,
|
||||
ip_address: '192.168.0.33'
|
||||
)
|
||||
expect(action).to eq(:updated)
|
||||
expect(updated_log_id).to eq(log_id)
|
||||
end
|
||||
action, updated_log_id = SearchLog.log(
|
||||
term: 'jabba the hut',
|
||||
search_type: :header,
|
||||
ip_address: '192.168.0.33'
|
||||
)
|
||||
expect(action).to eq(:updated)
|
||||
expect(updated_log_id).to eq(log_id)
|
||||
end
|
||||
|
||||
it "creates a new search with a different prefix" do
|
||||
Timecop.freeze do
|
||||
action, _ = SearchLog.log(
|
||||
term: 'darth',
|
||||
search_type: :header,
|
||||
ip_address: '127.0.0.1'
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
freeze_time
|
||||
action, _ = SearchLog.log(
|
||||
term: 'darth',
|
||||
search_type: :header,
|
||||
ip_address: '127.0.0.1'
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
|
||||
action, _ = SearchLog.log(
|
||||
term: 'anakin',
|
||||
search_type: :header,
|
||||
ip_address: '127.0.0.1'
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
end
|
||||
action, _ = SearchLog.log(
|
||||
term: 'anakin',
|
||||
search_type: :header,
|
||||
ip_address: '127.0.0.1'
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
end
|
||||
|
||||
it "creates a new search with a different ip" do
|
||||
Timecop.freeze do
|
||||
action, _ = SearchLog.log(
|
||||
term: 'darth',
|
||||
search_type: :header,
|
||||
ip_address: '127.0.0.1'
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
freeze_time
|
||||
action, _ = SearchLog.log(
|
||||
term: 'darth',
|
||||
search_type: :header,
|
||||
ip_address: '127.0.0.1'
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
|
||||
action, _ = SearchLog.log(
|
||||
term: 'darth',
|
||||
search_type: :header,
|
||||
ip_address: '127.0.0.2'
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
end
|
||||
action, _ = SearchLog.log(
|
||||
term: 'darth',
|
||||
search_type: :header,
|
||||
ip_address: '127.0.0.2'
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -89,71 +86,71 @@ RSpec.describe SearchLog, type: :model do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
it "logs and updates the search" do
|
||||
Timecop.freeze do
|
||||
action, log_id = SearchLog.log(
|
||||
term: 'hello',
|
||||
search_type: :full_page,
|
||||
ip_address: '192.168.0.1',
|
||||
user_id: user.id
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
log = SearchLog.find(log_id)
|
||||
expect(log.term).to eq('hello')
|
||||
expect(log.search_type).to eq(SearchLog.search_types[:full_page])
|
||||
expect(log.ip_address).to eq('192.168.0.1')
|
||||
expect(log.user_id).to eq(user.id)
|
||||
freeze_time
|
||||
action, log_id = SearchLog.log(
|
||||
term: 'hello',
|
||||
search_type: :full_page,
|
||||
ip_address: '192.168.0.1',
|
||||
user_id: user.id
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
log = SearchLog.find(log_id)
|
||||
expect(log.term).to eq('hello')
|
||||
expect(log.search_type).to eq(SearchLog.search_types[:full_page])
|
||||
expect(log.ip_address).to eq('192.168.0.1')
|
||||
expect(log.user_id).to eq(user.id)
|
||||
|
||||
action, updated_log_id = SearchLog.log(
|
||||
term: 'hello dolly',
|
||||
search_type: :header,
|
||||
ip_address: '192.168.0.33',
|
||||
user_id: user.id
|
||||
)
|
||||
expect(action).to eq(:updated)
|
||||
expect(updated_log_id).to eq(log_id)
|
||||
end
|
||||
action, updated_log_id = SearchLog.log(
|
||||
term: 'hello dolly',
|
||||
search_type: :header,
|
||||
ip_address: '192.168.0.33',
|
||||
user_id: user.id
|
||||
)
|
||||
expect(action).to eq(:updated)
|
||||
expect(updated_log_id).to eq(log_id)
|
||||
end
|
||||
|
||||
it "logs again if time has passed" do
|
||||
Timecop.freeze(10.minutes.ago) do
|
||||
action, _ = SearchLog.log(
|
||||
term: 'hello',
|
||||
search_type: :full_page,
|
||||
ip_address: '192.168.0.1',
|
||||
user_id: user.id
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
end
|
||||
freeze_time(10.minutes.ago)
|
||||
|
||||
Timecop.freeze do
|
||||
action, _ = SearchLog.log(
|
||||
term: 'hello',
|
||||
search_type: :full_page,
|
||||
ip_address: '192.168.0.1',
|
||||
user_id: user.id
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
end
|
||||
action, _ = SearchLog.log(
|
||||
term: 'hello',
|
||||
search_type: :full_page,
|
||||
ip_address: '192.168.0.1',
|
||||
user_id: user.id
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
|
||||
freeze_time(10.minutes.from_now)
|
||||
|
||||
action, _ = SearchLog.log(
|
||||
term: 'hello',
|
||||
search_type: :full_page,
|
||||
ip_address: '192.168.0.1',
|
||||
user_id: user.id
|
||||
)
|
||||
|
||||
expect(action).to eq(:created)
|
||||
end
|
||||
|
||||
it "logs again with a different user" do
|
||||
Timecop.freeze do
|
||||
action, _ = SearchLog.log(
|
||||
term: 'hello',
|
||||
search_type: :full_page,
|
||||
ip_address: '192.168.0.1',
|
||||
user_id: user.id
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
freeze_time
|
||||
|
||||
action, _ = SearchLog.log(
|
||||
term: 'hello dolly',
|
||||
search_type: :full_page,
|
||||
ip_address: '192.168.0.1',
|
||||
user_id: Fabricate(:user).id
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
end
|
||||
action, _ = SearchLog.log(
|
||||
term: 'hello',
|
||||
search_type: :full_page,
|
||||
ip_address: '192.168.0.1',
|
||||
user_id: user.id
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
|
||||
action, _ = SearchLog.log(
|
||||
term: 'hello dolly',
|
||||
search_type: :full_page,
|
||||
ip_address: '192.168.0.1',
|
||||
user_id: Fabricate(:user).id
|
||||
)
|
||||
expect(action).to eq(:created)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user