Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveRecord associations are no longer required (even though belongs_to_required_by_default == true) #268

Closed
mattscilipoti opened this issue Apr 10, 2017 · 5 comments

Comments

@mattscilipoti
Copy link

I'm using Rails 5.0.2, belongs_to_required_by_default = true. I have tests that verify my important associations are required.

After upgrading from 0.8.2 to 0.9.5, the specs in my app that ensure associations are required began to fail. I identified that it happened during the transition to 0.9.0. I attempted to test this within acts_as_list, but was not successful. Instead, I referenced act_as_list via local "path:" in my Gemfile and used git bisect on the cloned acts_as_list dir while testing via my app. This led me to: [4abf1371b243dbd3d924b74fc073e7da0952edbd] Improve load method (#240) and PR #240 by @brendon. There is a lot going on in there. I'm hoping that @brendon may have an idea.

I had a similar experience with simple_token_authentication: gonzalo-bulnes/simple_token_authentication#297. The workaround I found for them does not work for acts_as_list.

I hope we can use what we learn to help each other.

@mattscilipoti mattscilipoti changed the title ActiveRecord associations are no required by default ActiveRecord associations are no longer required (even though belongs_to_required_by_default == true) Apr 10, 2017
@brendon
Copy link
Owner

brendon commented Apr 10, 2017

Hi @mattscilipoti, the diff's in that PR are messed up. There's actually very little that changed apart from where things are required from and how the acts_as_list method is added to AR::Base.

It might pay to try another diffing application to see if that provides more clarity on the change that caused the problem. I use Diffmerge on the mac but there are other good ones too.

What we really need (and you allude to this) is a failing test in acts_as_list in isolation from your app, otherwise it's hard to say either way where the problem lies. I think it's likely to be a load order thing. This PR was in response to an issue about that but I'm unable to find the issue and we never linked the two together unfortunately.

In the meantime, could you have a go at trying to replicate this with a failing test in our repo?

@mattscilipoti
Copy link
Author

Thanks! I'll try some other diff viewers. I tried to replicate the problem with a fresh Rails app: https://github.com/mattscilipoti/test_belongs_to_required_by_default. No luck so far. I'll try some various appraisal configs next.

@brendon
Copy link
Owner

brendon commented Apr 11, 2017

That's interesting. Take a look at your initialisers. Because we changed the order of loading (I think it's earlier now) that could be causing grief with something that didn't expect it to be loaded yet?

@mattscilipoti
Copy link
Author

mattscilipoti commented Apr 12, 2017

I've tried a few things:

In the test project:

  • added Appraisals (with/without acts_as_list). All tests still pass (I expected them to fail).
  • used Gemfile from failing project in test project. All tests pass (again, those with acts_as_list were expected to fail)

In the "failing" project:

  • removed all initializers from failing project. Adding acts_as_lists causes "associations are required" specs to fail.
  • removed all added Gems from Gemfile of failing project (only rails default gems remain). Adding acts_as_lists causes "associations are required" specs to fail.

I even tried both minitests and rspec tests (just in case it was dependent on their load paths).

This is quite strange. I do not understand why the test project is responding to acts_as_list differently than the "failing" project.

@brendon
Copy link
Owner

brendon commented Apr 12, 2017

Yes that is very strange. I suspect something non-standard in the initialisation routine in you project.

If it's been through a few rails versions and you haven't done the following, I'd suggest giving it a go:

I usually will generate a blank rails project with all the settings (mysql as db engine) etc... set as flags on the rails command so you get everything set up as it should be (skip the bundle install). I then use diffmerge to compare it to my project and fix the differences. The bin and config directories will be the main culprits I'd say.

The other option is perhaps there's a monkey-patch somewhere in your project hiding away that is causing problems?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants