diff options
author | Andrew8xx8 <avk@8xx8.ru> | 2013-02-13 15:48:16 +0400 |
---|---|---|
committer | Andrew8xx8 <avk@8xx8.ru> | 2013-02-13 15:48:16 +0400 |
commit | 839957cf56acb905afc18605c0579d07083e0d37 (patch) | |
tree | 26d360e900fbd31548f269fa62bc504b419c1398 | |
parent | b9f8b4019073fe60515bda8947d9040b4b73ea38 (diff) |
Constants in Events looks good now
-rw-r--r-- | app/models/event.rb | 36 | ||||
-rw-r--r-- | app/models/merge_request.rb | 6 | ||||
-rw-r--r-- | app/models/project.rb | 4 | ||||
-rw-r--r-- | app/observers/activity_observer.rb | 2 | ||||
-rw-r--r-- | app/observers/users_project_observer.rb | 4 | ||||
-rw-r--r-- | features/steps/dashboard/dashboard.rb | 4 | ||||
-rw-r--r-- | features/steps/dashboard/dashboard_event_filters.rb | 6 | ||||
-rw-r--r-- | features/steps/shared/project.rb | 2 | ||||
-rw-r--r-- | lib/event_filter.rb | 10 | ||||
-rw-r--r-- | spec/factories.rb | 2 | ||||
-rw-r--r-- | spec/models/event_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/project_hooks_spec.rb | 2 | ||||
-rw-r--r-- | spec/observers/activity_observer_spec.rb | 6 |
13 files changed, 43 insertions, 43 deletions
diff --git a/app/models/event.rb b/app/models/event.rb index 97b1e3306aa..18422e192a4 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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? diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index b6ea85f6507..345b8d6e07d 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index acc1b8d2328..15b2d858b62 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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] ) diff --git a/app/observers/activity_observer.rb b/app/observers/activity_observer.rb index c188e5720ac..b568bb6b763 100644 --- a/app/observers/activity_observer.rb +++ b/app/observers/activity_observer.rb @@ -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 diff --git a/app/observers/users_project_observer.rb b/app/observers/users_project_observer.rb index b969d6a13ef..66b421753f0 100644 --- a/app/observers/users_project_observer.rb +++ b/app/observers/users_project_observer.rb @@ -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 diff --git a/features/steps/dashboard/dashboard.rb b/features/steps/dashboard/dashboard.rb index 8c13ad0e151..c6832056435 100644 --- a/features/steps/dashboard/dashboard.rb +++ b/features/steps/dashboard/dashboard.rb @@ -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 diff --git a/features/steps/dashboard/dashboard_event_filters.rb b/features/steps/dashboard/dashboard_event_filters.rb index bfc053631ab..afa15c31332 100644 --- a/features/steps/dashboard/dashboard_event_filters.rb +++ b/features/steps/dashboard/dashboard_event_filters.rb @@ -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 diff --git a/features/steps/shared/project.rb b/features/steps/shared/project.rb index 1623edb80d0..5e61a4132c0 100644 --- a/features/steps/shared/project.rb +++ b/features/steps/shared/project.rb @@ -33,7 +33,7 @@ module SharedProject @event = Event.create( project: @project, - action: Event::Pushed, + action: Event::PUSHED, data: data, author_id: @user.id ) diff --git a/lib/event_filter.rb b/lib/event_filter.rb index 14ab0193bf1..9b4b8c3801a 100644 --- a/lib/event_filter.rb +++ b/lib/event_filter.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index ae9066cb30c..d2e9f48c47b 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 82b46b68b64..cc78993905f 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -52,7 +52,7 @@ describe Event do @event = Event.create( project: project, - action: Event::Pushed, + action: Event::PUSHED, data: data, author_id: @user.id ) diff --git a/spec/models/project_hooks_spec.rb b/spec/models/project_hooks_spec.rb index 3559c72f6f0..65205538213 100644 --- a/spec/models/project_hooks_spec.rb +++ b/spec/models/project_hooks_spec.rb @@ -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 diff --git a/spec/observers/activity_observer_spec.rb b/spec/observers/activity_observer_spec.rb index 6af5d070888..3d503027360 100644 --- a/spec/observers/activity_observer_spec.rb +++ b/spec/observers/activity_observer_spec.rb @@ -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 |