Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
dcdb2fdf
Commit
dcdb2fdf
authored
Feb 28, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Observe issue, merge request, note creation - create event
parent
a847501f
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
130 additions
and
25 deletions
+130
-25
app/models/activity_observer.rb
app/models/activity_observer.rb
+12
-0
app/models/event.rb
app/models/event.rb
+27
-8
app/models/project.rb
app/models/project.rb
+1
-0
app/models/wiki.rb
app/models/wiki.rb
+1
-0
config/application.rb
config/application.rb
+1
-1
db/migrate/20120228130210_create_events.rb
db/migrate/20120228130210_create_events.rb
+3
-2
db/migrate/20120228134252_add_action_to_event.rb
db/migrate/20120228134252_add_action_to_event.rb
+5
-0
db/schema.rb
db/schema.rb
+6
-5
spec/factories.rb
spec/factories.rb
+9
-0
spec/models/activity_observer_spec.rb
spec/models/activity_observer_spec.rb
+42
-0
spec/models/event_spec.rb
spec/models/event_spec.rb
+22
-9
spec/models/project_spec.rb
spec/models/project_spec.rb
+1
-0
No files found.
app/models/activity_observer.rb
0 → 100644
View file @
dcdb2fdf
class
ActivityObserver
<
ActiveRecord
::
Observer
observe
:issue
,
:merge_request
,
:note
def
after_create
(
record
)
Event
.
create
(
:project
=>
record
.
project
,
:target_id
=>
record
.
id
,
:target_type
=>
record
.
class
.
name
,
:action
=>
Event
.
determine_action
(
record
)
)
end
end
app/models/event.rb
View file @
dcdb2fdf
class
Event
<
ActiveRecord
::
Base
class
Event
<
ActiveRecord
::
Base
Created
=
1
Updated
=
2
Closed
=
3
Reopened
=
4
Pushed
=
5
Commented
=
6
belongs_to
:project
belongs_to
:project
belongs_to
:target
,
:polymorphic
=>
true
serialize
:data
serialize
:data
def
self
.
determine_action
(
record
)
if
[
Issue
,
MergeRequest
].
include?
record
.
class
Event
::
Created
elsif
record
.
kind_of?
Note
Event
::
Commented
end
end
end
end
# == Schema Information
# == Schema Information
#
#
# Table name: events
# Table name: events
#
#
# id :integer not null, primary key
# id :integer not null, primary key
# data_type :string(255)
# target_type :string(255)
# data_id :string(255)
# target_id :integer
# title :string(255)
# title :string(255)
# data :text
# data :text
# project_id :integer
# project_id :integer
# created_at :datetime not null
# created_at :datetime not null
# updated_at :datetime not null
# updated_at :datetime not null
# action :integer
#
#
app/models/project.rb
View file @
dcdb2fdf
...
@@ -3,6 +3,7 @@ require "grit"
...
@@ -3,6 +3,7 @@ require "grit"
class
Project
<
ActiveRecord
::
Base
class
Project
<
ActiveRecord
::
Base
belongs_to
:owner
,
:class_name
=>
"User"
belongs_to
:owner
,
:class_name
=>
"User"
has_many
:events
,
:dependent
=>
:destroy
has_many
:merge_requests
,
:dependent
=>
:destroy
has_many
:merge_requests
,
:dependent
=>
:destroy
has_many
:issues
,
:dependent
=>
:destroy
,
:order
=>
"position"
has_many
:issues
,
:dependent
=>
:destroy
,
:order
=>
"position"
has_many
:users_projects
,
:dependent
=>
:destroy
has_many
:users_projects
,
:dependent
=>
:destroy
...
...
app/models/wiki.rb
View file @
dcdb2fdf
...
@@ -44,3 +44,4 @@ end
...
@@ -44,3 +44,4 @@ end
# slug :string(255)
# slug :string(255)
# user_id :integer
# user_id :integer
#
#
config/application.rb
View file @
dcdb2fdf
...
@@ -23,7 +23,7 @@ module Gitlab
...
@@ -23,7 +23,7 @@ module Gitlab
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# Activate observers that should always be running.
config
.
active_record
.
observers
=
:mailer_observer
config
.
active_record
.
observers
=
:mailer_observer
,
:activity_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
...
...
db/migrate/20120228130210_create_events.rb
View file @
dcdb2fdf
class
CreateEvents
<
ActiveRecord
::
Migration
class
CreateEvents
<
ActiveRecord
::
Migration
def
change
def
change
create_table
:events
do
|
t
|
create_table
:events
do
|
t
|
t
.
string
:data_type
,
:null
=>
true
t
.
string
:target_type
,
:null
=>
true
t
.
string
:data_id
,
:null
=>
true
t
.
integer
:target_id
,
:null
=>
true
t
.
string
:title
,
:null
=>
true
t
.
string
:title
,
:null
=>
true
t
.
text
:data
,
:null
=>
true
t
.
text
:data
,
:null
=>
true
t
.
integer
:project_id
,
:null
=>
true
t
.
integer
:project_id
,
:null
=>
true
...
...
db/migrate/20120228134252_add_action_to_event.rb
0 → 100644
View file @
dcdb2fdf
class
AddActionToEvent
<
ActiveRecord
::
Migration
def
change
add_column
:events
,
:action
,
:integer
,
:null
=>
true
end
end
db/schema.rb
View file @
dcdb2fdf
...
@@ -11,16 +11,17 @@
...
@@ -11,16 +11,17 @@
#
#
# It's strongly recommended to check this file into your version control system.
# It's strongly recommended to check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
:version
=>
2012022813
0210
)
do
ActiveRecord
::
Schema
.
define
(
:version
=>
2012022813
4252
)
do
create_table
"events"
,
:force
=>
true
do
|
t
|
create_table
"events"
,
:force
=>
true
do
|
t
|
t
.
string
"
data
_type"
t
.
string
"
target
_type"
t
.
string
"data
_id"
t
.
integer
"target
_id"
t
.
string
"title"
t
.
string
"title"
t
.
text
"data"
t
.
text
"data"
t
.
integer
"project_id"
t
.
integer
"project_id"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
integer
"action"
end
end
create_table
"issues"
,
:force
=>
true
do
|
t
|
create_table
"issues"
,
:force
=>
true
do
|
t
|
...
...
spec/factories.rb
View file @
dcdb2fdf
...
@@ -32,10 +32,14 @@ end
...
@@ -32,10 +32,14 @@ end
Factory
.
add
(
:issue
,
Issue
)
do
|
obj
|
Factory
.
add
(
:issue
,
Issue
)
do
|
obj
|
obj
.
title
=
Faker
::
Lorem
.
sentence
obj
.
title
=
Faker
::
Lorem
.
sentence
obj
.
author
=
Factory
:user
obj
.
assignee
=
Factory
:user
end
end
Factory
.
add
(
:merge_request
,
MergeRequest
)
do
|
obj
|
Factory
.
add
(
:merge_request
,
MergeRequest
)
do
|
obj
|
obj
.
title
=
Faker
::
Lorem
.
sentence
obj
.
title
=
Faker
::
Lorem
.
sentence
obj
.
author
=
Factory
:user
obj
.
assignee
=
Factory
:user
obj
.
source_branch
=
"master"
obj
.
source_branch
=
"master"
obj
.
target_branch
=
"master"
obj
.
target_branch
=
"master"
obj
.
closed
=
false
obj
.
closed
=
false
...
@@ -64,3 +68,8 @@ Factory.add(:wikis, WebHook) do |obj|
...
@@ -64,3 +68,8 @@ Factory.add(:wikis, WebHook) do |obj|
obj
.
title
=
Faker
::
Lorem
.
sentence
obj
.
title
=
Faker
::
Lorem
.
sentence
obj
.
content
=
Faker
::
Lorem
.
sentence
obj
.
content
=
Faker
::
Lorem
.
sentence
end
end
Factory
.
add
(
:event
,
Event
)
do
|
obj
|
obj
.
title
=
Faker
::
Lorem
.
sentence
obj
.
project
=
Factory
(
:project
)
end
spec/models/activity_observer_spec.rb
0 → 100644
View file @
dcdb2fdf
require
'spec_helper'
describe
ActivityObserver
do
let
(
:project
)
{
Factory
:project
}
describe
"Merge Request created"
do
before
do
@merge_request
=
Factory
:merge_request
,
:project
=>
project
@event
=
Event
.
last
end
it
{
@event
.
should_not
be_nil
}
it
{
@event
.
project
.
should
==
project
}
it
{
@event
.
action
.
should
==
Event
::
Created
}
it
{
@event
.
target
.
should
==
@merge_request
}
end
describe
"Issue created"
do
before
do
@issue
=
Factory
:issue
,
:project
=>
project
@event
=
Event
.
last
end
it
{
@event
.
should_not
be_nil
}
it
{
@event
.
project
.
should
==
project
}
it
{
@event
.
action
.
should
==
Event
::
Created
}
it
{
@event
.
target
.
should
==
@issue
}
end
describe
"Issue commented"
do
before
do
@issue
=
Factory
:issue
,
:project
=>
project
@note
=
Factory
:note
,
:noteable
=>
@issue
,
:project
=>
project
@event
=
Event
.
last
end
it
{
@event
.
should_not
be_nil
}
it
{
@event
.
project
.
should
==
project
}
it
{
@event
.
action
.
should
==
Event
::
Commented
}
it
{
@event
.
target
.
should
==
@note
}
end
end
spec/models/event_spec.rb
View file @
dcdb2fdf
...
@@ -2,18 +2,31 @@
...
@@ -2,18 +2,31 @@
#
#
# Table name: events
# Table name: events
#
#
# id :integer not null, primary key
# id :integer not null, primary key
# data_type :string(255)
# target_type :string(255)
# data_id :string(255)
# target_id :integer
# title :string(255)
# title :string(255)
# data :text
# data :text
# project_id :integer
# project_id :integer
# created_at :datetime not null
# created_at :datetime not null
# updated_at :datetime not null
# updated_at :datetime not null
# action :integer
#
#
require
'spec_helper'
require
'spec_helper'
describe
Event
do
describe
Event
do
pending
"add some examples to (or delete)
#{
__FILE__
}
"
describe
"Associations"
do
it
{
should
belong_to
(
:project
)
}
end
describe
"Creation"
do
before
do
@event
=
Factory
:event
end
it
"should create a valid event"
do
@event
.
should
be_valid
end
end
end
end
spec/models/project_spec.rb
View file @
dcdb2fdf
...
@@ -2,6 +2,7 @@ require 'spec_helper'
...
@@ -2,6 +2,7 @@ require 'spec_helper'
describe
Project
do
describe
Project
do
describe
"Associations"
do
describe
"Associations"
do
it
{
should
have_many
(
:events
)
}
it
{
should
have_many
(
:users
)
}
it
{
should
have_many
(
:users
)
}
it
{
should
have_many
(
:users_projects
)
}
it
{
should
have_many
(
:users_projects
)
}
it
{
should
have_many
(
:issues
)
}
it
{
should
have_many
(
:issues
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment