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
Jérome Perrin
gitlab-ce
Commits
1c3c7fb2
Commit
1c3c7fb2
authored
Mar 15, 2017
by
Jarka Kadlecova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add system_note_metadata model
parent
ad831ace
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
78 additions
and
2 deletions
+78
-2
app/models/note.rb
app/models/note.rb
+4
-1
app/models/system_note_metadata.rb
app/models/system_note_metadata.rb
+11
-0
config/initializers/0_inflections.rb
config/initializers/0_inflections.rb
+1
-1
db/migrate/20170314082049_create_system_note_metadata.rb
db/migrate/20170314082049_create_system_note_metadata.rb
+19
-0
db/schema.rb
db/schema.rb
+9
-0
spec/factories/system_note_metadata.rb
spec/factories/system_note_metadata.rb
+6
-0
spec/models/note_spec.rb
spec/models/note_spec.rb
+1
-0
spec/models/system_note_metadata_spec.rb
spec/models/system_note_metadata_spec.rb
+27
-0
No files found.
app/models/note.rb
View file @
1c3c7fb2
...
...
@@ -37,6 +37,7 @@ class Note < ActiveRecord::Base
has_many
:todos
,
dependent: :destroy
has_many
:events
,
as: :target
,
dependent: :destroy
has_one
:system_note_metadata
,
dependent: :destroy
delegate
:gfm_reference
,
:local_reference
,
to: :noteable
delegate
:name
,
to: :project
,
prefix:
true
...
...
@@ -70,7 +71,9 @@ class Note < ActiveRecord::Base
scope
:fresh
,
->
{
order
(
created_at: :asc
,
id: :asc
)
}
scope
:inc_author_project
,
->
{
includes
(
:project
,
:author
)
}
scope
:inc_author
,
->
{
includes
(
:author
)
}
scope
:inc_relations_for_view
,
->
{
includes
(
:project
,
:author
,
:updated_by
,
:resolved_by
,
:award_emoji
)
}
scope
:inc_relations_for_view
,
->
do
includes
(
:project
,
:author
,
:updated_by
,
:resolved_by
,
:award_emoji
,
:system_note_metadata
)
end
scope
:diff_notes
,
->
{
where
(
type:
%w(LegacyDiffNote DiffNote)
)
}
scope
:non_diff_notes
,
->
{
where
(
type:
[
'Note'
,
nil
])
}
...
...
app/models/system_note_metadata.rb
0 → 100644
View file @
1c3c7fb2
class
SystemNoteMetadata
<
ActiveRecord
::
Base
ICON_TYPES
=
%w[
commit merge confidentiality status label assignee cross_reference
title time_tracking branch milestone discussion task moved
]
.
freeze
validates
:note
,
presence:
true
validates
:icon
,
inclusion:
ICON_TYPES
,
allow_nil:
true
belongs_to
:note
end
config/initializers/0_inflections.rb
View file @
1c3c7fb2
...
...
@@ -10,5 +10,5 @@
# end
#
ActiveSupport
::
Inflector
.
inflections
do
|
inflect
|
inflect
.
uncountable
%w(award_emoji project_statistics)
inflect
.
uncountable
%w(award_emoji project_statistics
system_note_metadata
)
end
db/migrate/20170314082049_create_system_note_metadata.rb
0 → 100644
View file @
1c3c7fb2
class
CreateSystemNoteMetadata
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
change
create_table
:system_note_metadata
do
|
t
|
t
.
references
:note
,
null:
false
t
.
integer
:commit_count
t
.
string
:icon
t
.
timestamps
null:
false
end
add_concurrent_foreign_key
:system_note_metadata
,
:notes
,
column: :note_id
,
on_delete: :cascade
end
end
db/schema.rb
View file @
1c3c7fb2
...
...
@@ -1075,6 +1075,14 @@ ActiveRecord::Schema.define(version: 20170317203554) do
add_index
"subscriptions"
,
[
"subscribable_id"
,
"subscribable_type"
,
"user_id"
,
"project_id"
],
name:
"index_subscriptions_on_subscribable_and_user_id_and_project_id"
,
unique:
true
,
using: :btree
create_table
"system_note_metadata"
,
force: :cascade
do
|
t
|
t
.
integer
"note_id"
,
null:
false
t
.
integer
"commit_count"
t
.
string
"icon"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
end
create_table
"taggings"
,
force: :cascade
do
|
t
|
t
.
integer
"tag_id"
t
.
integer
"taggable_id"
...
...
@@ -1308,6 +1316,7 @@ ActiveRecord::Schema.define(version: 20170317203554) do
add_foreign_key
"protected_branch_merge_access_levels"
,
"protected_branches"
add_foreign_key
"protected_branch_push_access_levels"
,
"protected_branches"
add_foreign_key
"subscriptions"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"system_note_metadata"
,
"notes"
,
name:
"fk_d83a918cb1"
,
on_delete: :cascade
add_foreign_key
"timelogs"
,
"issues"
,
name:
"fk_timelogs_issues_issue_id"
,
on_delete: :cascade
add_foreign_key
"timelogs"
,
"merge_requests"
,
name:
"fk_timelogs_merge_requests_merge_request_id"
,
on_delete: :cascade
add_foreign_key
"trending_projects"
,
"projects"
,
on_delete: :cascade
...
...
spec/factories/system_note_metadata.rb
0 → 100644
View file @
1c3c7fb2
FactoryGirl
.
define
do
factory
:system_note_metadata
do
note
icon
'merge'
end
end
spec/models/note_spec.rb
View file @
1c3c7fb2
...
...
@@ -9,6 +9,7 @@ describe Note, models: true do
it
{
is_expected
.
to
belong_to
(
:author
).
class_name
(
'User'
)
}
it
{
is_expected
.
to
have_many
(
:todos
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_one
(
:system_note_metadata
).
dependent
(
:destroy
)
}
end
describe
'modules'
do
...
...
spec/models/system_note_metadata_spec.rb
0 → 100644
View file @
1c3c7fb2
require
'spec_helper'
describe
SystemNoteMetadata
,
models:
true
do
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:note
)
}
end
describe
'validation'
do
it
{
is_expected
.
to
validate_presence_of
(
:note
)
}
context
'when icon type is invalid'
do
subject
do
build
(
:system_note_metadata
,
note:
build
(
:note
),
icon:
'invalid_type'
)
end
it
{
is_expected
.
to
be_invalid
}
end
context
'when icon type is valid'
do
subject
do
build
(
:system_note_metadata
,
note:
build
(
:note
),
icon:
'merge'
)
end
it
{
is_expected
.
to
be_valid
}
end
end
end
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