diff --git a/lib/frozen_record/scope.rb b/lib/frozen_record/scope.rb index 1116876..05f54d5 100644 --- a/lib/frozen_record/scope.rb +++ b/lib/frozen_record/scope.rb @@ -169,7 +169,9 @@ def query_results end def matching_records - sort_records(select_records(@klass.load_records)) + ActiveSupport::Notifications.instrument 'query.frozen_record', path: @klass.file_path do + sort_records(select_records(@klass.load_records)) + end end def select_records(records) diff --git a/spec/scope_spec.rb b/spec/scope_spec.rb index e7eec52..a686395 100644 --- a/spec/scope_spec.rb +++ b/spec/scope_spec.rb @@ -460,4 +460,20 @@ end + describe 'ActiveSupport::Notification' do + + it 'sends a notification' do + callbacks = [] + ActiveSupport::Notifications.subscribe('query.frozen_record') do |_, _, _, _, data| + callbacks << data + end + + ids = Country.where(name: 'France').first + + expect(callbacks.count).to be 1 + expect(callbacks[0][:path]).to include('spec/fixtures/countries.yml.erb') + end + + end + end