@step is never set
Opened this issue · 2 comments
I tried this out on a very simple controller like so:
class AdminController < AuthenticatedController
include Wicked::Wizard
steps :step_1, :step_2, :step_3
def show
render_wizard
end
end
I've found a couple of what seem like bugs that prevented this from working and redirected straight away to /
.
First on this line: https://github.com/zombocom/wicked/blob/main/lib/wicked/wizard.rb#L81
This guard clause is pointless:
return if params[:id].nil?
Because you default to the first step already:
the_step ||= steps.first
And the latter code prevents @step
from being set causing it to think the Wizard is complete and redirect to /
.
Secondly on this line: https://github.com/zombocom/wicked/blob/main/lib/wicked/wizard.rb#L64
You're comparing steps that have been converted to a string to one that is not:
resolved_step = valid_steps.detect { |stp| stp.to_s == the_step }
It should be:
resolved_step = valid_steps.detect { |stp| stp.to_s == the_step.to_s }
In order to get this working, I've had to vendorize the gem and fix both of those lines and then it works fine. But I'm surprised no one else has encountered this issue... unless I've missed some settings in the controller?
This is very similar to a controller we already have a test for https://github.com/zombocom/wicked/blob/main/test/dummy/app/controllers/bar_controller.rb
One thing that jumps out is you don't have an update
action. No clue if that's related though.
Tests ran and were passing last year https://github.com/zombocom/wicked/actions/runs/4343778022.
Maybe try to convert your example into a test case and see if you can get it to fail the same way.
Also: I would take a PR that adds cron to run tests at regular intervals, like weekly/monthly, (instead of just on PR). Being able to trigger them manually as well would be nice.