previous_step defaults to first step, if current_step == first_step
rjaus opened this issue · comments
Riley James commented
def previous_step(current_step = nil)
return @previous_step if current_step.nil?
index = steps.index(current_step)
step = steps.at(index - 1) if index.present? && index != 0
step ||= steps.first
end
When on the first step of the wizard, I would have expected the previous_step to be nil. But it seems to default to the first step.
Is there a reason for that?
I realise I can monkey patch in a change here. But I was just trying to understand the design decision.
The same occurs for the previous/next_wizard_path view helpers.
Richard Schneeman commented
I wanted to always return a result and instead use predicate methods to check for edge conditions. What do the predicate methods return?
past_step?(step) # does step come before the current request's step in wizard_steps
future_step?(step) # does step come after the current request's step in wizard_steps
previous_step?(step) # is step immediately before the current request's step
next_step?(step)