aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <msabate@suse.com>2024-03-20 13:59:15 +0100
committerMiquel Sabaté Solà <msabate@suse.com>2024-03-20 13:59:15 +0100
commitccf588845a6e595d1c9b2726a05eddd34bc92488 (patch)
tree80ff56c17f5723ae8fff4f164bd0466df42ca348
parent37d4967780f5b3dd06bb05337149811d7d7f8788 (diff)
downloadoperum-ccf588845a6e595d1c9b2726a05eddd34bc92488.tar.gz
operum-ccf588845a6e595d1c9b2726a05eddd34bc92488.zip
tags: added a way to update tags
It's useful to just rename tags which have quite some references that you don't want to nuke. Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
-rw-r--r--Gemfile6
-rw-r--r--app/assets/stylesheets/tags.css2
-rw-r--r--app/controllers/tags_controller.rb12
-rw-r--r--app/views/tags/_tag.html.erb1
-rw-r--r--app/views/tags/edit.html.erb9
-rw-r--r--app/views/tags/new.html.erb2
-rw-r--r--config/locales/ca.yml2
-rw-r--r--config/locales/en.yml2
-rw-r--r--config/routes.rb2
-rw-r--r--test/system/tags_test.rb29
10 files changed, 59 insertions, 8 deletions
diff --git a/Gemfile b/Gemfile
index 28d2409..235e623 100644
--- a/Gemfile
+++ b/Gemfile
@@ -38,6 +38,9 @@ gem 'image_processing', '~> 1.2'
group :development, :test do
gem 'debug', platforms: %i[mri windows]
+ # Convenient & prettier printer.
+ gem 'awesome_print'
+
# Security
gem 'brakeman', require: false
gem 'bundle-audit', require: false
@@ -47,9 +50,6 @@ group :development do
# Use console on exceptions pages.
gem 'web-console'
- # Convenient & prettier printer.
- gem 'awesome_print'
-
# Style
gem 'rubocop', require: false
gem 'rubocop-minitest', require: false
diff --git a/app/assets/stylesheets/tags.css b/app/assets/stylesheets/tags.css
index 75dd87d..bcf74cf 100644
--- a/app/assets/stylesheets/tags.css
+++ b/app/assets/stylesheets/tags.css
@@ -3,7 +3,7 @@
vertical-align: middle;
}
-#tag-new h3 span {
+#tag-page h3 span {
font-size: 1rem;
vertical-align: middle;
}
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 8ae36d7..9d87687 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[destroy]
+ before_action :set_tag, only: %i[edit update destroy]
def index
@tags = Tag.order(:name)
@@ -11,6 +11,8 @@ class TagsController < ApplicationController
@tag = Tag.new
end
+ def edit; end
+
def create
@tag = Tag.new(tag_params)
@@ -21,6 +23,14 @@ class TagsController < ApplicationController
end
end
+ def update
+ if @tag.update(tag_params)
+ redirect_to tags_url, notice: t('tags.update-success')
+ else
+ render :edit, status: :unprocessable_entity
+ end
+ end
+
def destroy
@tag.destroy!
diff --git a/app/views/tags/_tag.html.erb b/app/views/tags/_tag.html.erb
index 65c6d4e..0a82898 100644
--- a/app/views/tags/_tag.html.erb
+++ b/app/views/tags/_tag.html.erb
@@ -3,6 +3,7 @@
<%= tag.name %>
</div>
<div class="action">
+ <%= link_to I18n.t('general.edit'), edit_tag_path(tag) %> |
<%= link_to I18n.t('general.delete'), tag_path(tag), data: { "turbo-method": :delete } %>
</div>
</div>
diff --git a/app/views/tags/edit.html.erb b/app/views/tags/edit.html.erb
new file mode 100644
index 0000000..44214a3
--- /dev/null
+++ b/app/views/tags/edit.html.erb
@@ -0,0 +1,9 @@
+<div class="center-contents">
+ <div></div>
+ <div id="tag-page">
+ <h3><%= I18n.t('tags.update') %> <span>&#8212; <%= link_to I18n.t('general.back-to-list'), tags_path %></span></h3>
+
+ <%= render "form", tag: @tag %>
+ </div>
+ <div></div>
+</div>
diff --git a/app/views/tags/new.html.erb b/app/views/tags/new.html.erb
index 9d6e1a8..97cd410 100644
--- a/app/views/tags/new.html.erb
+++ b/app/views/tags/new.html.erb
@@ -1,6 +1,6 @@
<div class="center-contents">
<div></div>
- <div id="tag-new">
+ <div id="tag-page">
<h3><%= I18n.t('tags.new') %> <span>&#8212; <%= link_to I18n.t('general.back-to-list'), tags_path %></span></h3>
<%= render "form", tag: @tag %>
diff --git a/config/locales/ca.yml b/config/locales/ca.yml
index a394caa..b9f9b7c 100644
--- a/config/locales/ca.yml
+++ b/config/locales/ca.yml
@@ -108,9 +108,11 @@ ca:
title: Etiquetes
new: Etiqueta nova
new-action: nova
+ update: Reanomena l'etiqueta
none: Encara no hi ha cap etiqueta. Pots crear-ne una fent click
create-success: Etiqueta creada correctament
+ update-success: S'ha canviat el nom de l'etiqueta correctament
destroy-success: Etiqueta esborrada correctament
things:
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 9cef5f8..e720a0c 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -107,10 +107,12 @@ en:
tags:
title: Tags
new: New tag
+ update: Rename tag
new-action: new
none: You have not created any tags. You can do so by clicking
create-success: Tag was successfully created
+ update-success: Tag was successfully updated
destroy-success: Tag was successfully deleted
things:
diff --git a/config/routes.rb b/config/routes.rb
index 1e5eedb..fe9ee96 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -12,7 +12,7 @@ Rails.application.routes.draw do
resource :exports, only: %i[new show]
end
- resources :tags, only: %i[index new create destroy]
+ resources :tags
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 8789087..7e2100f 100644
--- a/test/system/tags_test.rb
+++ b/test/system/tags_test.rb
@@ -22,7 +22,7 @@ class SharedSearchesTest < ApplicationSystemTestCase
end
end
- test 'gives feedback on errors' do
+ test 'gives feedback on create errors' do
visit new_tag_url
fill_in I18n.t('activerecord.attributes.tag.name'), with: tags(:tag1).name
@@ -31,6 +31,33 @@ class SharedSearchesTest < ApplicationSystemTestCase
assert_text "#{I18n.t('activerecord.attributes.tag.name')} #{I18n.t('errors.messages.taken')}"
end
+ test 'can visit the edit_tag path from #index' do
+ visit tags_url
+
+ click_link(I18n.t('general.edit'), match: :first)
+
+ assert_text I18n.t('tags.update')
+ end
+
+ test 'can update a tag' do
+ visit edit_tag_url(tags(:tag1))
+
+ fill_in I18n.t('activerecord.attributes.tag.name'), with: "#{tags(:tag1).name}-updated"
+ click_on I18n.t('helpers.submit.update')
+
+ assert_text I18n.t('tags.update-success')
+ assert_text "#{tags(:tag1).name}-updated"
+ end
+
+ test 'gives feedback on update errors' do
+ visit edit_tag_url(tags(:tag1))
+
+ fill_in I18n.t('activerecord.attributes.tag.name'), with: tags(:tag2).name
+ click_on I18n.t('helpers.submit.update')
+
+ assert_text "#{I18n.t('activerecord.attributes.tag.name')} #{I18n.t('errors.messages.taken')}"
+ end
+
test 'can delete an existing tag' do
visit tags_url