diff options
author | Matthew Draper <matthew@trebex.net> | 2014-05-20 23:15:08 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2014-05-20 23:15:08 +0930 |
commit | f9860fcbe2973025df6ccf4bba0431492af09575 (patch) | |
tree | 58e6096b25fa7db7e5cee76e241b6dbee03f899a /activerecord/test | |
parent | 528aff12888aaad131baab488fa1eabe6d2634fa (diff) | |
parent | 1f4daf15f8a60e9291afc2957aa57ae347490147 (diff) | |
download | rails-f9860fcbe2973025df6ccf4bba0431492af09575.tar.gz rails-f9860fcbe2973025df6ccf4bba0431492af09575.tar.bz2 rails-f9860fcbe2973025df6ccf4bba0431492af09575.zip |
Merge pull request #14965 from eric-chahin/issue_14824
Fixed the inferred table name of a HABTM auxiliar
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/schema_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/schema_test.rb b/activerecord/test/cases/adapters/postgresql/schema_test.rb index 11ec7599a3..b9e296ed8f 100644 --- a/activerecord/test/cases/adapters/postgresql/schema_test.rb +++ b/activerecord/test/cases/adapters/postgresql/schema_test.rb @@ -50,6 +50,16 @@ class SchemaTest < ActiveRecord::TestCase self.table_name = 'things' end + class Song < ActiveRecord::Base + self.table_name = "music.songs" + has_and_belongs_to_many :albums + end + + class Album < ActiveRecord::Base + self.table_name = "music.albums" + has_and_belongs_to_many :songs + end + def setup @connection = ActiveRecord::Base.connection @connection.execute "CREATE SCHEMA #{SCHEMA_NAME} CREATE TABLE #{TABLE_NAME} (#{COLUMNS.join(',')})" @@ -109,6 +119,22 @@ class SchemaTest < ActiveRecord::TestCase assert !@connection.schema_names.include?("test_schema3") end + def test_habtm_table_name_with_schema + ActiveRecord::Base.connection.execute <<-SQL + DROP SCHEMA IF EXISTS music CASCADE; + CREATE SCHEMA music; + CREATE TABLE music.albums (id serial primary key); + CREATE TABLE music.songs (id serial primary key); + CREATE TABLE music.albums_songs (album_id integer, song_id integer); + SQL + + song = Song.create + album = Album.create + assert_equal song, Song.includes(:albums).references(:albums).first + ensure + ActiveRecord::Base.connection.execute "DROP SCHEMA music CASCADE;" + end + def test_raise_drop_schema_with_nonexisting_schema assert_raises(ActiveRecord::StatementInvalid) do @connection.drop_schema "test_schema3" |