Upgrading extensions


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:
Spree::Order.class_eval do
has_many :new_custom_model
def some_method
# ...
the same decorator in the new notation:
module YourExtensionName::OrderDecorator
def self.prepended(base)
base.has_many :new_custom_model
def some_method
# ...

Travis CI configuration

You can always find up-to-date Travis CI config here: For the rationale of the changes please look at the blame view:

Appraisals config

For the rationale of the changes please look at the blame view:
After each change please remember to re-generate gemfiles by running:
bundle exec appraisal generate --travis

Fixing Deface Overrides

Please remember to prepare versioned overrides for both Spree 3.x and 4.x, eg.
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.

Migrate to Spree Dev Tools

Replace all development dependencies with:
s.add_development_dependency 'spree_dev_tools'
Replace spec_helper.rb contents with:
Example migrations: