summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-04-21 09:42:08 +0200
committerRémy Coutable <remy@rymai.me>2016-04-25 17:25:46 +0200
commit533cd8c2ee45cc0a34aca08f48f9ee0cf7d3c3fb (patch)
tree6aebb67e26efd93715491b4245c6490b196157cc /spec/models
parent81cb636e4fcb7ea76db84a92aac65a73f2376458 (diff)
downloadgitlab-ce-533cd8c2ee45cc0a34aca08f48f9ee0cf7d3c3fb.tar.gz
Throttle the update of `project.last_activity_at` to 1 minute15094-throttle-update-of-last_activity_at
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/event_spec.rb65
1 files changed, 43 insertions, 22 deletions
diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb
index 89909c2bcd7..0c3cd13f399 100644
--- a/spec/models/event_spec.rb
+++ b/spec/models/event_spec.rb
@@ -30,32 +30,29 @@ describe Event, models: true do
it { is_expected.to respond_to(:commits) }
end
+ describe 'Callbacks' do
+ describe 'after_create :reset_project_activity' do
+ let(:project) { create(:project) }
+
+ context "project's last activity was less than 5 minutes ago" do
+ it 'does not update project.last_activity_at if it has been touched less than 5 minutes ago' do
+ create_event(project, project.owner)
+ project.update_column(:last_activity_at, 5.minutes.ago)
+ project_last_activity_at = project.last_activity_at
+
+ create_event(project, project.owner)
+
+ expect(project.last_activity_at).to eq(project_last_activity_at)
+ end
+ end
+ end
+ end
+
describe "Push event" do
before do
project = create(:project)
@user = project.owner
-
- data = {
- before: Gitlab::Git::BLANK_SHA,
- after: "0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e",
- ref: "refs/heads/master",
- user_id: @user.id,
- user_name: @user.name,
- repository: {
- name: project.name,
- url: "localhost/rubinius",
- description: "",
- homepage: "localhost/rubinius",
- private: true
- }
- }
-
- @event = Event.create(
- project: project,
- action: Event::PUSHED,
- data: data,
- author_id: @user.id
- )
+ @event = create_event(project, @user)
end
it { expect(@event.push?).to be_truthy }
@@ -143,4 +140,28 @@ describe Event, models: true do
it { is_expected.to eq([event2]) }
end
end
+
+ def create_event(project, user, attrs = {})
+ data = {
+ before: Gitlab::Git::BLANK_SHA,
+ after: "0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e",
+ ref: "refs/heads/master",
+ user_id: user.id,
+ user_name: user.name,
+ repository: {
+ name: project.name,
+ url: "localhost/rubinius",
+ description: "",
+ homepage: "localhost/rubinius",
+ private: true
+ }
+ }
+
+ Event.create({
+ project: project,
+ action: Event::PUSHED,
+ data: data,
+ author_id: user.id
+ }.merge(attrs))
+ end
end