- # Now try as a normal user
- session_for(user)
- delete user_path(user)
- assert_redirected_to :controller => :errors, :action => :forbidden
-
- # Finally try as an administrator
- session_for(create(:administrator_user))
- delete user_path(user)
- assert_redirected_to :action => :show, :display_name => user.display_name
-
- # Check that the user was deleted properly
- user.reload
- assert_equal "user_#{user.id}", user.display_name
- assert_equal "", user.description
- assert_nil user.home_lat
- assert_nil user.home_lon
- assert_not user.avatar.attached?
- assert_not user.email_valid
- assert_nil user.new_email
- assert_nil user.auth_provider
- assert_nil user.auth_uid
- assert_equal "deleted", user.status
+ # Create an initial changeset
+ create(:changeset, :user => user, :created_at => 6.months.ago, :num_changes => 15)
+
+ # First request to populate the cache
+ get user_path(user.display_name)
+ first_response_data = assigns(:heatmap_data)
+ assert_not_nil first_response_data, "Expected heatmap data to be assigned on the first request"
+ assert_equal 1, first_response_data.size, "Expected one entry in the heatmap data"
+
+ # Inspect cache after the first request
+ cached_data = Rails.cache.read("heatmap_data_with_ids_user_#{user.id}")
+ assert_equal first_response_data, cached_data, "Expected the cache to contain the first response data"
+
+ # Add a new changeset to the database
+ create(:changeset, :user => user, :created_at => 3.months.ago, :num_changes => 20)
+
+ # Second request
+ get user_path(user.display_name)
+ second_response_data = assigns(:heatmap_data)
+
+ # Confirm that the cache is still being used
+ assert_equal first_response_data, second_response_data, "Expected cached data to be returned on the second request"
+
+ # Clear the cache and make a third request to confirm new data is retrieved
+ Rails.cache.clear
+ get user_path(user.display_name)
+ third_response_data = assigns(:heatmap_data)
+
+ # Ensure the new entry is now included
+ assert_equal 2, third_response_data.size, "Expected two entries in the heatmap data after clearing the cache"
+
+ # Reset caching config to defaults
+ Rails.cache.clear
+ Rails.cache = @original_cache_store