-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add member export and fix system tests (#1114)
# What it does Adds a member and membership export to the admin UI.
- Loading branch information
Showing
12 changed files
with
155 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,72 @@ | ||
require "csv" | ||
|
||
class MemberExporter | ||
def initialize | ||
@members = Member.for_export | ||
@year_range = Membership.year_range_for_export | ||
end | ||
|
||
def export(stream) | ||
headers = [ | ||
"circulate_id", | ||
"preferred_name", | ||
"legal_name", | ||
"email", | ||
"phone", | ||
"status", | ||
"address1", | ||
"address2", | ||
"city", | ||
"region", | ||
"postal_code", | ||
"number", | ||
"pronouns", | ||
"volunteer_interest", | ||
*year_headers | ||
] | ||
|
||
stream.write(CSV.generate_line(headers)) | ||
|
||
@members.find_each(batch_size: 250) do |member| | ||
# 16 rows | ||
row = [ | ||
member.id, | ||
member.preferred_name, | ||
member.full_name, | ||
member.email, | ||
member.phone_number, | ||
member.status, | ||
member.address1, | ||
member.address2, | ||
member.city, | ||
member.region, | ||
member.postal_code, | ||
member.number, | ||
member.pronouns.join(" "), | ||
member.volunteer_interest, | ||
*year_values(member) | ||
] | ||
stream.write(CSV.generate_line(row)) | ||
end | ||
end | ||
|
||
private | ||
|
||
def year_headers | ||
@year_range.flat_map { |year| ["#{year}_amount", "#{year}_started_at"] } | ||
end | ||
|
||
def year_values(member) | ||
@year_range.flat_map { |year| | ||
started_at = member["#{year}_started_at"] | ||
amount = member["#{year}_amount"].to_i | ||
if started_at | ||
[amount / 100, started_at.to_s(:short_date)] | ||
elsif amount > 0 | ||
[amount / 100, nil] | ||
else | ||
[nil, nil] | ||
end | ||
} | ||
end | ||
end |
This file contains 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 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 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 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 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 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 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,15 @@ | ||
require "test_helper" | ||
|
||
class MemberExporterTest < ActiveSupport::TestCase | ||
test "exports Members" do | ||
create(:membership, started_at: Date.new(2020, 3, 4)) | ||
|
||
exporter = MemberExporter.new | ||
stream = StringIO.new | ||
exporter.export(stream) | ||
|
||
stream.rewind | ||
|
||
assert_equal 2, stream.read.lines.size | ||
end | ||
end |