Add export enumerable for supporter notes
This commit is contained in:
parent
4cd4d946c7
commit
7f74b30129
2 changed files with 69 additions and 4 deletions
|
@ -379,7 +379,30 @@ UNION DISTINCT
|
|||
end
|
||||
end
|
||||
|
||||
def self.supporter_note_export_enumerable(npo_id, query, chunk_limit=35000)
|
||||
ParamValidation.new({npo_id: npo_id, query:query}, {npo_id: {required: true, is_int: true},
|
||||
query: {required:true, is_hash: true}})
|
||||
|
||||
return QxQueryChunker.for_export_enumerable(chunk_limit) do |offset, limit, skip_header|
|
||||
get_chunk_of_supporter_note_export(npo_id, query, offset, limit, skip_header)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def self.get_chunk_of_supporter_note_export(np_id, query, offset=nil, limit=nil, skip_header=false)
|
||||
return QxQueryChunker.get_chunk_of_query(offset, limit, skip_header) do
|
||||
expr = full_filter_expr(np_id, query)
|
||||
supporter_note_select = [
|
||||
'supporters.id',
|
||||
'supporters.email',
|
||||
'supporter_notes.created_at as "Note Created At"',
|
||||
'supporter_notes.content "Note Contents"'
|
||||
]
|
||||
expr.add_join(:supporter_notes, 'supporter_notes.supporter_id = supporters.id')
|
||||
|
||||
expr.select(supporter_note_select)
|
||||
end
|
||||
end
|
||||
|
||||
# Give supp data for csv
|
||||
def self.for_export(np_id, query)
|
||||
|
|
|
@ -22,6 +22,30 @@ describe QuerySupporters do
|
|||
let(:campaign_gift2) { force_create(:campaign_gift, campaign_gift_option: campaign_gift_option, donation: donation2)}
|
||||
let(:recurring) {force_create(:recurring_donation, donation: donation2, amount: GIFT_LEVEL_CHANGED_RECURRING)}
|
||||
|
||||
let(:note_content_1) do
|
||||
"CONTENT1"
|
||||
end
|
||||
|
||||
let(:note_content_2) do
|
||||
"CONTENT2"
|
||||
end
|
||||
|
||||
let(:note_content_3) do
|
||||
"CONTENT3"
|
||||
end
|
||||
|
||||
let(:supporter_note_for_s1) do
|
||||
force_create(:supporter_note, supporter: supporter1, created_at: DateTime.new(2018,1,5), content: note_content_1)
|
||||
end
|
||||
|
||||
let(:supporter_note_1_for_s2) do
|
||||
force_create(:supporter_note, supporter: supporter2, created_at: DateTime.new(2018,2,5), content: note_content_2)
|
||||
end
|
||||
|
||||
let(:supporter_note_2_for_s2) do
|
||||
force_create(:supporter_note, supporter: supporter2, created_at: DateTime.new(2020,4, 5), content: note_content_3)
|
||||
end
|
||||
|
||||
|
||||
let(:init_all) {
|
||||
np
|
||||
|
@ -40,11 +64,8 @@ describe QuerySupporters do
|
|||
QuerySupporters.campaign_list(np.id, campaign.id, {page: 0})
|
||||
}
|
||||
|
||||
before(:each) {
|
||||
init_all
|
||||
}
|
||||
|
||||
it 'counts gift donations properly' do
|
||||
init_all
|
||||
glm = campaign_list
|
||||
|
||||
data = glm[:data]
|
||||
|
@ -52,4 +73,25 @@ describe QuerySupporters do
|
|||
expect(data.map{|i| i['total_raised']}).to match_array([GIFT_LEVEL_ONE_TIME, GIFT_LEVEL_RECURRING])
|
||||
|
||||
end
|
||||
|
||||
describe '.supporter_note_export_enumerable' do
|
||||
let(:lazy_enumerable) do
|
||||
supporter_note_for_s1
|
||||
supporter_note_1_for_s2
|
||||
supporter_note_2_for_s2
|
||||
QuerySupporters.supporter_note_export_enumerable(np.id, {})
|
||||
end
|
||||
|
||||
it 'is a lazy enumerable' do
|
||||
expect(lazy_enumerable).to be_a Enumerator::Lazy
|
||||
end
|
||||
|
||||
it 'is three items long' do
|
||||
expect(lazy_enumerable.to_a.count).to eq 4
|
||||
end
|
||||
|
||||
it 'has correct headers' do
|
||||
expect(lazy_enumerable.to_a.first).to eq ['Id', 'Email', 'Note Created At', 'Note Contents']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue