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

Initializing with aliased state attribute doesn't work #27

Closed
mlarraz opened this issue May 28, 2015 · 1 comment · Fixed by #28
Closed

Initializing with aliased state attribute doesn't work #27

mlarraz opened this issue May 28, 2015 · 1 comment · Fixed by #28

Comments

@mlarraz
Copy link

mlarraz commented May 28, 2015

If you use alias_attribute on a state machine attribute, you can correctly use the aliased getters and setters. However, initializing a model with a hash containing the aliased attribute fails to set the state.

This is inconsistent with how attributes are supposed to work in ActiveModel.

A simple example:

require 'state_machines-activemodel'

class Foo
  include ActiveModel::Model

  attr_accessor :status

  alias_attribute :state, :status

  state_machine initial: :new
end

a = Foo.new(state: :old)
# a.state   => :old
# a.status  => :old

a.status = :new
# a.status  => :new
# a.state   => :new

b = Foo.new(status: :old)  # Assigns nothing
# b.state   => :new
# b.status  => :new

b.status = :old
# b.status  => :old
# b.state   => :old
@joelvh
Copy link
Contributor

joelvh commented Apr 16, 2021

@seuros is there any interest in fixing this issue? I've been looking at the source code, but am still familiarizing myself with where to hone in on the proper fix.

@seuros seuros transferred this issue from state-machines/state_machines-activemodel Apr 17, 2021
@seuros seuros transferred this issue from state-machines/state_machines-activerecord Apr 17, 2021
@seuros seuros closed this as completed in #28 Aug 7, 2022
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

Successfully merging a pull request may close this issue.

2 participants