Skip to content

Commit

Permalink
Use new machine_count field
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanTG committed Feb 11, 2025
1 parent 1bb0614 commit 5203d17
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/controllers/locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def self.locations_javascript_data(locations)
ids << l.id
lats << l.lat
lons << l.lon
num_machines << l.machines.size
num_machines << l.machine_count
end

[ ids, lats, lons, num_machines ]
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/maps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def map

if !params[:by_location_id].blank? && (loc = Location.where(id: params[:by_location_id]).first)
@title_params[:title] = "#{loc.name} - Pinball Map"
machine_length = " - " + loc.machines.length.to_s + " " + "machine".pluralize(loc.machines.length) unless loc.machines.empty?
machine_length = " - " + loc.machine_count.to_s + " " + "machine".pluralize(loc.machine_count) unless loc.machine_count.zero?
machine_list = " - " + loc.machine_names_first_no_year.join(", ") unless loc.machine_names_first_no_year.empty?
@title_params[:title_meta] = "#{loc.name} on Pinball Map! " + loc.full_street_address + machine_length.to_s + machine_list.to_s
end
Expand Down Expand Up @@ -86,7 +86,7 @@ def region

if !params[:by_location_id].blank? && (loc = Location.where(id: params[:by_location_id]).first)
@title_params[:title] = "#{loc.name} - #{@region.full_name} Pinball Map"
machine_length = " - " + loc.machines.length.to_s + " " + "machine".pluralize(loc.machines.length) unless loc.machines.empty?
machine_length = " - " + loc.machine_count.to_s + " " + "machine".pluralize(loc.machine_count) unless loc.machine_count.zero?
machine_list = " - " + loc.machine_names_first_no_year.join(", ") unless loc.machine_names_first_no_year.empty?
@title_params[:title_meta] = "#{loc.name} on Pinball Map! " + loc.full_street_address + machine_length.to_s + machine_list.to_s
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def user_fave?(user_id)
end

def num_machines
machines.length
machine_count
end

def machine_names
Expand Down
4 changes: 2 additions & 2 deletions app/models/region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def primary_email_contact
end

def machineless_locations
locations.select { |location| location.machines.empty? }
locations.select { |location| location.machine_count.zero? }
end

def locations_count
Expand Down Expand Up @@ -176,7 +176,7 @@ def self.generate_weekly_regionless_email_body
end

{ regionless_locations_count: regionless_locations.count, regionless_machines_count: LocationMachineXref.count_by_sql("select count(*) from location_machine_xrefs lmx inner join locations l on (lmx.location_id = l.id) where l.region_id is null"),
machineless_locations: regionless_locations.select { |location| location.machines.empty? }.each.map { |ml| ml.name + " (#{ml.city}, #{ml.state})" },
machineless_locations: regionless_locations.select { |location| location.machine_count.zero? }.each.map { |ml| ml.name + " (#{ml.city}, #{ml.state})" },
suggested_locations: SuggestedLocation.where("region_id is null").each.map(&:name),
suggested_locations_count: UserSubmission.where("region_id is null").select { |us| !us.created_at.nil? && us.created_at.between?(start_of_week, end_of_week) && us.submission_type == UserSubmission::SUGGEST_LOCATION_TYPE }.count,
locations_added_count: regionless_locations.select { |l| !l.created_at.nil? && l.created_at.between?(start_of_week, end_of_week) }.count,
Expand Down
6 changes: 3 additions & 3 deletions app/views/locations/_locations.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@
%div
#{machine.name}
%span.man_year (#{[machine.manufacturer, machine.year].reject(&:blank?).join(', ')})
- if (location.machines.size > 5)
- if (location.machine_count > 5)
%div.darkgrey.italic.pb_15
plus
= pluralize(location.machines.size - 5, 'more machine')
= pluralize(location.machine_count - 5, 'more machine')

%div.location_detail[l, :location_detail]{:style => 'display:none;'}

- l = nil
- total_num_machines += location.machines.size
- total_num_machines += location.machine_count
- unless @locations.size == 1
#search_results_count
%span
Expand Down
8 changes: 4 additions & 4 deletions spec/features/location_machine_xrefs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

sleep 1

expect(location.machines.size).to eq(1)
expect(location.reload.machine_count).to eq(1)
expect(location.machines.first).to eq(@machine_to_add)
expect(location.reload.date_last_updated).to eq(Date.today)

Expand All @@ -66,7 +66,7 @@

sleep 1

expect(@location.machines.size).to eq(1)
expect(@location.reload.machine_count).to eq(1)
expect(@location.machines.first).to eq(@machine_to_add)

expect(find("#show_machines_location_#{@location.id}")).to have_content(@machine_to_add.name)
Expand All @@ -79,7 +79,7 @@

sleep 1

expect(@location.machines.size).to eq(1)
expect(@location.machine_count).to eq(1)
expect(@location.machines.first).to eq(@machine_to_add)

expect(find("#show_machines_location_#{@location.id}")).to have_content(@machine_to_add.name)
Expand All @@ -96,7 +96,7 @@

sleep 1

expect(@location.machines.size).to eq(0)
expect(@location.machine_count).to eq(0)

expect(find("#show_machines_location_#{@location.id}")).to_not have_content('New Machine Name')
end
Expand Down

0 comments on commit 5203d17

Please sign in to comment.