diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-09-20 22:52:20 +0300 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-09-20 22:52:20 +0300 |
commit | 68e1b5bbc076398b2886fe1fe2cc440a52d7cab1 (patch) | |
tree | ec3584c5375990b68f24b94365a1184ac0949c07 /app | |
parent | 918e589c2b29c18d9fe3a8e6c93a3f490c86beb1 (diff) |
Use the `IssuableBaseService` lifecycle hooks to cache `MergeRequestsClosingIssues`
- Instead of overriding `create` and `update` in `MergeRequests::BaseService`
- Get all merge request service specs passing
Diffstat (limited to 'app')
-rw-r--r-- | app/models/issue.rb | 2 | ||||
-rw-r--r-- | app/models/merge_request.rb | 2 | ||||
-rw-r--r-- | app/services/issuable_base_service.rb | 5 | ||||
-rw-r--r-- | app/services/merge_requests/base_service.rb | 12 | ||||
-rw-r--r-- | app/services/merge_requests/create_service.rb | 1 | ||||
-rw-r--r-- | app/services/merge_requests/update_service.rb | 4 |
6 files changed, 12 insertions, 14 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index 25ba38a1cff..abd58e0454a 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -23,7 +23,7 @@ class Issue < ActiveRecord::Base has_many :events, as: :target, dependent: :destroy - has_many :merge_requests_closing_issues, class_name: 'MergeRequestsClosingIssues' + has_many :merge_requests_closing_issues, class_name: 'MergeRequestsClosingIssues', dependent: :delete_all validates :project, presence: true diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index c05718f4d5a..616efaf3c42 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -16,7 +16,7 @@ class MergeRequest < ActiveRecord::Base has_many :events, as: :target, dependent: :destroy - has_many :merge_requests_closing_issues, class_name: 'MergeRequestsClosingIssues' + has_many :merge_requests_closing_issues, class_name: 'MergeRequestsClosingIssues', dependent: :delete_all serialize :merge_params, Hash diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb index 4c8d93999a7..fbce46769f7 100644 --- a/app/services/issuable_base_service.rb +++ b/app/services/issuable_base_service.rb @@ -157,6 +157,10 @@ class IssuableBaseService < BaseService # To be overridden by subclasses end + def after_update(issuable) + # To be overridden by subclasses + end + def update_issuable(issuable, attributes) issuable.with_transaction_returning_status do issuable.update(attributes.merge(updated_by: current_user)) @@ -182,6 +186,7 @@ class IssuableBaseService < BaseService end handle_changes(issuable, old_labels: old_labels, old_mentioned_users: old_mentioned_users) + after_update(issuable) issuable.create_new_cross_references!(current_user) execute_hooks(issuable, 'update') end diff --git a/app/services/merge_requests/base_service.rb b/app/services/merge_requests/base_service.rb index 9704a7050eb..ba424b09463 100644 --- a/app/services/merge_requests/base_service.rb +++ b/app/services/merge_requests/base_service.rb @@ -35,18 +35,6 @@ module MergeRequests end end - def create(merge_request) - merge_request = super(merge_request) - merge_request.cache_merge_request_closes_issues!(current_user) - merge_request - end - - def update(merge_request) - merge_request = super(merge_request) - merge_request.cache_merge_request_closes_issues!(current_user) - merge_request - end - private def filter_params diff --git a/app/services/merge_requests/create_service.rb b/app/services/merge_requests/create_service.rb index 73247e62421..b0ae2dfe4ce 100644 --- a/app/services/merge_requests/create_service.rb +++ b/app/services/merge_requests/create_service.rb @@ -20,6 +20,7 @@ module MergeRequests event_service.open_mr(issuable, current_user) notification_service.new_merge_request(issuable, current_user) todo_service.new_merge_request(issuable, current_user) + issuable.cache_merge_request_closes_issues!(current_user) end end end diff --git a/app/services/merge_requests/update_service.rb b/app/services/merge_requests/update_service.rb index 398ec47f0ea..f14f9e4b327 100644 --- a/app/services/merge_requests/update_service.rb +++ b/app/services/merge_requests/update_service.rb @@ -77,5 +77,9 @@ module MergeRequests def close_service MergeRequests::CloseService end + + def after_update(issuable) + issuable.cache_merge_request_closes_issues!(current_user) + end end end |