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

human_state_name ignores display name #684

Closed
ashleyHutton opened this issue Jun 10, 2020 · 1 comment · Fixed by #697
Closed

human_state_name ignores display name #684

ashleyHutton opened this issue Jun 10, 2020 · 1 comment · Fixed by #697

Comments

@ashleyHutton
Copy link

Describe the bug
Using the .human_state_name on an instance's current state, it does not use the custom display name, if there is one present. It will use the localized state name.

To Reproduce
Steps to reproduce the behavior:

Overriding a state's display name:

state :enabled, display: "Active"
state :pending, initial: true
[3] pry(main)> o.aasm.current_state
=> :enabled
[4] pry(main)> o.aasm.human_state
=> "Enabled"
[6] pry(main)> obj.aasm.states.detect { |s| s.name == obj.aasm.current_state }.display_name
=> "Active"

Expected behavior
I'd expect o.aasm.human_state to return the custom display name, "Active"

Additional context
It looks like the human_state comes from the human_state_name method in the Localizer class:

def human_state_name(klass, state)
checklist = ancestors_list(klass).inject([]) do |list, ancestor|
list << item_for(klass, state, ancestor)
list << item_for(klass, state, ancestor, :old_style => true)
list
end
translate_queue(checklist) || I18n.translate(checklist.shift, :default => state.to_s.humanize)
end

Potentially the default could be changed to: :default => state.display_name.

@anilmaurya
Copy link
Member

Thank you for reporting it.

AASM 5.1.1 is released with the fix

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