solidusio / solidus_braintree

💳 Integrate Solidus with Braintree
https://www.braintreepayments.com/
BSD 3-Clause "New" or "Revised" License
19 stars 55 forks source link

Fix load order issue with `table_name_prefix` #161

Open forkata opened 1 month ago

forkata commented 1 month ago

Summary

When running bin/rails g solidus:install and selecting braintree as the payment method, there is currently a failure during the running of the db:seeds task that points to an issue with the table prefix not taking effect

ActiveRecord::StatementInvalid: Could not find table 'solidus_braintree_configurations' (ActiveRecord::StatementInvalid)

which comes from the store decorator here

app/decorators/models/solidus_braintree/spree_store_decorator.rb:14:in `build_default_configuration'

After some extensive testing, it seems like this is a load order issue in development (autoloading enabled) where the definition needs to happen before the engine is declared. The previous location of this method happens after the engine.rb require.

We attempted to move this to app/models/solidus_braintree.rb however that did not work either as the autoloader did not load that file at all, likely because the namespace is already defined elsewhere.

The cleanest solution here seems to be to declare the table name in each model as there are only 3 currently in the extension, so we've opted for that.

Steps to reproduce

  1. rails new my_store
  2. bundle add solidus
  3. bin/rails g solidus:install
  4. Select braintree as the payment method

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed: