Skip to content

Commit

Permalink
Limit former machines and recent activity to 30 items, and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanTG committed Nov 13, 2024
1 parent beed3d5 commit 1bd392f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/models/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/locations/_render_former_machines.html.haml
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
2 changes: 1 addition & 1 deletion app/views/locations/_render_recent_activity.html.haml
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down
46 changes: 46 additions & 0 deletions spec/features/locations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1bd392f

Please sign in to comment.