Error: “Association named ‘spree_roles’ was not found; perhaps you misspelled it?”

Association named ‘spree_roles’ was not found; perhaps you misspelled it?

I ran into this error while developing an extension for Spree 1-3-stable and writing request specs to run on the dummy test app generated via bundle exec rake test_app. You may have also run into this error on a normal Spree app if you installed Spree in your Rails apps using just your Gemfile and bundler instead of spree install <my_store>.

Regardless, this is an issue with Spree not setting the correct user model in the spree initializer during install. To correct this, update config/intializers/spree.rb to use:

Spree.user_class = "Spree::User"

instead of

Spree.user_class = "Spree::LegacyUser"

If you’re having this issue with the dummy test app in spec/dummy, just do the same for the dummy app’s initializer: spec/dummy/config/initializers/spree.rb

For more information:
See the issue for dummy test_app
See the issue for regular Spree

Posted in Code, Ruby, Spree | 2 Comments