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