From 73be70b87253a4f02aca0673c956132ce5438293 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Tue, 22 Jan 2019 15:41:13 -0600 Subject: [PATCH] Add Campaign Creator email to campaign export report --- lib/query/query_donations.rb | 17 +++++++++++----- spec/lib/query/query_donations_spec.rb | 28 +++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/lib/query/query_donations.rb b/lib/query/query_donations.rb index d8351aa1..eb9fdabc 100644 --- a/lib/query/query_donations.rb +++ b/lib/query/query_donations.rb @@ -26,7 +26,8 @@ module QueryDonations "#{QueryPayments.get_dedication_or_empty('contact', "phone")}::text AS \"Dedicated To: Phone\"", "#{QueryPayments.get_dedication_or_empty( "contact", "address")}::text AS \"Dedicated To: Address\"", "#{QueryPayments.get_dedication_or_empty( "note")}::text AS \"Dedicated To: Note\"", - "donations.campaign_id AS \"Campaign Id\"" + "donations.campaign_id AS \"Campaign Id\"", + "users.email AS \"Campaign Creator Email\"" ]) >>>>>>> 5c0d16c0b... Add campaign_id to export ).from(:donations) @@ -36,10 +37,16 @@ module QueryDonations .left_outer_join(:recurring_donations, "recurring_donations.donation_id = donations.id") .join_lateral(:payments, get_first_payment_for_donation.parse, true) - .where("donations.campaign_id IN (#{QueryCampaigns - .get_campaign_and_children(campaign_id) - .parse})") - .group_by("donations.id", "supporters.id", "payments.id", "payments.gross_amount") + .join(Qx.select('id, profile_id').from('campaigns') + .where("id IN (#{QueryCampaigns + .get_campaign_and_children(campaign_id) + .parse})").as('campaigns').parse, + 'donations.campaign_id=campaigns.id') + .join(Qx.select('users.id, profiles.id AS profiles_id, users.email') + .from('users') + .add_join('profiles', 'profiles.user_id = users.id') + .as("users").parse, "users.profiles_id=campaigns.profile_id") + .group_by("donations.id", "supporters.id", "payments.id", "payments.gross_amount", "users.email") .order_by("donations.date") ) end diff --git a/spec/lib/query/query_donations_spec.rb b/spec/lib/query/query_donations_spec.rb index f8a3b16a..3741b275 100644 --- a/spec/lib/query/query_donations_spec.rb +++ b/spec/lib/query/query_donations_spec.rb @@ -6,10 +6,27 @@ describe QueryDonations do describe :campaign_export do let(:nonprofit) {force_create(:nonprofit)} let(:supporter) {force_create(:supporter)} - let(:campaign) {force_create(:campaign, nonprofit:nonprofit, show_total_count:false, show_total_raised: false, goal_amount: 16000)} - let(:campaign_child) {force_create(:campaign, nonprofit:nonprofit, parent_campaign:campaign, show_total_count:true, show_total_raised: true, goal_amount: 8000)} - let(:campaign_child_2) {force_create(:campaign, nonprofit:nonprofit, parent_campaign:campaign, show_total_count:true, show_total_raised: true, goal_amount: 4000 )} + let(:profile_email) { 'something@profile_email.com'} + let(:profile) do + u = force_create(:user, email: profile_email) + profile = force_create(:profile, user: u) + end + let(:campaign) {force_create(:campaign, nonprofit:nonprofit, show_total_count:false, show_total_raised: false, goal_amount: 16000, profile: profile)} + + let(:profile_email1) { 'something1@profile_email.com'} + let(:profile1) { + u = force_create(:user, email: profile_email1) + profile = force_create(:profile, user: u) + } + let(:campaign_child) {force_create(:campaign, nonprofit:nonprofit, parent_campaign:campaign, show_total_count:true, show_total_raised: true, goal_amount: 8000, profile: profile1)} + + let(:profile_email2) { 'something2@profile_email.com'} + let(:profile2) { + u = force_create(:user, email: profile_email2) + profile = force_create(:profile, user: u) + } + let(:campaign_child_2) {force_create(:campaign, nonprofit:nonprofit, parent_campaign:campaign, show_total_count:true, show_total_raised: true, goal_amount: 4000, profile: profile2 )} let(:donation) { force_create(:donation, campaign: campaign, amount: 1000, supporter:supporter)} let(:payment) { force_create(:payment, donation: donation, gross_amount:1000, supporter:supporter)} @@ -50,6 +67,11 @@ describe QueryDonations do export = vector_to_hash(campaign_export) expect(export.map{|i| i['Campaign Id']}).to match_array([campaign.id, campaign.id, campaign_child.id, campaign_child_2.id]) end + + it 'includes user email' do + export = vector_to_hash(campaign_export) + expect(export.map{|i| i['Campaign Creator Email']}).to match_array([profile_email, profile_email, profile_email1, profile_email2]) + end end ## move to common area