提交 1c3c7fb2 编写于 作者: J Jarka Kadlecova

Add system_note_metadata model

上级 ad831ace
......@@ -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]) }
......
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
......@@ -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
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
......@@ -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
......
FactoryGirl.define do
factory :system_note_metadata do
note
icon 'merge'
end
end
......@@ -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
......
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册