From 1bd392f73f49015596a336b8597e8b969127501e Mon Sep 17 00:00:00 2001 From: RyanTG Date: Wed, 13 Nov 2024 12:55:15 -0800 Subject: [PATCH] Limit former machines and recent activity to 30 items, and add tests --- app/models/location.rb | 4 +- .../_render_former_machines.html.haml | 2 +- .../_render_recent_activity.html.haml | 2 +- spec/features/locations_controller_spec.rb | 46 +++++++++++++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/app/models/location.rb b/app/models/location.rb index 5bcbfe3e..8a16135a 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -170,11 +170,11 @@ def content_for_infowindow end def recent_activity - UserSubmission.where(submission_type: %w[new_lmx remove_machine new_condition new_msx confirm_location], location_id: self, created_at: '2019-05-03T07:00:00.00-07:00'..Date.today.end_of_day).order('created_at DESC') + UserSubmission.where(submission_type: %w[new_lmx remove_machine new_condition new_msx confirm_location], location_id: self, created_at: '2019-05-03T07:00:00.00-07:00'..Date.today.end_of_day).order('created_at DESC').limit(30) end def former_machines - UserSubmission.where.not(machine_name: nil).where(submission_type: 'remove_machine', location_id: self).where(location_id: self).order('created_at DESC') + UserSubmission.where.not(machine_name: nil).where(submission_type: 'remove_machine', location_id: self).where(location_id: self).order('created_at DESC').limit(30) end def full_street_address diff --git a/app/views/locations/_render_former_machines.html.haml b/app/views/locations/_render_former_machines.html.haml index 86e34772..47385f95 100644 --- a/app/views/locations/_render_former_machines.html.haml +++ b/app/views/locations/_render_former_machines.html.haml @@ -1,4 +1,4 @@ -%div.quick_button_content_header Machines That Used to be Here +%div.quick_button_content_header Former Machines (max of 30) - l.former_machines.each do |former_machines| %div.recent_activity_container{:style => 'padding-left: 20px;'} %div.recent_activity_submission.font16.bold.brightpurple #{former_machines.machine_name} diff --git a/app/views/locations/_render_recent_activity.html.haml b/app/views/locations/_render_recent_activity.html.haml index b0da9d5c..cfddff1a 100644 --- a/app/views/locations/_render_recent_activity.html.haml +++ b/app/views/locations/_render_recent_activity.html.haml @@ -1,4 +1,4 @@ -%div.quick_button_content_header Recent Location Activity +%div.quick_button_content_header Recent Location Activity (max of 30) - l.recent_activity.take(20).each do |recent_activity| - if (!recent_activity.user_name.blank?) - recent_activity_user = " by #{recent_activity.user_name}" diff --git a/spec/features/locations_controller_spec.rb b/spec/features/locations_controller_spec.rb index e0819979..8257bba7 100644 --- a/spec/features/locations_controller_spec.rb +++ b/spec/features/locations_controller_spec.rb @@ -525,6 +525,52 @@ end end + describe 'former_machines', type: :feature, js: true do + before(:each) do + @location = FactoryBot.create(:location, name: 'Cleo') + @location2 = FactoryBot.create(:location, name: 'Sassimo') + end + it 'returns a list of machines that have been removed from the location' do + FactoryBot.create(:user_submission, created_at: '2022-01-02', location: @location, machine_name: 'Sassy Madness', submission_type: UserSubmission::REMOVE_MACHINE_TYPE) + FactoryBot.create(:user_submission, created_at: '2022-01-02', location: @location2, machine_name: 'Pizza Attack', submission_type: UserSubmission::REMOVE_MACHINE_TYPE) + + visit '/map/?by_location_id=' + @location.id.to_s + + find("#former_machines_location_banner_#{@location.id}").click + sleep(0.5) + + expect(find('.former_machines_location')).to have_content('Sassy Madness') + expect(find('.former_machines_location')).to_not have_content('Pizza Attack') + end + end + + describe 'recent_activity', type: :feature, js: true do + before(:each) do + @location = FactoryBot.create(:location, name: 'Cleo', city: 'Townville') + @location2 = FactoryBot.create(:location, name: 'Sassimo') + end + it 'returns a list of recent activity at the location' do + FactoryBot.create(:user_submission, created_at: '2022-01-02', location: @location, user_name: 'ssw', machine_name: 'Sassy Madness', submission_type: UserSubmission::NEW_LMX_TYPE) + FactoryBot.create(:user_submission, created_at: '2022-01-03', location: @location, user_name: 'ssw', machine_name: 'Pizza Attack', submission_type: UserSubmission::REMOVE_MACHINE_TYPE) + FactoryBot.create(:user_submission, created_at: '2022-01-04', location: @location, user_name: 'ssw', comment: 'be best', machine_name: 'Sassy Madness', submission_type: UserSubmission::NEW_CONDITION_TYPE) + FactoryBot.create(:user_submission, created_at: '2022-01-05', location: @location, user_name: 'ssw', submission_type: UserSubmission::CONFIRM_LOCATION_TYPE) + FactoryBot.create(:user_submission, created_at: '2022-01-06', location: @location, user_name: 'ssw', high_score: '2222', machine_name: 'Sassy Madness', submission_type: UserSubmission::NEW_SCORE_TYPE) + FactoryBot.create(:user_submission, created_at: '2022-01-02', location: @location2, machine_name: 'Jolene Zone', submission_type: UserSubmission::REMOVE_MACHINE_TYPE) + + visit '/map/?by_location_id=' + @location.id.to_s + + find("#recent_location_activity_location_banner_#{@location.id}").click + sleep(0.5) + + expect(find('.recent_location_activity_location')).to have_content('added') + expect(find('.recent_location_activity_location')).to have_content('removed') + expect(find('.recent_location_activity_location')).to have_content('score') + expect(find('.recent_location_activity_location')).to have_content('confirmed') + expect(find('.recent_location_activity_location')).to have_content('be best') + expect(find('.recent_location_activity_location')).to_not have_content('Jolene Zone') + end + end + describe 'update_metadata', type: :feature, js: true do before(:each) do @user = FactoryBot.create(:user)