diff --git a/Gemfile.lock b/Gemfile.lock index 314b90e..1af1d27 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -154,8 +154,8 @@ GEM mini_magick (4.13.2) mini_mime (1.1.5) minitest (5.25.1) - msgpack (1.7.3) - net-imap (0.5.0) + msgpack (1.7.4) + net-imap (0.5.1) date net-protocol net-protocol (0.2.2) @@ -242,7 +242,7 @@ GEM rubocop-ast (>= 1.32.2, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.34.1) + rubocop-ast (1.35.0) parser (>= 3.3.1.0) rubocop-minitest (0.36.0) rubocop (>= 1.61, < 2.0) @@ -260,7 +260,7 @@ GEM ffi (~> 1.12) logger rubyzip (2.3.2) - securerandom (0.3.1) + securerandom (0.3.2) selenium-webdriver (4.26.0) base64 (~> 0.2) logger (~> 1.4) diff --git a/app/assets/stylesheets/tags.css b/app/assets/stylesheets/tags.css index bcf74cf..6d7e725 100644 --- a/app/assets/stylesheets/tags.css +++ b/app/assets/stylesheets/tags.css @@ -16,10 +16,19 @@ .tag-container { display: flex; align-items: flex-start; -} -.tag-container .name { - flex-grow: 1; + .name { + flex-grow: 1; + } + + .name a { + text-decoration: none; + color: var(--text) !important; + } + + .name a:hover { + text-decoration: underline; + } } .tag-container .action { diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index ee837ef..c5ca6a8 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class TagsController < ApplicationController - before_action :set_tag, only: %i[edit update destroy] + before_action :set_tag, only: %i[edit update destroy search] def index @tags = Tag.order(:name) @@ -57,10 +57,16 @@ def destroy redirect_to tags_url, notice: t('tags.destroy-success') end + def search + @search = Search.new(name: 'temporary', body: "tag:\"#{@tag.name}\"") + + render 'searches/show' + end + private def set_tag - @tag = Tag.find(params[:id]) + @tag = Tag.find(params[:id] || params[:tag_id]) end def tag_params diff --git a/app/views/searches/show.html.erb b/app/views/searches/show.html.erb index b7d3854..16e5996 100644 --- a/app/views/searches/show.html.erb +++ b/app/views/searches/show.html.erb @@ -1 +1 @@ -<%= render "search", items: @search.results %> +<%= render "searches/search", items: @search.results %> diff --git a/app/views/tags/_tag.html.erb b/app/views/tags/_tag.html.erb index 0a82898..9fe2669 100644 --- a/app/views/tags/_tag.html.erb +++ b/app/views/tags/_tag.html.erb @@ -1,9 +1,9 @@
- <%= tag.name %> + <%= link_to tag.name, edit_tag_path(tag), title: I18n.t('general.edit').capitalize %>
- <%= link_to I18n.t('general.edit'), edit_tag_path(tag) %> | + <%= link_to I18n.t('searches.object'), tag_search_path(tag) %> | <%= link_to I18n.t('general.delete'), tag_path(tag), data: { "turbo-method": :delete } %>
diff --git a/config/routes.rb b/config/routes.rb index fe9ee96..1f1df38 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,10 @@ resource :exports, only: %i[new show] end - resources :tags + resources :tags do + get 'search' => 'tags#search' + end + resources :things, except: %i[index] do resources :comments, only: %i[create update destroy] end diff --git a/test/system/tags_test.rb b/test/system/tags_test.rb index a690007..cf19e4f 100644 --- a/test/system/tags_test.rb +++ b/test/system/tags_test.rb @@ -2,7 +2,7 @@ require 'application_system_test_case' -class SharedSearchesTest < ApplicationSystemTestCase +class TagsTest < ApplicationSystemTestCase setup { sign_in! } test 'lists all the tags' do @@ -34,7 +34,7 @@ class SharedSearchesTest < ApplicationSystemTestCase test 'can visit the edit_tag path from #index' do visit tags_url - click_link(I18n.t('general.edit'), match: :first) + click_link(Tag.first.name, match: :first) assert_text I18n.t('tags.update') end @@ -73,11 +73,18 @@ class SharedSearchesTest < ApplicationSystemTestCase test 'can delete an existing tag' do visit tags_url - # TODO: flaky assert_difference 'Tag.count', -1 do click_link(I18n.t('general.delete'), match: :first) assert_text I18n.t('tags.title') end end + + test 'can search on a given tag' do + visit tags_url + + click_link(I18n.t('searches.object'), match: :first) + + assert_text Thing.find_by(target: 'target1').title + end end