From cc6dbc1682ab358a68c996250860153510f2471a Mon Sep 17 00:00:00 2001 From: Winson Tsang Wan <106371049+winsonwan@users.noreply.github.com> Date: Sat, 9 Mar 2024 22:08:16 -0800 Subject: [PATCH 1/8] Revert "Create recurring donations model + Update controller action to create new recurring donation instance " --- app/assets/javascripts/recurring_donations.js | 2 -- .../stylesheets/recurring_donations.scss | 3 -- .../recurring_donations_controller.rb | 2 -- app/controllers/store_controller.rb | 19 ++++------- app/helpers/recurring_donations_helper.rb | 2 -- app/models/items/donation.rb | 8 ++--- app/models/recurring_donation.rb | 16 --------- app/views/store/donate.html.haml | 4 +-- ...240229121243_create_recurring_donations.rb | 13 ------- db/schema.rb | 34 +++++++------------ .../recurring_donations_controller_spec.rb | 5 --- spec/factories/recurring_donations.rb | 5 --- .../recurring_donations_helper_spec.rb | 15 -------- spec/models/recurring_donation_spec.rb | 5 --- 14 files changed, 23 insertions(+), 110 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/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/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 439e5e5c8..f47dfa590 100644 --- a/app/controllers/store_controller.rb +++ b/app/controllers/store_controller.rb @@ -1,13 +1,13 @@ 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 +41,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 @@ -139,19 +139,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 @@ -202,10 +195,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 @@ -226,7 +219,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 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/store/donate.html.haml b/app/views/store/donate.html.haml index b8be754f2..33b877d89 100644 --- a/app/views/store/donate.html.haml +++ b/app/views/store/donate.html.haml @@ -46,9 +46,9 @@ .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' + = radio_button_tag 'donation_type', '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' + = radio_button_tag 'donation_type', '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} 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..53308aeae 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: 20240225093946) 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 @@ -232,15 +231,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/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 2/8] 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 3/8] [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 4/8] [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 5/8] [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 9f028e3c602150a7dc94a8dbe64b8e971aa3929f Mon Sep 17 00:00:00 2001 From: MayZamudio Date: Wed, 3 Apr 2024 21:43:10 -0700 Subject: [PATCH 6/8] 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 7/8] [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 8/8] 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