0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-14 05:52:52 +01:00
discourse-custom-wizard/spec/requests/custom_wizard/application_controller_spec.rb

59 Zeilen
1,6 KiB
Ruby

2021-03-11 07:30:15 +01:00
# frozen_string_literal: true
require_relative '../../plugin_helper'
2020-11-03 01:24:20 +01:00
describe ApplicationController do
2021-09-07 14:06:13 +02:00
fab!(:user) { Fabricate(:user, username: 'angus', email: "angus@email.com", trust_level: TrustLevel[3]) }
let(:wizard_template) { get_wizard_fixture("wizard") }
2020-11-03 01:24:20 +01:00
before do
2021-09-07 14:06:13 +02:00
CustomWizard::Template.save(wizard_template, skip_jobs: true)
2020-11-03 01:24:20 +01:00
@template = CustomWizard::Template.find('super_mega_fun_wizard')
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
context "with signed in user" do
before do
sign_in(user)
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
context "who is required to complete wizard" do
before do
user.custom_fields['redirect_to_wizard'] = 'super_mega_fun_wizard'
user.save_custom_fields(true)
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
it "redirects if user is required to complete a wizard" do
get "/"
expect(response).to redirect_to("/w/super-mega-fun-wizard")
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
it "saves original destination of user" do
get '/', headers: { 'REFERER' => "/t/2" }
expect(
CustomWizard::Wizard.create(@template['id'], user).submissions
2021-07-12 10:39:37 +02:00
.first.redirect_to
2020-11-03 01:24:20 +01:00
).to eq("/t/2")
end
it "does not redirect if wizard does not exist" do
CustomWizard::Template.remove('super_mega_fun_wizard')
get "/"
expect(response.status).to eq(200)
end
2020-11-03 01:24:20 +01:00
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
context "who is not required to complete wizard" do
it "does nothing" do
get "/"
expect(response.status).to eq(200)
end
end
end
2021-03-11 07:30:15 +01:00
2020-11-03 01:24:20 +01:00
context "with guest" do
it "does nothing" do
get "/"
expect(response.status).to eq(200)
end
end
2021-03-11 07:30:15 +01:00
end