Browse Source

Maintenance: Ported test/integration/object_manager_test.rb

Tobias Schäfer 2 years ago
parent
commit
b3c45f578f

+ 0 - 1
.github/workflows/ci/test.sh

@@ -22,4 +22,3 @@ bundle exec rspec --exclude-pattern "spec/system/**/*_spec.rb" -t ~searchindex -
 echo "Running basic minitest tests..."
 bundle exec rake zammad:db:reset
 bundle exec rake test:units
-ruby -I test/ test/integration/object_manager_test.rb

+ 0 - 1
.gitlab/ci/test/unit.yml

@@ -7,7 +7,6 @@
   script:
     - !reference [.scripts, zammad_db_init]
     - bundle exec rake test:units
-    - bundle exec rails test test/integration/object_manager_test.rb
 
 unit:mysql:
   stage: test

+ 0 - 1
.rubocop/default.yml

@@ -249,7 +249,6 @@ Lint/BooleanSymbol:
   Exclude:
     - "db/seeds/object_manager_attributes.rb"
     - "spec/requests/integration/object_manager_attributes_spec.rb"
-    - "test/integration/object_manager_test.rb"
 
 Lint/InterpolationCheck:
   Description: 'Raise warning for interpolation in single q strs'

+ 66 - 0
spec/models/object_manager/attribute/object/ticket_spec.rb

@@ -0,0 +1,66 @@
+# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
+
+require 'rails_helper'
+
+RSpec.describe 'ObjectManager::Attribute::Object::Ticket', aggregate_failures: true, db_strategy: :reset do
+  shared_context 'with ticket attribute setup' do
+    before { attribute }
+
+    let(:attribute) do
+      attribute = create(:object_manager_attribute_text)
+      ObjectManager::Attribute.migration_execute
+
+      attribute
+    end
+    let(:ticket) { create(:ticket) }
+  end
+
+  describe 'add ticket attribute' do
+    include_context 'with ticket attribute setup'
+
+    it 'is successful' do
+      ticket.update(attribute.name => 'Bazinga!')
+      expect(ticket.reload).to have_attributes(attribute.name => 'Bazinga!')
+    end
+  end
+
+  describe 'update ticket attribute' do
+    include_context 'with ticket attribute setup'
+
+    it 'is successful' do
+      skip 'Missing error handling on edit misconfiguration.'
+
+      ticket.update!(attribute.name => 'Bazinga!')
+
+      attributes = attribute.attributes
+      attributes.delete('data_option_new')
+      attributes['data_option'] = {
+        maxlength: 3,
+        type:      'text',
+        null:      false,
+      }
+      ObjectManager::Attribute.add(attributes.deep_symbolize_keys)
+      ObjectManager::Attribute.migration_execute
+      expect { ticket.reload }.not_to raise_error
+
+      new_ticket = create(:ticket).tap { |t| t.update!(attribute.name => 'Bazinga!') }
+      expect(new_ticket.attributes[attribute.name].length).to be(3)
+    end
+  end
+
+  describe 'remove ticket attribute' do
+    include_context 'with ticket attribute setup'
+
+    it 'is successful' do
+      ticket.update!(attribute.name => 'Bazinga!')
+
+      attribute_name = attribute.name
+      ObjectManager::Attribute.remove(
+        object: 'Ticket',
+        name:   attribute_name
+      )
+      ObjectManager::Attribute.migration_execute
+      expect(ticket.reload.attributes).not_to include(attribute_name)
+    end
+  end
+end

+ 32 - 0
spec/models/object_manager/attribute/validation/data_types_spec.rb

@@ -0,0 +1,32 @@
+# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
+
+require 'rails_helper'
+
+RSpec.describe 'ObjectManager::Attribute::Validation::DataTypes', aggregate_failures: true do
+
+  %w[
+    input
+    user_autocompletion
+    checkbox
+    select
+    multiselect
+    tree_select
+    multi_tree_select
+    datetime
+    date
+    tag
+    richtext
+    textarea
+    integer
+    autocompletion_ajax
+    autocompletion_ajax_customer_organization
+    boolean
+    user_permission
+    active
+  ].freeze.each do |data_type|
+    it "validates #{data_type} data type" do
+      expect(ObjectManager::Attribute::DATA_TYPES).to include(data_type)
+    end
+  end
+
+end

+ 109 - 0
spec/models/object_manager/attribute_spec.rb

@@ -166,6 +166,23 @@ RSpec.describe ObjectManager::Attribute, type: :model do
   end
 
   describe 'Class methods:' do
+    describe '.pending_migration?', db_strategy: :reset do
+      it 'returns false if there are no pending migrations' do
+        expect(described_class.pending_migration?).to be false
+      end
+
+      it 'returns true if there are pending migrations' do
+        create(:object_manager_attribute_text)
+        expect(described_class.pending_migration?).to be true
+      end
+
+      it 'returns false if migration was executed' do
+        create(:object_manager_attribute_text)
+        described_class.migration_execute
+        expect(described_class.pending_migration?).to be false
+      end
+    end
+
     describe '.attribute_to_references_hash_objects' do
       it 'returns classes with conditions' do
         expect(described_class.attribute_to_references_hash_objects).to match_array [Trigger, Overview, Job, Sla, Report::Profile ]
@@ -474,4 +491,96 @@ RSpec.describe ObjectManager::Attribute, type: :model do
       expect(select_field.reload.data_option[:historical_options]).to eq(expect_result)
     end
   end
