Constants in Events looks good now

5-0-stable
Andrew8xx8 2013-02-13 15:48:16 +04:00
parent b9f8b40190
commit 839957cf56
13 changed files with 43 additions and 43 deletions

View File

@ -20,15 +20,15 @@ class Event < ActiveRecord::Base
default_scope where("author_id IS NOT NULL")
Created = 1
Updated = 2
Closed = 3
Reopened = 4
Pushed = 5
Commented = 6
Merged = 7
Joined = 8 # User joined project
Left = 9 # User left project
CREATED = 1
UPDATED = 2
CLOSED = 3
REOPENED = 4
PUSHED = 5
COMMENTED = 6
MERGED = 7
JOINED = 8 # User joined project
LEFT = 9 # User left project
delegate :name, :email, to: :author, prefix: true, allow_nil: true
delegate :title, to: :issue, prefix: true, allow_nil: true
@ -43,15 +43,15 @@ class Event < ActiveRecord::Base
# Scopes
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 }
class << self
def determine_action(record)
if [Issue, MergeRequest].include? record.class
Event::Created
Event::CREATED
elsif record.kind_of? Note
Event::Commented
Event::COMMENTED
end
end
end
@ -79,19 +79,19 @@ class Event < ActiveRecord::Base
end
def push?
action == self.class::Pushed && valid_push?
action == self.class::PUSHED && valid_push?
end
def merged?
action == self.class::Merged
action == self.class::MERGED
end
def closed?
action == self.class::Closed
action == self.class::CLOSED
end
def reopened?
action == self.class::Reopened
action == self.class::REOPENED
end
def milestone?
@ -111,11 +111,11 @@ class Event < ActiveRecord::Base
end
def joined?
action == Joined
action == JOINED
end
def left?
action == Left
action == LEFT
end
def membership_changed?

View File

@ -133,11 +133,11 @@ class MergeRequest < ActiveRecord::Base
end
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
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
def commits
@ -184,7 +184,7 @@ class MergeRequest < ActiveRecord::Base
self.mark_as_merged!
Event.create(
project: self.project,
action: Event::Merged,
action: Event::MERGED,
target_id: self.id,
target_type: "MergeRequest",
author_id: user_id

View File

@ -103,7 +103,7 @@ class Project < ActiveRecord::Base
end
def with_push
includes(:events).where('events.action = ?', Event::Pushed)
includes(:events).where('events.action = ?', Event::PUSHED)
end
def active
@ -336,7 +336,7 @@ class Project < ActiveRecord::Base
def observe_push(data)
Event.create(
project: self,
action: Event::Pushed,
action: Event::PUSHED,
data: data,
author_id: data[:user_id]
)

View File

@ -26,7 +26,7 @@ class ActivityObserver < ActiveRecord::Observer
project: record.project,
target_id: record.id,
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
)
end

View File

@ -7,7 +7,7 @@ class UsersProjectObserver < ActiveRecord::Observer
def after_create(users_project)
Event.create(
project_id: users_project.project.id,
action: Event::Joined,
action: Event::JOINED,
author_id: users_project.user.id
)
end
@ -15,7 +15,7 @@ class UsersProjectObserver < ActiveRecord::Observer
def after_destroy(users_project)
Event.create(
project_id: users_project.project.id,
action: Event::Left,
action: Event::LEFT,
author_id: users_project.user.id
)
end

View File

@ -33,7 +33,7 @@ class Dashboard < Spinach::FeatureSteps
Event.create(
project: project,
author_id: user.id,
action: Event::Joined
action: Event::JOINED
)
end
@ -47,7 +47,7 @@ class Dashboard < Spinach::FeatureSteps
Event.create(
project: project,
author_id: user.id,
action: Event::Left
action: Event::LEFT
)
end

View File

@ -45,7 +45,7 @@ class EventFilters < Spinach::FeatureSteps
@event = Event.create(
project: @project,
action: Event::Pushed,
action: Event::PUSHED,
data: data,
author_id: @user.id
)
@ -56,7 +56,7 @@ class EventFilters < Spinach::FeatureSteps
Event.create(
project: @project,
author_id: user.id,
action: Event::Joined
action: Event::JOINED
)
end
@ -64,7 +64,7 @@ class EventFilters < Spinach::FeatureSteps
merge_request = create :merge_request, author: @user, project: @project
Event.create(
project: @project,
action: Event::Merged,
action: Event::MERGED,
target_id: merge_request.id,
target_type: "MergeRequest",
author_id: @user.id

View File

@ -33,7 +33,7 @@ module SharedProject
@event = Event.create(
project: @project,
action: Event::Pushed,
action: Event::PUSHED,
data: data,
author_id: @user.id
)

View File

@ -37,15 +37,15 @@ class EventFilter
filter = params.dup
actions = []
actions << Event::Pushed if filter.include? 'push'
actions << Event::Merged if filter.include? 'merged'
actions << Event::PUSHED if filter.include? 'push'
actions << Event::MERGED if filter.include? 'merged'
if filter.include? 'team'
actions << Event::Joined
actions << Event::Left
actions << Event::JOINED
actions << Event::LEFT
end
actions << Event::Commented if filter.include? 'comments'
actions << Event::COMMENTED if filter.include? 'comments'
events = events.where(action: actions)
end

View File

@ -123,7 +123,7 @@ FactoryGirl.define do
factory :event do
factory :closed_issue_event do
project
action { Event::Closed }
action { Event::CLOSED }
target factory: :closed_issue
author factory: :user
end

View File

@ -52,7 +52,7 @@ describe Event do
@event = Event.create(
project: project,
action: Event::Pushed,
action: Event::PUSHED,
data: data,
author_id: @user.id
)

View File

@ -19,7 +19,7 @@ describe Project, "Hooks" do
event.should_not be_nil
event.project.should == project
event.action.should == Event::Pushed
event.action.should == Event::PUSHED
event.data.should == data
end
end

View File

@ -17,7 +17,7 @@ describe ActivityObserver do
end
it_should_be_valid_event
it { @event.action.should == Event::Created }
it { @event.action.should == Event::CREATED }
it { @event.target.should == @merge_request }
end
@ -30,7 +30,7 @@ describe ActivityObserver do
end
it_should_be_valid_event
it { @event.action.should == Event::Created }
it { @event.action.should == Event::CREATED }
it { @event.target.should == @issue }
end
@ -44,7 +44,7 @@ describe ActivityObserver do
end
it_should_be_valid_event
it { @event.action.should == Event::Commented }
it { @event.action.should == Event::COMMENTED }
it { @event.target.should == @note }
end
end