use migration helpers in spec
This commit is contained in:
@@ -48,11 +48,11 @@ RSpec.describe ActiveRecord::AuxTable do
|
||||
end
|
||||
|
||||
class Car < Vehicle
|
||||
aux_table :vehicles_car_aux
|
||||
aux_table :car
|
||||
end
|
||||
|
||||
class Boat < Vehicle
|
||||
aux_table :vehicles_boat_aux
|
||||
aux_table :boat
|
||||
end
|
||||
end
|
||||
|
||||
@@ -504,21 +504,15 @@ RSpec.describe ActiveRecord::AuxTable do
|
||||
it "raises error when auxiliary table defines column that exists in main table" do
|
||||
# Create a test schema with overlapping columns
|
||||
ActiveRecord::Schema.define do
|
||||
create_table :test_overlap_mains do |t|
|
||||
t.string :type, null: false
|
||||
create_base_table :test_overlap_mains do |t|
|
||||
t.string :name
|
||||
t.string :description
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :test_overlap_auxes do |t|
|
||||
t.references :test_overlap_main,
|
||||
null: false,
|
||||
foreign_key: {
|
||||
to_table: :test_overlap_mains
|
||||
}
|
||||
t.string :name # This overlaps with main table
|
||||
t.string :extra_data
|
||||
t.create_aux :overlap do |t|
|
||||
t.string :name
|
||||
t.string :extra_data
|
||||
end
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
@@ -530,58 +524,25 @@ RSpec.describe ActiveRecord::AuxTable do
|
||||
|
||||
expect {
|
||||
class TestOverlapChild < TestOverlapMain
|
||||
aux_table :test_overlap_auxes
|
||||
aux_table :overlap
|
||||
end
|
||||
|
||||
# Trigger schema loading to activate validation
|
||||
TestOverlapChild.load_schema
|
||||
}.to raise_error(
|
||||
ArgumentError,
|
||||
/Auxiliary table 'test_overlap_auxes' defines column\(s\) 'name'/
|
||||
)
|
||||
end
|
||||
|
||||
it "allows auxiliary table with non-overlapping columns" do
|
||||
# Create a test schema with no overlapping columns
|
||||
ActiveRecord::Schema.define do
|
||||
create_table :test_no_overlap_main do |t|
|
||||
t.string :type, null: false
|
||||
t.string :name
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :test_no_overlap_aux do |t|
|
||||
t.references :test_no_overlap_main, null: false, foreign_key: true
|
||||
t.string :fuel_type # No overlap
|
||||
t.decimal :engine_size
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
class TestNoOverlapMain < ActiveRecord::Base
|
||||
include ActiveRecord::AuxTable
|
||||
end
|
||||
|
||||
expect {
|
||||
class TestNoOverlapChild < TestNoOverlapMain
|
||||
aux_table :test_no_overlap_aux
|
||||
end
|
||||
}.not_to raise_error
|
||||
}.to raise_error(ArgumentError, /defines column\(s\) 'name'/)
|
||||
end
|
||||
|
||||
it "ignores system columns and foreign keys when checking for overlaps" do
|
||||
# Create a test schema where system columns are duplicated (which should be allowed)
|
||||
ActiveRecord::Schema.define do
|
||||
create_table :test_system_cols_main do |t|
|
||||
t.string :type, null: false
|
||||
create_base_table :test_system_cols_main do |t|
|
||||
t.string :name
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :test_system_cols_aux do |t|
|
||||
t.references :test_system_cols_main, null: false, foreign_key: true
|
||||
t.string :special_data
|
||||
t.timestamps # These are system columns and should be ignored
|
||||
t.create_aux :has_timestamps do |t|
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
@@ -591,7 +552,7 @@ RSpec.describe ActiveRecord::AuxTable do
|
||||
|
||||
expect {
|
||||
class TestSystemColsChild < TestSystemColsMain
|
||||
aux_table :test_system_cols_aux
|
||||
aux_table :has_timestamps
|
||||
end
|
||||
}.not_to raise_error
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user