From b9e8c8867cf5ae0202e14496f88e7be1e8e2f0d4 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 26 Apr 2021 11:40:26 +0200 Subject: [PATCH] fix running test renew_as_admin_test --- app/controllers/api/subscriptions_controller.rb | 4 ++-- app/models/cart_item/event_reservation.rb | 2 +- app/models/cart_item/machine_reservation.rb | 2 +- app/models/cart_item/payment_schedule.rb | 2 +- app/models/cart_item/space_reservation.rb | 2 +- app/models/cart_item/subscription.rb | 2 +- app/models/cart_item/training_reservation.rb | 2 +- app/models/shopping_cart.rb | 2 +- app/services/cart_service.rb | 8 ++++---- app/services/footprint_service.rb | 2 +- app/services/invoices_service.rb | 2 +- app/services/payment_document_service.rb | 6 +++--- app/services/wallet_service.rb | 2 +- test/integration/subscriptions/renew_as_admin_test.rb | 4 ++-- 14 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/controllers/api/subscriptions_controller.rb b/app/controllers/api/subscriptions_controller.rb index 3b0228939..442995cb4 100644 --- a/app/controllers/api/subscriptions_controller.rb +++ b/app/controllers/api/subscriptions_controller.rb @@ -13,7 +13,7 @@ class API::SubscriptionsController < API::ApiController # otherwise, they must use payments_controller#confirm_payment. # Managers can create subscriptions for other users def create - user_id = current_user.admin? || current_user.manager? ? params[:subscription][:user_id] : current_user.id + user_id = current_user.admin? || current_user.manager? ? params[:customer_id] : current_user.id transaction = transaction_amount(user_id) authorize SubscriptionContext.new(Subscription, transaction[:amount], user_id) @@ -57,7 +57,7 @@ class API::SubscriptionsController < API::ApiController plan_id: subscription_params[:plan_id] }, coupon_code: coupon_params[:coupon_code], - payment_schedule: subscription_params[:payment_schedule]) + payment_schedule: params[:payment_schedule]) price_details = cart.total user = User.find(user_id) diff --git a/app/models/cart_item/event_reservation.rb b/app/models/cart_item/event_reservation.rb index 02e6f675b..5dd922300 100644 --- a/app/models/cart_item/event_reservation.rb +++ b/app/models/cart_item/event_reservation.rb @@ -5,7 +5,7 @@ class CartItem::EventReservation < CartItem::Reservation # @param normal_tickets {Number} number of tickets at the normal price # @param other_tickets {Array<{booked: Number, event_price_category_id: Number}>} def initialize(customer, operator, event, slots, normal_tickets: 0, other_tickets: []) - raise TypeError unless event.class == Event + raise TypeError unless event.is_a? Event super(customer, operator, event, slots) @normal_tickets = normal_tickets diff --git a/app/models/cart_item/machine_reservation.rb b/app/models/cart_item/machine_reservation.rb index ab8982767..7f0e1bd90 100644 --- a/app/models/cart_item/machine_reservation.rb +++ b/app/models/cart_item/machine_reservation.rb @@ -5,7 +5,7 @@ class CartItem::MachineReservation < CartItem::Reservation # @param plan {Plan} a subscription bought at the same time of the reservation OR an already running subscription # @param new_subscription {Boolean} true is new subscription is being bought at the same time of the reservation def initialize(customer, operator, machine, slots, plan: nil, new_subscription: false) - raise TypeError unless machine.class == Machine + raise TypeError unless machine.is_a? Machine super(customer, operator, machine, slots) @plan = plan diff --git a/app/models/cart_item/payment_schedule.rb b/app/models/cart_item/payment_schedule.rb index e0da49506..18e096104 100644 --- a/app/models/cart_item/payment_schedule.rb +++ b/app/models/cart_item/payment_schedule.rb @@ -3,7 +3,7 @@ # A payment schedule applied to plan in the shopping cart class CartItem::PaymentSchedule def initialize(plan, coupon, requested) - raise TypeError unless coupon.class == CartItem::Coupon + raise TypeError unless coupon.is_a? CartItem::Coupon @plan = plan @coupon = coupon diff --git a/app/models/cart_item/space_reservation.rb b/app/models/cart_item/space_reservation.rb index a4745a427..5a5924f2f 100644 --- a/app/models/cart_item/space_reservation.rb +++ b/app/models/cart_item/space_reservation.rb @@ -5,7 +5,7 @@ class CartItem::SpaceReservation < CartItem::Reservation # @param plan {Plan} a subscription bought at the same time of the reservation OR an already running subscription # @param new_subscription {Boolean} true is new subscription is being bought at the same time of the reservation def initialize(customer, operator, space, slots, plan: nil, new_subscription: false) - raise TypeError unless space.class == Space + raise TypeError unless space.is_a? Space super(customer, operator, space, slots) @plan = plan diff --git a/app/models/cart_item/subscription.rb b/app/models/cart_item/subscription.rb index 950ba87b4..d88c169d4 100644 --- a/app/models/cart_item/subscription.rb +++ b/app/models/cart_item/subscription.rb @@ -3,7 +3,7 @@ # A subscription added to the shopping cart class CartItem::Subscription < CartItem::BaseItem def initialize(plan) - raise TypeError unless plan.class == Plan + raise TypeError unless plan.is_a? Plan @plan = plan end diff --git a/app/models/cart_item/training_reservation.rb b/app/models/cart_item/training_reservation.rb index c8f629608..d0aee1886 100644 --- a/app/models/cart_item/training_reservation.rb +++ b/app/models/cart_item/training_reservation.rb @@ -5,7 +5,7 @@ class CartItem::TrainingReservation < CartItem::Reservation # @param plan {Plan} a subscription bought at the same time of the reservation OR an already running subscription # @param new_subscription {Boolean} true is new subscription is being bought at the same time of the reservation def initialize(customer, operator, training, slots, plan: nil, new_subscription: false) - raise TypeError unless training.class == Training + raise TypeError unless training.is_a? Training super(customer, operator, training, slots) @plan = plan diff --git a/app/models/shopping_cart.rb b/app/models/shopping_cart.rb index 2f7f26a64..f1eb811d7 100644 --- a/app/models/shopping_cart.rb +++ b/app/models/shopping_cart.rb @@ -9,7 +9,7 @@ class ShoppingCart # @param payment_schedule {CartItem::PaymentSchedule} # @param customer {User} def initialize(customer, coupon, payment_schedule, payment_method = '', items: []) - raise TypeError unless customer.class == User + raise TypeError unless customer.is_a? User @customer = customer @payment_method = payment_method diff --git a/app/services/cart_service.rb b/app/services/cart_service.rb index a3ff35952..33359622e 100644 --- a/app/services/cart_service.rb +++ b/app/services/cart_service.rb @@ -33,12 +33,12 @@ class CartService private def plan(cart_items) - plan = if @customer.subscribed_plan - new_plan_being_bought = false - @customer.subscribed_plan - elsif cart_items[:subscription] && cart_items[:subscription][:plan_id] + plan = if cart_items[:subscription] && cart_items[:subscription][:plan_id] new_plan_being_bought = true Plan.find(cart_items[:subscription][:plan_id]) + elsif @customer.subscribed_plan + new_plan_being_bought = false + @customer.subscribed_plan else new_plan_being_bought = false nil diff --git a/app/services/footprint_service.rb b/app/services/footprint_service.rb index 2ba6f38a8..db8b59fc0 100644 --- a/app/services/footprint_service.rb +++ b/app/services/footprint_service.rb @@ -64,7 +64,7 @@ class FootprintService # Return a comparable value for jsonb fields (with keys ordered alphabetically) def comparable(value) - return value unless value.class == Hash + return value unless value.is_a? Hash value.sort.to_h end diff --git a/app/services/invoices_service.rb b/app/services/invoices_service.rb index 6ba057235..5bf0ba7cf 100644 --- a/app/services/invoices_service.rb +++ b/app/services/invoices_service.rb @@ -121,7 +121,7 @@ class InvoicesService # This method must be called if reservation.reservable is an Event ## def self.generate_event_item(invoice, reservation, payment_details) - raise TypeError unless reservation.reservable.class == Event + raise TypeError unless reservation.reservable.is_a? Event reservation.slots.each do |slot| description = "#{reservation.reservable.name}\n" diff --git a/app/services/payment_document_service.rb b/app/services/payment_document_service.rb index 1bf78e28f..0eb975492 100644 --- a/app/services/payment_document_service.rb +++ b/app/services/payment_document_service.rb @@ -9,7 +9,7 @@ class PaymentDocumentService reference = replace_invoice_number_pattern(pattern) reference = replace_date_pattern(reference, date) - if document.class == Avoir + if document.is_a? Avoir # information about refund/avoir (R[text]) reference.gsub!(/R\[([^\]]+)\]/, '\1') @@ -17,14 +17,14 @@ class PaymentDocumentService reference.gsub!(/X\[([^\]]+)\]/, ''.to_s) # remove information about payment schedule (S[text]) reference.gsub!(/S\[([^\]]+)\]/, ''.to_s) - elsif document.class == PaymentSchedule + elsif document.is_a? PaymentSchedule # information about payment schedule reference.gsub!(/S\[([^\]]+)\]/, '\1') # remove information about online selling (X[text]) reference.gsub!(/X\[([^\]]+)\]/, ''.to_s) # remove information about refunds (R[text]) reference.gsub!(/R\[([^\]]+)\]/, ''.to_s) - elsif document.class == Invoice + elsif document.is_a? Invoice # information about online selling (X[text]) if document.paid_by_card? reference.gsub!(/X\[([^\]]+)\]/, '\1') diff --git a/app/services/wallet_service.rb b/app/services/wallet_service.rb index 8d4e4333e..43bd14a80 100644 --- a/app/services/wallet_service.rb +++ b/app/services/wallet_service.rb @@ -80,7 +80,7 @@ class WalletService # @param coupon {Coupon|String} Coupon object or code ## def self.wallet_amount_debit(payment, user, coupon = nil) - total = if payment.class == PaymentSchedule + total = if payment.is_a? PaymentSchedule payment.payment_schedule_items.first.amount else payment.total diff --git a/test/integration/subscriptions/renew_as_admin_test.rb b/test/integration/subscriptions/renew_as_admin_test.rb index ca11f82fa..4022249b1 100644 --- a/test/integration/subscriptions/renew_as_admin_test.rb +++ b/test/integration/subscriptions/renew_as_admin_test.rb @@ -15,9 +15,9 @@ class Subscriptions::RenewAsAdminTest < ActionDispatch::IntegrationTest VCR.use_cassette('subscriptions_admin_renew_success') do post '/api/subscriptions', params: { + customer_id: user.id, subscription: { - plan_id: plan.id, - user_id: user.id + plan_id: plan.id } }.to_json, headers: default_headers end