mirror of https://github.com/rails/rails
Add a test for eql? on new objects
New objects shouldn't eql? other new objects even if the id column sets the value to a default value
This commit is contained in:
parent
d4911c1ca3
commit
cd84c0ad3a
|
@ -7,10 +7,29 @@ require "pp"
|
|||
require "models/cpk"
|
||||
|
||||
class NonExistentTable < ActiveRecord::Base; end
|
||||
class PkWithDefault < ActiveRecord::Base; end
|
||||
|
||||
class CoreTest < ActiveRecord::TestCase
|
||||
fixtures :topics
|
||||
|
||||
def test_eql_on_default_pk
|
||||
saved_record = PkWithDefault.new
|
||||
saved_record.save!
|
||||
assert_equal 123, saved_record.id
|
||||
|
||||
record = PkWithDefault.new
|
||||
assert_equal 123, record.id
|
||||
|
||||
record2 = PkWithDefault.new
|
||||
assert_equal 123, record2.id
|
||||
|
||||
assert record.eql?(record), "record should eql? itself"
|
||||
assert_not record.eql?(saved_record), "new record should not eql? saved"
|
||||
assert_not saved_record.eql?(record), "saved record should not eql? new"
|
||||
assert_not record.eql?(record2), "new record should not eql? new record"
|
||||
assert_not record2.eql?(record), "new record should not eql? new record"
|
||||
end
|
||||
|
||||
def test_inspect_class
|
||||
assert_equal "ActiveRecord::Base", ActiveRecord::Base.inspect
|
||||
assert_equal "LoosePerson(abstract)", LoosePerson.inspect
|
||||
|
|
|
@ -1392,6 +1392,10 @@ ActiveRecord::Schema.define do
|
|||
t.bigint :toooooooo_long_a_id, null: false
|
||||
t.bigint :toooooooo_long_b_id, null: false
|
||||
end
|
||||
|
||||
create_table :pk_with_defaults, id: false, force: true do |t|
|
||||
t.bigint :id, default: 123
|
||||
end
|
||||
end
|
||||
|
||||
Course.connection.create_table :courses, force: true do |t|
|
||||
|
|
Loading…
Reference in New Issue