Added unit tests for "id in seeds.rb failed" issue.

This commit is contained in:
Martin Edenhofer 2015-02-02 14:44:37 +01:00
parent 3066e49eb1
commit 53d13b20f3
2 changed files with 63 additions and 7 deletions

View file

@ -1335,13 +1335,13 @@ Link::Object.create_if_not_exists( :name => 'Question/Answer' )
Link::Object.create_if_not_exists( :name => 'Idea' ) Link::Object.create_if_not_exists( :name => 'Idea' )
Link::Object.create_if_not_exists( :name => 'Bug' ) Link::Object.create_if_not_exists( :name => 'Bug' )
Ticket::StateType.create_if_not_exists( :id => 1, :name => 'new', :updated_by_id => 1 ) Ticket::StateType.create_if_not_exists( :id => 1, :name => 'new' )
Ticket::StateType.create_if_not_exists( :id => 2, :name => 'open', :updated_by_id => 1 ) Ticket::StateType.create_if_not_exists( :id => 2, :name => 'open' )
Ticket::StateType.create_if_not_exists( :id => 3, :name => 'pending reminder', :updated_by_id => 1 ) Ticket::StateType.create_if_not_exists( :id => 3, :name => 'pending reminder' )
Ticket::StateType.create_if_not_exists( :id => 4, :name => 'pending action', :updated_by_id => 1 ) Ticket::StateType.create_if_not_exists( :id => 4, :name => 'pending action' )
Ticket::StateType.create_if_not_exists( :id => 5, :name => 'closed', :updated_by_id => 1 ) Ticket::StateType.create_if_not_exists( :id => 5, :name => 'closed' )
Ticket::StateType.create_if_not_exists( :id => 6, :name => 'merged', :updated_by_id => 1 ) Ticket::StateType.create_if_not_exists( :id => 6, :name => 'merged' )
Ticket::StateType.create_if_not_exists( :id => 7, :name => 'removed', :updated_by_id => 1 ) Ticket::StateType.create_if_not_exists( :id => 7, :name => 'removed' )
Ticket::State.create_if_not_exists( :id => 1, :name => 'new', :state_type_id => Ticket::StateType.where(:name => 'new').first.id ) Ticket::State.create_if_not_exists( :id => 1, :name => 'new', :state_type_id => Ticket::StateType.where(:name => 'new').first.id )
Ticket::State.create_if_not_exists( :id => 2, :name => 'open', :state_type_id => Ticket::StateType.where(:name => 'open').first.id ) Ticket::State.create_if_not_exists( :id => 2, :name => 'open', :state_type_id => Ticket::StateType.where(:name => 'open').first.id )

View file

@ -0,0 +1,56 @@
# encoding: utf-8
require 'test_helper'
class DbAutoIncrementTest < ActiveSupport::TestCase
test 'id overwrite' do
setting_backup = Setting.get('system_init_done')
Setting.set('system_init_done', false)
Ticket::StateType.create_if_not_exists( :id => 200, :name => 'unit test 1', :updated_by_id => 1, :created_by_id => 1 )
state_type = Ticket::StateType.where( :name => 'unit test 1' ).first
assert_equal( Ticket::StateType.to_s, state_type.class.to_s )
assert_equal( 'unit test 1', state_type.name )
Ticket::StateType.create_if_not_exists( :id => 200, :name => 'unit test 1 _ should not be created', :updated_by_id => 1, :created_by_id => 1 )
state_type = Ticket::StateType.where( :id => 200 ).first
assert_equal( Ticket::StateType.to_s, state_type.class.to_s )
assert_equal( 'unit test 1', state_type.name )
Ticket::StateType.create_or_update( :id => 200, :name => 'unit test 1 _ should be updated', :updated_by_id => 1, :created_by_id => 1 )
state_type = Ticket::StateType.where( :name => 'unit test 1 _ should be updated' ).first
assert_equal( Ticket::StateType.to_s, state_type.class.to_s )
assert_equal( 'unit test 1 _ should be updated', state_type.name )
state_type = Ticket::StateType.where( :id => 200 ).first
assert_equal( Ticket::StateType.to_s, state_type.class.to_s )
assert_equal( 'unit test 1 _ should be updated', state_type.name )
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 )
state = Ticket::State.where( :name => 'unit test 1' ).first
assert_equal( Ticket::State.to_s, state.class.to_s )
assert_equal( 'unit test 1', state.name )
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 )
state = Ticket::State.where( :id => 210 ).first
assert_equal( Ticket::State.to_s, state.class.to_s )
assert_equal( 'unit test 1', state.name )
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 )
state = Ticket::State.where( :name => 'unit test 1 _ should be updated' ).first
assert_equal( Ticket::State.to_s, state.class.to_s )
assert_equal( 'unit test 1 _ should be updated', state.name )
state = Ticket::State.where( :id => 210 ).first
assert_equal( Ticket::State.to_s, state.class.to_s )
assert_equal( 'unit test 1 _ should be updated', state.name )
Setting.set('system_init_done', setting_backup)
end
end