summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarka Kadlecova <jarka@gitlab.com>2017-03-15 14:18:44 +0100
committerJarka Kadlecova <jarka@gitlab.com>2017-03-28 13:58:35 +0200
commit1c3c7fb25d972fc19d5b4bb371cb21094d81e478 (patch)
tree1989aa0a7964ccdac4f6a6751f50967fe5fe801d
parentad831ace7ed8d2ed999b15f8350aaa51f0490124 (diff)
downloadgitlab-ce-1c3c7fb25d972fc19d5b4bb371cb21094d81e478.tar.gz
Add system_note_metadata model
-rw-r--r--app/models/note.rb5
-rw-r--r--app/models/system_note_metadata.rb11
-rw-r--r--config/initializers/0_inflections.rb2
-rw-r--r--db/migrate/20170314082049_create_system_note_metadata.rb19
-rw-r--r--db/schema.rb9
-rw-r--r--spec/factories/system_note_metadata.rb6
-rw-r--r--spec/models/note_spec.rb1
-rw-r--r--spec/models/system_note_metadata_spec.rb27
8 files changed, 78 insertions, 2 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index e22e96aec6f..ba5a552f469 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -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]) }
diff --git a/app/models/system_note_metadata.rb b/app/models/system_note_metadata.rb
new file mode 100644
index 00000000000..e8d3600d341
--- /dev/null
+++ b/app/models/system_note_metadata.rb
@@ -0,0 +1,11 @@
+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
diff --git a/config/initializers/0_inflections.rb b/config/initializers/0_inflections.rb
index d4197da3fa9..f977104ff9d 100644
--- a/config/initializers/0_inflections.rb
+++ b/config/initializers/0_inflections.rb
@@ -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
diff --git a/db/migrate/20170314082049_create_system_note_metadata.rb b/db/migrate/20170314082049_create_system_note_metadata.rb
new file mode 100644
index 00000000000..c58da88631f
--- /dev/null
+++ b/db/migrate/20170314082049_create_system_note_metadata.rb
@@ -0,0 +1,19 @@
+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
diff --git a/db/schema.rb b/db/schema.rb
index f476637ceb2..456dbd41230 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -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
diff --git a/spec/factories/system_note_metadata.rb b/spec/factories/system_note_metadata.rb
new file mode 100644
index 00000000000..5855f8d1051
--- /dev/null
+++ b/spec/factories/system_note_metadata.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :system_note_metadata do
+ note
+ icon 'merge'
+ end
+end
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 33536487c41..0ebdf46074e 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -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
diff --git a/spec/models/system_note_metadata_spec.rb b/spec/models/system_note_metadata_spec.rb
new file mode 100644
index 00000000000..ae5a43281ac
--- /dev/null
+++ b/spec/models/system_note_metadata_spec.rb
@@ -0,0 +1,27 @@
+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