db_auto_increment_test.rb 2.7 KB

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