Rails 4.2 DEPRECATION WARNING: `serialized_attributes` is deprecated without replacement,
Asked Answered
B

1

11

This warning shows up for me (for everyone) in the majority of controller tests. I know its just a warning...for now...until 5 is released. I am unsure what I need to change to comply with this deprecation. What has changed with serialized_attributes? Id like to make this warning go away and improve my code in prep for 5.0...but unsure how to proceed. Thanks.

update

When hitting a standard update action from a controller test...I get the error:

@document.update_attributes(document_params)

in the test (condensed for this example):

    before do
      @document = documents(:drivers_license)
    end

    def valid_params
      { name: 'Passport' }
    end

    it "must update document" do
      put :update, id: @document, document: valid_params
      assert_redirected_to documents_path
    end

This test passes, but now in rails 4.2 puts the error: DEPRECATION WARNING: serialized_attributes is deprecated without replacement, and will be removed in Rails 5.0."

So, in this example...are the serialized_attributes "{ name: 'Passport' }"?

Brusa answered 23/12, 2014 at 4:4 Comment(3)
Knowing how to fix it, would depend on how you're using it.Titanomachy
Just because something was thought to be no longer good for the community as a whole does not mean that it is not good for you. You could extend your ActiveRecord module with the method from github.com/rails/rails/blob/4-2-stable/activerecord/lib/… which contains the serialized_attributes. However, if this deprecation warning is coming from a gem that you're using and not from your code, you will most likely want to open a ticket/issue with the authors of that gem so that can accommodate future versions of Rails.Startle
The deprecation is discussed in this issue: github.com/rails/rails/pull/15704. The warning comes across as a bit surprising and should probably include at least a reference to the Rails upgrading guide.Evonevonne
S
9

Are you perhaps using the paper_trail gem? If so, see issue #416 in that project.

Sampson answered 28/1, 2015 at 22:17 Comment(2)
i am using paper_trail. Thanks for that.Brusa
Upgrading to paper_trail's v4 beta (see that issue) removed the warnings for me. @Brusa please accept this answer if it fixed it for you. Although this is a generic Rails update, probably most developers in reality will encounter this because of a handful of gems like paper_trail and rails_admin.Evonevonne

© 2022 - 2024 — McMap. All rights reserved.