12

Had been in the process of getting a Rails Engine upgraded to Rails 5.1 and now in the process of getting the rspec tests back working.

I have a controller, and in that controller I have the following:

module Users
  class SessionsController < Devise::SessionsController
    skip_before_action :authenticate_user!
    skip_before_action :authorize_user!

    def create
      super
      flash[:analytics] = { "data-analytics-form-completed-name" => "#{StewardshipUser.app_slug}/sign-in", "data-analytics-form-completed-type" => "login" }
    end

    def repopulate_email
      (params[:user] && params[:user][:email]) ? params[:user][:email] : ''
    end
    helper_method :repopulate_email
  end
end

If I remove the skip_before_action :authorize_user! the tests run, but not all successfully.

With the line I'm getting the following error:

An error occurred while loading ./spec/validators/rfc_compliant_validator_spec.rb.
Failure/Error: Dummy::Application.initialize!

RuntimeError:
  can't modify frozen Array
# /Users/ahcarpenter/.rvm/gems/ruby-2.2.2/gems/railties-5.1.4/lib/rails/engine.rb:579:in `unshift'
# /Users/ahcarpenter/.rvm/gems/ruby-2.2.2/gems/railties-5.1.4/lib/rails/engine.rb:579:in `block in <class:Engine>'

Any thoughts on why the initializer would be breaking down with that line in there?

Additionally, when I had initially gone to reinitialize rspec, I had to comment out that method to get the initializer to run as it was not found any longer for some reason (I don't seem to have bumped any gem versions up that contained that method, but maybe so)

2
  • Can you share the code for your test? One thing that I am assuming is that in your test you are not logging in a user and that is somehow causing the failure. Also, where is the authorize_user! function coming from? Are you using pundit or something like that?
    – Ankit
    Commented Nov 3, 2017 at 20:21
  • I get the same error in both 5.0.1, Rails 5.1 and master branch. It seemed it was to do with the definition of a route in a third party engine. The hint was another failing spec Missing :action key on routes definition, please check your routes..
    – Kris
    Commented Nov 16, 2017 at 12:09

1 Answer 1

3

I'm sure you've fixed this by now, but I had this error, I realized that my test database was not initialized properly. I fixed the error by running the following command:

rails db:migrate RAILS_ENV=test

I hope this is helpful for anyone who stumbles across this post.

1
  • The amazing thing about this fix is that it turned over a completely unrelated error that nothing else was throwing, a duplicated factory. Thank you for this! Commented Dec 15, 2023 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.