Skip to content

Commit e83fb0b

Browse files
authored
Switch to the safe navigation operator in spec files (#3588)
Ruby now has native support safe navigation so it can sometimes be used instead of the Rails Object#try method. The change is limited to just the specs until other changes can be thoroughly verified. The safe navigation operator is different in that if the object is non-nil and the object does not respond to the method, a NoMethodError will be raised.
1 parent fa9a96b commit e83fb0b

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

spec/controllers/rails_admin/application_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
it 'works for dynamic names in the controller context' do
2525
RailsAdmin.config do |config|
26-
config.main_app_name = proc { |controller| [Rails.application.engine_name.try(:titleize), controller.params[:action].titleize] }
26+
config.main_app_name = proc { |controller| [Rails.application.engine_name&.titleize, controller.params[:action].titleize] }
2727
end
2828
controller.params[:action] = 'dashboard'
2929
expect(controller.send(:_get_plugin_name)).to eq(['Dummy App Application', 'Dashboard'])

spec/dummy_app/app/active_record/field_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FieldTest < ActiveRecord::Base
3030
attr_accessor :remove_active_storage_assets
3131

3232
after_save do
33-
Array(remove_active_storage_assets).each { |id| active_storage_assets.find_by_id(id).try(:purge) }
33+
Array(remove_active_storage_assets).each { |id| active_storage_assets.find_by_id(id)&.purge }
3434
end
3535
end
3636

0 commit comments

Comments
 (0)