Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Class.human_state_name stops returning real human name after transition #246

Open
iabdulin opened this Issue · 7 comments

3 participants

@iabdulin

In Ticket.rb I have

state_machine do
    event :next_step do
      transition :new => :issue_details_collected
      transition :issue_details_collected => :carrier_details_collected
      transition :carrier_details_collected => :closed
    end

    state :new, :human_name => 'Issue Details'

    state :issue_details_collected, :human_name => 'Carrier Details' do
    end

    state :carrier_details_collected, :human_name => 'Resolution' do
    end

    state :closed, :human_name => 'Closed' do
    end
  end

In console:

Ticket.human_state_name :issue_details_collected
=> "Carrier Details"

Ticket.first.next_step

Ticket.human_state_name :issue_details_collected
=> "issue details collected"

What's wrong?

@obrie
Owner

Hey @iabdulin -

Any chance the code that's referencing the state name is modifying the string in-place? I can't reproduce in a simple example using state_machine 1.2.0:

require 'state_machine'

class Ticket
  state_machine do
    event :next_step do
      transition :new => :issue_details_collected
      transition :issue_details_collected => :carrier_details_collected
      transition :carrier_details_collected => :closed
    end

    state :new, :human_name => 'Issue Details'

    state :issue_details_collected, :human_name => 'Carrier Details' do
    end

    state :carrier_details_collected, :human_name => 'Resolution' do
    end

    state :closed, :human_name => 'Closed' do
    end
  end
end

Ticket.human_state_name(:issue_details_collected) # => "Carrier Details" 
ticket = Ticket.new                               # => #<Ticket:0x87c6e1c>
ticket.state = 'new'                              # => "new"
ticket.next_step                                  # => true
Ticket.human_state_name(:issue_details_collected) # => "Carrier Details"

If you could provide a reproducible example or ensure that no other code is referencing the human name value, that'd be great. There's really nothing special that state_machine is doing with that string under the hood.

@obrie obrie was assigned
@obrie
Owner

@iabdulin Awesome find... looks like it has to do with the ActiveModel integration assuming that you'll be specifying the human name option in the locale. I'll look into fixing this over the next week or so.

@iabdulin

I've updated the repo with another test.
There are 2 models Ticket and Ticket2, both in ticket.rb. The only diff between classes is order of defining event and states. But the behaviour is different. Run Ticket.test in console.

@obrie
Owner

Just FYI -- haven't forgotten about this .. just been a little busy lately.

@iabdulin

cool

@mibamur

is solution ready?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.