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

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

Open
iabdulin opened this issue Apr 11, 2013 · 7 comments
Open
Assignees

Comments

@iabdulin
Copy link

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
Copy link
Member

obrie commented Apr 12, 2013

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.

@ghost ghost assigned obrie Apr 12, 2013
@iabdulin
Copy link
Author

Here's the example repo:
https://github.com/iabdulin/state_machine_human_name_issue

@obrie
Copy link
Member

obrie commented Apr 13, 2013

@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
Copy link
Author

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
Copy link
Member

obrie commented May 7, 2013

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

@iabdulin
Copy link
Author

iabdulin commented May 8, 2013

cool

@mibamur
Copy link

mibamur commented Feb 26, 2014

is solution ready?

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

No branches or pull requests

3 participants