Permalink
Browse files

Coerce strings in create_join_table.

If you accidentally pass a string and a symbol, this breaks. So
we coerce them both to strings.

Fixes #7715
  • Loading branch information...
steveklabnik committed Sep 20, 2012
1 parent 2068d30 commit 48a035712e9a4478ff248fd51ff43505d2aa2ddb
@@ -8,7 +8,7 @@ def find_join_table_name(table_1, table_2, options = {})
end
def join_table_name(table_1, table_2)
- [table_1, table_2].sort.join("_").to_sym
+ [table_1.to_s, table_2.to_s].sort.join("_").to_sym
end
end
end
@@ -759,4 +759,11 @@ def test_copying_migrations_to_empty_directory
ensure
clear
end
+
+ def test_create_join_table_with_symbol_and_string
+ connection.create_join_table :artists, 'musics'
+
+ assert_equal %w(artist_id music_id), connection.columns(:artists_musics).map(&:name).sort
+ end
+
end

3 comments on commit 48a0357

I'm wondering why this test method works because I've got errors with Ruby 1.9.3-p327 and sqlite3, mysql, mysql2 and postgresql adapters.

  1) Error:
test_create_join_table_with_symbol_and_string(CopyMigrationsTest):
NameError: undefined local variable or method `connection' for #<CopyMigrationsTest:0x00000003df56a8>
    test/cases/migration_test.rb:760:in `test_create_join_table_with_symbol_and_string'
Please sign in to comment.