Skip to content

Commit

Permalink
remove the index on the foreign key of the translation table when the…
Browse files Browse the repository at this point in the history
… table is dropped.

added tests and addition to test_helper - Thank you http://github.com/sgt
  • Loading branch information
hukl committed Jul 21, 2009
1 parent a24f438 commit 8b455c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/globalize/model/active_record/translated.rb
Expand Up @@ -107,6 +107,9 @@ def create_translation_table!(fields)

def drop_translation_table!
translation_table_name = self.name.underscore + '_translations'
self.connection.remove_index(
translation_table_name, "#{self.table_name.singularize}_id"
)
self.connection.drop_table translation_table_name
end

Expand Down
7 changes: 6 additions & 1 deletion test/model/active_record/migration_test.rb
Expand Up @@ -15,8 +15,10 @@ def setup

test 'globalize table added' do
assert !Post.connection.table_exists?( :post_translations )
assert !Post.connection.index_exists?( :post_translations, :post_id )
Post.create_translation_table! :subject => :string, :content => :text
assert Post.connection.table_exists?( :post_translations )
assert Post.connection.index_exists?( :post_translations, :post_id )
columns = Post.connection.columns( :post_translations )
assert locale = columns.detect {|c| c.name == 'locale' }
assert_equal :string, locale.type
Expand All @@ -34,10 +36,13 @@ def setup

test 'globalize table dropped' do
assert !Post.connection.table_exists?( :post_translations )
assert !Post.connection.index_exists?( :post_translations, :post_id )
Post.create_translation_table! :subject => :string, :content => :text
assert Post.connection.table_exists?( :post_translations )
assert Post.connection.table_exists?( :post_translations )
assert Post.connection.index_exists?( :post_translations, :post_id )
Post.drop_translation_table!
assert !Post.connection.table_exists?( :post_translations )
assert !Post.connection.index_exists?( :post_translations, :post_id )
end

test 'exception on untranslated field inputs' do
Expand Down
10 changes: 10 additions & 0 deletions test/test_helper.rb
Expand Up @@ -23,4 +23,14 @@ def assert_member(item, arr)
arr.member? item
end
end
end

module ActiveRecord
module ConnectionAdapters
class AbstractAdapter
def index_exists?(table_name, column_name)
indexes(table_name).any? { |index| index.name == index_name(table_name, column_name) }
end
end
end
end

0 comments on commit 8b455c3

Please sign in to comment.