diff options
| author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-03-22 13:55:00 -0700 |
|---|---|---|
| committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-03-22 13:55:00 -0700 |
| commit | 43afe46bbd19b1edf60abf3f104fb2b0d29af564 (patch) | |
| tree | e2a11249408e3403a5a125c50008e77ba1157e57 /app/models | |
| parent | 20a12438ab470afe1a5736fc46091a6ef4c30073 (diff) | |
| download | gitlab-ce-43afe46bbd19b1edf60abf3f104fb2b0d29af564.tar.gz | |
Refactor contributions events and write tests for calendar
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/event.rb | 6 | ||||
| -rw-r--r-- | app/models/user.rb | 7 |
2 files changed, 8 insertions, 5 deletions
diff --git a/app/models/event.rb b/app/models/event.rb index 2103a48a71b..57f6d5cd4e0 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -55,6 +55,12 @@ class Event < ActiveRecord::Base order('id DESC').limit(100). update_all(updated_at: Time.now) end + + def contributions + where("action = ? OR (target_type in (?) AND action in (?))", + Event::PUSHED, ["MergeRequest", "Issue"], + [Event::CREATED, Event::CLOSED, Event::MERGED]) + end end def proper? diff --git a/app/models/user.rb b/app/models/user.rb index ba325132df8..50f664a09a3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -603,13 +603,10 @@ class User < ActiveRecord::Base end def contributed_projects_ids - Event.where(author_id: self). + Event.contributions.where(author_id: self). where("created_at > ?", Time.now - 1.year). - where("action = :pushed OR (target_type = 'MergeRequest' AND action = :created)", - pushed: Event::PUSHED, created: Event::CREATED). reorder(project_id: :desc). select(:project_id). - uniq - .map(&:project_id) + uniq.map(&:project_id) end end |
