regexp_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. require 'rails_helper'
  2. # required due to some of rails autoloading issues
  3. require 'import/zendesk/object_attribute/regexp'
  4. RSpec.describe Import::Zendesk::ObjectAttribute::Regexp do
  5. it 'imports input object attribute from regexp object field' do
  6. regex = '.+?'
  7. attribute = double(
  8. title: 'Example attribute',
  9. description: 'Example attribute description',
  10. removable: false,
  11. active: true,
  12. position: 12,
  13. visible_in_portal: true,
  14. required_in_portal: true,
  15. required: true,
  16. type: 'regexp',
  17. regexp_for_validation: regex
  18. )
  19. expected_structure = {
  20. object: 'Ticket',
  21. name: 'example_field',
  22. display: 'Example attribute',
  23. data_type: 'input',
  24. data_option: {
  25. null: false,
  26. note: 'Example attribute description',
  27. type: 'text',
  28. maxlength: 255,
  29. regex: regex,
  30. },
  31. editable: true,
  32. active: true,
  33. screens: {
  34. edit: {
  35. Customer: {
  36. shown: true,
  37. null: false
  38. },
  39. view: {
  40. '-all-' => {
  41. shown: true
  42. }
  43. }
  44. }
  45. },
  46. position: 12,
  47. created_by_id: 1,
  48. updated_by_id: 1
  49. }
  50. expect(ObjectManager::Attribute).to receive(:add).with(expected_structure)
  51. expect(ObjectManager::Attribute).to receive(:migration_execute)
  52. described_class.new('Ticket', 'example_field', attribute)
  53. end
  54. end