Commit 839957cf56acb905afc18605c0579d07083e0d37

Authored by Andrew8xx8
1 parent b9f8b401

Constants in Events looks good now

app/models/event.rb
... ... @@ -20,15 +20,15 @@ class Event < ActiveRecord::Base
20 20  
21 21 default_scope where("author_id IS NOT NULL")
22 22  
23   - Created = 1
24   - Updated = 2
25   - Closed = 3
26   - Reopened = 4
27   - Pushed = 5
28   - Commented = 6
29   - Merged = 7
30   - Joined = 8 # User joined project
31   - Left = 9 # User left project
  23 + CREATED = 1
  24 + UPDATED = 2
  25 + CLOSED = 3
  26 + REOPENED = 4
  27 + PUSHED = 5
  28 + COMMENTED = 6
  29 + MERGED = 7
  30 + JOINED = 8 # User joined project
  31 + LEFT = 9 # User left project
32 32  
33 33 delegate :name, :email, to: :author, prefix: true, allow_nil: true
34 34 delegate :title, to: :issue, prefix: true, allow_nil: true
... ... @@ -43,15 +43,15 @@ class Event < ActiveRecord::Base
43 43  
44 44 # Scopes
45 45 scope :recent, -> { order("created_at DESC") }
46   - scope :code_push, -> { where(action: Pushed) }
  46 + scope :code_push, -> { where(action: PUSHED) }
47 47 scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent }
48 48  
49 49 class << self
50 50 def determine_action(record)
51 51 if [Issue, MergeRequest].include? record.class
52   - Event::Created
  52 + Event::CREATED
53 53 elsif record.kind_of? Note
54   - Event::Commented
  54 + Event::COMMENTED
55 55 end
56 56 end
57 57 end
... ... @@ -79,19 +79,19 @@ class Event &lt; ActiveRecord::Base
79 79 end
80 80  
81 81 def push?
82   - action == self.class::Pushed && valid_push?
  82 + action == self.class::PUSHED && valid_push?
83 83 end
84 84  
85 85 def merged?
86   - action == self.class::Merged
  86 + action == self.class::MERGED
87 87 end
88 88  
89 89 def closed?
90   - action == self.class::Closed
  90 + action == self.class::CLOSED
91 91 end
92 92  
93 93 def reopened?
94   - action == self.class::Reopened
  94 + action == self.class::REOPENED
95 95 end
96 96  
97 97 def milestone?
... ... @@ -111,11 +111,11 @@ class Event &lt; ActiveRecord::Base
111 111 end
112 112  
113 113 def joined?
114   - action == Joined
  114 + action == JOINED
115 115 end
116 116  
117 117 def left?
118   - action == Left
  118 + action == LEFT
119 119 end
120 120  
121 121 def membership_changed?
... ...
app/models/merge_request.rb
... ... @@ -133,11 +133,11 @@ class MergeRequest &lt; ActiveRecord::Base
133 133 end
134 134  
135 135 def merge_event
136   - self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::Merged).last
  136 + self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::MERGED).last
137 137 end
138 138  
139 139 def closed_event
140   - self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::Closed).last
  140 + self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::CLOSED).last
