paulelliott / fabrication

This project has moved to GitLab! Please check there for the latest updates.
https://gitlab.com/fabrication-gem/fabrication
MIT License
998 stars 97 forks source link

Models with deep namespace #301

Closed thiagoramos23 closed 7 years ago

thiagoramos23 commented 7 years ago

Hi guys, awesome work with this lib, thank you a lot. I am having some trouble now that I have my models deep nested with namespaces and they are not on app/models folder. Here is the example:

I have a model at: MY_APPLICATION_ROOT_FOLDER/infrastructure/models/sales/charge.rb My model:

 module Infrastructure
    module Models
      module Sales
        class Charge < ::ActiveRecord::Base
          self.table_name = 'charges'
        end
      end
    end
  end

And my fabricator at spec/fabricators/charge_fabricator.rb

Fabricator(:infrastructure_models_sales_charge, aliases: [:sales_charge], class_name: "::Infrastructure::Models::Sales::Charge") do
  attributes...
end

And I am getting a weird error saying:

uninitialized constant Infrastructure::Models::Sales

Am I doing something wrong?

thiagoramos23 commented 7 years ago

Since I am not using rails and autoloading everything. I forgot that I need to require files.

paulelliott commented 7 years ago

Glad you figured it out! I think we've all been bitten by that at some point.