Skip to content

Migrate from Virtus to ActiveModel::Attributes (and get rid of Rectify::Form)#8669

Merged
andreslucena merged 149 commits intodecidim:developfrom
mainio:refactor/activemodel-attributes-forms
Jan 17, 2022
Merged

Migrate from Virtus to ActiveModel::Attributes (and get rid of Rectify::Form)#8669
andreslucena merged 149 commits intodecidim:developfrom
mainio:refactor/activemodel-attributes-forms

Conversation

@ahukkanen
Copy link
Copy Markdown
Contributor

@ahukkanen ahukkanen commented Dec 30, 2021

🎩 What? Why?

The basic idea of this PR is to refactor the Virtus models (such as all instances of Rectify::Form) in the core to the new ActiveModel::Attributes based solution as discussed at #7234. The reason for this is the discontinuation of Virtus.

This provides a compatibility layer that preserves backwards compatibility as long as possible with the Rectify::Forms API requiring little to no changes in the existing Form classes. ActiveModel::Attributes works a bit differently than Rectify::Form (e.g. no nested Forms or attributes), so we need this layer to keep functionality as-is without any major changes.

📌 Related Issues

Link your PR to an issue

Testing

Run the specs and test the application with this implementation.

📋 Checklist

  • CONSIDER adding a unit test if your PR resolves an issue.
  • ✔️ DO check open PR's to avoid duplicates.
  • ✔️ DO keep pull requests small so they can be easily reviewed.
  • ✔️ DO build locally before pushing.
  • ✔️ DO make sure tests pass.
  • ✔️ DO make sure any new changes are documented in docs/.
  • ✔️ DO add and modify seeds if necessary.
  • ✔️ DO add CHANGELOG upgrade notes if required.
  • ✔️ DO add to GraphQL API if there are new public fields.
  • ✔️ DO add link to MetaDecidim if it's a new feature.
  • AVOID breaking the continuous integration build.
  • AVOID making significant changes to the overall architecture.

ahukkanen added 30 commits April 3, 2021 17:39
Fix several bugs in different form cases used all over the
application related to both, the top-level attributes as well as
nested attributes.
Copy link
Copy Markdown
Member

@andreslucena andreslucena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All is OK for me! 👍🏽

@andreslucena
Copy link
Copy Markdown
Member

Can we merge this one @ahukkanen? Or is there anything else that you want to add to this PR?

@ahukkanen
Copy link
Copy Markdown
Contributor Author

@andreslucena On my part it's ready.

@alecslupu Raised some concerns regarding compatibility with 3rd party modules. I thought I'd still test those two modules he mentioned.

I'm not expecting zero changes in these but I would expect most of the things to work fine without changes. Specs will likely need some updates, though.

@andreslucena andreslucena merged commit 369f293 into decidim:develop Jan 17, 2022
@ahukkanen ahukkanen deleted the refactor/activemodel-attributes-forms branch January 17, 2022 14:26
@ahukkanen
Copy link
Copy Markdown
Contributor Author

ahukkanen commented Jan 17, 2022

@alecslupu @andreslucena

I have tested both NavbarLinks and Decidim Awesome modules with the ActiveModel::Attributes changes.

Here's my findings:

NavbarLinks

Branch master, changed the version number to ~> 0.27.0.dev.

No problems identified. No changes done.

All other specs pass except this one:
https://github.com/OpenSourcePolitics/decidim-module-navbar_links/blob/6de93c18ebaa3a788b1e1ba26f1c771cc319aa51/spec/system/navbar_links/navbar_links_spec.rb#L16

This failing spec is not related to the ActiveModel::Attributes migration, it is failing because of the external link warnings added at #7397 which causes the unrecognized external URLs to be linked through /link?external_url=http....

Decidim Awesome

Branch upgrade_025, changed the version number to ~> 0.27.0.dev. Also had to add admin engines to the Awesome modules (iframe and map components) for them not to throw any exceptions in the admin panel participatory space views. For the specs to run had to change factory :editor_image to :awesome_editor_image because this factory now already exists in the core.

Working fine:

  • Dropping image to a WYSIWYG field (image saved as a blob)
  • Updating constraints for configs

Not working without changes:

After the above fix, all configuration forms work normally in the admin panel.

All other non-system specs pass after this change except for the following specs:

  • ./spec/uploaders/image_uploader_spec.rb - Needs the module to be updated to support ActiveStorage
  • ./spec/lib/system_checker_spec.rb - Something with the checksums/decidim version changes did not check further
  • ./spec/forms/admin/menu_form_spec.rb - Label keys need to be converted from symbols to hashes in the expectation
  • ./spec/commands/admin/update_constraint_spec.rb - Extra id field in the constraint form attributes (spec update needed)
  • ./spec/controllers/editor_images_controller_spec.rb - Needs the module to be updated to support ActiveStorage
  • ./spec/controllers/admin/checks_controller_spec.rb - I believe needs some changes with the module versions (?)

I believe most of the system specs failures are caused by the missing assets (or broken front-end), as the module has not yet been updated to be compatible with Webpacker. And the uploader specs are failing because ActiveStorage is not fully updated (as far as I understood). It would make much more sense to test these after the module has been upgraded to 0.25 or 0.26.

Further notes

I am no expert in either of these modules, these were just quick tests within the UI and by running the specs.

@alecslupu
Copy link
Copy Markdown
Contributor

This failing spec is not related to the ActiveModel::Attributes migration, it is failing because of the external link warnings added at #7397 which causes the unrecognized external URLs to be linked through /link?external_url=http....

Addressed here ... pending @armandfardeau 's input : OpenSourcePolitics/decidim-module-navbar_links#23

andreslucena pushed a commit that referenced this pull request Jan 25, 2022
@ahukkanen ahukkanen mentioned this pull request Jul 5, 2022
12 tasks
@alecslupu alecslupu added this to the 0.27.0 milestone Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate from Virtus to ActiveModel::Attributes API

3 participants