Unable to autoload constant Version.table_name if gems uses Version class
At the moment this problem does not exist with Gem packages from Redmine itself, but gems from plugins.
Existing tests are broken, e.g.
bin/rails test test/unit/project_test.rb -n test_move_a_root_project_to_a_project # Running: E Error: ProjectTest#test_move_a_root_project_to_a_project: NoMethodError: undefined method `table_name' for AttrEncrypted::Version:Module app/models/issue.rb:1739:in `update_versions' app/models/issue.rb:1385:in `update_versions_from_hierarchy_change' app/models/project.rb:935:in `update_versions_from_hierarchy_change' app/models/project.rb:424:in `set_parent!' test/unit/project_test.rb:316:in `test_move_a_root_project_to_a_project'
Similar problem was #23269. A better description of the problem with examples are here: https://stackoverflow.com/questions/21115567/autoloading-classes-using-class-self-in-rails
I added a patch for a more solid solution to prevent the problem. It would be great to have this change in Redmine.
Updated by Alexander Meindl over 3 years ago
I added another version of patch, which uses Rails 5 where.not and Arel::Table. With this solution, no more table name specification is required.
Both solutions work, but second one is more cleaner - but more refactoring.
Updated by Go MAEDA over 2 years ago
- Tracker changed from Patch to Defect
- Status changed from New to Confirmed
- Target version set to Candidate for next minor release
Steps to reproduce the issue:
echo gem \'attr_encrypted\' >> Gemfile.local bundle install bin/rails test test/unit/project_test.rb -n test_move_a_root_project_to_a_project