Upgrading extensions

Overview

This guide covers the process of migrating an old Spree 2/3 extension to Spree 4.

Zeitwerk compatibility

This doesn't work well with the old approach to decorators (files that name ends with decorator.rb, eg. app/models/spree/order_decorator.rb) using class_eval.
To fix this we need to convert all class_eval decorators to modules and use Module.prepend. Also we need to name them properly according to Zeitwerk naming rules
Example of an old decorator:
app/models/spree/order_decorator.rb
1
Spree::Order.class_eval do
2
has_many :new_custom_model
3
4
def some_method
5
# ...
6
end
7
end
Copied!
the same decorator in the new notation:
app/models/your_extension_name/order_decorator.rb
1
module YourExtensionName::OrderDecorator
2
def self.prepended(base)
3
base.has_many :new_custom_model
4
end
5
6
def some_method
7
# ...
8
end
9
end
10
11
::Spree::Order.prepend(YourExtensionName::OrderDecorator)
Copied!

Travis CI configuration

You can always find up-to-date Travis CI config here: https://github.com/spree/spree/blob/master/cmd/lib/spree_cmd/templates/extension/travis.yml For the rationale of the changes please look at the blame view: https://github.com/spree/spree/blame/master/cmd/lib/spree_cmd/templates/extension/travis.yml

Appraisals config

For the rationale of the changes please look at the blame view: https://github.com/spree/spree/blame/master/cmd/lib/spree_cmd/templates/extension/Appraisals
After each change please remember to re-generate gemfiles by running:
1
bundle exec appraisal generate --travis
Copied!

Fixing Deface Overrides

Please remember to prepare versioned overrides for both Spree 3.x and 4.x, eg. https://github.com/spree-contrib/spree_static_content/commit/e4b9e4900024235158d0ec1a48a100b4732348ef
Spree 4 uses Bootstrap 4 and many partials and HTML structure changed compared to Spree 3.x.
Also - remember to add deface gem to gemspec as deface itself was removed as a dependency of Spree. eg. https://github.com/spree/spree_auth_devise/commit/d729689ca87d8586e541ffcc865ef1e0a5a79fe4

Migrate to Spree Dev Tools

Replace all development dependencies with:
1
s.add_development_dependency 'spree_dev_tools'
Copied!
Replace spec_helper.rb contents with:
Example migrations:
Last modified 3mo ago