+
+  describe '#add' do
+    context 'when data is valid' do
+      let(:attribute) do
+        {
+          object:        'Ticket',
+          name:          'test1',
+          display:       'Test 1',
+          data_type:     'input',
+          data_option:   {
+            maxlength: 200,
+            type:      'text',
+            null:      false,
+          },
+          active:        true,
+          screens:       {},
+          position:      20,
+          created_by_id: 1,
+          updated_by_id: 1,
+          editable:      false,
+          to_migrate:    false,
+        }
+      end
+
+      it 'is successful' do
+        expect { described_class.add(attribute) }.to change(described_class, :count)
+        expect(described_class.get(object: 'Ticket', name: 'test1')).to have_attributes(attribute)
+      end
+    end
+
+    context 'when data is invalid' do
+      let(:attribute) do
+        {
+          object:        'Ticket',
+          name:          'test2_id',
+          display:       'Test 2 with id',
+          data_type:     'input',
+          data_option:   {
+            maxlength: 200,
+            type:      'text',
+            null:      false,
+          },
+          active:        true,
+          screens:       {},
+          position:      20,
+          created_by_id: 1,
+          updated_by_id: 1,
+        }
+      end
+
+      it 'raises an error' do
+        expect { described_class.add(attribute) }.to raise_error(ActiveRecord::RecordInvalid)
+      end
+    end
+  end
+
+  describe '#get' do
+    context 'when attribute exists' do
+      before do
+        create(:object_manager_attribute_text, name: 'test3')
+      end
+
+      it 'returns the attribute' do
+        expect(described_class.get(object: 'Ticket', name: 'test3')).to have_attributes(name: 'test3', editable: true)
+      end
+    end
+
+    context 'when attribute does not exist' do
+      it 'returns nil' do
+        expect(described_class.get(object: 'Ticket', name: 'test4')).to be_nil
+      end
+    end
+  end
+
+  describe '#remove' do
+    context 'when attribute exists' do
+      before do
+        create(:object_manager_attribute_text, name: 'test3')
+      end
+
+      it 'is successful' do
+        expect { described_class.remove(object: 'Ticket', name: 'test3') }.to change(described_class, :count)
+        expect(described_class.get(object: 'Ticket', name: 'test3')).to be_nil
+      end
+    end
+
+    context 'when attribute does not exist' do
+      it 'raises an error' do
+        expect { described_class.remove(object: 'Ticket', name: 'test4') }.to raise_error(RuntimeError)
+      end
+    end
+  end
 end

+ 21 - 0
spec/models/object_manager_spec.rb

@@ -0,0 +1,21 @@
+# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
+
+require 'rails_helper'
+RSpec.describe ObjectManager, aggregate_failures: true, type: :model do
+
+  describe 'class methods' do
+    describe 'list_objects' do
+      it 'returns an array of objects' do
+        expect(described_class.list_objects).to be_an(Array)
+        expect(described_class.list_objects.sort).to match_array(%w[Group Organization User Ticket TicketArticle])
+      end
+    end
+
+    describe 'list_frontend_objects' do
+      it 'returns an array of objects' do
+        expect(described_class.list_frontend_objects).to be_an(Array)
+        expect(described_class.list_frontend_objects.sort).to match_array(%w[Group Organization User Ticket])
+      end
+    end
+  end
+end

+ 51 - 0
spec/models/ticket/selector/attribute_spec.rb

@@ -0,0 +1,51 @@
+# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
+
+require 'rails_helper'
+
+RSpec.describe 'Ticket::Selector', db_strategy: :reset, searchindex: true do
+  before do
+    Ticket.destroy_all
+    attribute
+    tickets
+    searchindex_model_reload([Ticket])
+  end
+
+  let(:agent) { create(:agent, groups: [Group.first]) }
+  let(:attribute) do
+    attribute = create(:object_manager_attribute_text)
+    ObjectManager::Attribute.migration_execute
+
+    attribute
+  end
+  let(:tickets) do
+    tickets = create_list(:ticket, 10, group: Group.first)
+    tickets.each_with_index do |ticket, index|
+      ticket[attribute.name] = index.odd? ? '1st value' : '2nd value'
+      ticket.save!
+    end
+  end
+  let(:condition) do
+    {
+      "ticket.#{attribute.name}" => {
+        operator: 'is',
+        value:    '1st value',
+      },
+    }
+  end
+
+  describe 'select by condition attribute' do
+    context 'when using the ticket selector' do
+      it 'is successful' do
+        ticket_count, = Ticket.selectors(condition, limit: 100)
+        expect(ticket_count).to eq(5)
+      end
+    end
+
+    context 'when using the search index backend' do
+      it 'is successful' do
+        result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
+        expect(result[:count]).to eq(5)
+      end
+    end
+  end
+end

+ 66 - 0
spec/system/overview/attribute_spec.rb

@@ -0,0 +1,66 @@
+# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
+
+require 'rails_helper'
+
+RSpec.describe 'Overview with custom attributes', authenticated_as: :authenticate, db_strategy: :reset, type: :system do
+  let(:attribute) { create(:object_manager_attribute_boolean) }
+  let(:agent)     { create(:agent, groups: [Group.find_by(name: 'Users')]) }
+  let(:overview)  { nil }
+  let(:ticket)    { nil }
+
+  def authenticate
+    agent
+    attribute
+    ObjectManager::Attribute.migration_execute
+    overview
+    ticket
+
+    true
+  end
+
+  before do
+    visit "ticket/view/#{overview.link}"
+  end
+
+  context 'when the custom attribute used in a view in an overview' do
+    let(:overview) do
+      create(:overview,
+             view: { s:                 ['title', 'number', attribute.name],
+                     view_mode_default: 's' })
+    end
+
+    it 'shows the custom attribute display description' do
+      within :active_content do
+        expect(page).to have_text attribute.display.to_s.upcase
+      end
+    end
+  end
+
+  context 'when the custom attribute is used as condition in an overview' do
+    let(:overview) do
+      create(:overview,
+             condition: { "ticket.#{attribute.name}" => { operator: 'is', value: true } },
+             view:      { s:                 ['title', 'number', attribute.name],
+                          view_mode_default: 's' })
+    end
+
+    context 'with no ticket with custom attribute value true' do
+      it 'shows no entries' do
+        within :active_content do
+          expect(page).to have_text 'NO ENTRIES'
+        end
+      end
+    end
+
+    context 'with a ticket with custom attribute value true' do
+      let(:ticket) { create(:ticket, group: Group.find_by(name: 'Users'), attribute.name => true) }
+
+      it 'shows the ticket' do
+        within :active_content do
+          expect(page).to have_text attribute.display.to_s.upcase
+          expect(page).to have_text ticket.title
+        end
+      end
+    end
+  end
+end

