-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revamp tagging stuff, ensure it works on the ticket model
- Loading branch information
Showing
6 changed files
with
51 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 14 additions & 6 deletions
20
db/migrate/20241218224853_acts_as_taggable_on_migration.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |