LoadError Unable to autoload constant Message

By convention in rails (and this is enforced by autoloader), file paths should match namespaces.

So, if you have a Mailboxer::Message model, it should be in app/models/mailboxer/message.rb.

Additionally, you probably have autoloader kicking in when trying to load a Message class (my guess is that it happens from within ActAsMessageable). It looks for a message.rb file in load path, find it in app/model/ and thus load that file so it can find the Message class.

Problem is, it doesn't find a Message class in that file, only a Mailboxer::Message class (which is radically different). This is why it throws "Unable to autoload constant Message, expected /app/models/message.rb to define it".

To fix that, create directory app/models/mailboxer/ and put Mailboxer::Message in it.


I got this during integration testing. Turns out, it was fixtures related. Had to delete the my unused file in /test/fixtures/wrong_name.yml