From e260241dea5df4bff9f0803e0dba90a8a6d4fe4c Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Fri, 13 Aug 2021 18:58:33 +0530 Subject: [PATCH] group specs related to `skip` functionality in a context --- .../custom_wizard/wizard_controller_spec.rb | 79 ++++++++++--------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/spec/requests/custom_wizard/wizard_controller_spec.rb b/spec/requests/custom_wizard/wizard_controller_spec.rb index 4cd47c80..87ff7efe 100644 --- a/spec/requests/custom_wizard/wizard_controller_spec.rb +++ b/spec/requests/custom_wizard/wizard_controller_spec.rb @@ -50,52 +50,55 @@ describe CustomWizard::WizardController do expect(response.parsed_body["error"]).to eq("We couldn't find a wizard at that address.") end - it 'skips a wizard if user is allowed to skip' do - put '/w/super-mega-fun-wizard/skip.json' - expect(response.status).to eq(200) - end + context 'when user skips the wizard' do - it 'lets user skip if user cant access wizard' do - @template["permitted"] = permitted_json["permitted"] - CustomWizard::Template.save(@template, skip_jobs: true) + it 'skips a wizard if user is allowed to skip' do + put '/w/super-mega-fun-wizard/skip.json' + expect(response.status).to eq(200) + end - put '/w/super-mega-fun-wizard/skip.json' - expect(response.status).to eq(200) - end + it 'lets user skip if user cant access wizard' do + @template["permitted"] = permitted_json["permitted"] + CustomWizard::Template.save(@template, skip_jobs: true) - it 'returns a no skip message if user is not allowed to skip' do - @template['required'] = 'true' - CustomWizard::Template.save(@template) - put '/w/super-mega-fun-wizard/skip.json' - expect(response.parsed_body['error']).to eq("Wizard can't be skipped") - end + put '/w/super-mega-fun-wizard/skip.json' + expect(response.status).to eq(200) + end - it 'skip response contains a redirect_to if in users submissions' do - @wizard = CustomWizard::Wizard.create(@template["id"], user) - CustomWizard::Submission.new(@wizard, redirect_to: "/t/2").save - put '/w/super-mega-fun-wizard/skip.json' - expect(response.parsed_body['redirect_to']).to eq('/t/2') - end + it 'returns a no skip message if user is not allowed to skip' do + @template['required'] = 'true' + CustomWizard::Template.save(@template) + put '/w/super-mega-fun-wizard/skip.json' + expect(response.parsed_body['error']).to eq("Wizard can't be skipped") + end - it "deletes the submission if user has filled up some data" do - @wizard = CustomWizard::Wizard.create(@template["id"], user) - CustomWizard::Submission.new(@wizard, step_1_field_1: "Hello World").save - current_submission = @wizard.current_submission - put '/w/super-mega-fun-wizard/skip.json' - list = CustomWizard::Submission.list(@wizard) + it 'skip response contains a redirect_to if in users submissions' do + @wizard = CustomWizard::Wizard.create(@template["id"], user) + CustomWizard::Submission.new(@wizard, redirect_to: "/t/2").save + put '/w/super-mega-fun-wizard/skip.json' + expect(response.parsed_body['redirect_to']).to eq('/t/2') + end - expect(list.any? { |submission| submission.id == current_submission.id }).to eq(false) - end + it "deletes the submission if user has filled up some data" do + @wizard = CustomWizard::Wizard.create(@template["id"], user) + CustomWizard::Submission.new(@wizard, step_1_field_1: "Hello World").save + current_submission = @wizard.current_submission + put '/w/super-mega-fun-wizard/skip.json' + list = CustomWizard::Submission.list(@wizard) - it "starts from the first step if user visits after skipping the wizard" do - put '/w/super-mega-fun-wizard/steps/step_1.json', params: { - fields: { - step_1_field_1: "Text input" + expect(list.any? { |submission| submission.id == current_submission.id }).to eq(false) + end + + it "starts from the first step if user visits after skipping the wizard" do + put '/w/super-mega-fun-wizard/steps/step_1.json', params: { + fields: { + step_1_field_1: "Text input" + } } - } - put '/w/super-mega-fun-wizard/skip.json' - get '/w/super-mega-fun-wizard.json' + put '/w/super-mega-fun-wizard/skip.json' + get '/w/super-mega-fun-wizard.json' - expect(response.parsed_body["start"]).to eq('step_1') + expect(response.parsed_body["start"]).to eq('step_1') + end end end