141 141 end
142 142  
143 143 def commits
... ... @@ -184,7 +184,7 @@ class MergeRequest &lt; ActiveRecord::Base
184 184 self.mark_as_merged!
185 185 Event.create(
186 186 project: self.project,
187   - action: Event::Merged,
  187 + action: Event::MERGED,
188 188 target_id: self.id,
189 189 target_type: "MergeRequest",
190 190 author_id: user_id
... ...
app/models/project.rb
... ... @@ -103,7 +103,7 @@ class Project &lt; ActiveRecord::Base
103 103 end
104 104  
105 105 def with_push
106   - includes(:events).where('events.action = ?', Event::Pushed)
  106 + includes(:events).where('events.action = ?', Event::PUSHED)
107 107 end
108 108  
109 109 def active
... ... @@ -336,7 +336,7 @@ class Project &lt; ActiveRecord::Base
336 336 def observe_push(data)
337 337 Event.create(
338 338 project: self,
339   - action: Event::Pushed,
  339 + action: Event::PUSHED,
340 340 data: data,
341 341 author_id: data[:user_id]
342 342 )
... ...
app/observers/activity_observer.rb
... ... @@ -26,7 +26,7 @@ class ActivityObserver &lt; ActiveRecord::Observer
26 26 project: record.project,
27 27 target_id: record.id,
28 28 target_type: record.class.name,
29   - action: (record.closed ? Event::Closed : Event::Reopened),
  29 + action: (record.closed ? Event::CLOSED : Event::REOPENED),
30 30 author_id: record.author_id_of_changes
31 31 )
32 32 end
... ...
app/observers/users_project_observer.rb
... ... @@ -7,7 +7,7 @@ class UsersProjectObserver &lt; ActiveRecord::Observer
7 7 def after_create(users_project)
8 8 Event.create(
9 9 project_id: users_project.project.id,
10   - action: Event::Joined,
  10 + action: Event::JOINED,
11 11 author_id: users_project.user.id
12 12 )
13 13 end
... ... @@ -15,7 +15,7 @@ class UsersProjectObserver &lt; ActiveRecord::Observer
15 15 def after_destroy(users_project)
16 16 Event.create(
17 17 project_id: users_project.project.id,
18   - action: Event::Left,
  18 + action: Event::LEFT,
19 19 author_id: users_project.user.id
20 20 )
21 21 end
... ...
features/steps/dashboard/dashboard.rb
... ... @@ -33,7 +33,7 @@ class Dashboard &lt; Spinach::FeatureSteps
33 33 Event.create(
34 34 project: project,
35 35 author_id: user.id,
36   - action: Event::Joined
  36 + action: Event::JOINED
37 37 )
38 38 end
39 39  
... ... @@ -47,7 +47,7 @@ class Dashboard &lt; Spinach::FeatureSteps
47 47 Event.create(
48 48 project: project,
49 49 author_id: user.id,
50   - action: Event::Left
  50 + action: Event::LEFT
51 51 )
52 52 end
53 53  
... ...
features/steps/dashboard/dashboard_event_filters.rb
... ... @@ -45,7 +45,7 @@ class EventFilters &lt; Spinach::FeatureSteps
45 45  
46 46 @event = Event.create(
47 47 project: @project,
48   - action: Event::Pushed,
  48 + action: Event::PUSHED,
49 49 data: data,
50 50 author_id: @user.id
51 51 )
... ... @@ -56,7 +56,7 @@ class EventFilters &lt; Spinach::FeatureSteps
56 56 Event.create(
57 57 project: @project,
58 58 author_id: user.id,
59   - action: Event::Joined
  59 + action: Event::JOINED
60 60 )
61 61 end
62 62  
... ... @@ -64,7 +64,7 @@ class EventFilters &lt; Spinach::FeatureSteps
64 64 merge_request = create :merge_request, author: @user, project: @project
65 65 Event.create(
66 66 project: @project,
67   - action: Event::Merged,
  67 + action: Event::MERGED,
68 68 target_id: merge_request.id,
69 69 target_type: "MergeRequest",
70 70 author_id: @user.id
... ...
features/steps/shared/project.rb
... ... @@ -33,7 +33,7 @@ module SharedProject
33 33  
34 34 @event = Event.create(
35 35 project: @project,
36   - action: Event::Pushed,
  36 + action: Event::PUSHED,
37 37 data: data,
38 38 author_id: @user.id
39 39 )
... ...
lib/event_filter.rb
... ... @@ -37,15 +37,15 @@ class EventFilter
37 37 filter = params.dup
38 38  
39 39 actions = []
40   - actions << Event::Pushed if filter.include? 'push'
41   - actions << Event::Merged if filter.include? 'merged'
  40 + actions << Event::PUSHED if filter.include? 'push'
  41 + actions << Event::MERGED if filter.include? 'merged'
42 42  
43 43 if filter.include? 'team'
44   - actions << Event::Joined
45   - actions << Event::Left
  44 + actions << Event::JOINED
  45 + actions << Event::LEFT
46 46 end
47 47  
48   - actions << Event::Commented if filter.include? 'comments'
  48 + actions << Event::COMMENTED if filter.include? 'comments'
49 49  
50 50 events = events.where(action: actions)
51 51 end
... ...
spec/factories.rb
... ... @@ -123,7 +123,7 @@ FactoryGirl.define do
123 123 factory :event do
124 124 factory :closed_issue_event do
125 125 project
126   - action { Event::Closed }
  126 + action { Event::CLOSED }
127 127 target factory: :closed_issue
128 128 author factory: :user
129 129 end
... ...
spec/models/event_spec.rb
... ... @@ -52,7 +52,7 @@ describe Event do
52 52  
53 53 @event = Event.create(
54 54 project: project,
55   - action: Event::Pushed,
  55 + action: Event::PUSHED,
56 56 data: data,
57 57 author_id: @user.id
58 58 )
... ...
spec/models/project_hooks_spec.rb
... ... @@ -19,7 +19,7 @@ describe Project, &quot;Hooks&quot; do
19 19  
20 20 event.should_not be_nil
21 21 event.project.should == project
22   - event.action.should == Event::Pushed
  22 + event.action.should == Event::PUSHED
23 23 event.data.should == data
24 24 end
25 25 end
... ...
spec/observers/activity_observer_spec.rb
... ... @@ -17,7 +17,7 @@ describe ActivityObserver do
17 17 end
18 18  
19 19 it_should_be_valid_event
20   - it { @event.action.should == Event::Created }
  20 + it { @event.action.should == Event::CREATED }
21 21 it { @event.target.should == @merge_request }
22 22 end
23 23  
... ... @@ -30,7 +30,7 @@ describe ActivityObserver do
30 30 end
31 31  
32 32 it_should_be_valid_event
33   - it { @event.action.should == Event::Created }
  33 + it { @event.action.should == Event::CREATED }
34 34 it { @event.target.should == @issue }
35 35 end
36 36  
... ... @@ -44,7 +44,7 @@ describe ActivityObserver do
44 44 end
45 45  
46 46 it_should_be_valid_event
47   - it { @event.action.should == Event::Commented }
  47 + it { @event.action.should == Event::COMMENTED }
48 48 it { @event.target.should == @note }
49 49 end
50 50 end
... ...