diff --git a/assets/javascripts/discourse/components/wizard-table-field.js.es6 b/assets/javascripts/discourse/components/wizard-table-field.js.es6 index ce6b1584..049b4d40 100644 --- a/assets/javascripts/discourse/components/wizard-table-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-table-field.js.es6 @@ -102,8 +102,12 @@ export default Component.extend({ @discourseComputed("isUser", "field", "value") username(isUser, field, value) { - if (isUser) {return value.username;} - if (field === "username") {return value.value;} + if (isUser) { + return value.username; + } + if (field === "username") { + return value.value; + } return null; }, @@ -111,7 +115,9 @@ export default Component.extend({ @discourseComputed("username") userProfileUrl(username) { - if (username) {return `/u/${username}`;} + if (username) { + return `/u/${username}`; + } return "/"; }, diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index a25ab6d0..a20b61a7 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -39,7 +39,6 @@ const step = { id: null, index: null, title: null, - key: null, banner: null, raw_description: null, required_data: null, @@ -68,7 +67,6 @@ const field = { description: null, property: null, required: null, - key: null, type: null, condition: null, }, diff --git a/assets/javascripts/discourse/models/custom-wizard-logs.js.es6 b/assets/javascripts/discourse/models/custom-wizard-logs.js.es6 index 1bd19dfe..23565e2c 100644 --- a/assets/javascripts/discourse/models/custom-wizard-logs.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard-logs.js.es6 @@ -31,14 +31,20 @@ CustomWizardLogs.reopenClass({ result.logs = result.logs.map((item) => { let map = {}; - if (item.date) {map.date = logItem(item, "date");} - if (item.action) {map.action = logItem(item, "action");} + if (item.date) { + map.date = logItem(item, "date"); + } + if (item.action) { + map.action = logItem(item, "action"); + } if (item.user) { map.user = item.user; } else { map.user = logItem(item, "username"); } - if (item.message) {map.message = logItem(item, "message");} + if (item.message) { + map.message = logItem(item, "message"); + } return map; }); diff --git a/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs b/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs index 7645c20e..472cbfcb 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs @@ -126,25 +126,29 @@ -
-
- + {{#if proSubscribed}} +
+
+ + {{i18n "admin.wizard.pro.label"}} +
+
+ {{input type="checkbox" checked=wizard.save_submissions}} + {{i18n "admin.wizard.save_submissions_label"}} +
-
- {{input type="checkbox" checked=wizard.save_submissions}} - {{i18n "admin.wizard.save_submissions_label"}} -
-
-
-
- +
+
+ + {{i18n "admin.wizard.pro.label"}} +
+
+ {{input type="checkbox" checked=wizard.restart_on_revisit}} + {{i18n "admin.wizard.restart_on_revisit_label"}} +
-
- {{input type="checkbox" checked=wizard.restart_on_revisit}} - {{i18n "admin.wizard.restart_on_revisit_label"}} -
-
+ {{/if}}
{{wizard-links diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs index 8c8bb6d4..fe3089ac 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs @@ -253,19 +253,6 @@
{{/if}} -
-
- - {{i18n "admin.wizard.pro.label"}} -
-
- {{input - name="key" - value=field.key - placeholderKey="admin.wizard.translation_placeholder"}} -
-
- {{#if validations}} {{wizard-realtime-validations field=field validations=validations}} {{/if}} diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs index 91476ae3..3feb6731 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs @@ -100,19 +100,6 @@ )}} - -
-
- - {{i18n "admin.wizard.pro.label"}} -
-
- {{input - name="key" - value=step.key - placeholderKey="admin.wizard.translation_placeholder"}} -
-
{{/if}} {{wizard-links diff --git a/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 b/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 index 2a92f12a..c4cc950c 100644 --- a/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 +++ b/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 @@ -33,7 +33,7 @@ export default ComposerEditor.extend({ lastValidatedAt: "lastValidatedAt", popupMenuOptions: [], draftStatus: "null", - replyPlaceholder: alias("field.placeholder"), + replyPlaceholder: alias("field.translatedPlaceholder"), @on("didInsertElement") _composerEditorInit() { diff --git a/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 b/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 index f5deb927..6f2a80b7 100644 --- a/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 +++ b/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 @@ -16,19 +16,23 @@ export default { const DEditor = requirejs("discourse/components/d-editor").default; const { clipboardHelpers } = requirejs("discourse/lib/utilities"); const toMarkdown = requirejs("discourse/lib/to-markdown").default; + const { translatedText } = requirejs( + "discourse/plugins/discourse-custom-wizard/wizard/lib/wizard-i18n" + ); FieldComponent.reopen({ classNameBindings: ["field.id"], + @discourseComputed("field.translatedDescription") + cookedDescription(description) { + return cook(description); + }, + @discourseComputed("field.type") textType(fieldType) { return ["text", "textarea"].includes(fieldType); }, - cookedDescription: function () { - return cook(this.get("field.description")); - }.property("field.description"), - inputComponentName: function () { const type = this.get("field.type"); const id = this.get("field.id"); @@ -57,6 +61,26 @@ export default { ]; FieldModel.reopen({ + @discourseComputed("wizardId", "stepId", "id") + i18nKey(wizardId, stepId, id) { + return `${wizardId}.${stepId}.${id}`; + }, + + @discourseComputed("i18nKey", "label") + translatedLabel(i18nKey, label) { + return translatedText(`${i18nKey}.label`, label); + }, + + @discourseComputed("i18nKey", "placeholder") + translatedPlaceholder(i18nKey, placeholder) { + return translatedText(`${i18nKey}.placeholder`, placeholder); + }, + + @discourseComputed("i18nKey", "description") + translatedDescription(i18nKey, description) { + return translatedText(`${i18nKey}.description`, description); + }, + check() { if (this.customCheck) { return this.customCheck(); diff --git a/assets/javascripts/wizard/initializers/custom-wizard-step.js.es6 b/assets/javascripts/wizard/initializers/custom-wizard-step.js.es6 index fbbe7d8b..6a679796 100644 --- a/assets/javascripts/wizard/initializers/custom-wizard-step.js.es6 +++ b/assets/javascripts/wizard/initializers/custom-wizard-step.js.es6 @@ -22,8 +22,26 @@ export default { ).cook; const { schedule } = requirejs("@ember/runloop"); const { alias, not } = requirejs("@ember/object/computed"); + const { translatedText } = requirejs( + "discourse/plugins/discourse-custom-wizard/wizard/lib/wizard-i18n" + ); StepModel.reopen({ + @discourseComputed("wizardId", "id") + i18nKey(wizardId, stepId) { + return `${wizardId}.${stepId}`; + }, + + @discourseComputed("i18nKey", "title") + translatedTitle(i18nKey, title) { + return translatedText(`${i18nKey}.title`, title); + }, + + @discourseComputed("i18nKey", "description") + translatedDescription(i18nKey, description) { + return translatedText(`${i18nKey}.description`, description); + }, + save() { const wizardId = this.get("wizardId"); const fields = {}; @@ -128,13 +146,15 @@ export default { return index === 0 && !required; }.property("step.index", "wizard.required"), - cookedTitle: function () { - return cook(this.get("step.title")); - }.property("step.title"), + @discourseComputed("step.translatedTitle") + cookedTitle(title) { + return cook(title); + }, - cookedDescription: function () { - return cook(this.get("step.description")); - }.property("step.description"), + @discourseComputed("step.translatedDescription") + cookedDescription(description) { + return cook(description); + }, bannerImage: function () { const src = this.get("step.banner"); diff --git a/assets/javascripts/wizard/lib/wizard-i18n.js.es6 b/assets/javascripts/wizard/lib/wizard-i18n.js.es6 index fdefab77..ae69f54c 100644 --- a/assets/javascripts/wizard/lib/wizard-i18n.js.es6 +++ b/assets/javascripts/wizard/lib/wizard-i18n.js.es6 @@ -20,13 +20,25 @@ const translationExists = (key) => { ); }; +const getThemeKey = (key) => { + const themeId = getThemeId(); + return `theme_translations.${themeId}.${key}`; +}; + +const translatedText = (key, value) => { + const themeKey = getThemeKey(key); + return translationExists(themeKey) ? I18n.t(themeKey) : value; +}; + +export { translatedText }; + const WizardI18n = (key, params = {}) => { const themeId = getThemeId(); if (!themeId) { return I18n.t(key, params); } - const themeKey = `theme_translations.${themeId}.${key}`; + let themeKey = getThemeKey(key); if (translationExists(themeKey)) { return I18n.t(themeKey, params); diff --git a/assets/javascripts/wizard/models/custom.js.es6 b/assets/javascripts/wizard/models/custom.js.es6 index 31a403da..39ce098c 100644 --- a/assets/javascripts/wizard/models/custom.js.es6 +++ b/assets/javascripts/wizard/models/custom.js.es6 @@ -41,6 +41,7 @@ CustomWizard.reopenClass({ wizardJson.steps = wizardJson.steps .map((step) => { const stepObj = Step.create(step); + stepObj.wizardId = wizardJson.id; stepObj.fields.sort((a, b) => { return parseFloat(a.number) - parseFloat(b.number); @@ -57,7 +58,11 @@ CustomWizard.reopenClass({ } }); - stepObj.fields = stepObj.fields.map((f) => WizardField.create(f)); + stepObj.fields = stepObj.fields.map((f) => { + f.wizardId = wizardJson.id; + f.stepId = stepObj.id; + return WizardField.create(f); + }); return stepObj; }) diff --git a/assets/javascripts/wizard/templates/components/wizard-field-text.hbs b/assets/javascripts/wizard/templates/components/wizard-field-text.hbs index be44e8e7..08733d3f 100644 --- a/assets/javascripts/wizard/templates/components/wizard-field-text.hbs +++ b/assets/javascripts/wizard/templates/components/wizard-field-text.hbs @@ -1 +1 @@ -{{input id=field.id value=field.value class=fieldClass placeholder=field.placeholder tabindex=field.tabindex autocomplete=autocomplete}} +{{input id=field.id value=field.value class=fieldClass placeholder=field.translatedPlaceholder tabindex=field.tabindex autocomplete=autocomplete}} diff --git a/assets/javascripts/wizard/templates/components/wizard-field-textarea.hbs b/assets/javascripts/wizard/templates/components/wizard-field-textarea.hbs index 6efb7560..dda299bc 100644 --- a/assets/javascripts/wizard/templates/components/wizard-field-textarea.hbs +++ b/assets/javascripts/wizard/templates/components/wizard-field-textarea.hbs @@ -1 +1 @@ -{{textarea id=field.id value=field.value class=fieldClass placeholder=field.placeholder tabindex=field.tabindex}} +{{textarea id=field.id value=field.value class=fieldClass placeholder=field.translatedPlaceholder tabindex=field.tabindex}} diff --git a/assets/javascripts/wizard/templates/components/wizard-field.hbs b/assets/javascripts/wizard/templates/components/wizard-field.hbs index e0dd1551..efda8629 100644 --- a/assets/javascripts/wizard/templates/components/wizard-field.hbs +++ b/assets/javascripts/wizard/templates/components/wizard-field.hbs @@ -1,5 +1,5 @@ {{#if field.image}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index cb30cf76..04b9ceab 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -44,8 +44,6 @@ en: key: "Key" value: "Value" profile: "profile" - translation: "Translation" - translation_placeholder: "key" type: "Type" none: "Make a selection" submission_key: 'submission key' @@ -174,10 +172,10 @@ en: banner: "Banner" description: "Description" required_data: - label: "Required" + label: "Required Data" not_permitted_message: "Message shown when required data not present" permitted_params: - label: "Params" + label: "Permitted Params" force_final: label: "Conditional Final Step" description: "Display this step as the final step if conditions on later steps have not passed when the user reaches this step." diff --git a/lib/custom_wizard/field.rb b/lib/custom_wizard/field.rb index eb4af65d..888afa6b 100644 --- a/lib/custom_wizard/field.rb +++ b/lib/custom_wizard/field.rb @@ -11,7 +11,6 @@ class CustomWizard::Field :label, :description, :image, - :key, :validations, :min_length, :max_length, @@ -36,7 +35,6 @@ class CustomWizard::Field @value = attrs[:value] || default_value @description = attrs[:description] @image = attrs[:image] - @key = attrs[:key] @validations = attrs[:validations] @min_length = attrs[:min_length] @max_length = attrs[:max_length] diff --git a/lib/custom_wizard/step.rb b/lib/custom_wizard/step.rb index 5ffd8024..17827ea1 100644 --- a/lib/custom_wizard/step.rb +++ b/lib/custom_wizard/step.rb @@ -9,7 +9,6 @@ class CustomWizard::Step attr_accessor :index, :title, :description, - :key, :permitted, :permitted_message, :fields, diff --git a/lib/custom_wizard/validators/template.rb b/lib/custom_wizard/validators/template.rb index 839a070f..4311bbbc 100644 --- a/lib/custom_wizard/validators/template.rb +++ b/lib/custom_wizard/validators/template.rb @@ -54,10 +54,15 @@ class CustomWizard::TemplateValidator def self.pro { - wizard: {}, + wizard: { + save_submissions: 'false', + restart_on_revisit: 'true', + }, step: { condition: 'present', - index: 'conditional' + index: 'conditional', + required_data: 'present', + permitted_params: 'present' }, field: { condition: 'present', @@ -87,10 +92,12 @@ class CustomWizard::TemplateValidator def validate_pro(object, type) self.class.pro[type].each do |property, pro_type| - is_pro = object[property.to_s].present? && ( - pro_type === 'present' || - (pro_type === 'conditional' && object[property.to_s].is_a?(Hash)) || - (pro_type.is_a?(Array) && pro_type.include?(object[property.to_s])) + val = object[property.to_s] + is_pro = (val != nil) && ( + pro_type === 'present' && val.present? || + (['true', 'false'].include?(pro_type) && cast_bool(val) == cast_bool(pro_type)) || + (pro_type === 'conditional' && val.is_a?(Hash)) || + (pro_type.is_a?(Array) && pro_type.include?(val)) ) if is_pro && !@pro.subscribed? @@ -122,4 +129,8 @@ class CustomWizard::TemplateValidator errors.add :base, I18n.t("wizard.validation.after_time") end end + + def cast_bool(val) + ActiveRecord::Type::Boolean.new.cast(val) + end end diff --git a/serializers/custom_wizard/wizard_field_serializer.rb b/serializers/custom_wizard/wizard_field_serializer.rb index 37f7a80f..fc2575ef 100644 --- a/serializers/custom_wizard/wizard_field_serializer.rb +++ b/serializers/custom_wizard/wizard_field_serializer.rb @@ -41,13 +41,8 @@ class CustomWizard::FieldSerializer < ::ApplicationSerializer object.value end - def i18n_key - @i18n_key ||= "wizard.step.#{object.step.id}.fields.#{object.id}".underscore - end - def label - return object.label if object.label.present? - I18n.t("#{object.key || i18n_key}.label", default: '') + I18n.t("#{i18n_key}.label", default: object.label, base_url: Discourse.base_url) end def include_label? @@ -55,14 +50,21 @@ class CustomWizard::FieldSerializer < ::ApplicationSerializer end def description - return object.description if object.description.present? - I18n.t("#{object.key || i18n_key}.description", default: '', base_url: Discourse.base_url) + I18n.t("#{i18n_key}.description", default: object.description, base_url: Discourse.base_url) end def include_description? description.present? end + def placeholder + I18n.t("#{i18n_key}.placeholder", default: object.placeholder) + end + + def include_placeholder? + placeholder.present? + end + def image object.image end @@ -71,15 +73,6 @@ class CustomWizard::FieldSerializer < ::ApplicationSerializer object.image.present? end - def placeholder - return object.placeholder if object.placeholder.present? - I18n.t("#{object.key || i18n_key}.placeholder", default: '') - end - - def include_placeholder? - placeholder.present? - end - def file_types object.file_types end @@ -122,4 +115,14 @@ class CustomWizard::FieldSerializer < ::ApplicationSerializer def preview_template object.preview_template end + + protected + + def i18n_key + @i18n_key ||= "#{object.step.wizard.id}.#{object.step.id}.#{object.id}".underscore + end + + def subscribed? + @subscribed ||= CustomWizard::Pro.subscribed? + end end diff --git a/serializers/custom_wizard/wizard_serializer.rb b/serializers/custom_wizard/wizard_serializer.rb index 7a162ba5..4a29d3ea 100644 --- a/serializers/custom_wizard/wizard_serializer.rb +++ b/serializers/custom_wizard/wizard_serializer.rb @@ -9,7 +9,8 @@ class CustomWizard::WizardSerializer < CustomWizard::BasicWizardSerializer :required, :permitted, :uncategorized_category_id, - :categories + :categories, + :pro_subscribed has_many :steps, serializer: ::CustomWizard::StepSerializer, embed: :objects has_one :user, serializer: ::BasicUserSerializer, embed: :objects @@ -60,4 +61,8 @@ class CustomWizard::WizardSerializer < CustomWizard::BasicWizardSerializer def categories object.categories.map { |c| c.to_h } end + + def pro_subscribed + CustomWizard::Pro.subscribed? + end end diff --git a/serializers/custom_wizard/wizard_step_serializer.rb b/serializers/custom_wizard/wizard_step_serializer.rb index 85f527bb..463fa3d6 100644 --- a/serializers/custom_wizard/wizard_step_serializer.rb +++ b/serializers/custom_wizard/wizard_step_serializer.rb @@ -39,13 +39,8 @@ class CustomWizard::StepSerializer < ::ApplicationSerializer object.previous.present? end - def i18n_key - @i18n_key ||= "wizard.step.#{object.id}".underscore - end - def title - return PrettyText.cook(object.title) if object.title - PrettyText.cook(I18n.t("#{object.key || i18n_key}.title", default: '')) + I18n.t("#{i18n_key}.title", default: object.title, base_url: Discourse.base_url) end def include_title? @@ -53,8 +48,7 @@ class CustomWizard::StepSerializer < ::ApplicationSerializer end def description - return object.description if object.description - PrettyText.cook(I18n.t("#{object.key || i18n_key}.description", default: '', base_url: Discourse.base_url)) + I18n.t("#{i18n_key}.description", default: object.description, base_url: Discourse.base_url) end def include_description? @@ -80,4 +74,14 @@ class CustomWizard::StepSerializer < ::ApplicationSerializer def final object.final? end + + protected + + def i18n_key + @i18n_key ||= "#{object.wizard.id}.#{object.id}".underscore + end + + def subscribed? + @subscribed ||= CustomWizard::Pro.subscribed? + end end diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index 34a08461..c92a0d61 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -176,7 +176,7 @@ describe CustomWizard::Action do context "pro actions" do before do - enable_pro + enable_subscription end it '#send_message' do diff --git a/spec/components/custom_wizard/builder_spec.rb b/spec/components/custom_wizard/builder_spec.rb index 9b9c6000..28880409 100644 --- a/spec/components/custom_wizard/builder_spec.rb +++ b/spec/components/custom_wizard/builder_spec.rb @@ -176,6 +176,7 @@ describe CustomWizard::Builder do context "restart is enabled" do before do + enable_subscription @template[:restart_on_revisit] = true CustomWizard::Template.save(@template.as_json) end @@ -204,6 +205,7 @@ describe CustomWizard::Builder do context 'with required data' do before do + enable_subscription @template[:steps][0][:required_data] = required_data_json['required_data'] @template[:steps][0][:required_data_message] = required_data_json['required_data_message'] CustomWizard::Template.save(@template.as_json) @@ -239,6 +241,7 @@ describe CustomWizard::Builder do context "with permitted params" do before do + enable_subscription @template[:steps][0][:permitted_params] = permitted_param_json['permitted_params'] CustomWizard::Template.save(@template.as_json) end @@ -253,7 +256,7 @@ describe CustomWizard::Builder do context "with condition" do before do - enable_pro + enable_subscription @template[:steps][0][:condition] = user_condition_json['condition'] CustomWizard::Template.save(@template.as_json) end @@ -292,7 +295,7 @@ describe CustomWizard::Builder do context "with condition" do before do - enable_pro + enable_subscription @template[:steps][0][:fields][0][:condition] = user_condition_json['condition'] CustomWizard::Template.save(@template.as_json) end @@ -324,6 +327,7 @@ describe CustomWizard::Builder do context 'save submissions disabled' do before do + enable_subscription @template[:save_submissions] = false CustomWizard::Template.save(@template.as_json) @wizard = CustomWizard::Builder.new(@template[:id], user).build diff --git a/spec/components/custom_wizard/custom_field_spec.rb b/spec/components/custom_wizard/custom_field_spec.rb index 2204264f..3bcfab46 100644 --- a/spec/components/custom_wizard/custom_field_spec.rb +++ b/spec/components/custom_wizard/custom_field_spec.rb @@ -217,7 +217,7 @@ describe CustomWizard::CustomField do context "with a pro subscription" do before do - enable_pro + enable_subscription end it "saves pro field types" do diff --git a/spec/components/custom_wizard/field_spec.rb b/spec/components/custom_wizard/field_spec.rb index 0fcf9fc2..c6daa516 100644 --- a/spec/components/custom_wizard/field_spec.rb +++ b/spec/components/custom_wizard/field_spec.rb @@ -23,7 +23,6 @@ describe CustomWizard::Field do expect(field.image).to eq("field_image_url.png") expect(field.description).to eq("Field description") expect(field.required).to eq(true) - expect(field.key).to eq("field.locale.key") expect(field.type).to eq("field_type") expect(field.content).to eq([]) end diff --git a/spec/components/custom_wizard/mapper_spec.rb b/spec/components/custom_wizard/mapper_spec.rb index b210c588..7ef2a5a8 100644 --- a/spec/components/custom_wizard/mapper_spec.rb +++ b/spec/components/custom_wizard/mapper_spec.rb @@ -359,7 +359,7 @@ describe CustomWizard::Mapper do context "with a pro subscription" do before do - enable_pro + enable_subscription end it "treats replaced values as string literals" do diff --git a/spec/components/custom_wizard/template_validator_spec.rb b/spec/components/custom_wizard/template_validator_spec.rb index 7a84660c..e8b8af28 100644 --- a/spec/components/custom_wizard/template_validator_spec.rb +++ b/spec/components/custom_wizard/template_validator_spec.rb @@ -43,47 +43,63 @@ describe CustomWizard::TemplateValidator do ).to eq(false) end - it "invalidates pro step attributes without a pro subscription" do - template[:steps][0][:condition] = user_condition['condition'] - expect( - CustomWizard::TemplateValidator.new(template).perform - ).to eq(false) - end - - it "invalidates pro field attributes without a pro subscription" do - template[:steps][0][:fields][0][:condition] = user_condition['condition'] - expect( - CustomWizard::TemplateValidator.new(template).perform - ).to eq(false) - end - - it "invalidates pro actions without a pro subscription" do - template[:actions] << create_category - expect( - CustomWizard::TemplateValidator.new(template).perform - ).to eq(false) - end - - context "with pro subscription" do - before do - enable_pro + context "without subscription" do + it "invalidates subscription wizard attributes" do + template[:save_submissions] = false + expect( + CustomWizard::TemplateValidator.new(template).perform + ).to eq(false) end - it "validates pro step attributes" do + it "invalidates subscription step attributes" do + template[:steps][0][:condition] = user_condition['condition'] + expect( + CustomWizard::TemplateValidator.new(template).perform + ).to eq(false) + end + + it "invalidates subscription field attributes" do + template[:steps][0][:fields][0][:condition] = user_condition['condition'] + expect( + CustomWizard::TemplateValidator.new(template).perform + ).to eq(false) + end + + it "invalidates subscription actions" do + template[:actions] << create_category + expect( + CustomWizard::TemplateValidator.new(template).perform + ).to eq(false) + end + end + + context "with subscription" do + before do + enable_subscription + end + + it "validates wizard attributes" do + template[:save_submissions] = false + expect( + CustomWizard::TemplateValidator.new(template).perform + ).to eq(true) + end + + it "validates step attributes" do template[:steps][0][:condition] = user_condition['condition'] expect( CustomWizard::TemplateValidator.new(template).perform ).to eq(true) end - it "validates pro field attributes" do + it "validates field attributes" do template[:steps][0][:fields][0][:condition] = user_condition['condition'] expect( CustomWizard::TemplateValidator.new(template).perform ).to eq(true) end - it "validates pro actions" do + it "validates actions" do template[:actions] << create_category expect( CustomWizard::TemplateValidator.new(template).perform diff --git a/spec/extensions/custom_field_extensions_spec.rb b/spec/extensions/custom_field_extensions_spec.rb index bf1b3ff2..7ada17a4 100644 --- a/spec/extensions/custom_field_extensions_spec.rb +++ b/spec/extensions/custom_field_extensions_spec.rb @@ -74,7 +74,7 @@ describe "custom field extensions" do context "pro custom fields" do before do - enable_pro + enable_subscription pro_custom_field_json['custom_fields'].each do |field_json| custom_field = CustomWizard::CustomField.new(nil, field_json) diff --git a/spec/plugin_helper.rb b/spec/plugin_helper.rb index 4aa34029..348e7791 100644 --- a/spec/plugin_helper.rb +++ b/spec/plugin_helper.rb @@ -28,7 +28,7 @@ def authenticate_pro CustomWizard::ProAuthentication.any_instance.stubs(:active?).returns(true) end -def enable_pro +def enable_subscription CustomWizard::Pro.any_instance.stubs(:subscribed?).returns(true) end diff --git a/spec/requests/custom_wizard/custom_field_extensions_spec.rb b/spec/requests/custom_wizard/custom_field_extensions_spec.rb index 64d7c755..9ec3f5b1 100644 --- a/spec/requests/custom_wizard/custom_field_extensions_spec.rb +++ b/spec/requests/custom_wizard/custom_field_extensions_spec.rb @@ -40,7 +40,7 @@ describe "custom field extensions" do context "with a pro subscription" do before do - enable_pro + enable_subscription pro_custom_field_json['custom_fields'].each do |field_json| custom_field = CustomWizard::CustomField.new(nil, field_json) diff --git a/spec/requests/custom_wizard/steps_controller_spec.rb b/spec/requests/custom_wizard/steps_controller_spec.rb index 85353e4c..d4ad4042 100644 --- a/spec/requests/custom_wizard/steps_controller_spec.rb +++ b/spec/requests/custom_wizard/steps_controller_spec.rb @@ -121,7 +121,7 @@ describe CustomWizard::StepsController do context "pro" do before do - enable_pro + enable_subscription end it "raises an error when user cant see the step due to conditions" do diff --git a/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb b/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb index 53afa8e5..0a9f7e89 100644 --- a/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb +++ b/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb @@ -18,7 +18,7 @@ describe CustomWizard::StepSerializer do each_serializer: described_class, scope: Guardian.new(user) ).as_json - expect(json_array[0][:title]).to eq("

Text

") + expect(json_array[0][:title]).to eq("Text") expect(json_array[0][:description]).to eq("

Text inputs!

") expect(json_array[1][:index]).to eq(1) end @@ -34,6 +34,7 @@ describe CustomWizard::StepSerializer do context 'with required data' do before do + enable_subscription wizard_template['steps'][0]['required_data'] = required_data_json['required_data'] wizard_template['steps'][0]['required_data_message'] = required_data_json['required_data_message'] CustomWizard::Template.save(wizard_template)