Skip to content

Commit

Permalink
cleanup and rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
beingmattlevy committed Jul 28, 2024
1 parent 6a107bf commit f3dbace
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
1 change: 1 addition & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/ticket_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions app/models/ticket_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
26 changes: 20 additions & 6 deletions db/migrate/20240728211432_remove_ea_ld.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 11 additions & 2 deletions db/migrate/20240728223048_event_prices_as_integers.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f3dbace

Please sign in to comment.