Require conflicting dependencies

spec/lib/tasks/dev_seed_spec.rb:8
This test was failing and we could see messages like:

db/dev_seeds/polls.rb:147:
warning: toplevel constant Answer referenced by Poll::Answer

Resulting in the error:

rake db:dev_seed seeds the database without errors
  Failure/Error: expect { run_rake_task }.not_to raise_error
    expected no Exception, got #<ActiveModel::UnknownAttributeError:
    unknown attribute 'question_id' for Answer

Apparently the lookup was not correclty being performed, due to
conflicting names.

"Naming conflicts of this kind are rare in practice, but if one
occurs, require_dependency provides a solution by ensuring that
the constant needed to trigger the heuristic is defined in the
conflicting place."

https://guides.rubyonrails.org/v5.0/autoloading_and_reloading_constants.html
This commit is contained in:
Julian Herrero
2019-04-05 13:07:11 +02:00
parent 97974a8bc7
commit 58b9899406

View File

@@ -1,3 +1,6 @@
require_dependency "poll/answer"
require_dependency "poll/question/answer"
section "Creating polls" do
Poll.create(name: I18n.t("seeds.polls.current_poll"),