diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 30b23651..b3b46f6d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -157,6 +157,7 @@ Rails/ReversibleMigration: - 'db/migrate/20140605053705_remove_ask_how_many_shifts_from_events.rb' - 'db/migrate/20140605060026_add_camping_type_to_ticket_requests.rb' - 'db/migrate/20140616030905_change_camping_type_on_ticket_requests.rb' + - 'db/migrate/20240728211432_remove_ea_ld.rb' # Offense count: 3 # Configuration parameters: ForbiddenMethods, AllowedMethods. diff --git a/app/controllers/ticket_requests_controller.rb b/app/controllers/ticket_requests_controller.rb index 3573db96..6d9f267b 100644 --- a/app/controllers/ticket_requests_controller.rb +++ b/app/controllers/ticket_requests_controller.rb @@ -21,11 +21,11 @@ def index requests = @ticket_requests.select { |tr| tr.send("#{status}?") } stats[status] = { - requests: requests.count, - adults: requests.sum(&:adults), - kids: requests.sum(&:kids), - event_addons: requests.sum(&:active_ticket_request_event_addons_count), - raised: requests.sum(&:price) + requests: requests.count, + adults: requests.sum(&:adults), + kids: requests.sum(&:kids), + event_addons: requests.sum(&:active_ticket_request_event_addons_count), + raised: requests.sum(&:price) } end diff --git a/app/models/event.rb b/app/models/event.rb index 1bd34ae7..4be7a39f 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -222,7 +222,7 @@ def active_event_addons end def active_event_addons? - event_addons.where('price > ?', 0).count > 0 + event_addons.where('price > ?', 0).count.positive? end def active_sorted_event_addons diff --git a/app/models/ticket_request.rb b/app/models/ticket_request.rb index 96e84d33..720bb013 100644 --- a/app/models/ticket_request.rb +++ b/app/models/ticket_request.rb @@ -365,9 +365,7 @@ def active_ticket_request_event_addons ticket_request_event_addons.where('quantity > ?', 0) end - def active_ticket_request_event_addons_count - active_ticket_request_event_addons.count - end + delegate :count, to: :active_ticket_request_event_addons, prefix: true def set_defaults self.status = nil if status.blank? diff --git a/db/migrate/20240728211432_remove_ea_ld.rb b/db/migrate/20240728211432_remove_ea_ld.rb index d7f386cc..8c9afc90 100644 --- a/db/migrate/20240728211432_remove_ea_ld.rb +++ b/db/migrate/20240728211432_remove_ea_ld.rb @@ -1,12 +1,26 @@ +# frozen_string_literal: true + class RemoveEaLd < ActiveRecord::Migration[7.1] def change - remove_column :events, :early_arrival_price - remove_column :events, :late_departure_price - remove_column :events, :cabin_price - remove_column :events, :max_cabin_requests - remove_column :events, :max_cabins_per_request + reversible do |direction| + change_table :events do |t| + direction.up { t.change :early_arrival_price, :decimal } + direction.down { t.remove :early_arrival_price } - drop_table :eald_payments + direction.up { t.change :late_departure_price, :decimal } + direction.down { t.remove :late_departure_price } + + direction.up { t.change :cabin_price, :decimal } + direction.down { t.remove :cabin_price } + direction.up { t.change :max_cabin_requests, :integer } + direction.down { t.remove :max_cabin_requests } + + direction.up { t.change :max_cabins_per_request, :integer } + direction.down { t.remove :max_cabins_per_request } + end + end + + drop_table :eald_payments end end diff --git a/db/migrate/20240728223048_event_prices_as_integers.rb b/db/migrate/20240728223048_event_prices_as_integers.rb index 50b17e61..9e6ddae3 100644 --- a/db/migrate/20240728223048_event_prices_as_integers.rb +++ b/db/migrate/20240728223048_event_prices_as_integers.rb @@ -1,6 +1,15 @@ +# frozen_string_literal: true + class EventPricesAsIntegers < ActiveRecord::Migration[7.1] def change - change_column :events, :adult_ticket_price, :integer - change_column :events, :kid_ticket_price, :integer + reversible do |direction| + change_table :events do |t| + direction.up { t.change :adult_ticket_price, :decimal, precision: 2 } + direction.down { t.change :adult_ticket_price, :integer } + + direction.up { t.change :kid_ticket_price, :decimal, precision: 2 } + direction.down { t.change :kid_ticket_price, :integer } + end + end end end