+ 0 - 1209
test/integration/object_manager_test.rb

@@ -1,1209 +0,0 @@
-# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
-
-require 'integration_test_helper'
-
-class ObjectManagerTest < ActiveSupport::TestCase
-
-  test 'a object manager' do
-
-    list_objects = ObjectManager.list_objects
-    assert_equal(%w[Ticket TicketArticle User Organization Group], list_objects)
-
-    list_objects = ObjectManager.list_frontend_objects
-    assert_equal(%w[Ticket User Organization Group], list_objects)
-
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-
-    # create simple attribute
-    attribute1 = ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          'test1',
-      display:       'Test 1',
-      data_type:     'input',
-      data_option:   {
-        maxlength: 200,
-        type:      'text',
-        null:      false,
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-      editable:      false,
-      to_migrate:    false,
-    )
-    assert(attribute1)
-    assert_equal('test1', attribute1.name)
-    assert_equal(true, attribute1.editable)
-    assert_equal(true, attribute1.to_create)
-    assert_equal(true, attribute1.to_migrate)
-    assert_equal(false, attribute1.to_delete)
-    assert_equal(true, ObjectManager::Attribute.pending_migration?)
-
-    attribute1 = ObjectManager::Attribute.get(
-      object: 'Ticket',
-      name:   'test1',
-    )
-    assert(attribute1)
-    assert_equal('test1', attribute1.name)
-    assert_equal(true, attribute1.editable)
-    assert_equal(true, attribute1.to_create)
-    assert_equal(true, attribute1.to_migrate)
-    assert_equal(false, attribute1.to_delete)
-    assert_equal(true, ObjectManager::Attribute.pending_migration?)
-
-    # delete attribute without execute migrations
-    ObjectManager::Attribute.remove(
-      object: 'Ticket',
-      name:   'test1',
-    )
-
-    attribute1 = ObjectManager::Attribute.get(
-      object: 'Ticket',
-      name:   'test1',
-    )
-    assert_not(attribute1)
-
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-    assert(ObjectManager::Attribute.migration_execute)
-
-    attribute1 = ObjectManager::Attribute.get(
-      object: 'Ticket',
-      name:   'test1',
-    )
-    assert_not(attribute1)
-
-    # create invalid attributes
-    assert_raises(ActiveRecord::RecordInvalid) do
-      ObjectManager::Attribute.add(
-        object:        'Ticket',
-        name:          'test2_id',
-        display:       'Test 2 with id',
-        data_type:     'input',
-        data_option:   {
-          maxlength: 200,
-          type:      'text',
-          null:      false,
-        },
-        active:        true,
-        screens:       {},
-        position:      20,
-        created_by_id: 1,
-        updated_by_id: 1,
-      )
-    end
-    assert_raises(ActiveRecord::RecordInvalid) do
-      ObjectManager::Attribute.add(
-        object:        'Ticket',
-        name:          'test3_ids',
-        display:       'Test 3 with id',
-        data_type:     'input',
-        data_option:   {
-          maxlength: 200,
-          type:      'text',
-          null:      false,
-        },
-        active:        true,
-        screens:       {},
-        position:      20,
-        created_by_id: 1,
-        updated_by_id: 1,
-      )
-    end
-    assert_raises(ActiveRecord::RecordInvalid) do
-      ObjectManager::Attribute.add(
-        object:        'Ticket',
-        name:          'test4',
-        display:       'Test 4 with missing data_option[:type]',
-        data_type:     'input',
-        data_option:   {
-          maxlength: 200,
-          null:      false,
-        },
-        active:        true,
-        screens:       {},
-        position:      20,
-        created_by_id: 1,
-        updated_by_id: 1,
-      )
-    end
-
-    attribute5 = ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          'test5',
-      display:       'Test 5',
-      data_type:     'boolean',
-      data_option:   {
-        default: true,
-        options: {
-          true:  'Yes',
-          false: 'No',
-        },
-        null:    false,
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-    )
-    assert(attribute5)
-    assert_equal('test5', attribute5.name)
-    ObjectManager::Attribute.remove(
-      object: 'Ticket',
-      name:   'test5',
-    )
-
-    assert_raises(ActiveRecord::RecordInvalid) do
-      ObjectManager::Attribute.add(
-        object:        'Ticket',
-        name:          'test6',
-        display:       'Test 6',
-        data_type:     'boolean',
-        data_option:   {
-          options: {
-            true:  'Yes',
-            false: 'No',
-          },
-          null:    false,
-        },
-        active:        true,
-        screens:       {},
-        position:      20,
-        created_by_id: 1,
-        updated_by_id: 1,
-      )
-    end
-
-    attribute7 = ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          'test7',
-      display:       'Test 7',
-      data_type:     'select',
-      data_option:   {
-        default: 1,
-        options: {
-          '1' => 'aa',
-          '2' => 'bb',
-        },
-        null:    false,
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-    )
-    assert(attribute7)
-    assert_equal('test7', attribute7.name)
-    ObjectManager::Attribute.remove(
-      object: 'Ticket',
-      name:   'test7',
-    )
-
-    assert_raises(ActiveRecord::RecordInvalid) do
-      ObjectManager::Attribute.add(
-        object:        'Ticket',
-        name:          'test8',
-        display:       'Test 8',
-        data_type:     'select',
-        data_option:   {
-          default: 1,
-          null:    false,
-        },
-        active:        true,
-        screens:       {},
-        position:      20,
-        created_by_id: 1,
-        updated_by_id: 1,
-      )
-    end
-
-    attribute9 = ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          'test9',
-      display:       'Test 9',
-      data_type:     'datetime',
-      data_option:   {
-        future: true,
-        past:   false,
-        diff:   24,
-        null:   true,
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-    )
-    assert(attribute9)
-    assert_equal('test9', attribute9.name)
-    ObjectManager::Attribute.remove(
-      object: 'Ticket',
-      name:   'test9',
-    )
-
-    assert_raises(ActiveRecord::RecordInvalid) do
-      ObjectManager::Attribute.add(
-        object:        'Ticket',
-        name:          'test10',
-        display:       'Test 10',
-        data_type:     'datetime',
-        data_option:   {
-          past: false,
-          diff: 24,
-          null: true,
-        },
-        active:        true,
-        screens:       {},
-        position:      20,
-        created_by_id: 1,
-        updated_by_id: 1,
-      )
-    end
-
-    attribute11 = ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          'test11',
-      display:       'Test 11',
-      data_type:     'date',
-      data_option:   {
-        future: true,
-        past:   false,
-        diff:   24,
-        null:   true,
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-    )
-    assert(attribute11)
-    assert_equal('test11', attribute11.name)
-    ObjectManager::Attribute.remove(
-      object: 'Ticket',
-      name:   'test11',
-    )
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-
-    assert_raises(ActiveRecord::RecordInvalid) do
-      ObjectManager::Attribute.add(
-        object:        'Ticket',
-        name:          'test13|',
-        display:       'Test 13',
-        data_type:     'date',
-        data_option:   {
-          future: true,
-          past:   false,
-          diff:   24,
-          null:   true,
-        },
-        active:        true,
-        screens:       {},
-        position:      20,
-        created_by_id: 1,
-        updated_by_id: 1,
-      )
-    end
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-
-    assert_raises(ActiveRecord::RecordInvalid) do
-      ObjectManager::Attribute.add(
-        object:        'Ticket',
-        name:          'test14!',
-        display:       'Test 14',
-        data_type:     'date',
-        data_option:   {
-          future: true,
-          past:   false,
-          diff:   24,
-          null:   true,
-        },
-        active:        true,
-        screens:       {},
-        position:      20,
-        created_by_id: 1,
-        updated_by_id: 1,
-      )
-    end
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-
-    assert_raises(ActiveRecord::RecordInvalid) do
-      ObjectManager::Attribute.add(
-        object:        'Ticket',
-        name:          'test15ä',
-        display:       'Test 15',
-        data_type:     'date',
-        data_option:   {
-          future: true,
-          past:   false,
-          diff:   24,
-          null:   true,
-        },
-        active:        true,
-        screens:       {},
-        position:      20,
-        created_by_id: 1,
-        updated_by_id: 1,
-      )
-    end
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-
-    # Test case #16 invalidated after callback added to set default #data_option[:null] value
-
-    assert_raises(ActiveRecord::RecordInvalid) do
-      ObjectManager::Attribute.add(
-        object:        'Ticket',
-        name:          'test17',
-        display:       'Test 17',
-        data_type:     'integer',
-        data_option:   {
-          default: 2,
-          min:     1,
-        },
-        active:        true,
-        screens:       {},
-        position:      20,
-        created_by_id: 1,
-        updated_by_id: 1,
-      )
-    end
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-
-    assert_raises(ActiveRecord::RecordInvalid) do
-      ObjectManager::Attribute.add(
-        object:        'Ticket',
-        name:          'delete',
-        display:       'Test 18',
-        data_type:     'input',
-        data_option:   {
-          maxlength: 200,
-          type:      'text',
-          null:      false,
-        },
-        active:        true,
-        screens:       {},
-        position:      20,
-        created_by_id: 1,
-        updated_by_id: 1,
-      )
-    end
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-
-    attribute_count = ObjectManager::Attribute.count
-    assert_raises(ActiveRecord::RecordInvalid) do
-      ObjectManager::Attribute.add(
-        object:        'Ticket',
-        name:          'updated_at',
-        display:       'Update Time',
-        data_type:     'datetime',
-        data_option:   {
-          future: true,
-          past:   true,
-          diff:   24,
-          null:   true,
-        },
-        active:        true,
-        screens:       {},
-        position:      20,
-        created_by_id: 1,
-        updated_by_id: 1,
-      )
-      assert_equal(false, ObjectManager::Attribute.pending_migration?)
-    end
-    assert_equal(attribute_count, ObjectManager::Attribute.count)
-
-    assert_raises(ActiveRecord::RecordInvalid) do
-      ObjectManager::Attribute.add(
-        object:        'Ticket',
-        name:          'updated_AT',
-        display:       'Update Time',
-        data_type:     'datetime',
-        data_option:   {
-          future: true,
-          past:   true,
-          diff:   24,
-          null:   true,
-        },
-        active:        true,
-        screens:       {},
-        position:      20,
-        created_by_id: 1,
-        updated_by_id: 1,
-      )
-      assert_equal(false, ObjectManager::Attribute.pending_migration?)
-    end
-
-    assert_equal(attribute_count, ObjectManager::Attribute.count)
-
-  end
-
-  test 'b object manager attribute' do
-
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-    assert_equal(0, ObjectManager::Attribute.where(to_migrate: true).count)
-    assert_equal(0, ObjectManager::Attribute.migrations.count)
-
-    attribute1 = ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          'attribute1',
-      display:       'Attribute 1',
-      data_type:     'input',
-      data_option:   {
-        maxlength: 200,
-        type:      'text',
-        null:      true,
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-    )
-    assert(attribute1)
-
-    assert_equal(true, ObjectManager::Attribute.pending_migration?)
-    assert_equal(1, ObjectManager::Attribute.where(to_migrate: true).count)
-    assert_equal(1, ObjectManager::Attribute.migrations.count)
-
-    # execute migrations
-    assert(ObjectManager::Attribute.migration_execute)
-
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-    assert_equal(0, ObjectManager::Attribute.where(to_migrate: true).count)
-    assert_equal(0, ObjectManager::Attribute.migrations.count)
-
-    # create example ticket
-    ticket1 = Ticket.create(
-      title:         'some attribute test1',
-      group:         Group.lookup(name: 'Users'),
-      customer_id:   2,
-      state:         Ticket::State.lookup(name: 'new'),
-      priority:      Ticket::Priority.lookup(name: '2 normal'),
-      attribute1:    'some attribute text',
-      updated_by_id: 1,
-      created_by_id: 1,
-    )
-    assert('ticket1 created', ticket1)
-
-    assert_equal('some attribute test1', ticket1.title)
-    assert_equal('Users', ticket1.group.name)
-    assert_equal('new', ticket1.state.name)
-    assert_equal('some attribute text', ticket1.attribute1)
-
-    # add additional attributes
-    ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          'attribute2',
-      display:       'Attribute 2',
-      data_type:     'select',
-      data_option:   {
-        default: '2',
-        options: {
-          '1' => 'aa',
-          '2' => 'bb',
-        },
-        null:    true,
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-    )
-    ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          'attribute3',
-      display:       'Attribute 3',
-      data_type:     'datetime',
-      data_option:   {
-        future: true,
-        past:   false,
-        diff:   24,
-        null:   true,
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-    )
-    ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          'attribute4',
-      display:       'Attribute 4',
-      data_type:     'datetime',
-      data_option:   {
-        future: true,
-        past:   false,
-        diff:   24,
-        null:   true,
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-    )
-
-    # execute migrations
-    assert_equal(true, ObjectManager::Attribute.pending_migration?)
-    assert(ObjectManager::Attribute.migration_execute)
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-
-    # create example ticket
-    ticket2 = Ticket.create(
-      title:         'some attribute test2',
-      group:         Group.lookup(name: 'Users'),
-      customer_id:   2,
-      state:         Ticket::State.lookup(name: 'new'),
-      priority:      Ticket::Priority.lookup(name: '2 normal'),
-      attribute1:    'some attribute text',
-      attribute2:    '1',
-      attribute3:    Time.zone.parse('2016-05-12 00:59:59 UTC'),
-      attribute4:    Date.parse('2016-05-11'),
-      updated_by_id: 1,
-      created_by_id: 1,
-    )
-    assert('ticket2 created', ticket2)
-
-    assert_equal('some attribute test2', ticket2.title)
-    assert_equal('Users', ticket2.group.name)
-    assert_equal('new', ticket2.state.name)
-    assert_equal('some attribute text', ticket2.attribute1)
-    assert_equal('1', ticket2.attribute2)
-    assert_equal(Time.zone.parse('2016-05-12 00:59:59 UTC'), ticket2.attribute3)
-    assert_equal(Date.parse('2016-05-11'), ticket2.attribute4)
-
-    # update data_option null -> to_config
-    attribute1 = ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          'attribute1',
-      display:       'Attribute 1',
-      data_type:     'input',
-      data_option:   {
-        maxlength: 200,
-        type:      'text',
-        null:      false,
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-    )
-    assert(attribute1)
-
-    assert_equal(true, ObjectManager::Attribute.pending_migration?)
-    assert_equal(0, ObjectManager::Attribute.where(to_migrate: true).count)
-    assert_equal(1, ObjectManager::Attribute.where(to_config: true).count)
-    assert_equal(1, ObjectManager::Attribute.migrations.count)
-
-    # execute migrations
-    assert(ObjectManager::Attribute.migration_execute)
-
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-    assert_equal(0, ObjectManager::Attribute.where(to_migrate: true).count)
-    assert_equal(0, ObjectManager::Attribute.where(to_config: true).count)
-    assert_equal(0, ObjectManager::Attribute.migrations.count)
-
-    # update data_option maxlength -> to_config && to_migrate
-    attribute1 = ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          'attribute1',
-      display:       'Attribute 1',
-      data_type:     'input',
-      data_option:   {
-        maxlength: 250,
-        type:      'text',
-        null:      false,
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-    )
-    assert(attribute1)
-
-    assert_equal(true, ObjectManager::Attribute.pending_migration?)
-    assert_equal(1, ObjectManager::Attribute.where(to_migrate: true).count)
-    assert_equal(1, ObjectManager::Attribute.where(to_config: true).count)
-    assert_equal(1, ObjectManager::Attribute.migrations.count)
-
-    # execute migrations
-    assert(ObjectManager::Attribute.migration_execute)
-
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-    assert_equal(0, ObjectManager::Attribute.where(to_migrate: true).count)
-    assert_equal(0, ObjectManager::Attribute.where(to_config: true).count)
-    assert_equal(0, ObjectManager::Attribute.migrations.count)
-
-    # remove attribute
-    ObjectManager::Attribute.remove(
-      object: 'Ticket',
-      name:   'attribute1',
-    )
-    ObjectManager::Attribute.remove(
-      object: 'Ticket',
-      name:   'attribute2',
-    )
-    ObjectManager::Attribute.remove(
-      object: 'Ticket',
-      name:   'attribute3',
-    )
-    ObjectManager::Attribute.remove(
-      object: 'Ticket',
-      name:   'attribute4',
-    )
-    assert(ObjectManager::Attribute.migration_execute)
-
-    ticket2 = Ticket.find(ticket2.id)
-    assert('ticket2 created', ticket2)
-
-    assert_equal('some attribute test2', ticket2.title)
-    assert_equal('Users', ticket2.group.name)
-    assert_equal('new', ticket2.state.name)
-    assert_nil(ticket2[:attribute1])
-    assert_nil(ticket2[:attribute2])
-    assert_nil(ticket2[:attribute3])
-    assert_nil(ticket2[:attribute4])
-
-  end
-
-  test 'c object manager attribute - certain names' do
-
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-    assert_equal(0, ObjectManager::Attribute.where(to_migrate: true).count)
-    assert_equal(0, ObjectManager::Attribute.migrations.count)
-
-    attribute1 = ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          '1_a_anfrage_status',
-      display:       '1_a_anfrage_status',
-      data_type:     'input',
-      data_option:   {
-        maxlength: 200,
-        type:      'text',
-        null:      true,
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-    )
-    assert(attribute1)
-
-    assert_equal(true, ObjectManager::Attribute.pending_migration?)
-    assert_equal(1, ObjectManager::Attribute.where(to_migrate: true).count)
-    assert_equal(1, ObjectManager::Attribute.migrations.count)
-
-    # execute migrations
-    assert(ObjectManager::Attribute.migration_execute)
-
-    assert_equal(false, ObjectManager::Attribute.pending_migration?)
-    assert_equal(0, ObjectManager::Attribute.where(to_migrate: true).count)
-    assert_equal(0, ObjectManager::Attribute.migrations.count)
-
-    # create example ticket
-    ticket1 = Ticket.create!(
-      title:                'some attribute test3',
-      group:                Group.lookup(name: 'Users'),
-      customer_id:          2,
-      state:                Ticket::State.lookup(name: 'new'),
-      priority:             Ticket::Priority.lookup(name: '2 normal'),
-      '1_a_anfrage_status': 'some attribute text',
-      updated_by_id:        1,
-      created_by_id:        1,
-    )
-    assert('ticket1 created', ticket1)
-
-    assert_equal('some attribute test3', ticket1.title)
-    assert_equal('Users', ticket1.group.name)
-    assert_equal('new', ticket1.state.name)
-    assert_equal('some attribute text', ticket1['1_a_anfrage_status'])
-
-    condition = {
-      'ticket.title' => {
-        operator: 'is',
-        value:    'some attribute test3',
-      },
-    }
-    ticket_count, tickets = Ticket.selectors(condition, limit: 10)
-    assert_equal(ticket_count, 1)
-    assert_equal(tickets[0].id, ticket1.id)
-
-    condition = {
-      'ticket.1_a_anfrage_status' => {
-        operator: 'is',
-        value:    'some attribute text',
-      },
-    }
-    ticket_count, tickets = Ticket.selectors(condition, limit: 10)
-    assert_equal(ticket_count, 1)
-    assert_equal(tickets[0].id, ticket1.id)
-
-    agent1 = User.create_or_update(
-      login:         'agent1@example.com',
-      firstname:     'Notification',
-      lastname:      'Agent1',
-      email:         'agent1@example.com',
-      password:      'agentpw',
-      active:        true,
-      roles:         Role.where(name: 'Agent'),
-      groups:        Group.all,
-      updated_by_id: 1,
-      created_by_id: 1,
-    )
-
-    Overview.create!(
-      name:          'Overview1',
-      link:          'my_overview',
-      roles:         Role.all,
-      condition:     {
-        'ticket.1_a_anfrage_status' => {
-          operator: 'is',
-          value:    'some attribute text',
-        },
-      },
-      order:         {
-        by:        '1_a_anfrage_status',
-        direction: 'DESC',
-      },
-      group_by:      '1_a_anfrage_status',
-      view:          {
-        d:                 %w[title customer state created_at],
-        s:                 %w[number title customer state created_at],
-        m:                 %w[number title customer state created_at],
-        view_mode_default: 's',
-      },
-      prio:          1,
-      updated_by_id: 1,
-      created_by_id: 1,
-    )
-
-    result = Ticket::Overviews.index(agent1)
-
-    overview = nil
-    result.each do |local_overview|
-      next if local_overview[:overview][:name] != 'Overview1'
-
-      overview = local_overview
-      break
-    end
-    assert(overview)
-
-    assert_equal(1, overview[:tickets].count)
-    assert_equal(1, overview[:count])
-    assert_equal(ticket1.id, overview[:tickets][0][:id])
-  end
-
-  test 'd object manager attribute - update attribute type' do
-
-    attribute1 = ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          'example_1',
-      display:       'example_1',
-      data_type:     'input',
-      data_option:   {
-        default:   '',
-        maxlength: 200,
-        type:      'text',
-        null:      true,
-        options:   {},
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-    )
-
-    assert_equal(true, ObjectManager::Attribute.pending_migration?)
-    assert_equal(1, ObjectManager::Attribute.migrations.count)
-
-    assert(ObjectManager::Attribute.migration_execute)
-
-    assert_raises(ActiveRecord::RecordInvalid) do
-      ObjectManager::Attribute.add(
-        object:        'Ticket',
-        name:          'example_1',
-        display:       'example_1',
-        data_type:     'boolean',
-        data_option:   {
-          default: true,
-          options: {
-            true:  'Yes',
-            false: 'No',
-          },
-          null:    false,
-        },
-        active:        true,
-        screens:       {},
-        position:      200,
-        created_by_id: 1,
-        updated_by_id: 1,
-      )
-    end
-
-    attribute2 = ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          'example_1',
-      display:       'example_1',
-      data_type:     'select',
-      data_option:   {
-        default:   '',
-        maxlength: 200,
-        type:      'text',
-        null:      true,
-        options:   {
-          aa: 'aa',
-          bb: 'bb',
-        },
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-    )
-
-    assert_equal(attribute1.id, attribute2.id)
-    assert_equal(true, ObjectManager::Attribute.pending_migration?)
-    assert_equal(1, ObjectManager::Attribute.migrations.count)
-
-    assert(ObjectManager::Attribute.migration_execute)
-
-  end
-
-  test 'overview any owner / no owner is set' do
-
-    group = Group.create!(
-      name:          'OverviewTest',
-      updated_at:    '2015-02-05 16:37:00',
-      updated_by_id: 1,
-      created_by_id: 1,
-    )
-    roles = Role.where(name: 'Agent')
-    agent1 = User.create!(
-      login:         'ticket-overview-agent1@example.com',
-      firstname:     'Overview',
-      lastname:      'Agent1',
-      email:         'ticket-overview-agent1@example.com',
-      password:      'agentpw',
-      active:        true,
-      roles:         roles,
-      groups:        [group],
-      updated_at:    '2015-02-05 16:37:00',
-      updated_by_id: 1,
-      created_by_id: 1,
-    )
-
-    ObjectManager::Attribute.add(
-      object:        'Ticket',
-      name:          'watcher',
-      display:       'watcher',
-      data_type:     'select',
-      data_option:   {
-        default:   '',
-        maxlength: 200,
-        type:      'text',
-        null:      true,
-        options:   {
-          aa: 'agent a',
-          bb: 'agent b',
-          cc: 'agent c',
-        },
-      },
-      active:        true,
-      screens:       {},
-      position:      20,
-      created_by_id: 1,
-      updated_by_id: 1,
-    )
-
-    assert_equal(true, ObjectManager::Attribute.pending_migration?)
-    assert_equal(1, ObjectManager::Attribute.migrations.count)
-
-    assert(ObjectManager::Attribute.migration_execute)
-
-    Ticket.destroy_all
-    Overview.destroy_all
-
-    UserInfo.current_user_id = 1
-    overview_role = Role.find_by(name: 'Agent')
-    overview1 = Overview.create!(
-      name:      'not watched',
-      prio:      1000,
-      role_ids:  [overview_role.id],
-      condition: {
-        'ticket.watcher' => {
-          operator: 'is',
-          value:    '',
-        },
-      },
-      order:     {
-        by:        'created_at',
-        direction: 'ASC',
-      },
-      view:      {
-        d:                 %w[title customer group created_at],
-        s:                 %w[title customer group created_at],
-        m:                 %w[number title customer group created_at],
-        view_mode_default: 's',
-      },
-    )
-
-    overview2 = Overview.create!(
-      name:      'not watched by somebody',
-      prio:      2000,
-      role_ids:  [overview_role.id],
-      condition: {
-        'ticket.watcher' => {
-          operator: 'is not',
-          value:    '',
-        },
-      },
-      order:     {
-        by:        'created_at',
-        direction: 'ASC',
-      },
-      view:      {
-        d:                 %w[title customer group created_at],
-        s:                 %w[title customer group created_at],
-        m:                 %w[number title customer group created_at],
-        view_mode_default: 's',
-      },
-    )
-
-    overview3 = Overview.create!(
-      name:      'not watched as array',
-      prio:      3000,
-      role_ids:  [overview_role.id],
-      condition: {
-        'ticket.watcher' => {
-          operator: 'is',
-          value:    [''],
-        },
-      },
-      order:     {
-        by:        'created_at',
-        direction: 'ASC',
-      },
-      view:      {
-        d:                 %w[title customer group created_at],
-        s:                 %w[title customer group created_at],
-        m:                 %w[number title customer group created_at],
-        view_mode_default: 's',
-      },
-    )
-
-    overview4 = Overview.create!(
-      name:      'not watched by somebody as array',
-      prio:      4000,
-      role_ids:  [overview_role.id],
-      condition: {
-        'ticket.watcher' => {
-          operator: 'is not',
-          value:    [''],
-        },
-      },
-      order:     {
-        by:        'created_at',
-        direction: 'ASC',
-      },
-      view:      {
-        d:                 %w[title customer group created_at],
-        s:                 %w[title customer group created_at],
-        m:                 %w[number title customer group created_at],
-        view_mode_default: 's',
-      },
-    )
-
-    overview5 = Overview.create!(
-      name:      'watched by aa',
-      prio:      5000,
-      role_ids:  [overview_role.id],
-      condition: {
-        'ticket.watcher' => {
-          operator: 'is',
-          value:    'aa',
-        },
-      },
-      order:     {
-        by:        'created_at',
-        direction: 'ASC',
-      },
-      view:      {
-        d:                 %w[title customer group created_at],
-        s:                 %w[title customer group created_at],
-        m:                 %w[number title customer group created_at],
-        view_mode_default: 's',
-      },
-    )
-
-    overview6 = Overview.create!(
-      name:      'not watched by aa',
-      prio:      6000,
-      role_ids:  [overview_role.id],
-      condition: {
-        'ticket.watcher' => {
-          operator: 'is not',
-          value:    'aa',
-        },
-      },
-      order:     {
-        by:        'created_at',
-        direction: 'ASC',
-      },
-      view:      {
-        d:                 %w[title customer group created_at],
-        s:                 %w[title customer group created_at],
-        m:                 %w[number title customer group created_at],
-        view_mode_default: 's',
-      },
-    )
-
-    overview7 = Overview.create!(
-      name:      'watched by aa array',
-      prio:      7000,
-      role_ids:  [overview_role.id],
-      condition: {
-        'ticket.watcher' => {
-          operator: 'is',
-          value:    ['aa'],
-        },
-      },
-      order:     {
-        by:        'created_at',
-        direction: 'ASC',
-      },
-      view:      {
-        d:                 %w[title customer group created_at],
-        s:                 %w[title customer group created_at],
-        m:                 %w[number title customer group created_at],
-        view_mode_default: 's',
-      },
-    )
-
-    overview8 = Overview.create!(
-      name:      'not watched by aa array',
-      prio:      8000,
-      role_ids:  [overview_role.id],
-      condition: {
-        'ticket.watcher' => {
-          operator: 'is not',
-          value:    ['aa'],
-        },
-      },
-      order:     {
-        by:        'created_at',
-        direction: 'ASC',
-      },
-      view:      {
-        d:                 %w[title customer group created_at],
-        s:                 %w[title customer group created_at],
-        m:                 %w[number title customer group created_at],
-        view_mode_default: 's',
-      },
-    )
-
-    ticket1 = Ticket.create!(
-      title:       'overview test 1',
-      group:       Group.lookup(name: 'OverviewTest'),
-      customer_id: 2,
-      owner_id:    1,
-      watcher:     '',
-      state:       Ticket::State.lookup(name: 'new'),
-      priority:    Ticket::Priority.lookup(name: '2 normal'),
-    )
-
-    travel 2.seconds
-    ticket2 = Ticket.create!(
-      title:       'overview test 2',
-      group:       Group.lookup(name: 'OverviewTest'),
-      customer_id: 2,
-      owner_id:    nil,
-      watcher:     nil,
-      state:       Ticket::State.lookup(name: 'new'),
-      priority:    Ticket::Priority.lookup(name: '2 normal'),
-    )
-
-    travel 2.seconds
-    ticket3 = Ticket.create!(
-      title:       'overview test 3',
-      group:       Group.lookup(name: 'OverviewTest'),
-      customer_id: 2,
-      owner_id:    agent1.id,
-      watcher:     'aa',
-      state:       Ticket::State.lookup(name: 'new'),
-      priority:    Ticket::Priority.lookup(name: '2 normal'),
-    )
-
-    result = Ticket::Overviews.index(agent1)
-    assert_equal(result[0][:overview][:id], overview1.id)
-    assert_equal(result[0][:overview][:name], 'not watched')
-    assert_equal(result[0][:overview][:view], 'not_watched')
-    assert_equal(result[0][:tickets].class, Array)
-    assert_equal(result[0][:tickets][0][:id], ticket1.id)
-    assert_equal(result[0][:tickets][1][:id], ticket2.id)
-    assert_equal(result[0][:count], 2)
-
-    assert_equal(result[1][:overview][:id], overview2.id)
-    assert_equal(result[1][:overview][:name], 'not watched by somebody')
-    assert_equal(result[1][:overview][:view], 'not_watched_by_somebody')
-    assert_equal(result[1][:tickets].class, Array)
-    assert_equal(result[1][:tickets][0][:id], ticket3.id)
-    assert_equal(result[1][:count], 1)
-
-    assert_equal(result[2][:overview][:id], overview3.id)
-    assert_equal(result[2][:overview][:name], 'not watched as array')
-    assert_equal(result[2][:overview][:view], 'not_watched_as_array')
-    assert_equal(result[2][:tickets].class, Array)
-    assert_equal(result[2][:tickets][0][:id], ticket1.id)
-    assert_equal(result[2][:tickets][1][:id], ticket2.id)
-    assert_equal(result[2][:count], 2)
-
-    assert_equal(result[3][:overview][:id], overview4.id)
-    assert_equal(result[3][:overview][:name], 'not watched by somebody as array')
-    assert_equal(result[3][:overview][:view], 'not_watched_by_somebody_as_array')
-    assert_equal(result[3][:tickets].class, Array)
-    assert_equal(result[3][:tickets][0][:id], ticket3.id)
-    assert_equal(result[3][:count], 1)
-
-    assert_equal(result[4][:overview][:id], overview5.id)
-    assert_equal(result[4][:overview][:name], 'watched by aa')
-    assert_equal(result[4][:overview][:view], 'watched_by_aa')
-    assert_equal(result[4][:tickets].class, Array)
-    assert_equal(result[4][:tickets][0][:id], ticket3.id)
-    assert_equal(result[4][:count], 1)
-
-    assert_equal(result[5][:overview][:id], overview6.id)
-    assert_equal(result[5][:overview][:name], 'not watched by aa')
-    assert_equal(result[5][:overview][:view], 'not_watched_by_aa')
-    assert_equal(result[5][:tickets].class, Array)
-    assert_equal(result[5][:tickets][0][:id], ticket1.id)
-    assert_equal(result[5][:tickets][1][:id], ticket2.id)
-    assert_equal(result[5][:count], 2)
-
-    assert_equal(result[6][:overview][:id], overview7.id)
-    assert_equal(result[6][:overview][:name], 'watched by aa array')
-    assert_equal(result[6][:overview][:view], 'watched_by_aa_array')
-    assert_equal(result[6][:tickets].class, Array)
-    assert_equal(result[6][:tickets][0][:id], ticket3.id)
-    assert_equal(result[6][:count], 1)
-
-    assert_equal(result[7][:overview][:id], overview8.id)
-    assert_equal(result[7][:overview][:name], 'not watched by aa array')
-    assert_equal(result[7][:overview][:view], 'not_watched_by_aa_array')
-    assert_equal(result[7][:tickets].class, Array)
-    assert_equal(result[7][:tickets][0][:id], ticket1.id)
-    assert_equal(result[7][:tickets][1][:id], ticket2.id)
-    assert_equal(result[7][:count], 2)
-
-  end
-
-end