-
-
Notifications
You must be signed in to change notification settings - Fork 572
4987 annual survey export #5540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
angyb00
wants to merge
7
commits into
rubyforgood:main
Choose a base branch
from
angyb00:4987-annual-survey-export
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+245
−6
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
216fbfd
Extend annual reports controller and export csv service to handle exp…
angyb00 06f5191
optimize generate_range_csv_data to only iterate through entries once
angyb00 1027eee
specs
angyb00 888df87
update user guide
angyb00 2925e43
refactor controller and create separate reports service
angyb00 6a5b74f
update specs
angyb00 d6d8ef0
lint
angyb00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| module Reports | ||
| class AnnualSurveyReportService | ||
| def initialize(organization:, year_start:, year_end:) | ||
| @organization = organization | ||
| @year_start = year_start | ||
| @year_end = year_end | ||
| end | ||
|
|
||
| def call | ||
| (@year_start..@year_end).map do |year| | ||
| Reports.retrieve_report(organization: @organization, year: year, recalculate: true) | ||
| rescue ActiveRecord::RecordInvalid => e | ||
| Rails.logger.error("Failed to retrieve annual report for year #{year}: #{e.message}") | ||
| nil | ||
| end.compact | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+689 KB
docs/user_guide/bank/images/reports/reports-anual-survey-yearly-export.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
spec/services/reports/annual_survey_report_service_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| RSpec.describe Reports::AnnualSurveyReportService, type: :service do | ||
| let(:organization) { create(:organization) } | ||
|
|
||
| subject(:service) do | ||
| described_class.new(organization: organization, year_start: year_start, year_end: year_end) | ||
| end | ||
|
|
||
| describe "#call" do | ||
| context "with a valid year range" do | ||
| let(:year_start) { 2020 } | ||
| let(:year_end) { 2022 } | ||
|
|
||
| let(:report_2020) { instance_double(AnnualReport) } | ||
| let(:report_2021) { instance_double(AnnualReport) } | ||
| let(:report_2022) { instance_double(AnnualReport) } | ||
|
|
||
| before do | ||
| allow(Reports).to receive(:retrieve_report) | ||
| .with(hash_including(year: 2020)).and_return(report_2020) | ||
| allow(Reports).to receive(:retrieve_report) | ||
| .with(hash_including(year: 2021)).and_return(report_2021) | ||
| allow(Reports).to receive(:retrieve_report) | ||
| .with(hash_including(year: 2022)).and_return(report_2022) | ||
| end | ||
|
|
||
| it "returns one report per year in the range" do | ||
| expect(service.call).to eq([report_2020, report_2021, report_2022]) | ||
| end | ||
|
|
||
| it "calls retrieve_report with recalculate: true for each year" do | ||
| service.call | ||
| expect(Reports).to have_received(:retrieve_report) | ||
| .with(hash_including(organization: organization, year: 2020, recalculate: true)) | ||
| expect(Reports).to have_received(:retrieve_report) | ||
| .with(hash_including(organization: organization, year: 2021, recalculate: true)) | ||
| expect(Reports).to have_received(:retrieve_report) | ||
| .with(hash_including(organization: organization, year: 2022, recalculate: true)) | ||
| end | ||
| end | ||
|
|
||
| context "with a single year range" do | ||
| let(:year_start) { 2021 } | ||
| let(:year_end) { 2021 } | ||
|
|
||
| let(:report_2021) { instance_double(AnnualReport) } | ||
|
|
||
| before do | ||
| allow(Reports).to receive(:retrieve_report) | ||
| .with(hash_including(year: 2021)).and_return(report_2021) | ||
| end | ||
|
|
||
| it "returns a single report" do | ||
| expect(service.call).to eq([report_2021]) | ||
| end | ||
| end | ||
|
|
||
| context "when a year's report raises ActiveRecord::RecordInvalid" do | ||
| let(:year_start) { 2020 } | ||
| let(:year_end) { 2022 } | ||
|
|
||
| let(:report_2020) { instance_double(AnnualReport) } | ||
| let(:report_2022) { instance_double(AnnualReport) } | ||
|
|
||
| before do | ||
| allow(Reports).to receive(:retrieve_report) | ||
| .with(hash_including(year: 2020)).and_return(report_2020) | ||
| allow(Reports).to receive(:retrieve_report) | ||
| .with(hash_including(year: 2021)).and_raise(ActiveRecord::RecordInvalid) | ||
| allow(Reports).to receive(:retrieve_report) | ||
| .with(hash_including(year: 2022)).and_return(report_2022) | ||
| end | ||
|
|
||
| it "skips the failed year and returns the remaining reports" do | ||
| expect(service.call).to eq([report_2020, report_2022]) | ||
| end | ||
|
|
||
| it "logs the error" do | ||
| allow(Rails.logger).to receive(:error) | ||
| service.call | ||
| expect(Rails.logger).to have_received(:error).with(/Failed to retrieve annual report for year 2021/) | ||
| end | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might make sense to pair with #5495. Not sure if using this with actual data might time out right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's reasonable. I saw that the PR was stale, so I just created a new PR based off it here: #5542. The new PR contains some changes based on the feedback. I think we should release that PR first to see that everything is working fine for distributions, and then I can update this PR once those changes are successfully integrated. How does that sound?