From 66d8f99a30f9e6062f1bff37d5115beddce9b55d Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 18 Apr 2017 13:36:18 -0400 Subject: Admin reports with accounts (#2092) * Add a ReportFilter class * Add reports and targeted_reports relationships to Account * Use ReportFilter from admin/reports controller * Link to admin/reports filtered views from admin account show view * Add indexes to reports.account_id and reports.target_account_id --- spec/models/report_filter_spec.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 spec/models/report_filter_spec.rb (limited to 'spec') diff --git a/spec/models/report_filter_spec.rb b/spec/models/report_filter_spec.rb new file mode 100644 index 000000000..fc0b7d7b5 --- /dev/null +++ b/spec/models/report_filter_spec.rb @@ -0,0 +1,31 @@ +require 'rails_helper' + +describe ReportFilter do + describe 'with empty params' do + it 'defaults to unresolved reports list' do + filter = ReportFilter.new({}) + + expect(filter.results).to eq Report.unresolved + end + end + + describe 'with invalid params' do + it 'raises with key error' do + filter = ReportFilter.new(wrong: true) + + expect { filter.results }.to raise_error(/wrong/) + end + end + + describe 'with valid params' do + it 'combines filters on Report' do + filter = ReportFilter.new(account_id: '123', resolved: true) + + allow(Report).to receive(:where).and_return(Report.none) + allow(Report).to receive(:resolved).and_return(Report.none) + filter.results + expect(Report).to have_received(:where).with(account_id: '123') + expect(Report).to have_received(:resolved) + end + end +end -- cgit