From a5949a4b289c1f9fb05a76a52cc5f32c55c663ca Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 22 Sep 2019 23:14:55 -0500 Subject: [PATCH] saved searches: always show 'Saved searches' link in navbar. * Always display 'Saved searches' link in subnav bar, even if the user hasn't created any saved searches yet. * Eliminate use of `has_saved_searches` bitpref on users. --- app/models/saved_search.rb | 14 -------------- app/models/user.rb | 1 + .../partials/common/_secondary_links.html.erb | 4 +--- app/views/users/_statistics.html.erb | 2 +- test/unit/saved_search_test.rb | 17 ----------------- 5 files changed, 3 insertions(+), 35 deletions(-) diff --git a/app/models/saved_search.rb b/app/models/saved_search.rb index c83d357dc..301c1ec24 100644 --- a/app/models/saved_search.rb +++ b/app/models/saved_search.rb @@ -151,8 +151,6 @@ class SavedSearch < ApplicationRecord belongs_to :user validates :query, presence: true validate :validate_count - before_create :update_user_on_create - after_destroy :update_user_on_destroy before_validation :normalize_query before_validation :normalize_labels scope :labeled, ->(label) { label.present? ? where("labels @> string_to_array(?, '~~~~')", label) : where("true") } @@ -163,18 +161,6 @@ class SavedSearch < ApplicationRecord end end - def update_user_on_create - if !user.has_saved_searches? - user.update(has_saved_searches: true) - end - end - - def update_user_on_destroy - if user.saved_searches.count == 0 - user.update(has_saved_searches: false) - end - end - def disable_labels=(value) CurrentUser.update(disable_categorized_saved_searches: true) if value.to_s.truthy? end diff --git a/app/models/user.rb b/app/models/user.rb index 0040056a0..7afe3efc6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -32,6 +32,7 @@ class User < ApplicationRecord # - disable_tagged_filenames (enabled by 387) # - enable_recent_searches (enabled by 499) # - disable_cropped_thumbnails (enabled by 22) + # - has_saved_searches BOOLEAN_ATTRIBUTES = %w( is_banned has_mail diff --git a/app/views/posts/partials/common/_secondary_links.html.erb b/app/views/posts/partials/common/_secondary_links.html.erb index 4500860c4..ee3ba3fa2 100644 --- a/app/views/posts/partials/common/_secondary_links.html.erb +++ b/app/views/posts/partials/common/_secondary_links.html.erb @@ -8,9 +8,7 @@ <% unless CurrentUser.is_anonymous? %> <%= subnav_link_to "Favorites", posts_path(tags: "ordfav:#{CurrentUser.user.name}") %> <%= subnav_link_to "Fav groups", favorite_groups_path %> - <% if CurrentUser.has_saved_searches? %> - <%= subnav_link_to "Saved searches", posts_path(:tags => "search:all") %> - <% end %> + <%= subnav_link_to "Saved searches", posts_path(tags: "search:all") %> <% end %> <%= subnav_link_to "Changes", post_versions_path %> <% if CurrentUser.can_approve_posts? %> diff --git a/app/views/users/_statistics.html.erb b/app/views/users/_statistics.html.erb index 6a063d2c7..227c380c4 100644 --- a/app/views/users/_statistics.html.erb +++ b/app/views/users/_statistics.html.erb @@ -170,7 +170,7 @@ <% end %> <% if CurrentUser.id == user.id %> - <% if CurrentUser.has_saved_searches? %> + <% if SavedSearch.labels_for(CurrentUser.user.id).present? %> Saved Searches diff --git a/test/unit/saved_search_test.rb b/test/unit/saved_search_test.rb index 0c0dc1e2b..b875fc021 100644 --- a/test/unit/saved_search_test.rb +++ b/test/unit/saved_search_test.rb @@ -146,11 +146,6 @@ class SavedSearchTest < ActiveSupport::TestCase @saved_search = @user.saved_searches.create(query: " ZZZ xxx ") end - should "update the bitpref on the user" do - @user.reload - assert(@user.has_saved_searches?, "should have saved_searches bitpref set") - end - should "normalize the query aside from the order" do assert_equal("yyy xxx", @saved_search.query) end @@ -164,18 +159,6 @@ class SavedSearchTest < ActiveSupport::TestCase end end - context "Destroying a saved search" do - setup do - @saved_search = @user.saved_searches.create(query: "xxx") - @saved_search.destroy - end - - should "update the bitpref on the user" do - @user.reload - assert(!@user.has_saved_searches?, "should not have the saved_searches bitpref set") - end - end - context "A user with max saved searches" do setup do @user = FactoryBot.create(:gold_user)