Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fixture_kit/sql_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def self.capture(&block)
end

def self.base_table_model(model)
model = model.superclass until model.superclass.abstract_class?
model = model.superclass until model.superclass == ActiveRecord::Base || model.superclass.abstract_class?
model
end
private_class_method :base_table_model
Expand Down
4 changes: 4 additions & 0 deletions spec/dummy/app/models/gadget.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Gadget < ActiveRecord::Base
end
4 changes: 4 additions & 0 deletions spec/dummy/app/models/phone.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Phone < Gadget
end
4 changes: 4 additions & 0 deletions spec/dummy/app/models/tablet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Tablet < Gadget
end
7 changes: 7 additions & 0 deletions spec/dummy/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def setup_databases
ActiveRecord::Base.connection.drop_table(:projects, if_exists: true)
ActiveRecord::Base.connection.drop_table(:users, if_exists: true)
ActiveRecord::Base.connection.drop_table(:vehicles, if_exists: true)
ActiveRecord::Base.connection.drop_table(:gadgets, if_exists: true)
end

AnalyticsRecord.connection.disable_referential_integrity do
Expand Down Expand Up @@ -68,6 +69,12 @@ def setup_databases
t.timestamps
end

ActiveRecord::Base.connection.create_table :gadgets, force: true do |t|
t.string :type, null: false
t.string :name, null: false
t.timestamps
end

AnalyticsRecord.connection.create_table :activity_logs, force: true do |t|
t.integer :external_user_id, null: false
t.string :action, null: false
Expand Down
7 changes: 7 additions & 0 deletions spec/dummy/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def setup_databases
ActiveRecord::Base.connection.drop_table(:projects, if_exists: true)
ActiveRecord::Base.connection.drop_table(:users, if_exists: true)
ActiveRecord::Base.connection.drop_table(:vehicles, if_exists: true)
ActiveRecord::Base.connection.drop_table(:gadgets, if_exists: true)
end

AnalyticsRecord.connection.disable_referential_integrity do
Expand Down Expand Up @@ -71,6 +72,12 @@ def setup_databases
t.timestamps
end

ActiveRecord::Base.connection.create_table :gadgets, force: true do |t|
t.string :type, null: false
t.string :name, null: false
t.timestamps
end

AnalyticsRecord.connection.create_table :activity_logs, force: true do |t|
t.integer :external_user_id, null: false
t.string :action, null: false
Expand Down
7 changes: 7 additions & 0 deletions spec/support/dummy_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def setup_databases
ActiveRecord::Base.connection.drop_table(:projects, if_exists: true)
ActiveRecord::Base.connection.drop_table(:users, if_exists: true)
ActiveRecord::Base.connection.drop_table(:vehicles, if_exists: true)
ActiveRecord::Base.connection.drop_table(:gadgets, if_exists: true)
end

AnalyticsRecord.connection.disable_referential_integrity do
Expand Down Expand Up @@ -80,6 +81,12 @@ def setup_databases
t.timestamps
end

ActiveRecord::Base.connection.create_table :gadgets, force: true do |t|
t.string :type, null: false
t.string :name, null: false
t.timestamps
end

# Analytics database schema
AnalyticsRecord.connection.create_table :activity_logs, force: true do |t|
t.integer :external_user_id, null: false
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/sql_subscriber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ def exercise_user_write_operations(suffix)

expect(models).to contain_exactly(Vehicle)
end

it "resolves STI subclasses whose base model inherits directly from ActiveRecord::Base" do
models = described_class.capture do
Phone.create!(name: "iPhone")
Tablet.create!(name: "iPad")
end

expect(models).to contain_exactly(Gadget)
end
end

describe "sql.active_record payload name format assumptions" do
Expand Down