diff options
author | kennyj <kennyj@gmail.com> | 2013-05-08 01:24:50 +0900 |
---|---|---|
committer | kennyj <kennyj@gmail.com> | 2013-05-08 01:24:50 +0900 |
commit | abf3fef1e68eb89173b76a8bb3afcdda3f05f0a3 (patch) | |
tree | d85a3371075bf4478550a563921eb18c3bb2e799 /activerecord/test/cases | |
parent | ca0275d36b395631725c4583db5a45c06443fdb9 (diff) | |
download | rails-abf3fef1e68eb89173b76a8bb3afcdda3f05f0a3.tar.gz rails-abf3fef1e68eb89173b76a8bb3afcdda3f05f0a3.tar.bz2 rails-abf3fef1e68eb89173b76a8bb3afcdda3f05f0a3.zip |
Fixed a bug in when using has_many association with :inverse_of option and UUID primary key.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/uuid_test.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/uuid_test.rb b/activerecord/test/cases/adapters/postgresql/uuid_test.rb index b573d48807..e4cf5d2ef6 100644 --- a/activerecord/test/cases/adapters/postgresql/uuid_test.rb +++ b/activerecord/test/cases/adapters/postgresql/uuid_test.rb @@ -93,3 +93,43 @@ class PostgresqlUUIDTestNilDefault < ActiveRecord::TestCase assert_nil col_desc["default"] end end + +class PostgresqlUUIDTestInverseOf < ActiveRecord::TestCase + class UuidPost < ActiveRecord::Base + self.table_name = 'pg_uuid_posts' + has_many :uuid_comments, inverse_of: :uuid_post + end + + class UuidComment < ActiveRecord::Base + self.table_name = 'pg_uuid_comments' + belongs_to :uuid_post + end + + def setup + @connection = ActiveRecord::Base.connection + @connection.reconnect! + + @connection.transaction do + @connection.create_table('pg_uuid_posts', id: :uuid) do |t| + t.string 'title' + end + @connection.create_table('pg_uuid_comments', id: :uuid) do |t| + t.uuid :uuid_post_id, default: 'uuid_generate_v4()' + t.string 'content' + end + end + end + + def teardown + @connection.transaction do + @connection.execute 'drop table if exists pg_uuid_comments' + @connection.execute 'drop table if exists pg_uuid_posts' + end + end + + def test_collection_association_with_uuid + post = UuidPost.create! + comment = post.uuid_comments.create! + assert post.uuid_comments.find(comment.id) + end +end |