diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 091c94676e012f49188adc4be91308ebc0a57b75..27f6fa575d0c80f9301e2f20014f3d5d15e91f10 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -16,6 +16,8 @@ require 'models/toy' require 'models/invoice' require 'models/line_item' +require 'models/column' +require 'models/record' class BelongsToAssociationsTest < ActiveRecord::TestCase fixtures :accounts, :companies, :developers, :projects, :topics, @@ -886,21 +888,9 @@ def test_reflect_the_most_recent_change end end - test 'belongs_to works with model name Record' do - Record = Class.new(ActiveRecord::Base) do - connection.create_table :records - end - - Foo = Class.new(ActiveRecord::Base) do - connection.create_table :foos do |t| - t.belongs_to :record - end - - belongs_to :record - end - + test 'belongs_to works with model called Record' do record = Record.create! - Foo.create! record: record - assert_equal 1, Foo.count + Column.create! record: record + assert_equal 1, Column.count end end diff --git a/activerecord/test/models/column.rb b/activerecord/test/models/column.rb new file mode 100644 index 0000000000000000000000000000000000000000..499358b4cf47a9d82edeb389ee67890b71a0d2a0 --- /dev/null +++ b/activerecord/test/models/column.rb @@ -0,0 +1,3 @@ +class Column < ActiveRecord::Base + belongs_to :record +end diff --git a/activerecord/test/models/record.rb b/activerecord/test/models/record.rb new file mode 100644 index 0000000000000000000000000000000000000000..f77ac9fc039d783dda37de5f9e4d47cb75177c59 --- /dev/null +++ b/activerecord/test/models/record.rb @@ -0,0 +1,2 @@ +class Record < ActiveRecord::Base +end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index a9c4980283825c98cff8731f9f43820bd483cf33..5bd3a51a8403a1b1111060982303e04f9f06de63 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -161,6 +161,10 @@ def create_table(*args, &block) t.integer :references, null: false end + create_table :columns, force: true do |t| + t.references :record + end + create_table :comments, force: true do |t| t.integer :post_id, null: false # use VARCHAR2(4000) instead of CLOB datatype as CLOB data type has many limitations in @@ -819,6 +823,8 @@ def create_table(*args, &block) t.integer :department_id end + create_table :records, force: true do |t| + end except 'SQLite' do # fk_test_has_fk should be before fk_test_has_pk