Skip to content

Commit

Permalink
Revamp tagging stuff, ensure it works on the ticket model
Browse files Browse the repository at this point in the history
  • Loading branch information
crismali committed Dec 18, 2024
1 parent beeefd8 commit 4a6d192
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ gem "good_job", "~> 4.6"

gem "blazer", "~> 3.1"

gem "acts-as-taggable-on", "~> 5.0"
gem 'acts-as-taggable-on', '~> 12.0'
7 changes: 4 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ GEM
minitest (>= 5.1)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
acts-as-taggable-on (5.0.0)
activerecord (>= 4.2.8)
acts-as-taggable-on (12.0.0)
activerecord (>= 7.1, < 8.1)
zeitwerk (>= 2.4, < 3.0)
acts_as_list (1.2.4)
activerecord (>= 6.1)
activesupport (>= 6.1)
Expand Down Expand Up @@ -594,7 +595,7 @@ PLATFORMS

DEPENDENCIES
activerecord-postgres_enum
acts-as-taggable-on (~> 5.0)
acts-as-taggable-on (~> 12.0)
acts_as_list
acts_as_tenant
ahoy_matey (~> 5.2)
Expand Down
2 changes: 2 additions & 0 deletions app/models/ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Ticket < ApplicationRecord

has_rich_text :body

acts_as_taggable_on :tags

validates :title, presence: true
validates :status, inclusion: {in: Ticket.statuses.keys}

Expand Down
20 changes: 14 additions & 6 deletions db/migrate/20241218224853_acts_as_taggable_on_migration.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
class ActsAsTaggableOnMigration < ActiveRecord::Migration[7.2]
def change
create_table "taggings", id: :serial, force: :cascade do |t|
t.integer "tag_id"
create_table "taggings", force: :cascade do |t|
t.bigint "tag_id"
t.string "taggable_type"
t.integer "taggable_id"
t.bigint "taggable_id"
t.string "tagger_type"
t.integer "tagger_id"
t.bigint "tagger_id"
t.string "context", limit: 128
t.datetime "created_at", precision: nil
t.string "tenant", limit: 128
t.index ["context"], name: "index_taggings_on_context"
t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
t.index ["tag_id"], name: "index_taggings_on_tag_id"
t.index ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context"
t.index ["taggable_id", "taggable_type", "context"], name: "taggings_taggable_context_idx"
t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy"
t.index ["taggable_id"], name: "index_taggings_on_taggable_id"
t.index ["taggable_type", "taggable_id"], name: "index_taggings_on_taggable_type_and_taggable_id"
t.index ["taggable_type"], name: "index_taggings_on_taggable_type"
t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type"
t.index ["tagger_id"], name: "index_taggings_on_tagger_id"
t.index ["tagger_type", "tagger_id"], name: "index_taggings_on_tagger_type_and_tagger_id"
t.index ["tenant"], name: "index_taggings_on_tenant"
end

create_table "tags", id: :serial, force: :cascade do |t|
create_table "tags", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "taggings_count", default: 0
t.index ["name"], name: "index_tags_on_name", unique: true
end

add_foreign_key "taggings", "tags"
end
end
19 changes: 13 additions & 6 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -855,27 +855,33 @@
t.index ["question_id"], name: "index_stems_on_question_id"
end

create_table "taggings", id: :serial, force: :cascade do |t|
t.integer "tag_id"
create_table "taggings", force: :cascade do |t|
t.bigint "tag_id"
t.string "taggable_type"
t.integer "taggable_id"
t.bigint "taggable_id"
t.string "tagger_type"
t.integer "tagger_id"
t.bigint "tagger_id"
t.string "context", limit: 128
t.datetime "created_at", precision: nil
t.string "tenant", limit: 128
t.index ["context"], name: "index_taggings_on_context"
t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
t.index ["tag_id"], name: "index_taggings_on_tag_id"
t.index ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context"
t.index ["taggable_id", "taggable_type", "context"], name: "taggings_taggable_context_idx"
t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy"
t.index ["taggable_id"], name: "index_taggings_on_taggable_id"
t.index ["taggable_type", "taggable_id"], name: "index_taggings_on_taggable_type_and_taggable_id"
t.index ["taggable_type"], name: "index_taggings_on_taggable_type"
t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type"
t.index ["tagger_id"], name: "index_taggings_on_tagger_id"
t.index ["tagger_type", "tagger_id"], name: "index_taggings_on_tagger_type_and_tagger_id"
t.index ["tenant"], name: "index_taggings_on_tenant"
end

create_table "tags", id: :serial, force: :cascade do |t|
create_table "tags", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "taggings_count", default: 0
t.index ["name"], name: "index_tags_on_name", unique: true
end
Expand Down Expand Up @@ -984,6 +990,7 @@
add_foreign_key "reservations", "users", column: "reviewer_id"
add_foreign_key "reservations", "users", column: "submitted_by_id"
add_foreign_key "stems", "questions"
add_foreign_key "taggings", "tags"
add_foreign_key "ticket_updates", "audits"
add_foreign_key "ticket_updates", "tickets"
add_foreign_key "ticket_updates", "users", column: "creator_id"
Expand Down
20 changes: 17 additions & 3 deletions test/models/ticket_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
require "test_helper"

class TicketTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "has tags" do
ticket = create(:ticket)

ticket.tag_list.add("awesome", "not awesome")
assert ticket.save

ticket.reload

assert_equal ['awesome', 'not awesome'], ticket.tag_list

ticket.tag_list.remove("not awesome")

assert ticket.save

ticket.reload
assert_equal ['awesome'], ticket.tag_list
end
end

0 comments on commit 4a6d192

Please sign in to comment.