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

Already on GitHub? Sign in to your account

ActiveRecord::Store and ActiveModel::Dirty incorrect was value #8847

Closed
chrismhilton opened this Issue Jan 9, 2013 · 7 comments

Comments

Projects
None yet
5 participants

I'm using Rails 3.2.11 and have a model that's using the ActiveRecord::Store like so:

store :settings, accessors: [ :state, :status ]

I have encountered an issue with the settings_was method returning the wrong value which appears to occur when performing the initial change on a store attribute. Here's an example that will hopefully explain the behaviour that I'm seeing.

  1. fetch a model object and the _was method returns the correct values

    document.settings_was
    => {:state=>3, :status=>3}

  2. change one of the store attributes and the _was method returns the new value of that attribute and not the original value

    document.state = 99
    => 99
    document.settings_was
    => {:state=>99, :status=>3}

  3. change another store attributes and the _was method returns the correct original value for that one

    document.status = 99
    => 99
    document.settings_was
    => {:state=>99, :status=>3}

Member

senny commented Jan 12, 2013

This works on rails/master. The commit that probably fixed it is 20f943f

Member

senny commented Jan 12, 2013

/cc @al2o3cr

Contributor

al2o3cr commented Jan 12, 2013

Yep, this is exactly the issue solved by 20f943f - in particular, with the swap of lines 60 + 61. Is it worth backporting that patch?

Member

senny commented Jan 12, 2013

since it is a bug I would consider backporting it but let's see what @rafaelfranca or @carlosantoniodasilva thinks.

Member

steveklabnik commented Jan 13, 2013

I'm 👍 on backporting, but since it's not a bug on master, I'm closing for now.

Thanks for the info guys, should I just wait for another comment on the issue to know whether this has been backported?

Owner

rafaelfranca commented Jan 14, 2013

It would be great if someone want to open a pull request to backport this fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment