Fix Event#reset_project_activity updates
!6678 removed the lease from Event#reset_project_activity, but it wasn't actually updating the project's last_activity_at timestamp properly. The WHERE clause would always return no matching projects. The spec passed occasionally because the created_at timestamp was automatically set to last_activity_at.
This commit is contained in:
parent
a625757cb4
commit
1662640985
|
@ -335,7 +335,7 @@ class Event < ActiveRecord::Base
|
|||
# update the project. Only one query should actually perform the update,
|
||||
# hence we add the extra WHERE clause for last_activity_at.
|
||||
Project.unscoped.where(id: project_id).
|
||||
where('last_activity_at > ?', RESET_PROJECT_ACTIVITY_INTERVAL.ago).
|
||||
where('last_activity_at <= ?', RESET_PROJECT_ACTIVITY_INTERVAL.ago).
|
||||
update_all(last_activity_at: created_at)
|
||||
end
|
||||
|
||||
|
|
|
@ -308,7 +308,9 @@ describe Project, models: true do
|
|||
end
|
||||
|
||||
describe 'last_activity methods' do
|
||||
let(:project) { create(:project, last_activity_at: 2.hours.ago) }
|
||||
let(:timestamp) { 2.hours.ago }
|
||||
# last_activity_at gets set to created_at upon creation
|
||||
let(:project) { create(:project, created_at: timestamp, updated_at: timestamp) }
|
||||
|
||||
describe 'last_activity' do
|
||||
it 'alias last_activity to last_event' do
|
||||
|
@ -322,6 +324,7 @@ describe Project, models: true do
|
|||
it 'returns the creation date of the project\'s last event if present' do
|
||||
new_event = create(:event, project: project, created_at: Time.now)
|
||||
|
||||
project.reload
|
||||
expect(project.last_activity_at.to_i).to eq(new_event.created_at.to_i)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue