Skip to content

Delegate Requirement model attributes to associated issue

What does this MR do and why?

Related to #323781 (closed)

In preparation to stop using the model RequirementsManagement::Requirement, and now that every requirement has a requirement_issue, we can delegate attributes to the associated Issue.

Because we still need to use the model as a thin proxy, all attributes except iid and project will be delegated.

The presence validation for :title and :author is removed to be able to create the record, but because we create the associated issue every time we create a requirement, the validation is still performed at the issue level.

I thoroughly tested that the synching functionality still works after delegating, and because the record will still track becoming dirty and preserve the attribute values, we will be able to compare changes and update accordingly.

Example:

[5] pry(main)> requirement.title
=> "test req issue"
[6] pry(main)> requirement.requirement_issue.title
=> "test req issue"
[7] pry(main)> requirement.changed?
=> false
[8] pry(main)> requirement.title = 'new title'
=> "new title"
[9] pry(main)> requirement.changed?
=> true
[10] pry(main)> requirement.title
=> "test req issue"
[13] pry(main)> requirement.requirement_issue.title
=> "test req issue"
[14] pry(main)> requirement.changed
=> ["title"]
[15] pry(main)> changed_attrs = requirement.changed.map(&:to_sym)
=> [:title]
[16] pry(main)> requirement.attributes.with_indifferent_access.slice(*changed_attrs)
=> {"title"=>"new title"}

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Eugenia Grieff

Merge request reports

Loading