Testing ActiveRecord Safe Send Implementation in rails_admin
This test suite examines the ActiveRecord extensions implemented in Rails Admin, specifically focusing on the safe_send method functionality. The tests validate the optimized attribute reading behavior to ensure efficient database interactions and prevent redundant calls.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
railsadminteam/rails_admin
spec/rails_admin/active_record_extension_spec.rb
# frozen_string_literal: true
require 'spec_helper'
require File.expand_path('../../config/initializers/active_record_extensions', __dir__)
RSpec.describe 'ActiveRecord::Base', active_record: true do
describe '#safe_send' do
it 'only calls #read_attribute once' do
@player = Player.new
@player.number = 23
original_method = @player.method(:read_attribute)
expect(@player).to receive(:read_attribute).exactly(1).times do |*args|
original_method.call(*args)
end
expect(@player.safe_send(:number)).to eq(23)
end
end
end