diff options
author | James Lopez <james@jameslopez.es> | 2016-07-01 16:34:10 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-07-01 16:34:10 +0300 |
commit | f29c30475e621dedae24791ae9b144b6bef2f80a (patch) | |
tree | 3850dee7b3703d2e0046015ec84ed700379b0124 | |
parent | d6d0a35598c6fefd31dcc6b43bc2698792788faa (diff) |
use has_many relationship with events
-rw-r--r-- | app/models/concerns/eventable.rb | 15 | ||||
-rw-r--r-- | app/models/issue.rb | 3 | ||||
-rw-r--r-- | app/models/merge_request.rb | 3 | ||||
-rw-r--r-- | app/models/milestone.rb | 2 | ||||
-rw-r--r-- | app/models/note.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/import_export/relation_factory.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/project_tree_restorer_spec.rb | 6 |
7 files changed, 13 insertions, 19 deletions
diff --git a/app/models/concerns/eventable.rb b/app/models/concerns/eventable.rb deleted file mode 100644 index aa23b350a06..00000000000 --- a/app/models/concerns/eventable.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Eventable - extend ActiveSupport::Concern - - def events - Event.where(target_id: id, target_type: self.class.to_s) - end - - def events=(events) - events.each do |event| - event.target_id = id - event.data.deep_symbolize_keys! if event.data - event.save! - end - end -end diff --git a/app/models/issue.rb b/app/models/issue.rb index ae177c041e7..60abd47409e 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -6,7 +6,6 @@ class Issue < ActiveRecord::Base include Referable include Sortable include Taskable - include Eventable DueDateStruct = Struct.new(:title, :name).freeze NoDueDate = DueDateStruct.new('No Due Date', '0').freeze @@ -20,6 +19,8 @@ class Issue < ActiveRecord::Base belongs_to :project belongs_to :moved_to, class_name: 'Issue' + has_many :events, as: :target, dependent: :destroy + validates :project, presence: true scope :cared, ->(user) { where(assignee_id: user) } diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 326a0430eb4..5ebc8f0c99f 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -5,7 +5,6 @@ class MergeRequest < ActiveRecord::Base include Sortable include Taskable include Importable - include Eventable belongs_to :target_project, foreign_key: :target_project_id, class_name: "Project" belongs_to :source_project, foreign_key: :source_project_id, class_name: "Project" @@ -13,6 +12,8 @@ class MergeRequest < ActiveRecord::Base has_one :merge_request_diff, dependent: :destroy + has_many :events, as: :target, dependent: :destroy + serialize :merge_params, Hash after_create :create_merge_request_diff, unless: :importing diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 2283376c8ac..2bd7f198030 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -11,13 +11,13 @@ class Milestone < ActiveRecord::Base include Referable include StripAttribute include Milestoneish - include Eventable belongs_to :project has_many :issues has_many :labels, -> { distinct.reorder('labels.title') }, through: :issues has_many :merge_requests has_many :participants, -> { distinct.reorder('users.name') }, through: :issues, source: :assignee + has_many :events, as: :target, dependent: :destroy scope :active, -> { with_state(:active) } scope :closed, -> { with_state(:closed) } diff --git a/app/models/note.rb b/app/models/note.rb index ed26fb2d88a..c2bb117eb03 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -5,7 +5,6 @@ class Note < ActiveRecord::Base include Mentionable include Awardable include Importable - include Eventable # Attribute containing rendered and redacted Markdown as generated by # Banzai::ObjectRenderer. @@ -22,6 +21,7 @@ class Note < ActiveRecord::Base belongs_to :updated_by, class_name: "User" has_many :todos, dependent: :destroy + has_many :events, as: :target, dependent: :destroy delegate :gfm_reference, :local_reference, to: :noteable delegate :name, to: :project, prefix: true diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb index 92bf7e0a2fc..3fd89e08f09 100644 --- a/lib/gitlab/import_export/relation_factory.rb +++ b/lib/gitlab/import_export/relation_factory.rb @@ -33,6 +33,7 @@ module Gitlab update_user_references update_project_references reset_ci_tokens if @relation_name == 'Ci::Trigger' + @relation_hash['data'].deep_symbolize_keys! if @relation_name == :events && @relation_hash['data'] generate_imported_object end diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb index 23036ab8108..e401ca99077 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -24,6 +24,12 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do expect(Ci::Pipeline.first.notes).not_to be_empty end + + it 'restores the correct event' do + restored_project_json + + expect(Event.where.not(data: nil).first.data[:ref]).not_to be_empty + end end end end |