Defect #32977 » 0001-removes-references-to-deleted-users-in-custom-field-.patch
| app/models/user.rb | ||
|---|---|---|
|
Watcher.where('user_id = ?', id).delete_all
|
||
|
WikiContent.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id])
|
||
|
WikiContent::Version.where(['author_id = ?', id]).update_all(['author_id = ?', substitute.id])
|
||
|
user_custom_field_ids = CustomField.where(field_format: 'user').pluck(:id).map(&:to_s)
|
||
|
if user_custom_field_ids.any?
|
||
|
CustomValue.where(custom_field_id: user_custom_field_ids, value: self.id.to_s).delete_all
|
||
|
end
|
||
|
end
|
||
|
# Singleton class method is public
|
||
| test/unit/user_test.rb | ||
|---|---|---|
|
assert_equal [], User.find(2).bookmarked_project_ids
|
||
|
end
|
||
|
def test_remove_custom_field_references_upon_destroy
|
||
|
cf1 = IssueCustomField.create(field_format: 'user', name: 'user cf', is_for_all: true, tracker_ids: Tracker.pluck(:id))
|
||
|
cf2 = IssueCustomField.create(field_format: 'user', name: 'users cf', is_for_all: true, multiple: true, tracker_ids: Tracker.pluck(:id))
|
||
|
issue = Issue.first
|
||
|
issue.init_journal(@admin)
|
||
|
assert_difference ->{cf1.custom_values.count} do
|
||
|
assert_difference ->{cf2.custom_values.count}, 2 do
|
||
|
issue.update_attributes(custom_field_values: {
|
||
|
cf1.id => @jsmith.id,
|
||
|
cf2.id => [@dlopper.id, @jsmith.id]
|
||
|
})
|
||
|
end
|
||
|
end
|
||
|
assert cv1 = cf1.custom_values.where(customized_id: issue.id).last
|
||
|
assert_equal @jsmith.id.to_s, cv1.value
|
||
|
assert cv2 = cf2.custom_values.where(customized_id: issue.id)
|
||
|
assert_equal 2, cv2.size
|
||
|
assert cv2a = cv2.detect{|cv|cv.value == @dlopper.id.to_s}
|
||
|
assert cv2b = cv2.detect{|cv|cv.value == @jsmith.id.to_s}
|
||
|
assert_difference ->{CustomValue.count}, -2 do
|
||
|
@jsmith.destroy
|
||
|
end
|
||
|
assert_raise(ActiveRecord::RecordNotFound){cv1.reload}
|
||
|
assert_raise(ActiveRecord::RecordNotFound){cv2b.reload}
|
||
|
cv2a.reload
|
||
|
assert_equal @dlopper.id.to_s, cv2a.value
|
||
|
end
|
||
|
if Object.const_defined?(:OpenID)
|
||
|
def test_setting_identity_url
|
||
|
normalized_open_id_url = 'http://example.com/'
|
||