From ee4b12f48aa2e28f6627f75b492c7827ffc6d6ff Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 26 Apr 2016 11:43:27 +0200 Subject: [PATCH] Improved setup. --- test/controllers/search_controller_test.rb | 36 +++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/test/controllers/search_controller_test.rb b/test/controllers/search_controller_test.rb index 9bb9f1b6b..ea0da700b 100644 --- a/test/controllers/search_controller_test.rb +++ b/test/controllers/search_controller_test.rb @@ -4,14 +4,22 @@ require 'test_helper' class SearchControllerTest < ActionDispatch::IntegrationTest setup do + # clear cache + Cache.clear + + # remove background jobs + Delayed::Job.destroy_all + + # set current user + UserInfo.current_user_id = 1 + # set accept header @headers = { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' } # create agent - roles = Role.where( name: %w(Admin Agent) ) + roles = Role.where(name: %w(Admin Agent)) groups = Group.all - UserInfo.current_user_id = 1 @admin = User.create_or_update( login: 'search-admin', firstname: 'Search', @@ -24,7 +32,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest ) # create agent - roles = Role.where( name: 'Agent' ) + roles = Role.where(name: 'Agent') @agent = User.create_or_update( login: 'search-agent@example.com', firstname: 'Search 1234', @@ -37,7 +45,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest ) # create customer without org - roles = Role.where( name: 'Customer' ) + roles = Role.where(name: 'Customer') @customer_without_org = User.create_or_update( login: 'search-customer1@example.com', firstname: 'Search', @@ -86,10 +94,10 @@ class SearchControllerTest < ActionDispatch::IntegrationTest @ticket1 = Ticket.create( title: 'test 1234-1', - group: Group.lookup( name: 'Users'), + group: Group.lookup(name: 'Users'), customer_id: @customer_without_org.id, - state: Ticket::State.lookup( name: 'new' ), - priority: Ticket::Priority.lookup( name: '2 normal' ), + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) @@ -109,10 +117,10 @@ class SearchControllerTest < ActionDispatch::IntegrationTest sleep 1 @ticket2 = Ticket.create( title: 'test 1234-2', - group: Group.lookup( name: 'Users'), + group: Group.lookup(name: 'Users'), customer_id: @customer_with_org2.id, - state: Ticket::State.lookup( name: 'new' ), - priority: Ticket::Priority.lookup( name: '2 normal' ), + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) @@ -132,10 +140,10 @@ class SearchControllerTest < ActionDispatch::IntegrationTest sleep 1 @ticket3 = Ticket.create( title: 'test 1234-2', - group: Group.lookup( name: 'Users'), + group: Group.lookup(name: 'Users'), customer_id: @customer_with_org3.id, - state: Ticket::State.lookup( name: 'new' ), - priority: Ticket::Priority.lookup( name: '2 normal' ), + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) @@ -164,7 +172,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest # Setting.set('es_password', 'zammad') # set max attachment size in mb - Setting.set('es_attachment_max_size_in_mb', 1 ) + Setting.set('es_attachment_max_size_in_mb', 1) if ENV['ES_INDEX'] #fail "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"