Skip to content

Commit

Permalink
Constants in Events looks good now
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew8xx8 committed Feb 13, 2013
1 parent b9f8b40 commit 839957c
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 43 deletions.
36 changes: 18 additions & 18 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -79,19 +79,19 @@ def target_title
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?
Expand All @@ -111,11 +111,11 @@ def merge_request?
end

def joined?
action == Joined
action == JOINED
end

def left?
action == Left
action == LEFT
end

def membership_changed?
Expand Down
6 changes: 3 additions & 3 deletions app/models/merge_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ def merged?
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
Expand Down Expand Up @@ -184,7 +184,7 @@ def merge!(user_id)
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
Expand Down
4 changes: 2 additions & 2 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def abandoned
end

def with_push
includes(:events).where('events.action = ?', Event::Pushed)
includes(:events).where('events.action = ?', Event::PUSHED)
end

def active
Expand Down Expand Up @@ -336,7 +336,7 @@ def push_to_branch? ref, oldrev
def observe_push(data)
Event.create(
project: self,
action: Event::Pushed,
action: Event::PUSHED,
data: data,
author_id: data[:user_id]
)
Expand Down
2 changes: 1 addition & 1 deletion app/observers/activity_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def after_save(record)
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
Expand Down
4 changes: 2 additions & 2 deletions app/observers/users_project_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ def after_commit(users_project)
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

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
Expand Down
4 changes: 2 additions & 2 deletions features/steps/dashboard/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Dashboard < Spinach::FeatureSteps
Event.create(
project: project,
author_id: user.id,
action: Event::Joined
action: Event::JOINED
)
end

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

Expand Down
6 changes: 3 additions & 3 deletions features/steps/dashboard/dashboard_event_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -56,15 +56,15 @@ class EventFilters < Spinach::FeatureSteps
Event.create(
project: @project,
author_id: user.id,
action: Event::Joined
action: Event::JOINED
)
end

And 'this project has merge request event' do
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
Expand Down
2 changes: 1 addition & 1 deletion features/steps/shared/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module SharedProject

@event = Event.create(
project: @project,
action: Event::Pushed,
action: Event::PUSHED,
data: data,
author_id: @user.id
)
Expand Down
10 changes: 5 additions & 5 deletions lib/event_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def apply_filter events
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
Expand Down
2 changes: 1 addition & 1 deletion spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
factory :event do
factory :closed_issue_event do
project
action { Event::Closed }
action { Event::CLOSED }
target factory: :closed_issue
author factory: :user
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

@event = Event.create(
project: project,
action: Event::Pushed,
action: Event::PUSHED,
data: data,
author_id: @user.id
)
Expand Down
2 changes: 1 addition & 1 deletion spec/models/project_hooks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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
Expand Down
6 changes: 3 additions & 3 deletions spec/observers/activity_observer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def self.it_should_be_valid_event
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

Expand All @@ -30,7 +30,7 @@ def self.it_should_be_valid_event
end

it_should_be_valid_event
it { @event.action.should == Event::Created }
it { @event.action.should == Event::CREATED }
it { @event.target.should == @issue }
end

Expand All @@ -44,7 +44,7 @@ def self.it_should_be_valid_event
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

0 comments on commit 839957c

Please sign in to comment.