Rails 4.1 - help needed

Hi, so I've moved to getting foreman to run on rails 4.1
Something has gone wrong, and now tests are sporadically failing on
permissions, which I don't understand very well.
I'd really appreciate some help, when you guys have some time, go
to https://github.com/unorthodoxgeek/foreman/tree/rails41 and run tests
(using ruby 2.0, 2.1 or 2.2), you'll see some tests failing on 403
(unauthorised), maybe a test about timezone being FIJI instead of UTC, and
something regarding counter cache.
All of these tests fail because the authorized method on the API controller
sometimes (sporadically) returns false, when it should return true. all of
those failures run the authorize method in
app/controllers/api/base_controller.rb:109, so this is why I arrived at the
conclusion that the problem is there.

I'm stuck, and in need of help.
Thanks,
Tom

Update:
there seems to be an issue with rails 4.1's way of running tests, as it
does so in a non thread safe fashion.
This caused tests to "leak" the User.current method from one test to the
next one, causing the sporadic failures in the authorization model.
Fixing that was fairly easy - simply add a global before block, setting
User.current to nil before each test.

Now, there are two other problems:

  1. sometimes the Nic::Base#allowed_types is empty in the interfaces
    controller test, causing all those tests to fail. this happens sporadically
  • some test runs pass, some fail.
  1. sometimes UnattendedController does not have TemplateKind.all return
    anything useful, probably because something did TemplateKind.delete_all or
    similar. This causes all Unattended controller tests to fail. Happened only
    once, but I think it's also an issue with the async way Rails 4.1 runs
    tests in.

forgot to link the rails issue: https://github.com/rails/rails/issues/15089