Merge pull request #2979 from Undev/fix_naming
Constants in Events looks good now
This commit is contained in:
commit
95e4217a2b
13 changed files with 43 additions and 43 deletions
|
@ -20,15 +20,15 @@ class Event < ActiveRecord::Base
|
||||||
|
|
||||||
default_scope where("author_id IS NOT NULL")
|
default_scope where("author_id IS NOT NULL")
|
||||||
|
|
||||||
Created = 1
|
CREATED = 1
|
||||||
Updated = 2
|
UPDATED = 2
|
||||||
Closed = 3
|
CLOSED = 3
|
||||||
Reopened = 4
|
REOPENED = 4
|
||||||
Pushed = 5
|
PUSHED = 5
|
||||||
Commented = 6
|
COMMENTED = 6
|
||||||
Merged = 7
|
MERGED = 7
|
||||||
Joined = 8 # User joined project
|
JOINED = 8 # User joined project
|
||||||
Left = 9 # User left project
|
LEFT = 9 # User left project
|
||||||
|
|
||||||
delegate :name, :email, to: :author, prefix: true, allow_nil: true
|
delegate :name, :email, to: :author, prefix: true, allow_nil: true
|
||||||
delegate :title, to: :issue, prefix: true, allow_nil: true
|
delegate :title, to: :issue, prefix: true, allow_nil: true
|
||||||
|
@ -43,15 +43,15 @@ class Event < ActiveRecord::Base
|
||||||
|
|
||||||
# Scopes
|
# Scopes
|
||||||
scope :recent, -> { order("created_at DESC") }
|
scope :recent, -> { order("created_at DESC") }
|
||||||
scope :code_push, -> { where(action: Pushed) }
|
scope :code_push, -> { where(action: PUSHED) }
|
||||||
scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent }
|
scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent }
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def determine_action(record)
|
def determine_action(record)
|
||||||
if [Issue, MergeRequest].include? record.class
|
if [Issue, MergeRequest].include? record.class
|
||||||
Event::Created
|
Event::CREATED
|
||||||
elsif record.kind_of? Note
|
elsif record.kind_of? Note
|
||||||
Event::Commented
|
Event::COMMENTED
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -79,19 +79,19 @@ class Event < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def push?
|
def push?
|
||||||
action == self.class::Pushed && valid_push?
|
action == self.class::PUSHED && valid_push?
|
||||||
end
|
end
|
||||||
|
|
||||||
def merged?
|
def merged?
|
||||||
action == self.class::Merged
|
action == self.class::MERGED
|
||||||
end
|
end
|
||||||
|
|
||||||
def closed?
|
def closed?
|
||||||
action == self.class::Closed
|
action == self.class::CLOSED
|
||||||
end
|
end
|
||||||
|
|
||||||
def reopened?
|
def reopened?
|
||||||
action == self.class::Reopened
|
action == self.class::REOPENED
|
||||||
end
|
end
|
||||||
|
|
||||||
def milestone?
|
def milestone?
|
||||||
|
@ -111,11 +111,11 @@ class Event < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def joined?
|
def joined?
|
||||||
action == Joined
|
action == JOINED
|
||||||
end
|
end
|
||||||
|
|
||||||
def left?
|
def left?
|
||||||
action == Left
|
action == LEFT
|
||||||
end
|
end
|
||||||
|
|
||||||
def membership_changed?
|
def membership_changed?
|
||||||
|
|
|
@ -133,11 +133,11 @@ class MergeRequest < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def merge_event
|
def merge_event
|
||||||
self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::Merged).last
|
self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::MERGED).last
|
||||||
end
|
end
|
||||||
|
|
||||||
def closed_event
|
def closed_event
|
||||||
self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::Closed).last
|
self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::CLOSED).last
|
||||||
end
|
end
|
||||||
|
|
||||||
def commits
|
def commits
|
||||||
|
@ -184,7 +184,7 @@ class MergeRequest < ActiveRecord::Base
|
||||||
self.mark_as_merged!
|
self.mark_as_merged!
|
||||||
Event.create(
|
Event.create(
|
||||||
project: self.project,
|
project: self.project,
|
||||||
action: Event::Merged,
|
action: Event::MERGED,
|
||||||
target_id: self.id,
|
target_id: self.id,
|
||||||
target_type: "MergeRequest",
|
target_type: "MergeRequest",
|
||||||
author_id: user_id
|
author_id: user_id
|
||||||
|
|
|
@ -103,7 +103,7 @@ class Project < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_push
|
def with_push
|
||||||
includes(:events).where('events.action = ?', Event::Pushed)
|
includes(:events).where('events.action = ?', Event::PUSHED)
|
||||||
end
|
end
|
||||||
|
|
||||||
def active
|
def active
|
||||||
|
@ -336,7 +336,7 @@ class Project < ActiveRecord::Base
|
||||||
def observe_push(data)
|
def observe_push(data)
|
||||||
Event.create(
|
Event.create(
|
||||||
project: self,
|
project: self,
|
||||||
action: Event::Pushed,
|
action: Event::PUSHED,
|
||||||
data: data,
|
data: data,
|
||||||
author_id: data[:user_id]
|
author_id: data[:user_id]
|
||||||
)
|
)
|
||||||
|
|
|
@ -26,7 +26,7 @@ class ActivityObserver < ActiveRecord::Observer
|
||||||
project: record.project,
|
project: record.project,
|
||||||
target_id: record.id,
|
target_id: record.id,
|
||||||
target_type: record.class.name,
|
target_type: record.class.name,
|
||||||
action: (record.closed ? Event::Closed : Event::Reopened),
|
action: (record.closed ? Event::CLOSED : Event::REOPENED),
|
||||||
author_id: record.author_id_of_changes
|
author_id: record.author_id_of_changes
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ class UsersProjectObserver < ActiveRecord::Observer
|
||||||
def after_create(users_project)
|
def after_create(users_project)
|
||||||
Event.create(
|
Event.create(
|
||||||
project_id: users_project.project.id,
|
project_id: users_project.project.id,
|
||||||
action: Event::Joined,
|
action: Event::JOINED,
|
||||||
author_id: users_project.user.id
|
author_id: users_project.user.id
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -15,7 +15,7 @@ class UsersProjectObserver < ActiveRecord::Observer
|
||||||
def after_destroy(users_project)
|
def after_destroy(users_project)
|
||||||
Event.create(
|
Event.create(
|
||||||
project_id: users_project.project.id,
|
project_id: users_project.project.id,
|
||||||
action: Event::Left,
|
action: Event::LEFT,
|
||||||
author_id: users_project.user.id
|
author_id: users_project.user.id
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,7 +33,7 @@ class Dashboard < Spinach::FeatureSteps
|
||||||
Event.create(
|
Event.create(
|
||||||
project: project,
|
project: project,
|
||||||
author_id: user.id,
|
author_id: user.id,
|
||||||
action: Event::Joined
|
action: Event::JOINED
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class Dashboard < Spinach::FeatureSteps
|
||||||
Event.create(
|
Event.create(
|
||||||
project: project,
|
project: project,
|
||||||
author_id: user.id,
|
author_id: user.id,
|
||||||
action: Event::Left
|
action: Event::LEFT
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ class EventFilters < Spinach::FeatureSteps
|
||||||
|
|
||||||
@event = Event.create(
|
@event = Event.create(
|
||||||
project: @project,
|
project: @project,
|
||||||
action: Event::Pushed,
|
action: Event::PUSHED,
|
||||||
data: data,
|
data: data,
|
||||||
author_id: @user.id
|
author_id: @user.id
|
||||||
)
|
)
|
||||||
|
@ -56,7 +56,7 @@ class EventFilters < Spinach::FeatureSteps
|
||||||
Event.create(
|
Event.create(
|
||||||
project: @project,
|
project: @project,
|
||||||
author_id: user.id,
|
author_id: user.id,
|
||||||
action: Event::Joined
|
action: Event::JOINED
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class EventFilters < Spinach::FeatureSteps
|
||||||
merge_request = create :merge_request, author: @user, project: @project
|
merge_request = create :merge_request, author: @user, project: @project
|
||||||
Event.create(
|
Event.create(
|
||||||
project: @project,
|
project: @project,
|
||||||
action: Event::Merged,
|
action: Event::MERGED,
|
||||||
target_id: merge_request.id,
|
target_id: merge_request.id,
|
||||||
target_type: "MergeRequest",
|
target_type: "MergeRequest",
|
||||||
author_id: @user.id
|
author_id: @user.id
|
||||||
|
|
|
@ -33,7 +33,7 @@ module SharedProject
|
||||||
|
|
||||||
@event = Event.create(
|
@event = Event.create(
|
||||||
project: @project,
|
project: @project,
|
||||||
action: Event::Pushed,
|
action: Event::PUSHED,
|
||||||
data: data,
|
data: data,
|
||||||
author_id: @user.id
|
author_id: @user.id
|
||||||
)
|
)
|
||||||
|
|
|
@ -37,15 +37,15 @@ class EventFilter
|
||||||
filter = params.dup
|
filter = params.dup
|
||||||
|
|
||||||
actions = []
|
actions = []
|
||||||
actions << Event::Pushed if filter.include? 'push'
|
actions << Event::PUSHED if filter.include? 'push'
|
||||||
actions << Event::Merged if filter.include? 'merged'
|
actions << Event::MERGED if filter.include? 'merged'
|
||||||
|
|
||||||
if filter.include? 'team'
|
if filter.include? 'team'
|
||||||
actions << Event::Joined
|
actions << Event::JOINED
|
||||||
actions << Event::Left
|
actions << Event::LEFT
|
||||||
end
|
end
|
||||||
|
|
||||||
actions << Event::Commented if filter.include? 'comments'
|
actions << Event::COMMENTED if filter.include? 'comments'
|
||||||
|
|
||||||
events = events.where(action: actions)
|
events = events.where(action: actions)
|
||||||
end
|
end
|
||||||
|
|
|
@ -123,7 +123,7 @@ FactoryGirl.define do
|
||||||
factory :event do
|
factory :event do
|
||||||
factory :closed_issue_event do
|
factory :closed_issue_event do
|
||||||
project
|
project
|
||||||
action { Event::Closed }
|
action { Event::CLOSED }
|
||||||
target factory: :closed_issue
|
target factory: :closed_issue
|
||||||
author factory: :user
|
author factory: :user
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,7 +52,7 @@ describe Event do
|
||||||
|
|
||||||
@event = Event.create(
|
@event = Event.create(
|
||||||
project: project,
|
project: project,
|
||||||
action: Event::Pushed,
|
action: Event::PUSHED,
|
||||||
data: data,
|
data: data,
|
||||||
author_id: @user.id
|
author_id: @user.id
|
||||||
)
|
)
|
||||||
|
|
|
@ -19,7 +19,7 @@ describe Project, "Hooks" do
|
||||||
|
|
||||||
event.should_not be_nil
|
event.should_not be_nil
|
||||||
event.project.should == project
|
event.project.should == project
|
||||||
event.action.should == Event::Pushed
|
event.action.should == Event::PUSHED
|
||||||
event.data.should == data
|
event.data.should == data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,7 +17,7 @@ describe ActivityObserver do
|
||||||
end
|
end
|
||||||
|
|
||||||
it_should_be_valid_event
|
it_should_be_valid_event
|
||||||
it { @event.action.should == Event::Created }
|
it { @event.action.should == Event::CREATED }
|
||||||
it { @event.target.should == @merge_request }
|
it { @event.target.should == @merge_request }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ describe ActivityObserver do
|
||||||
end
|
end
|
||||||
|
|
||||||
it_should_be_valid_event
|
it_should_be_valid_event
|
||||||
it { @event.action.should == Event::Created }
|
it { @event.action.should == Event::CREATED }
|
||||||
it { @event.target.should == @issue }
|
it { @event.target.should == @issue }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ describe ActivityObserver do
|
||||||
end
|
end
|
||||||
|
|
||||||
it_should_be_valid_event
|
it_should_be_valid_event
|
||||||
it { @event.action.should == Event::Commented }
|
it { @event.action.should == Event::COMMENTED }
|
||||||
it { @event.target.should == @note }
|
it { @event.target.should == @note }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue