mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 02:48:28 +08:00
DEV: add a remove_step method to Wizard (#24063)
Using Wizard.exclude_steps applies to all sites in a multisite cluster. In order to exclude steps for individual sites at run-time, a new instance method `remove_step` is being added.
This commit is contained in:
@ -56,6 +56,68 @@ RSpec.describe Wizard do
|
||||
end
|
||||
end
|
||||
|
||||
describe "remove_step" do
|
||||
let(:user) { Fabricate.build(:moderator) }
|
||||
let(:wizard) { Wizard.new(user) }
|
||||
let(:step1) { wizard.create_step("first-step") }
|
||||
let(:step2) { wizard.create_step("second-step") }
|
||||
let(:step3) { wizard.create_step("third-step") }
|
||||
|
||||
before do
|
||||
wizard.append_step(step1)
|
||||
wizard.append_step(step2)
|
||||
wizard.append_step(step3)
|
||||
end
|
||||
|
||||
it "does nothing if step id doesn't match any steps" do
|
||||
wizard.remove_step("nope")
|
||||
expect(wizard.steps).to contain_exactly(step1, step2, step3)
|
||||
expect(wizard.start).to eq(step1)
|
||||
end
|
||||
|
||||
it "can remove the first step" do
|
||||
wizard.remove_step(step1.id)
|
||||
expect(wizard.steps).to contain_exactly(step2, step3)
|
||||
expect(step2.index).to eq(0)
|
||||
expect(step2.previous).to be_blank
|
||||
expect(step2.next).to eq(step3)
|
||||
|
||||
expect(step3.index).to eq(1)
|
||||
expect(step3.previous).to eq(step2)
|
||||
expect(step3.next).to be_blank
|
||||
|
||||
expect(wizard.start).to eq(step2)
|
||||
end
|
||||
|
||||
it "can remove a middle step" do
|
||||
wizard.remove_step(step2.id)
|
||||
expect(wizard.steps).to contain_exactly(step1, step3)
|
||||
expect(step1.index).to eq(0)
|
||||
expect(step1.previous).to be_blank
|
||||
expect(step1.next).to eq(step3)
|
||||
|
||||
expect(step3.index).to eq(1)
|
||||
expect(step3.previous).to eq(step1)
|
||||
expect(step3.next).to be_blank
|
||||
|
||||
expect(wizard.start).to eq(step1)
|
||||
end
|
||||
|
||||
it "can remove the last step" do
|
||||
wizard.remove_step(step3.id)
|
||||
expect(wizard.steps).to contain_exactly(step1, step2)
|
||||
expect(step1.index).to eq(0)
|
||||
expect(step1.previous).to be_blank
|
||||
expect(step1.next).to eq(step2)
|
||||
|
||||
expect(step2.index).to eq(1)
|
||||
expect(step2.previous).to eq(step1)
|
||||
expect(step2.next).to be_blank
|
||||
|
||||
expect(wizard.start).to eq(step1)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".exclude_step" do
|
||||
let(:user) { Fabricate.build(:moderator) }
|
||||
let(:wizard) { Wizard.new(user) }
|
||||
|
Reference in New Issue
Block a user