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
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ def timeline(**query)
.to eq(%w[main other])
end

# The ActiveRecord datasource skips nameless models: a name would expose the audit table as a collection.
it 'keeps its model anonymous' do
expect(store.send(:model).name).to be_nil
end

it 'lists only entries whose diff touched one of the given fields' do
store.append(record(previous_values: { 'status' => 'open' }, new_values: { 'status' => 'closed' }))
store.append(record(previous_values: { 'note' => 'a' }, new_values: { 'note' => 'b' }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def primary_key?(model)
end

def fetch_model(model)
# A collection is named after its model, so an anonymous one (such as the audit trail's) can't be one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applies to: packages/forest_admin_agent/lib/forest_admin_agent/audit_trail/store.rb:250 (not in this diff)
Claude Opus 5.5 (claude-opus-5-5): Preferential: if the audit store's model is ever given a name, Forest users see the audit table as a collection and no spec fails.

Code

store.rb:250 builds the audit model with Class.new(Sql::AuditLog), and that missing name is now all that keeps the audit table out of the schema.

A way out: assert store.send(:model).name is nil in store_spec.rb, next to the table_name check at line 272.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Opus 5.5 (claude-opus-5-5): Added keeps its model anonymous to store_spec.rb, which fails if the store ever names its audit model.

5a99639

return if model.name.nil?

if model.name.start_with?('HABTM_')
build_habtm(model)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ module ForestAdminDatasourceActiveRecord
expect(collections).to all(be_a(String))
end

describe 'with an anonymous model' do
let!(:anonymous_model) { Class.new(ActiveRecord::Base) { self.table_name = 'accounts' } }

it 'boots instead of failing on the nameless model' do
expect { described_class.new({ adapter: 'sqlite3', database: 'db/database.db' }) }.not_to raise_error
end

it 'leaves the nameless model out of the collections and keeps the named ones' do
datasource = described_class.new({ adapter: 'sqlite3', database: 'db/database.db' })

expect(datasource.collections.values.map(&:model)).not_to include(anonymous_model)
expect(datasource.collections.keys).to include('Account')
end
end

describe '#init_orm' do
it 'uses connection_pool.db_config instead of deprecated connection_db_config' do
mock_db_config = instance_double(ActiveRecord::DatabaseConfigurations::HashConfig, env_name: 'test')
Expand Down
Loading