db_auto_increment_test.rb 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. require 'test_helper'
  2. class DbAutoIncrementTest < ActiveSupport::TestCase
  3. test 'id overwrite' do
  4. setting_backup = Setting.get('system_init_done')
  5. Setting.set('system_init_done', false)
  6. Ticket::StateType.create_if_not_exists( id: 200, name: 'unit test 1', updated_by_id: 1, created_by_id: 1 )
  7. state_type = Ticket::StateType.where( name: 'unit test 1' ).first
  8. assert_equal( Ticket::StateType.to_s, state_type.class.to_s )
  9. assert_equal( 'unit test 1', state_type.name )
  10. Ticket::StateType.create_if_not_exists( id: 200, name: 'unit test 1 _ should not be created', updated_by_id: 1, created_by_id: 1 )
  11. state_type = Ticket::StateType.where( id: 200 ).first
  12. assert_equal( Ticket::StateType.to_s, state_type.class.to_s )
  13. assert_equal( 'unit test 1', state_type.name )
  14. Ticket::StateType.create_or_update( id: 200, name: 'unit test 1 _ should be updated', updated_by_id: 1, created_by_id: 1 )
  15. state_type = Ticket::StateType.where( name: 'unit test 1 _ should be updated' ).first
  16. assert_equal( Ticket::StateType.to_s, state_type.class.to_s )
  17. assert_equal( 'unit test 1 _ should be updated', state_type.name )
  18. state_type = Ticket::StateType.where( id: 200 ).first
  19. assert_equal( Ticket::StateType.to_s, state_type.class.to_s )
  20. assert_equal( 'unit test 1 _ should be updated', state_type.name )
  21. Ticket::State.create_if_not_exists( id: 210, name: 'unit test 1', state_type_id: Ticket::StateType.where(name: 'unit test 1 _ should be updated').first.id, updated_by_id: 1, created_by_id: 1 )
  22. state = Ticket::State.where( name: 'unit test 1' ).first
  23. assert_equal( Ticket::State.to_s, state.class.to_s )
  24. assert_equal( 'unit test 1', state.name )
  25. Ticket::State.create_if_not_exists( id: 210, name: 'unit test 1 _ should not be created', state_type_id: Ticket::StateType.where(name: 'unit test 1 _ should be updated').first.id, updated_by_id: 1, created_by_id: 1 )
  26. state = Ticket::State.where( id: 210 ).first
  27. assert_equal( Ticket::State.to_s, state.class.to_s )
  28. assert_equal( 'unit test 1', state.name )
  29. Ticket::State.create_or_update( id: 210, name: 'unit test 1 _ should be updated', state_type_id: Ticket::StateType.where(name: 'unit test 1 _ should be updated').first.id, updated_by_id: 1, created_by_id: 1 )
  30. state = Ticket::State.where( name: 'unit test 1 _ should be updated' ).first
  31. assert_equal( Ticket::State.to_s, state.class.to_s )
  32. assert_equal( 'unit test 1 _ should be updated', state.name )
  33. state = Ticket::State.where( id: 210 ).first
  34. assert_equal( Ticket::State.to_s, state.class.to_s )
  35. assert_equal( 'unit test 1 _ should be updated', state.name )
  36. Setting.set('system_init_done', setting_backup)
  37. end
  38. end