Commit 9bffa830 authored by Jan Provaznik's avatar Jan Provaznik

Fixed iid generation

* also minor spec fixes
parent bb468849
...@@ -21,7 +21,7 @@ class InternalId < ApplicationRecord ...@@ -21,7 +21,7 @@ class InternalId < ApplicationRecord
belongs_to :project belongs_to :project
belongs_to :namespace belongs_to :namespace
enum usage: { issues: 0, merge_requests: 1, deployments: 2, milestones: 3, epics: 4, ci_pipelines: 5, operations_feature_flags: 6 } enum usage: ::InternalIdEnums.usage_resources
validates :usage, presence: true validates :usage, presence: true
......
# frozen_string_literal: true
module InternalIdEnums
def self.usage_resources
# when adding new resource, make sure it doesn't conflict with EE usage_resources
{ issues: 0, merge_requests: 1, deployments: 2, milestones: 3, epics: 4, ci_pipelines: 5, operations_feature_flags: 6 }
end
end
InternalIdEnums.prepend_if_ee('EE::InternalIdEnums')
...@@ -9,6 +9,7 @@ class CreateRequirements < ActiveRecord::Migration[6.0] ...@@ -9,6 +9,7 @@ class CreateRequirements < ActiveRecord::Migration[6.0]
create_table :requirements do |t| create_table :requirements do |t|
t.integer :state, limit: 2, default: 1, null: false t.integer :state, limit: 2, default: 1, null: false
t.integer :iid, null: false t.integer :iid, null: false
t.integer :cached_markdown_version
t.references :project, null: false, index: true, foreign_key: { on_delete: :cascade } t.references :project, null: false, index: true, foreign_key: { on_delete: :cascade }
t.references :author, index: true, foreign_key: { to_table: :users, on_delete: :nullify } t.references :author, index: true, foreign_key: { to_table: :users, on_delete: :nullify }
t.timestamps_with_timezone null: false t.timestamps_with_timezone null: false
......
...@@ -3725,6 +3725,7 @@ ActiveRecord::Schema.define(version: 2020_02_27_165129) do ...@@ -3725,6 +3725,7 @@ ActiveRecord::Schema.define(version: 2020_02_27_165129) do
create_table "requirements", force: :cascade do |t| create_table "requirements", force: :cascade do |t|
t.integer "state", limit: 2, default: 1, null: false t.integer "state", limit: 2, default: 1, null: false
t.integer "iid", null: false t.integer "iid", null: false
t.integer "cached_markdown_version"
t.bigint "project_id", null: false t.bigint "project_id", null: false
t.bigint "author_id" t.bigint "author_id"
t.datetime_with_timezone "created_at", null: false t.datetime_with_timezone "created_at", null: false
......
# frozen_string_literal: true
module EE
module InternalIdEnums
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :usage_resources
def usage_resources
super.merge(requirements: 7)
end
end
end
end
...@@ -2,12 +2,18 @@ ...@@ -2,12 +2,18 @@
class Requirement < ApplicationRecord class Requirement < ApplicationRecord
include CacheMarkdownField include CacheMarkdownField
include StripAttribute
include AtomicInternalId
cache_markdown_field :title, pipeline: :single_line cache_markdown_field :title, pipeline: :single_line
strip_attributes :title
belongs_to :author, class_name: 'User' belongs_to :author, class_name: 'User'
belongs_to :project belongs_to :project
has_internal_id :iid, scope: :project, init: ->(s) { s&.project&.requirements&.maximum(:iid) }
validates :author, :project, :title, presence: true validates :author, :project, :title, presence: true
validates :title, length: { maximum: Issuable::TITLE_LENGTH_MAX } validates :title, length: { maximum: Issuable::TITLE_LENGTH_MAX }
...@@ -16,7 +22,7 @@ class Requirement < ApplicationRecord ...@@ -16,7 +22,7 @@ class Requirement < ApplicationRecord
enum state: { opened: 1, archived: 2 } enum state: { opened: 1, archived: 2 }
# In the next iteration we will support also group-level requirements # In the next iteration we will support also group-level requirements
# so it use resource_parent instead of project directly # so it's better to use resource_parent instead of project directly
def resource_parent def resource_parent
project project
end end
......
# frozen_string_literal: true # frozen_string_literal: true
FactoryBot.define do FactoryBot.define do
......
...@@ -48,4 +48,13 @@ describe Users::MigrateToGhostUserService do ...@@ -48,4 +48,13 @@ describe Users::MigrateToGhostUserService do
let(:created_record) { create(:review, author: user) } let(:created_record) { create(:review, author: user) }
end end
end end
context 'requirements' do
let!(:user) { create(:user) }
let(:service) { described_class.new(user) }
include_examples "migrating a deleted user's associated records to the ghost user", Requirement, [:author] do
let(:created_record) { create(:requirement, author: user) }
end
end
end end
...@@ -467,6 +467,7 @@ project: ...@@ -467,6 +467,7 @@ project:
- resource_groups - resource_groups
- autoclose_referenced_issues - autoclose_referenced_issues
- status_page_setting - status_page_setting
- requirements
award_emoji: award_emoji:
- awardable - awardable
- user - user
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment