diff options
author | Rémy Coutable <remy@rymai.me> | 2016-09-20 10:20:17 +0300 |
---|---|---|
committer | Ruben Davila <rdavila84@gmail.com> | 2016-09-20 19:08:14 +0300 |
commit | b5f849e5240d41bb9620b2cb2688083d2544a488 (patch) | |
tree | c9c7fc80efffd3276682dc2c144a0166a62f035d /spec | |
parent | 30e98e486a61ab52573b5b5cdce43966af4268ce (diff) |
Merge branch 'sh-fix-last-activity-at-specs' into 'master'
Fix broken spec due to last_activity_at updates being throttled
In https://gitlab.com/gitlab-org/gitlab-ce/builds/4218398, the build failed because the last_activity_at column was only being updated once per hour. We
can fix this spec by stubbing out the throttling and adjusting the spec to test the right event timestamp.
See merge request !6424
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/events.rb | 5 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 13 |
2 files changed, 11 insertions, 7 deletions
diff --git a/spec/factories/events.rb b/spec/factories/events.rb index 90788f30ac9..8820d527c61 100644 --- a/spec/factories/events.rb +++ b/spec/factories/events.rb @@ -1,10 +1,11 @@ FactoryGirl.define do factory :event do + project + author factory: :user + factory :closed_issue_event do - project action { Event::CLOSED } target factory: :closed_issue - author factory: :user end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 7ca1bd1e5c9..a388ff703a6 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -308,20 +308,23 @@ describe Project, models: true do end describe 'last_activity methods' do - let(:project) { create(:project) } - let(:last_event) { double(created_at: Time.now) } + let(:timestamp) { Time.now - 2.hours } + let(:project) { create(:project, created_at: timestamp, updated_at: timestamp) } describe 'last_activity' do it 'alias last_activity to last_event' do - allow(project).to receive(:last_event).and_return(last_event) + last_event = create(:event, project: project) + expect(project.last_activity).to eq(last_event) end end describe 'last_activity_date' do it 'returns the creation date of the project\'s last event if present' do - create(:event, project: project) - expect(project.last_activity_at.to_i).to eq(last_event.created_at.to_i) + expect_any_instance_of(Event).to receive(:try_obtain_lease).and_return(true) + new_event = create(:event, project: project, created_at: Time.now) + + expect(project.last_activity_at.to_i).to eq(new_event.created_at.to_i) end it 'returns the project\'s last update date if it has no events' do |