Skip to content

Commit

Permalink
Fix issue with remove_index and add unit test [#5645 state:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Connor authored and josevalim committed Sep 18, 2010
1 parent 55d0d57 commit 37de59e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Expand Up @@ -363,8 +363,7 @@ def add_index(table_name, column_name, options = {})
def remove_index(table_name, options = {})
index_name = index_name(table_name, options)
unless index_name_exists?(table_name, index_name, true)
@logger.warn("Index name '#{index_name}' on table '#{table_name}' does not exist. Skipping.")
return
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' does not exist"
end
remove_index!(table_name, index_name)
end
Expand Down
7 changes: 4 additions & 3 deletions activerecord/test/cases/migration_test.rb
Expand Up @@ -127,16 +127,17 @@ def test_add_index
def test_add_index_length_limit
good_index_name = 'x' * Person.connection.index_name_length
too_long_index_name = good_index_name + 'x'
assert_nothing_raised { Person.connection.add_index("people", "first_name", :name => too_long_index_name) }
assert_raise(ArgumentError) { Person.connection.add_index("people", "first_name", :name => too_long_index_name) }
assert !Person.connection.index_name_exists?("people", too_long_index_name, false)
assert_nothing_raised { Person.connection.add_index("people", "first_name", :name => good_index_name) }
assert Person.connection.index_name_exists?("people", good_index_name, false)
Person.connection.remove_index("people", :name => good_index_name)
end

def test_remove_nonexistent_index
# we do this by name, so OpenBase is a wash as noted above
unless current_adapter?(:OpenBaseAdapter)
assert_nothing_raised { Person.connection.remove_index("people", "no_such_index") }
assert_raise(ArgumentError) { Person.connection.remove_index("people", "no_such_index") }
end
end

Expand All @@ -154,7 +155,7 @@ def test_rename_index
def test_double_add_index
unless current_adapter?(:OpenBaseAdapter)
Person.connection.add_index('people', [:first_name], :name => 'some_idx')
assert_nothing_raised { Person.connection.add_index('people', [:first_name], :name => 'some_idx') }
assert_raise(ArgumentError) { Person.connection.add_index('people', [:first_name], :name => 'some_idx') }
end
end

Expand Down

0 comments on commit 37de59e

Please sign in to comment.