diff options
author | Long Nguyen <long.polyglot@gmail.com> | 2016-05-21 00:37:48 +0700 |
---|---|---|
committer | Long Nguyen <long.polyglot@gmail.com> | 2016-05-21 00:37:48 +0700 |
commit | ad17741008b5ec874f92016ed48c2c1e6638dab5 (patch) | |
tree | 0bc4256bcb79945ea573aebf6a5ca99e6acc6faf /app/models | |
parent | ed9b6497865e28c60e96dbc30567987165b0b221 (diff) | |
download | gitlab-ce-ad17741008b5ec874f92016ed48c2c1e6638dab5.tar.gz |
Remove todos when destroy project member and specs
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/members/project_member.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 2 |
2 files changed, 4 insertions, 2 deletions
diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index 8dae3bb2ef2..0ced9c31581 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -3,9 +3,9 @@ class ProjectMember < Member include Gitlab::ShellAdapter + has_many :todos, through: :user belongs_to :project, class_name: 'Project', foreign_key: 'source_id' - # Make sure project member points only to project as it source default_value_for :source_type, SOURCE_TYPE validates_format_of :source_type, with: /\AProject\z/ @@ -15,6 +15,8 @@ class ProjectMember < Member scope :in_projects, ->(projects) { where(source_id: projects.pluck(:id)) } scope :with_user, ->(user) { where(user_id: user.id) } + before_destroy { todos.each(&:destroy) } + class << self # Add users to project teams with passed access option diff --git a/app/models/user.rb b/app/models/user.rb index 70a966491eb..6a09b78455b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -77,7 +77,7 @@ class User < ActiveRecord::Base has_one :abuse_report, dependent: :destroy has_many :spam_logs, dependent: :destroy has_many :builds, dependent: :nullify, class_name: 'Ci::Build' - has_many :todos, -> { joins("join members on members.source_id = todos.project_id and members.user_id = todos.user_id") }, dependent: :destroy + has_many :todos, dependent: :destroy has_many :notification_settings, dependent: :destroy # |