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

Error destroying new Rails model #316

Closed thejonanshow closed 4 years ago

thejonanshow commented 4 years ago

It's not immediately obvious to me what's going on here as I don't know the Rails destroy mechanism very well, but destroying a model right after creating it in a brand new app throws a file not found error:

...
13: from .../gems/fabrication-2.21.0/lib/.../model_generator.rb:11:in `create_fabrication_file'
12: from .../gems/fabrication-2.21.0/.../model_generator.rb:27:in `copy_attributes_from_model'
...
`require': cannot load such file -- ~/test_app/app/models/fakemodel.rb

Repro:

rails new test_app; cd test_app
rails g fakemodel
rails d fakemodel

I wouldn't guess that it's relevant but I'm installing fabrication automatically in all new Rails apps using .railsrc and a template file. If you think it matters I can include them here.

https://github.com/paulelliott/fabrication/blob/2fe931c083067c6b499da44445a5dc92a08e2875/lib/rails/generators/fabrication/model/model_generator.rb#L11

Thanks for taking a look!

paulelliott commented 4 years ago

I was unable to reproduce this in an app running Ruby 2.6.5, Rails 6.0.1, and fabrication 2.21.0. I see you're on the latest fabrication but what versions of Ruby and Rails do you have?

thejonanshow commented 4 years ago

Versions:

ruby 2.6.5p114
Rails 6.0.2.1

.railsrc

--skip-action-cable
--skip-spring
--skip-coffee
--skip-turbolinks
--skip-test-unit
--template=~/.rails_template.rb

rails_template.rb

gem_group :development, :test do
  gem "dotenv-rails"
  gem "pry-byebug"
  gem "faker"
  gem "fabrication"
  gem "rspec-rails"
end

run "bundle install"

generate :controller, "home index"
route "root to: 'home#index'"

generate "rspec:install"

If you can't reproduce it I think it's reasonable to assume that it's not something in fabrication, in which case please feel free to close. Just thought I'd let you know in case it was something you'd missed.

paulelliott commented 4 years ago

In your initial report you said you ran:

rails g fakemodel
rails d fakemodel

You can't run those commands without specifying what you're generating though. Unless I'm missing something? I've tried doing it as a model and as a scaffold on a new app but both worked just fine.

thejonanshow commented 4 years ago

I'm going to assume this is PEBKAC and tidy up your issues. Thanks for a great project, hope you're well 😁