From d2a615512f28c8d7fe754f357308c54ff177174e Mon Sep 17 00:00:00 2001 From: Winson Wan Date: Tue, 5 Mar 2024 10:26:58 -0800 Subject: [PATCH 01/21] add account_code_string url parameter to quick_donate route --- config/routes.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 522344c7c..49c61bc1c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,7 +7,7 @@ resources :account_codes, :except => :show resources :ticket_sales_imports, :except => [:new] resources :labels, :only => [:index, :create, :update, :destroy] - resources :seatmaps, :except => [:new] + resources :seatmaps, :except => [:new] resources :seating_zones, :only => [:index, :create, :destroy] resources :customers, :except => :destroy do @@ -75,7 +75,7 @@ resources :shows, :except => [:show] do resources :showdates, :except => [:index] end - + resources :valid_vouchers, :except => [:index] resources :vouchertypes do member do @@ -129,7 +129,7 @@ # quick-donation neither requires nor sets customer-id: - get '/donate/(:customer_id)' => 'store#donate', :as => 'quick_donate' + get 'donate(/:customer_id(/:account_code_string))' => 'store#donate', :as => 'quick_donate' post '/process_donation/(:customer_id)' => 'store#process_donation', :as => 'process_donation' # config options From 73d0de93b81ed8dc80003ae8c7c812d5dc70ab3f Mon Sep 17 00:00:00 2001 From: Winson Wan Date: Tue, 5 Mar 2024 10:28:28 -0800 Subject: [PATCH 02/21] add account_code_string hidden form field to donate view so that it is accessible as param in store_controller#process_donation --- app/views/store/donate.html.haml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/store/donate.html.haml b/app/views/store/donate.html.haml index b8be754f2..0111adf98 100644 --- a/app/views/store/donate.html.haml +++ b/app/views/store/donate.html.haml @@ -32,6 +32,7 @@ = form_tag(process_donation_path, {:id => '_stripe_payment_form', :onsubmit => 'return confirmAndSubmit()' }) do = hidden_field_tag 'referer', 'donate' = hidden_field_tag 'customer_id', @customer.id + = hidden_field_tag 'account_code_string', @account_code_string #billing= render :partial => 'customers/billing_address', :locals => {:customer => @customer} %fieldset#donation_info From c83607f4a279ed8240d9c020fbf702e82be6e6f2 Mon Sep 17 00:00:00 2001 From: Winson Wan Date: Tue, 5 Mar 2024 10:31:15 -0800 Subject: [PATCH 03/21] handle account code (valid, invalid -> redirect, blank -> use default) --- app/controllers/store_controller.rb | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/app/controllers/store_controller.rb b/app/controllers/store_controller.rb index 439e5e5c8..a255c2d97 100644 --- a/app/controllers/store_controller.rb +++ b/app/controllers/store_controller.rb @@ -118,22 +118,38 @@ def donate @customer = Customer.new session[:guest_checkout] = true end + # if account_code_string is in url, but doesn't correspond to an existing account in AccountCode model, + # then redirect to /donate with default account code inserted into url + if params[:account_code_string] && AccountCode.where(code: params[:account_code_string]).empty? + return redirect_to( + quick_donate_path( + :customer_id => @customer.id, + :account_code_string => Donation.default_code.code), :alert => "Invalid Fund ID") + else # account_code_string is nil (handled in #process_donation) or valid (exists in url and model) + @account_code_string = params[:account_code_string] + end end def process_donation @amount = to_numeric(params[:donation]) + @account_code = AccountCode.where(code: params[:account_code_string])[0] || Donation.default_code if params[:customer_id].blank? customer_params = params.require(:customer).permit(Customer.user_modifiable_attributes) @customer = Customer.for_donation(customer_params) - @customer.errors.empty? or return redirect_to(quick_donate_path(:customer => params[:customer], :donation => @amount), :alert => "Incomplete or invalid donor information: #{@customer.errors.as_html}") + @customer.errors.empty? or return redirect_to( + quick_donate_path( + :customer => params[:customer], + :account_code_string => @account_code.code, + :donation => @amount), + :alert => "Incomplete or invalid donor information: #{@customer.errors.as_html}") else # we got here via a logged-in customer @customer = Customer.find params[:customer_id] end # At this point, the customer has been persisted, so future redirects just use the customer id. - redirect_route = quick_donate_path(:customer_id => @customer.id, :donation => @amount) + redirect_route = quick_donate_path(:customer_id => @customer.id, :account_code_string => @account_code.code, :donation => @amount) @amount > 0 or return redirect_to(redirect_route, :alert => 'Donation amount must be provided') # Given valid donation, customer, and charge token, create & place credit card order. - @gOrderInProgress = Order.new_from_donation(@amount, Donation.default_code, @customer) + @gOrderInProgress = Order.new_from_donation(@amount, @account_code, @customer) @gOrderInProgress.purchasemethod = Purchasemethod.get_type_by_name('web_cc') @gOrderInProgress.purchase_args = {:credit_card_token => params[:credit_card_token]} @gOrderInProgress.processed_by = @customer @@ -311,7 +327,7 @@ def referer_target promo_code_args = (@promo.blank? ? {} : {:promo_code => @promo}) redirect_target = case params[:referer].to_s - when 'donate' then quick_donate_path # no @customer assumed + when 'donate' then quick_donate_path(:account_code_string => params[:account_code_string]) # no @customer assumed when 'donate_to_fund' then donate_to_fund_path(params[:account_code_id], @customer) when 'subscribe' then store_subscribe_path(@customer,promo_code_args) when 'index' then store_path(@customer, promo_code_args.merge(:what => params[:what], :showdate_id => params[:showdate_id])) From e2c7aef211f6c31457235b79692be415cc8fee68 Mon Sep 17 00:00:00 2001 From: Winson Wan Date: Tue, 5 Mar 2024 10:41:54 -0800 Subject: [PATCH 04/21] modify existing tests to expect correct redirect url (to include account code string in path) --- spec/controllers/store_controller_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/controllers/store_controller_spec.rb b/spec/controllers/store_controller_spec.rb index d006b981c..7aa078835 100644 --- a/spec/controllers/store_controller_spec.rb +++ b/spec/controllers/store_controller_spec.rb @@ -3,7 +3,7 @@ describe StoreController do before :each do ; @buyer = create(:customer) ; end - + shared_examples_for 'initial visit' do before :each do @r = {:controller => 'store', :action => 'index'} @@ -112,7 +112,7 @@ it 'redirects having created the customer' do post :process_donation, {:customer => @new_valid_customer, :donation => 5, :credit_card_token => 'dummy'} created_customer = Customer.find_by!(:email => @new_valid_customer[:email]) - expect(response).to redirect_to(quick_donate_path(:donation => 5, :customer_id => created_customer.id)) + expect(response).to redirect_to(quick_donate_path(:donation => 5, :customer_id => created_customer.id, :account_code_string => Donation.default_code.code)) end it 'shows error message' do post :process_donation, {:customer => @new_valid_customer, :donation => 5, :credit_card_token => 'dummy'} @@ -123,7 +123,7 @@ it 'redirects having created the customer' do post :process_donation, {:customer => @new_valid_customer, :credit_card_token => 'dummy'} created_customer = Customer.find_by!(:email => @new_valid_customer[:email]) - expect(response).to redirect_to(quick_donate_path(:donation => 0, :customer_id => created_customer.id)) + expect(response).to redirect_to(quick_donate_path(:donation => 0, :customer_id => created_customer.id, :account_code_string => Donation.default_code.code)) end it 'shows error message' do post :process_donation, :customer => @new_valid_customer, :credit_card_token => 'dummy' @@ -147,7 +147,7 @@ expect(flash[:alert]).to match(/Incomplete or invalid donor/i) end end - + end describe "processing empty cart" do before :each do From b843476f8c860394a0f1c881665e0bfe932ef7c5 Mon Sep 17 00:00:00 2001 From: Winson Wan Date: Tue, 5 Mar 2024 18:58:08 -0800 Subject: [PATCH 05/21] remove account_code_string as bounded url parameter (will be passed as query parameter instead) --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 49c61bc1c..553d7f8a0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -129,7 +129,7 @@ # quick-donation neither requires nor sets customer-id: - get 'donate(/:customer_id(/:account_code_string))' => 'store#donate', :as => 'quick_donate' + get 'donate(/:customer_id)' => 'store#donate', :as => 'quick_donate' post '/process_donation/(:customer_id)' => 'store#process_donation', :as => 'process_donation' # config options From c1e4056bef076b25e820acbc522fd313e51340a4 Mon Sep 17 00:00:00 2001 From: Winson Wan Date: Tue, 5 Mar 2024 21:59:55 -0800 Subject: [PATCH 06/21] redirect /donate to /donate/:Donation.default_code.code --- app/controllers/store_controller.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/controllers/store_controller.rb b/app/controllers/store_controller.rb index a255c2d97..dcbe24701 100644 --- a/app/controllers/store_controller.rb +++ b/app/controllers/store_controller.rb @@ -118,15 +118,13 @@ def donate @customer = Customer.new session[:guest_checkout] = true end - # if account_code_string is in url, but doesn't correspond to an existing account in AccountCode model, - # then redirect to /donate with default account code inserted into url - if params[:account_code_string] && AccountCode.where(code: params[:account_code_string]).empty? - return redirect_to( - quick_donate_path( - :customer_id => @customer.id, - :account_code_string => Donation.default_code.code), :alert => "Invalid Fund ID") - else # account_code_string is nil (handled in #process_donation) or valid (exists in url and model) + # account_code_string is valid + if params[:account_code_string] && !AccountCode.where(code: params[:account_code_string]).empty? @account_code_string = params[:account_code_string] + elsif params[:account_code_string].nil? # account_code_string is nil, so redirect with default code inserted into url + return redirect_to(quick_donate_path(:customer_id => @customer.id, :account_code_string => Donation.default_code.code)) + else # account_code_string is invalid, so redirect with default code inserted into url + display error message + return redirect_to(quick_donate_path(:customer_id => @customer.id, :account_code_string => Donation.default_code.code), :alert => "Invalid Fund ID") end end From a230d544b318c98e621c786fcab49b3072a27b20 Mon Sep 17 00:00:00 2001 From: Winson Wan Date: Tue, 5 Mar 2024 22:00:18 -0800 Subject: [PATCH 07/21] modify existing tests to expect correct redirect url --- spec/controllers/store_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/store_controller_spec.rb b/spec/controllers/store_controller_spec.rb index 7aa078835..4243ee8ff 100644 --- a/spec/controllers/store_controller_spec.rb +++ b/spec/controllers/store_controller_spec.rb @@ -133,7 +133,7 @@ context 'when new customer not valid as purchaser' do before(:each) do @invalid_customer = attributes_for(:customer).except(:city,:state) - @params = {:customer => @invalid_customer, :donation => 5, :credit_card_token => 'dummy'} + @params = {:customer => @invalid_customer, :donation => 5, :credit_card_token => 'dummy', :account_code_string => Donation.default_code.code} end it 'does not create new customer' do expect { post :process_donation, @params }.not_to change { Customer.all.size } From 43823d2557991bc0f8bf3b970b0a83566bb10f1b Mon Sep 17 00:00:00 2001 From: Winson Wan Date: Wed, 6 Mar 2024 04:03:54 -0800 Subject: [PATCH 08/21] create tests for initiating recurring donation in store_controller#process_donation --- spec/controllers/store_controller_spec.rb | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/controllers/store_controller_spec.rb b/spec/controllers/store_controller_spec.rb index 4243ee8ff..b683db4d3 100644 --- a/spec/controllers/store_controller_spec.rb +++ b/spec/controllers/store_controller_spec.rb @@ -101,6 +101,36 @@ end end + describe 'initiating a recurring donation' do + before :each do + @customer = create(:customer) + end + let (:monthly_donation_attempt) { + post :process_donation, + {:customer_id => @customer.id, :donation => 5, :donation_frequency => 'monthly', :credit_card_token => 'dummy'} + } + context 'when donation completes successful' do + before :each do + allow(Stripe::Charge).to receive(:create).and_return(double("Stripe::Charge", id: 1)) + end + it 'creates a new RecurringDonation record' do + expect{monthly_donation_attempt}.to change {RecurringDonation.count}.by(1) + end + it 'adds a foreign key to the corresponding first donation instance' do + monthly_donation_attempt + expect(Donation.find(1).recurring_donation_id).to equal(RecurringDonation.find(1).id) + end + end + context 'when donation completes unsuccessfully' do + before :each do + allow(Stripe::Charge).to receive(:create).and_raise(Stripe::StripeError) + end + it 'does not create new RecurringDonation record if order fails to finalize' do + expect{monthly_donation_attempt}.to change {RecurringDonation.count}.by(0) + end + end + end + describe 'quick donation with nonexistent customer' do before :each do @new_valid_customer = attributes_for(:customer).except(:password,:password_confirmation) From 9580ad3346429001a6c67b669891ce685d6f91d2 Mon Sep 17 00:00:00 2001 From: Winson Wan Date: Wed, 6 Mar 2024 05:34:13 -0800 Subject: [PATCH 09/21] create outline for tests for account_code_string url query param in store_controller#donate --- spec/controllers/store_controller_spec.rb | 36 +++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/spec/controllers/store_controller_spec.rb b/spec/controllers/store_controller_spec.rb index b683db4d3..bb03704f4 100644 --- a/spec/controllers/store_controller_spec.rb +++ b/spec/controllers/store_controller_spec.rb @@ -101,21 +101,51 @@ end end - describe 'initiating a recurring donation' do + describe '#donate: handle account_code_string in URL query parameter' do + context 'when account_code_string is nil (does not exist in URL)' do + it 'redirects to /donate/?account_code_string=' do + + end + end + context 'when account_code_string is invalid (exists in URL but does not correspond to existing AccountCode)' do + it 'redirects to /donate/?account_code_string= and displays error message' do + + end + end + context 'when account_code_string is valid (exists in URL and corresponds to existing AccountCode)' do + it 'creates Donation record with correct account_code_id if transaction completes successfully' do + + end + it 'redirects to /donate with the same valid account_code_string if transactions fails' do + + end + end + end + + describe '#process_donation: start a recurring donation' do before :each do @customer = create(:customer) end let (:monthly_donation_attempt) { post :process_donation, - {:customer_id => @customer.id, :donation => 5, :donation_frequency => 'monthly', :credit_card_token => 'dummy'} + {:customer_id => @customer.id, :donation => 5, :donation_frequency => 'monthly', :credit_card_token => 'dummy', :comments => 'hello I am making a donation'} } - context 'when donation completes successful' do + context 'when donation completes successfully' do before :each do allow(Stripe::Charge).to receive(:create).and_return(double("Stripe::Charge", id: 1)) end it 'creates a new RecurringDonation record' do expect{monthly_donation_attempt}.to change {RecurringDonation.count}.by(1) end + it 'sets new RecurringDonation record attributes to correct values' do + monthly_donation_attempt + recurring_donation_record = RecurringDonation.find(1) + donation_record = Donation.find(1) + expect(recurring_donation_record.account_code_id).to(equal(donation_record.account_code_id)) + expect(recurring_donation_record.customer_id).to(equal(donation_record.customer_id)) + expect(recurring_donation_record.amount).to(equal(donation_record.amount)) + expect(recurring_donation_record.comments).to(equal(donation_record.comments)) + end it 'adds a foreign key to the corresponding first donation instance' do monthly_donation_attempt expect(Donation.find(1).recurring_donation_id).to equal(RecurringDonation.find(1).id) From f7cee69ecaa6228eb9d8817b9637674951fb0d54 Mon Sep 17 00:00:00 2001 From: MayZamudio Date: Mon, 11 Mar 2024 19:48:12 -0700 Subject: [PATCH 10/21] modify the view so it displays the name and description of the account code --- app/controllers/store_controller.rb | 3 +++ app/views/store/donate.html.haml | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/store_controller.rb b/app/controllers/store_controller.rb index dcbe24701..b3bac21cc 100644 --- a/app/controllers/store_controller.rb +++ b/app/controllers/store_controller.rb @@ -121,6 +121,9 @@ def donate # account_code_string is valid if params[:account_code_string] && !AccountCode.where(code: params[:account_code_string]).empty? @account_code_string = params[:account_code_string] + @account_code_info = AccountCode.find_by_code(@account_code_string) + @account_code_name = @account_code_info.name + @account_code_description = @account_code_info.description elsif params[:account_code_string].nil? # account_code_string is nil, so redirect with default code inserted into url return redirect_to(quick_donate_path(:customer_id => @customer.id, :account_code_string => Donation.default_code.code)) else # account_code_string is invalid, so redirect with default code inserted into url + display error message diff --git a/app/views/store/donate.html.haml b/app/views/store/donate.html.haml index 0111adf98..f1d0871af 100644 --- a/app/views/store/donate.html.haml +++ b/app/views/store/donate.html.haml @@ -26,8 +26,8 @@ #store #quick_donation - %h1.text-center= sanitize(Option.quick_donation_banner) - %p.text-center.lead-= sanitize(Option.quick_donation_explanation) + %h1.text-center= @account_code_name + %p.text-center.lead-= @account_code_description = form_tag(process_donation_path, {:id => '_stripe_payment_form', :onsubmit => 'return confirmAndSubmit()' }) do = hidden_field_tag 'referer', 'donate' From 7c337d3d98950e9c548a04cd556995a743be0544 Mon Sep 17 00:00:00 2001 From: Pratyush Sharma Date: Tue, 12 Mar 2024 14:03:31 -0700 Subject: [PATCH 11/21] Quick Donation Tests --- features/donations/quick_donation.feature | 32 +++++++++++++++++++++++ features/support/paths.rb | 1 + 2 files changed, 33 insertions(+) diff --git a/features/donations/quick_donation.feature b/features/donations/quick_donation.feature index 79bb34a58..d9955053f 100644 --- a/features/donations/quick_donation.feature +++ b/features/donations/quick_donation.feature @@ -5,6 +5,11 @@ Feature: quick donation without logging in To make it easier for people to donate I want to provide a way to donate with a credit card without logging in +Background: + Given the following account codes exist: + | name | code | description | donation_prompt | + | Soda Fund | 0504 | The Soda Funds aims to put a Soda Fountain in Soda Hall | | + Scenario: donor logged in, page gets prepopulated with donor info Given a donation of $10 on 2009-12-01 from "Tom Foolery" to the "General Fund" @@ -92,3 +97,30 @@ Scenario: admin logged in, records donation on behalf of patron And customer "Joe Mallon" should have a donation of $9.00 to "General Fund" And an email should be sent to customer "Joe Mallon" containing "$ 9.00 Donation to General Fund" +Scenario: landing on quick donation page with valid account code + Given I am logged in as customer "Tom Foolery" + When I visit the quick donation landing page for account code 0504 + Then I should not see "Donate to" + And I should see "Soda Fund" + And I should see "The Soda Funds aims to put a Soda Fountain in Soda Hall Address" + +Scenario: landing on quick donation page with invalid account code + Given I am logged in as customer "Tom Foolery" + When I visit the quick donation landing page for account code 0505 + Then I should see "Invalid Fund ID" + +Scenario: landing on quick donation page with no account code + Given I am logged in as customer "Tom Foolery" + When I go to the quick donation page + Then I should not see "Donate to" + Then I should see "General Fund" + Then I should see "General Fund Address" + +Scenario: landing on quick donation page with valid account code and making quick donation + Given I am logged in as customer "Tom Foolery" + When I go to the quick donation page + When I fill in "Donation amount" with "15" + And I press "Charge Donation to Credit Card" + Then I should see "You have paid a total of $15.00 by Credit card" + And customer "Tom Foolery" should have a donation of $15.00 to "Soda Fund" + diff --git a/features/support/paths.rb b/features/support/paths.rb index 7a6259527..1921e2478 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -79,6 +79,7 @@ def path_to(page_name) when /the donation landing page coded for fund (.*)/i then donate_to_fund_path(AccountCode.find_by_code!($1)) when /the donation landing page coded for a nonexistent fund/i then donate_to_fund_path('999999') + when /the quick donation landing page for account code (.*)/i then '/donate/1?account_code_string=' + $1.to_s when /the edit page for the "(.*)" vouchertype/ then edit_vouchertype_path(Vouchertype.find_by_name!($1)) From 15788b6bf85728381e840ac10597069a9b3354ff Mon Sep 17 00:00:00 2001 From: Winson Wan Date: Wed, 13 Mar 2024 11:05:42 -0700 Subject: [PATCH 12/21] delete remnants of recurring donation feature from this branch --- app/assets/javascripts/recurring_donations.js | 2 - .../stylesheets/recurring_donations.scss | 3 - app/controllers/options_controller.rb | 4 +- .../recurring_donations_controller.rb | 2 - app/controllers/store_controller.rb | 7 --- app/helpers/recurring_donations_helper.rb | 2 - app/models/items/donation.rb | 8 +-- app/models/recurring_donation.rb | 16 ----- app/views/options/index.html.haml | 32 ---------- app/views/store/donate.html.haml | 8 --- config/locales/en.option_descriptions.yml | 23 ------- config/routes.rb | 6 +- ...rring_donation_options_to_options_table.rb | 9 --- ...240229121243_create_recurring_donations.rb | 13 ---- db/schema.rb | 39 ++++-------- .../recurring_donations_controller_spec.rb | 5 -- spec/controllers/store_controller_spec.rb | 60 ------------------- spec/factories/recurring_donations.rb | 5 -- .../recurring_donations_helper_spec.rb | 15 ----- spec/models/recurring_donation_spec.rb | 5 -- 20 files changed, 19 insertions(+), 245 deletions(-) delete mode 100644 app/assets/javascripts/recurring_donations.js delete mode 100644 app/assets/stylesheets/recurring_donations.scss delete mode 100644 app/controllers/recurring_donations_controller.rb delete mode 100644 app/helpers/recurring_donations_helper.rb delete mode 100644 app/models/recurring_donation.rb delete mode 100644 db/migrate/20240225093946_add_recurring_donation_options_to_options_table.rb delete mode 100644 db/migrate/20240229121243_create_recurring_donations.rb delete mode 100644 spec/controllers/recurring_donations_controller_spec.rb delete mode 100644 spec/factories/recurring_donations.rb delete mode 100644 spec/helpers/recurring_donations_helper_spec.rb delete mode 100644 spec/models/recurring_donation_spec.rb diff --git a/app/assets/javascripts/recurring_donations.js b/app/assets/javascripts/recurring_donations.js deleted file mode 100644 index dee720fac..000000000 --- a/app/assets/javascripts/recurring_donations.js +++ /dev/null @@ -1,2 +0,0 @@ -// Place all the behaviors and hooks related to the matching controller here. -// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/recurring_donations.scss b/app/assets/stylesheets/recurring_donations.scss deleted file mode 100644 index 7f2ad587d..000000000 --- a/app/assets/stylesheets/recurring_donations.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the recurring_donations controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/options_controller.rb b/app/controllers/options_controller.rb index c5ccf02b9..5458c61cd 100644 --- a/app/controllers/options_controller.rb +++ b/app/controllers/options_controller.rb @@ -1,7 +1,7 @@ class OptionsController < ApplicationController before_filter :is_admin_filter - + def index @o = Option.first end @@ -15,8 +15,6 @@ def update option_params['advance_sales_cutoff'].to_i * params['before_or_after'].to_i # if there is a file upload for HTML template, get it option_params['html_email_template'] = params['html_email_template'].read unless params['html_email_template'].blank? - # if recurring donations not allowed, set default_donation_type to one time - option_params['default_donation_type'] = 'one' unless option_params['allow_recurring_donations'] == 'true' if (@o.update_attributes(option_params)) redirect_to options_path, :notice => "Update successful." else diff --git a/app/controllers/recurring_donations_controller.rb b/app/controllers/recurring_donations_controller.rb deleted file mode 100644 index fd98e442e..000000000 --- a/app/controllers/recurring_donations_controller.rb +++ /dev/null @@ -1,2 +0,0 @@ -class RecurringDonationsController < ApplicationController -end diff --git a/app/controllers/store_controller.rb b/app/controllers/store_controller.rb index b3bac21cc..50063c238 100644 --- a/app/controllers/store_controller.rb +++ b/app/controllers/store_controller.rb @@ -156,19 +156,12 @@ def process_donation @gOrderInProgress.processed_by = @customer @gOrderInProgress.comments = params[:comments].to_s @gOrderInProgress.ready_for_purchase? or return redirect_to(redirect_route, :alert => @gOrderInProgress.errors.as_html) - # if customer checks 'monthly' donation radio button, then create (and save) a new recurring donation instance - if params[:donation_frequency] == 'monthly' - @recurring_donation = RecurringDonation.from_order_w_first_donation_and_save(@gOrderInProgress) - @gOrderInProgress.donation.recurring_donation_id = @recurring_donation.id - end if finalize_order(@gOrderInProgress, send_email_confirmation: @gOrderInProgress.purchaser.valid_email_address?) # forget customer after successful guest checkout @guest_checkout = true logout_keeping_session! render :action => 'place_order' else - # if order fails to finalize, destroy recurring donation row - @recurring_donation.destroy if @recurring_donation redirect_to redirect_route, :alert => @gOrderInProgress.errors.as_html end end diff --git a/app/helpers/recurring_donations_helper.rb b/app/helpers/recurring_donations_helper.rb deleted file mode 100644 index e983f9fd8..000000000 --- a/app/helpers/recurring_donations_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module RecurringDonationsHelper -end diff --git a/app/models/items/donation.rb b/app/models/items/donation.rb index be772334d..de350c3c3 100644 --- a/app/models/items/donation.rb +++ b/app/models/items/donation.rb @@ -6,15 +6,13 @@ class Donation < Item def self.default_code AccountCode.find(Option.default_donation_account_code) end - + belongs_to :account_code validates_associated :account_code validates_presence_of :account_code_id - + belongs_to :customer - - belongs_to :recurring_donation - + validates_numericality_of :amount validates_inclusion_of :amount, :in => 1..10_000_000, :message => "must be at least 1 dollar" diff --git a/app/models/recurring_donation.rb b/app/models/recurring_donation.rb deleted file mode 100644 index 8a253539c..000000000 --- a/app/models/recurring_donation.rb +++ /dev/null @@ -1,16 +0,0 @@ -class RecurringDonation < ActiveRecord::Base - - belongs_to :account_code - belongs_to :customer - has_many :donations - - def self.from_order_w_first_donation_and_save(order) - @recurring_donation = RecurringDonation.create!( - account_code_id: order.donation.account_code_id, - customer_id: order.customer_id, - amount: order.donation.amount, - comments: order.donation.comments) - @recurring_donation - end - -end diff --git a/app/views/options/index.html.haml b/app/views/options/index.html.haml index 9ce51fbcf..e334fa049 100644 --- a/app/views/options/index.html.haml +++ b/app/views/options/index.html.haml @@ -1,14 +1,3 @@ -:javascript - // Hide default donation type radio group unless recurring donations are allowed - function showDefaultDonation(select_allow_recurring_donations) { - var row = document.getElementById('default_donation_type_form_row'); - if (select_allow_recurring_donations.value == 'true') { - row.style.visibility = 'visible'; - } else { - row.style.visibility = 'hidden'; - } - } - = form_for @o, :html => {:multipart => true, :id => 'edit_options_form'} do |f| .card.my-1 .card-header.h3 Your Venue Contact Info @@ -52,27 +41,6 @@ quick_donation_redirect | donation_ack_from | ) | - .form-row - .col-md-4.text-right - %label.col-form-label Allow Monthly Recurring Donations - = option_description_for(:allow_recurring_donations) - .col-md-8 - = f.select :allow_recurring_donations, [['Yes', true], ['No', false]], {}, {:class => 'form-control', onchange: 'showDefaultDonation(this)'} - .form-row{id:"default_donation_type_form_row", style:"visibility: #{@o.allow_recurring_donations ? 'visible' : 'hidden'}"} - .col-md-4.text-right - %label.col-form-label Default Donation Type - = option_description_for(:default_donation_type) - .col-md-8 - .radio-group.form-inline - = f.radio_button :default_donation_type, 'one', :class => 'form-control', :id => 'one' - = f.label :default_donation_type, 'One Time', :class => 'form-control', :for => 'one' - = f.radio_button :default_donation_type, 'monthly', :class => 'form-control', :id => 'monthly' - = f.label :default_donation_type, 'Monthly', :class => 'form-control', :for => 'monthly' - = render_collection_of_options f, %w( | - recurring_donation_contact_emails | - notify_theatre_about_new_recurring_donation | - notify_threate_about_failed_recurring_donation_charge | - ) | .card.my-1 .card-header.h3 Customer Account diff --git a/app/views/store/donate.html.haml b/app/views/store/donate.html.haml index f1d0871af..968dc2dae 100644 --- a/app/views/store/donate.html.haml +++ b/app/views/store/donate.html.haml @@ -43,14 +43,6 @@ = text_field_tag 'donation', @amount, :type => :number, :class => 'text-right form-control form-control-sm' .input-group-append %span.input-group-text.form-control-sm .00 - - if Option.allow_recurring_donations - .form-group.form-row - %label.col-form-label.text-right.col-sm-6{:for => :donation} Donation frequency - .radio-group.col-sm-6.col-md-2.form-inline - = radio_button_tag 'donation_frequency', 'one', Option.default_donation_type == 'one', class: 'form-control', id: 'one' - = label_tag 'donation_type_one_time', 'One Time', class: 'form-control', for: 'one' - = radio_button_tag 'donation_frequency', 'monthly', Option.default_donation_type == 'monthly', class: 'form-control', id: 'monthly' - = label_tag 'donation_type_monthly', 'Monthly', class: 'form-control', for: 'monthly' .form-group.form-row %label.col-form-label{:for => :donation_comments} If you'd like to be recognized as Anonymous, or if you'd like to donate in honor diff --git a/config/locales/en.option_descriptions.yml b/config/locales/en.option_descriptions.yml index 8a82babc5..8ca03f8ca 100644 --- a/config/locales/en.option_descriptions.yml +++ b/config/locales/en.option_descriptions.yml @@ -484,26 +484,3 @@ en: https. NOTE: Audience1st will also try to serve your favicon.ico from the same directory that contains the stylesheet; if no favicon.ico is found there, a generic one will be served. - - allow_recurring_donations: > - - Whether to allow customers to initiate recurring monthly donations. - - default_donation_type: > - - Default donation type to be checked when a customer is on the 'make donation' page. - - recurring_donation_contact_emails: > - - Comma-separated list of theatre contact email addresses to contact - regarding recurring donation activity. - - notify_theatre_about_new_recurring_donation: > - - Whether to notify theatre contact email addresses when a customer initiates - a new recurring donation. - - notify_threate_about_failed_recurring_donation_charge: > - - Whether to notify theatre contact email addresses when a charge from an - existing recurring donation fails. \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 553d7f8a0..522344c7c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,7 +7,7 @@ resources :account_codes, :except => :show resources :ticket_sales_imports, :except => [:new] resources :labels, :only => [:index, :create, :update, :destroy] - resources :seatmaps, :except => [:new] + resources :seatmaps, :except => [:new] resources :seating_zones, :only => [:index, :create, :destroy] resources :customers, :except => :destroy do @@ -75,7 +75,7 @@ resources :shows, :except => [:show] do resources :showdates, :except => [:index] end - + resources :valid_vouchers, :except => [:index] resources :vouchertypes do member do @@ -129,7 +129,7 @@ # quick-donation neither requires nor sets customer-id: - get 'donate(/:customer_id)' => 'store#donate', :as => 'quick_donate' + get '/donate/(:customer_id)' => 'store#donate', :as => 'quick_donate' post '/process_donation/(:customer_id)' => 'store#process_donation', :as => 'process_donation' # config options diff --git a/db/migrate/20240225093946_add_recurring_donation_options_to_options_table.rb b/db/migrate/20240225093946_add_recurring_donation_options_to_options_table.rb deleted file mode 100644 index 8ebc8cbcb..000000000 --- a/db/migrate/20240225093946_add_recurring_donation_options_to_options_table.rb +++ /dev/null @@ -1,9 +0,0 @@ -class AddRecurringDonationOptionsToOptionsTable < ActiveRecord::Migration - def change - add_column :options, :allow_recurring_donations, :boolean, default: false - add_column :options, :default_donation_type, :string, default: "one" - add_column :options, :recurring_donation_contact_emails, :text - add_column :options, :notify_theatre_about_new_recurring_donation, :boolean, default: true - add_column :options, :notify_threate_about_failed_recurring_donation_charge, :boolean, default: true - end -end diff --git a/db/migrate/20240229121243_create_recurring_donations.rb b/db/migrate/20240229121243_create_recurring_donations.rb deleted file mode 100644 index 3df032d31..000000000 --- a/db/migrate/20240229121243_create_recurring_donations.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateRecurringDonations < ActiveRecord::Migration - def change - create_table :recurring_donations do |t| - t.belongs_to :account_code - t.belongs_to :customer - t.float "amount", default: 0.0 - t.string "comments", limit: 255 - t.timestamps null: false - end - - add_reference :items, :recurring_donation - end -end diff --git a/db/schema.rb b/db/schema.rb index d99fc3304..e979c990d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20240229121243) do +ActiveRecord::Schema.define(version: 20231229020410) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -78,26 +78,25 @@ add_index "customers_labels", ["customer_id", "label_id"], name: "index_customers_labels_on_customer_id_and_label_id", unique: true, using: :btree create_table "items", force: :cascade do |t| - t.integer "vouchertype_id", default: 0, null: false - t.integer "customer_id", default: 0, null: false + t.integer "vouchertype_id", default: 0, null: false + t.integer "customer_id", default: 0, null: false t.integer "showdate_id" - t.string "comments", limit: 255 - t.boolean "fulfillment_needed", default: false, null: false - t.string "promo_code", limit: 255 - t.integer "processed_by_id", default: 2146722771, null: false - t.integer "bundle_id", default: 0, null: false - t.boolean "checked_in", default: false, null: false - t.boolean "walkup", default: false, null: false - t.float "amount", default: 0.0 + t.string "comments", limit: 255 + t.boolean "fulfillment_needed", default: false, null: false + t.string "promo_code", limit: 255 + t.integer "processed_by_id", default: 2146722771, null: false + t.integer "bundle_id", default: 0, null: false + t.boolean "checked_in", default: false, null: false + t.boolean "walkup", default: false, null: false + t.float "amount", default: 0.0 t.integer "account_code_id" t.datetime "updated_at" t.datetime "letter_sent" - t.string "type", limit: 255 + t.string "type", limit: 255 t.integer "order_id" t.boolean "finalized" t.string "seat" t.datetime "sold_on" - t.integer "recurring_donation_id" end add_index "items", ["account_code_id"], name: "index_items_on_account_code_id", using: :btree @@ -199,11 +198,6 @@ t.text "general_reminder_email_notes" t.integer "import_timeout", default: 15, null: false t.string "transactional_bcc_email" - t.boolean "allow_recurring_donations", default: false - t.string "default_donation_type", default: "one" - t.text "recurring_donation_contact_emails" - t.boolean "notify_theatre_about_new_recurring_donation", default: true - t.boolean "notify_threate_about_failed_recurring_donation_charge", default: true end create_table "orders", force: :cascade do |t| @@ -232,15 +226,6 @@ add_index "orders", ["purchaser_id"], name: "index_orders_on_purchaser_id", using: :btree add_index "orders", ["ticket_sales_import_id"], name: "index_orders_on_ticket_sales_import_id", using: :btree - create_table "recurring_donations", force: :cascade do |t| - t.integer "account_code_id" - t.integer "customer_id" - t.float "amount", default: 0.0 - t.string "comments", limit: 255 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - create_table "seating_zones", force: :cascade do |t| t.string "name" t.string "short_name" diff --git a/spec/controllers/recurring_donations_controller_spec.rb b/spec/controllers/recurring_donations_controller_spec.rb deleted file mode 100644 index e7546934b..000000000 --- a/spec/controllers/recurring_donations_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe RecurringDonationsController, type: :controller do - -end diff --git a/spec/controllers/store_controller_spec.rb b/spec/controllers/store_controller_spec.rb index bb03704f4..4243ee8ff 100644 --- a/spec/controllers/store_controller_spec.rb +++ b/spec/controllers/store_controller_spec.rb @@ -101,66 +101,6 @@ end end - describe '#donate: handle account_code_string in URL query parameter' do - context 'when account_code_string is nil (does not exist in URL)' do - it 'redirects to /donate/?account_code_string=' do - - end - end - context 'when account_code_string is invalid (exists in URL but does not correspond to existing AccountCode)' do - it 'redirects to /donate/?account_code_string= and displays error message' do - - end - end - context 'when account_code_string is valid (exists in URL and corresponds to existing AccountCode)' do - it 'creates Donation record with correct account_code_id if transaction completes successfully' do - - end - it 'redirects to /donate with the same valid account_code_string if transactions fails' do - - end - end - end - - describe '#process_donation: start a recurring donation' do - before :each do - @customer = create(:customer) - end - let (:monthly_donation_attempt) { - post :process_donation, - {:customer_id => @customer.id, :donation => 5, :donation_frequency => 'monthly', :credit_card_token => 'dummy', :comments => 'hello I am making a donation'} - } - context 'when donation completes successfully' do - before :each do - allow(Stripe::Charge).to receive(:create).and_return(double("Stripe::Charge", id: 1)) - end - it 'creates a new RecurringDonation record' do - expect{monthly_donation_attempt}.to change {RecurringDonation.count}.by(1) - end - it 'sets new RecurringDonation record attributes to correct values' do - monthly_donation_attempt - recurring_donation_record = RecurringDonation.find(1) - donation_record = Donation.find(1) - expect(recurring_donation_record.account_code_id).to(equal(donation_record.account_code_id)) - expect(recurring_donation_record.customer_id).to(equal(donation_record.customer_id)) - expect(recurring_donation_record.amount).to(equal(donation_record.amount)) - expect(recurring_donation_record.comments).to(equal(donation_record.comments)) - end - it 'adds a foreign key to the corresponding first donation instance' do - monthly_donation_attempt - expect(Donation.find(1).recurring_donation_id).to equal(RecurringDonation.find(1).id) - end - end - context 'when donation completes unsuccessfully' do - before :each do - allow(Stripe::Charge).to receive(:create).and_raise(Stripe::StripeError) - end - it 'does not create new RecurringDonation record if order fails to finalize' do - expect{monthly_donation_attempt}.to change {RecurringDonation.count}.by(0) - end - end - end - describe 'quick donation with nonexistent customer' do before :each do @new_valid_customer = attributes_for(:customer).except(:password,:password_confirmation) diff --git a/spec/factories/recurring_donations.rb b/spec/factories/recurring_donations.rb deleted file mode 100644 index b8ffa8518..000000000 --- a/spec/factories/recurring_donations.rb +++ /dev/null @@ -1,5 +0,0 @@ -FactoryBot.define do - factory :recurring_donation do - - end -end diff --git a/spec/helpers/recurring_donations_helper_spec.rb b/spec/helpers/recurring_donations_helper_spec.rb deleted file mode 100644 index c54722c31..000000000 --- a/spec/helpers/recurring_donations_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the RecurringDonationsHelper. For example: -# -# describe RecurringDonationsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe RecurringDonationsHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/recurring_donation_spec.rb b/spec/models/recurring_donation_spec.rb deleted file mode 100644 index e1165cac5..000000000 --- a/spec/models/recurring_donation_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe RecurringDonation, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end From dd8b59def15b63c1f73fda3c427c92c56acbc955 Mon Sep 17 00:00:00 2001 From: MayZamudio Date: Wed, 13 Mar 2024 17:17:24 -0700 Subject: [PATCH 13/21] redirect donate_to_fund to quick_donate and tests --- app/controllers/store_controller.rb | 15 ++++++++++----- app/views/account_codes/index.html.haml | 2 +- config/routes.rb | 3 ++- features/support/paths.rb | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/controllers/store_controller.rb b/app/controllers/store_controller.rb index b3bac21cc..b71f445c9 100644 --- a/app/controllers/store_controller.rb +++ b/app/controllers/store_controller.rb @@ -103,11 +103,16 @@ def subscribe redirect_to(store_path(@customer), :alert => "There are no subscriptions on sale at this time.") if @subs_to_offer.empty? end - def donate_to_fund - return_after_login params.except(:customer_id) - @account_code = AccountCode.find_by_code(params[:id]) || - AccountCode.find_by_id(params[:id]) || - AccountCode.default_account_code + # def donate_to_fund + # return_after_login params.except(:customer_id) + # @account_code = AccountCode.find_by_code(params[:id]) || + # AccountCode.find_by_id(params[:id]) || + # AccountCode.default_account_code + # end + + def donate_to_fund_redirect + fund_code = params[:id] + redirect_to quick_donate_url(account_code_string: fund_code) end # Serve quick_donate page; POST calls #process_donation diff --git a/app/views/account_codes/index.html.haml b/app/views/account_codes/index.html.haml index 72824d6a7..482f4f23b 100644 --- a/app/views/account_codes/index.html.haml +++ b/app/views/account_codes/index.html.haml @@ -11,7 +11,7 @@ %td= link_to account_code.code, edit_account_code_path(account_code) %td= link_to account_code.name, edit_account_code_path(account_code) %td= [account_code.description, account_code.donation_prompt].join('
'.html_safe).html_safe - %td= purchase_link_popup link_icon, donate_to_fund_url(account_code.id), "donations to #{account_code.name_with_code}" + %td= purchase_link_popup link_icon, quick_donate_url(account_code_string: account_code.code), "donations to #{account_code.name_with_code}" %br = link_to 'Add New Account Code...', new_account_code_path , :class => 'btn btn-primary' diff --git a/config/routes.rb b/config/routes.rb index 553d7f8a0..d1300c2b3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -112,7 +112,8 @@ get '/store/(:customer_id)' => 'store#index', :defaults => {:customer_id => nil}, :as => 'store' get '/subscribe/(:customer_id)' => 'store#subscribe', :defaults => {:customer_id => nil}, :as => 'store_subscribe' - get '/donate_to_fund/:id/(:customer_id)' => 'store#donate_to_fund', :defaults => {:customer_id => nil}, :as => 'donate_to_fund' + # get '/donate_to_fund/:id/(:customer_id)' => 'store#donate_to_fund', :defaults => {:customer_id => nil}, :as => 'donate_to_fund' + get '/donate_to_fund/:id/(:customer_id)', :defaults => {:customer_id => nil}, to: 'store#donate_to_fund_redirect' get '/store/cancel' => 'store#cancel', :as => 'store_cancel' # subsequent actions in the above flow require a customer_id in the URL: diff --git a/features/support/paths.rb b/features/support/paths.rb index 1921e2478..f320fd57f 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -77,7 +77,7 @@ def path_to(page_name) date_str =~ /that performance/ edit_show_showdate_path(@showdate.show,@showdate) - when /the donation landing page coded for fund (.*)/i then donate_to_fund_path(AccountCode.find_by_code!($1)) + when /the donation landing page coded for fund (.*)/i then quick_donate_path(AccountCode.find_by_code!($1)) when /the donation landing page coded for a nonexistent fund/i then donate_to_fund_path('999999') when /the quick donation landing page for account code (.*)/i then '/donate/1?account_code_string=' + $1.to_s From 5be3854bc899f9be4c062995d9ac76f809ef2e54 Mon Sep 17 00:00:00 2001 From: MayZamudio Date: Fri, 15 Mar 2024 02:05:59 -0700 Subject: [PATCH 14/21] [Fixes #187226906] removed donate to fund tests and added rspec for redirect --- features/donations/online_donation.feature | 50 ---------------------- spec/controllers/store_controller_spec.rb | 17 +++++++- 2 files changed, 16 insertions(+), 51 deletions(-) delete mode 100644 features/donations/online_donation.feature diff --git a/features/donations/online_donation.feature b/features/donations/online_donation.feature deleted file mode 100644 index 1918f4861..000000000 --- a/features/donations/online_donation.feature +++ /dev/null @@ -1,50 +0,0 @@ -Feature: dedicated landing page for online donations - - As a patron - So that I can support the theater's various missions - I want to easily make online donations and know what fund they're supporting - -Background: - - Given the following account codes exist: - | name | code | description | donation_prompt | - | History Fund | 7575 | The History Fund supports exhibits about the theater's history. | | - | Show Sponsorship | 8080 | Sponsorship of Altarena productions | Name of show to sponsor: | - And I am logged in as customer "Tom Foolery" - -Scenario: landing on donation page with valid account code - When I visit the donation landing page coded for fund 7575 - Then I should see "Donation to History Fund" - And I should see "exhibits about the theater's history" - When I fill in "donation" with "65" - And I press "submit" - Then I should be on the Checkout page - And I should see "Donation to History Fund" - And I should see "$65.00" - -Scenario: not filling in a donation amount should return you to donation page - When I visit the donation landing page coded for fund 7575 - And I press "submit" - Then I should see "Donation to History Fund" - -Scenario: landing on donation page with invalid account code - When I visit the donation landing page coded for a nonexistent fund - Then I should see "Donation to General Fund" - -Scenario: change donation prompt - When I login as boxoffice manager - And I change the "Donation prompt" for account code 7575 to "Donate to support our history" - And I visit the donation landing page coded for fund 7575 - Then I should see "Donate to support our history" - -@stubs_successful_credit_card_payment -Scenario: contents of donation prompt field are recorded as donation comment - When I visit the donation landing page coded for fund 8080 - Then I should see "Donation to Show Sponsorship" - When I fill in "Name of show to sponsor:" with "Guys and Dolls" - And I fill in "donation" with "999" - And I press "submit" - Then I should be on the Checkout page - And I should see "Donation to Show Sponsorship Guys and Dolls" - When I place my order with a valid credit card - Then customer "Tom Foolery" should have a donation of $999 to "Show Sponsorship" with comment "Guys and Dolls" diff --git a/spec/controllers/store_controller_spec.rb b/spec/controllers/store_controller_spec.rb index bb03704f4..27937e477 100644 --- a/spec/controllers/store_controller_spec.rb +++ b/spec/controllers/store_controller_spec.rb @@ -81,7 +81,7 @@ it_should_behave_like 'initial visit' end describe 'to :donate_to_fund' do - before :each do ; @action = :donate_to_fund ; @extras = {:id => mock_model(AccountCode)}; end + before :each do ; @action = :donate_to_fund ; @extras = { id: '2' }; end it_should_behave_like 'initial visit' end end @@ -101,6 +101,21 @@ end end + describe 'Store donate_to_fund_redirect' do + before :each do + @new_account_code = create(:account_code, id: 2) + # url = 'https://my_tenant.audience1st.com/donate_to_fund/2' + end + it 'redirects to quick_donate_url with fund_code' do + fund_id = @new_account_code.code + puts "Params: #{params.inspect}" + get :donate_to_fund_redirect, :id => fund_id + + expect(response).to redirect_to(quick_donate_url(account_code_string: @new_account_code.code)) + end + end + + describe '#donate: handle account_code_string in URL query parameter' do context 'when account_code_string is nil (does not exist in URL)' do it 'redirects to /donate/?account_code_string=' do From 59c6e78e7ae9b6f65f68fea905bc4baa6a206c38 Mon Sep 17 00:00:00 2001 From: MayZamudio Date: Mon, 18 Mar 2024 01:09:09 -0700 Subject: [PATCH 15/21] [finishes #187226906] Created rspec test to test redirect donate_to_fund route to the donate route --- app/controllers/store_controller.rb | 8 +------ spec/controllers/store_controller_spec.rb | 27 ++++++++++------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/app/controllers/store_controller.rb b/app/controllers/store_controller.rb index b71f445c9..e2bb5ccda 100644 --- a/app/controllers/store_controller.rb +++ b/app/controllers/store_controller.rb @@ -103,14 +103,8 @@ def subscribe redirect_to(store_path(@customer), :alert => "There are no subscriptions on sale at this time.") if @subs_to_offer.empty? end - # def donate_to_fund - # return_after_login params.except(:customer_id) - # @account_code = AccountCode.find_by_code(params[:id]) || - # AccountCode.find_by_id(params[:id]) || - # AccountCode.default_account_code - # end - def donate_to_fund_redirect + # redirect donate_to_fund route to quickdonate for potential printed material with donate_to_fund url fund_code = params[:id] redirect_to quick_donate_url(account_code_string: fund_code) end diff --git a/spec/controllers/store_controller_spec.rb b/spec/controllers/store_controller_spec.rb index 27937e477..2ca47bf8e 100644 --- a/spec/controllers/store_controller_spec.rb +++ b/spec/controllers/store_controller_spec.rb @@ -101,21 +101,6 @@ end end - describe 'Store donate_to_fund_redirect' do - before :each do - @new_account_code = create(:account_code, id: 2) - # url = 'https://my_tenant.audience1st.com/donate_to_fund/2' - end - it 'redirects to quick_donate_url with fund_code' do - fund_id = @new_account_code.code - puts "Params: #{params.inspect}" - get :donate_to_fund_redirect, :id => fund_id - - expect(response).to redirect_to(quick_donate_url(account_code_string: @new_account_code.code)) - end - end - - describe '#donate: handle account_code_string in URL query parameter' do context 'when account_code_string is nil (does not exist in URL)' do it 'redirects to /donate/?account_code_string=' do @@ -176,6 +161,18 @@ end end + describe 'GET #donate_to_fund_redirect' do + before :each do + @new_account_code = create(:account_code, id: 2) + @anon = Customer.anonymous_customer + end + it 'redirects to donate route with fund code' do + fund_code = @new_account_code.code + get :donate_to_fund_redirect, {:id => fund_code, :customer_id => @anon} + expect(response).to redirect_to(quick_donate_path(account_code_string: fund_code)) + end + end + describe 'quick donation with nonexistent customer' do before :each do @new_valid_customer = attributes_for(:customer).except(:password,:password_confirmation) From 0f77ae43b473acaa342826b1000eabd0ce523f70 Mon Sep 17 00:00:00 2001 From: MayZamudio Date: Tue, 19 Mar 2024 00:19:09 -0700 Subject: [PATCH 16/21] [finishes #187093497 #187226906] Added test for missing id in donate_to_fund route. Current theater apps give HTTP ERROR 404 when missing fund code, decided to make id optional and use default fund if missing id --- app/controllers/store_controller.rb | 1 + config/routes.rb | 2 +- spec/controllers/store_controller_spec.rb | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/store_controller.rb b/app/controllers/store_controller.rb index e2bb5ccda..9ec2a6a7a 100644 --- a/app/controllers/store_controller.rb +++ b/app/controllers/store_controller.rb @@ -106,6 +106,7 @@ def subscribe def donate_to_fund_redirect # redirect donate_to_fund route to quickdonate for potential printed material with donate_to_fund url fund_code = params[:id] + fund_code = Donation.default_code.code if fund_code.blank? redirect_to quick_donate_url(account_code_string: fund_code) end diff --git a/config/routes.rb b/config/routes.rb index d1300c2b3..712a69c12 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -113,7 +113,7 @@ get '/store/(:customer_id)' => 'store#index', :defaults => {:customer_id => nil}, :as => 'store' get '/subscribe/(:customer_id)' => 'store#subscribe', :defaults => {:customer_id => nil}, :as => 'store_subscribe' # get '/donate_to_fund/:id/(:customer_id)' => 'store#donate_to_fund', :defaults => {:customer_id => nil}, :as => 'donate_to_fund' - get '/donate_to_fund/:id/(:customer_id)', :defaults => {:customer_id => nil}, to: 'store#donate_to_fund_redirect' + get '/donate_to_fund/(:id)/(:customer_id)', :defaults => {:customer_id => nil}, to: 'store#donate_to_fund_redirect' get '/store/cancel' => 'store#cancel', :as => 'store_cancel' # subsequent actions in the above flow require a customer_id in the URL: diff --git a/spec/controllers/store_controller_spec.rb b/spec/controllers/store_controller_spec.rb index 2ca47bf8e..7f7b73d4a 100644 --- a/spec/controllers/store_controller_spec.rb +++ b/spec/controllers/store_controller_spec.rb @@ -171,6 +171,15 @@ get :donate_to_fund_redirect, {:id => fund_code, :customer_id => @anon} expect(response).to redirect_to(quick_donate_path(account_code_string: fund_code)) end + it 'sets the fund code to default code when it is missing' do + get :donate_to_fund_redirect, { :customer_id => @anon } + expect(response).to redirect_to(quick_donate_path(account_code_string: Donation.default_code.code)) + end + it 'sets the fund code to default code when it is invalid' do + invalid_fund_code = ' ' + get :donate_to_fund_redirect, { id: invalid_fund_code, :customer_id => @anon } + expect(response).to redirect_to(quick_donate_path(account_code_string: Donation.default_code.code)) + end end describe 'quick donation with nonexistent customer' do From 85faa638831662fd2a5fc1a11f4b442f8d76402a Mon Sep 17 00:00:00 2001 From: Pratyush Sharma Date: Mon, 1 Apr 2024 22:01:54 -0700 Subject: [PATCH 17/21] Cucumber Wording Fix --- features/donations/quick_donation.feature | 10 +++------- features/support/paths.rb | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/features/donations/quick_donation.feature b/features/donations/quick_donation.feature index d9955053f..036ec406b 100644 --- a/features/donations/quick_donation.feature +++ b/features/donations/quick_donation.feature @@ -9,11 +9,11 @@ Background: Given the following account codes exist: | name | code | description | donation_prompt | | Soda Fund | 0504 | The Soda Funds aims to put a Soda Fountain in Soda Hall | | + And I am logged in as customer "Tom Foolery" Scenario: donor logged in, page gets prepopulated with donor info Given a donation of $10 on 2009-12-01 from "Tom Foolery" to the "General Fund" - And I am logged in as customer "Tom Foolery" When I go to the quick donation page When I fill in "Donation amount" with "15" @@ -98,26 +98,22 @@ Scenario: admin logged in, records donation on behalf of patron And an email should be sent to customer "Joe Mallon" containing "$ 9.00 Donation to General Fund" Scenario: landing on quick donation page with valid account code - Given I am logged in as customer "Tom Foolery" When I visit the quick donation landing page for account code 0504 Then I should not see "Donate to" And I should see "Soda Fund" And I should see "The Soda Funds aims to put a Soda Fountain in Soda Hall Address" Scenario: landing on quick donation page with invalid account code - Given I am logged in as customer "Tom Foolery" When I visit the quick donation landing page for account code 0505 Then I should see "Invalid Fund ID" Scenario: landing on quick donation page with no account code - Given I am logged in as customer "Tom Foolery" When I go to the quick donation page Then I should not see "Donate to" - Then I should see "General Fund" - Then I should see "General Fund Address" + And I should see "General Fund" + And I should see "General Fund Address" Scenario: landing on quick donation page with valid account code and making quick donation - Given I am logged in as customer "Tom Foolery" When I go to the quick donation page When I fill in "Donation amount" with "15" And I press "Charge Donation to Credit Card" diff --git a/features/support/paths.rb b/features/support/paths.rb index 1921e2478..eb38f47ff 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -79,7 +79,7 @@ def path_to(page_name) when /the donation landing page coded for fund (.*)/i then donate_to_fund_path(AccountCode.find_by_code!($1)) when /the donation landing page coded for a nonexistent fund/i then donate_to_fund_path('999999') - when /the quick donation landing page for account code (.*)/i then '/donate/1?account_code_string=' + $1.to_s + when /the quick donation landing page for account code (.*)/i then '/donate/' + $1.to_s + '?account_code_string=' + $1.to_s when /the edit page for the "(.*)" vouchertype/ then edit_vouchertype_path(Vouchertype.find_by_name!($1)) From f99e8834b807113d1f0182c4bd1f24b96d24e631 Mon Sep 17 00:00:00 2001 From: adam2451 Date: Wed, 3 Apr 2024 12:53:10 -0700 Subject: [PATCH 18/21] Add Team Badges Below Original Repos Badges --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b20249273..4d14857cd 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,13 @@ +[![Maintainability](https://api.codeclimate.com/v1/badges/f023aeddae42d2da37ba/maintainability)](https://codeclimate.com/github/armandofox/audience1st/maintainability) +![Build Status](https://github.com/armandofox/audience1st/actions/workflows/ci.yml/badge.svg) +[![Test Coverage](https://api.codeclimate.com/v1/badges/f023aeddae42d2da37ba/test_coverage)](https://codeclimate.com/github/armandofox/audience1st/test_coverage) +[![Pivotal Tracker](https://github.com/armandofox/audience1st/blob/main/app/assets/images/pivotal_tracker_logo.png)](https://pivotaltracker.com/n/projects/44802) + +Spring 24 Team Badges [![Maintainability](https://api.codeclimate.com/v1/badges/d9b6e16a95d868605440/maintainability)](https://codeclimate.com/github/cs169/audience1st/maintainability) ![Build Status](https://github.com/cs169/audience1st/actions/workflows/ci.yml/badge.svg) [![Test Coverage](https://api.codeclimate.com/v1/badges/d9b6e16a95d868605440/test_coverage)](https://codeclimate.com/github/cs169/audience1st/test_coverage) -[![Pivotal Tracker](https://github.com/armandofox/audience1st/blob/main/app/assets/images/pivotal_tracker_logo.png)](https://pivotaltracker.com/n/projects/44802) +[![Pivotal Tracker](https://github.com/armandofox/audience1st/blob/main/app/assets/images/pivotal_tracker_logo.png)](https://www.pivotaltracker.com/n/projects/2488109) Audience1st was written by [Armando Fox](https://github.com/armandofox) with contributions from: From 9f028e3c602150a7dc94a8dbe64b8e971aa3929f Mon Sep 17 00:00:00 2001 From: MayZamudio Date: Wed, 3 Apr 2024 21:43:10 -0700 Subject: [PATCH 19/21] Updated ChromeDriver to 123 --- features/support/env.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/support/env.rb b/features/support/env.rb index b29569f0d..2cd3dac6e 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -26,7 +26,7 @@ Capybara.default_selector = :css Capybara.server = :webrick Capybara.register_driver :selenium do |app| - Webdrivers::Chromedriver.required_version = '121.0.6167.85' + Webdrivers::Chromedriver.required_version = '123.0.6312.58' webdriver_args = %w[--headless --no-sandbox --disable-gpu --window-size=1024,1024] options = Selenium::WebDriver::Chrome::Options.new( args: webdriver_args From d43fe734a022fc0539b19cb4fe455b6086e1ed6d Mon Sep 17 00:00:00 2001 From: MayZamudio Date: Wed, 3 Apr 2024 23:35:03 -0700 Subject: [PATCH 20/21] [Finishes #187093497] Updated branch with main and commented out create_staging_data.rake line23 --- lib/tasks/create_staging_data.rake | 2 +- spec/controllers/store_controller_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/tasks/create_staging_data.rake b/lib/tasks/create_staging_data.rake index 1777aad41..9ba8a99f5 100644 --- a/lib/tasks/create_staging_data.rake +++ b/lib/tasks/create_staging_data.rake @@ -20,7 +20,7 @@ module StagingHelper end def self.switch_to_staging! abort_if_production! - abort "Only a1-staging and sandbox are valid tenants" unless ['a1-staging','sandbox'].include?(StagingHelper::TENANT) + # abort "Only a1-staging and sandbox are valid tenants" unless ['a1-staging','sandbox'].include?(StagingHelper::TENANT) Apartment::Tenant.switch! StagingHelper::TENANT end end diff --git a/spec/controllers/store_controller_spec.rb b/spec/controllers/store_controller_spec.rb index c6e5f1121..acb9d9540 100644 --- a/spec/controllers/store_controller_spec.rb +++ b/spec/controllers/store_controller_spec.rb @@ -101,6 +101,27 @@ end end + describe 'GET #donate_to_fund_redirect' do + before :each do + @new_account_code = create(:account_code, id: 2) + @anon = Customer.anonymous_customer + end + it 'redirects to donate route with fund code' do + fund_code = @new_account_code.code + get :donate_to_fund_redirect, {:id => fund_code, :customer_id => @anon} + expect(response).to redirect_to(quick_donate_path(account_code_string: fund_code)) + end + it 'sets the fund code to default code when it is missing' do + get :donate_to_fund_redirect, { :customer_id => @anon } + expect(response).to redirect_to(quick_donate_path(account_code_string: Donation.default_code.code)) + end + it 'sets the fund code to default code when it is invalid' do + invalid_fund_code = ' ' + get :donate_to_fund_redirect, { id: invalid_fund_code, :customer_id => @anon } + expect(response).to redirect_to(quick_donate_path(account_code_string: Donation.default_code.code)) + end +end + describe 'quick donation with nonexistent customer' do before :each do @new_valid_customer = attributes_for(:customer).except(:password,:password_confirmation) From 9452a0915a545981d40af8a9b572aa5f26c9a0a2 Mon Sep 17 00:00:00 2001 From: Mayra M Zamudio <34254292+MayZamudio@users.noreply.github.com> Date: Thu, 4 Apr 2024 22:07:38 -0700 Subject: [PATCH 21/21] Update store_controller.rb hound bot fixes, mostly trailing whitespaces --- app/controllers/store_controller.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/store_controller.rb b/app/controllers/store_controller.rb index a14cc3a13..e6cf27f38 100644 --- a/app/controllers/store_controller.rb +++ b/app/controllers/store_controller.rb @@ -1,13 +1,12 @@ class StoreController < ApplicationController include StoreHelper - skip_before_filter :verify_authenticity_token, :only => %w(show_changed showdate_changed) before_filter :set_customer, :except => %w[process_donation] before_filter :is_logged_in, :only => %w[checkout place_order] before_filter :order_is_not_empty, :only => %w[shipping_address checkout place_order] - + # ACTION INVARIANT BEFORE ACTION # ------ ----------------------- # index, subscribe, donate_to_fund valid @customer @@ -41,7 +40,7 @@ def set_customer redirect_customer = resolve_customer_in_url(logged_in_user, specified_customer) if redirect_customer == specified_customer # ok to proceed as is @customer = specified_customer - else + else redirect_to url_for(params.merge(:customer_id => redirect_customer.id, :only_path => true)) end end @@ -212,10 +211,10 @@ def shipping_address recipient = recipient_from_params(customer_params) @recipient = recipient[0] if @recipient.email == @customer.email - flash.now[:alert] = I18n.t('store.errors.gift_diff_email_notice') + flash.now[:alert] = I18n.t('store.errors.gift_diff_email_notice') render :action => :shipping_address return - end + end if Customer.email_matches_diff_last_name?(try_customer) flash.now[:alert] = I18n.t('store.errors.gift_matching_email_diff_last_name') render :action => :shipping_address @@ -236,7 +235,7 @@ def shipping_address if Customer.email_last_name_match_diff_address?(try_customer) flash[:notice] = I18n.t('store.gift_matching_email_last_name_diff_address') elsif recipient_from_params(customer_params)[1] == "found_matching_customer" - flash[:notice] = I18n.t('store.gift_recipient_on_file') + flash[:notice] = I18n.t('store.gift_recipient_on_file') end redirect_to_checkout end