From 82149f463a03760c9876de564a6a647b4bb7314e Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Thu, 20 Feb 2020 09:44:50 +0100 Subject: [PATCH] Fixes #2920 - Link-Template attributes within Organizations and user cause Organization and user creation to fail within UI --- .../_application_controller_form.coffee | 2 +- spec/factories/object_manager_attribute.rb | 14 ++++- spec/system/manage/organizations_spec.rb | 51 +++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 spec/system/manage/organizations_spec.rb diff --git a/app/assets/javascripts/app/controllers/_application_controller_form.coffee b/app/assets/javascripts/app/controllers/_application_controller_form.coffee index 426651eae..496997b06 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_form.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_form.coffee @@ -361,7 +361,7 @@ class App.ControllerForm extends App.Controller return item else placeholderObjects = {} - if @model.className && !_.isEmpty(attribute.linktemplate) && !_.isEmpty(@params[attribute.name]) + if @model.className && @params && !_.isEmpty(attribute.linktemplate) && !_.isEmpty(@params[attribute.name]) placeholderObjects = { attribute: attribute, session: App.Session.get(), config: App.Config.all() } placeholderObjects[@model.className.toLowerCase()] = @params fullItem = $( diff --git a/spec/factories/object_manager_attribute.rb b/spec/factories/object_manager_attribute.rb index e4ec58e21..eccfb980a 100644 --- a/spec/factories/object_manager_attribute.rb +++ b/spec/factories/object_manager_attribute.rb @@ -1,6 +1,11 @@ FactoryBot.define do factory :object_manager_attribute, class: ObjectManager::Attribute do - object_lookup_id { ObjectLookup.by_name('Ticket') } + transient do + object_name { 'Ticket' } + additional_data_options { nil } + end + + object_lookup_id { ObjectLookup.by_name(object_name) } sequence(:name) { |n| "internal_name#{n}" } sequence(:display) { |n| "Display Name #{n}" } data_option_new { {} } @@ -23,6 +28,13 @@ FactoryBot.define do 'edit' => {} } end + + callback(:after_stub, :before_create) do |object, context| + next if context.additional_data_options.blank? + + object.data_option ||= {} + object.data_option.merge! context.additional_data_options + end end factory :object_manager_attribute_text, parent: :object_manager_attribute do diff --git a/spec/system/manage/organizations_spec.rb b/spec/system/manage/organizations_spec.rb new file mode 100644 index 000000000..2d5950435 --- /dev/null +++ b/spec/system/manage/organizations_spec.rb @@ -0,0 +1,51 @@ +require 'rails_helper' + +RSpec.describe 'Manage > Organizations', type: :system do + + context 'custom attribute' do + + context 'text' do + + context 'linktemplate' do + + it 'creates record', db_strategy: :reset do + + # required to edit attribute in admin interface + screens = { edit: { "admin.organization": { shown: true, required: false } } } + + attribute = create(:object_manager_attribute_text, + object_name: 'Organization', + screens: screens, + additional_data_options: { linktemplate: 'https://example.com' }) + + ObjectManager::Attribute.migration_execute + + refresh + + visit 'manage/organizations' + + within(:active_content) do + click '[data-type="new"]' + end + + modal_ready + + name = "Organization #{rand(999_999)}" + + within '.modal-dialog' do + fill_in 'name', with: name + fill_in attribute.name, with: 'value' + + click '.js-submit' + end + + modal_disappear + + within(:active_content) do + expect(page).to have_text name + end + end + end + end + end +end