Use Tag instead of ActsAsTaggableOn::Tag
It's shorter, it's easier to extend its behaviour, and it's easier to integrate with other parts of our application, like translations.
This commit is contained in:
@@ -4,12 +4,12 @@ class Admin::TagsController < Admin::BaseController
|
||||
respond_to :html, :js
|
||||
|
||||
def index
|
||||
@tags = ActsAsTaggableOn::Tag.category.page(params[:page])
|
||||
@tag = ActsAsTaggableOn::Tag.category.new
|
||||
@tags = Tag.category.page(params[:page])
|
||||
@tag = Tag.category.new
|
||||
end
|
||||
|
||||
def create
|
||||
ActsAsTaggableOn::Tag.category.create(tag_params)
|
||||
Tag.category.create(tag_params)
|
||||
redirect_to admin_tags_path
|
||||
end
|
||||
|
||||
@@ -25,7 +25,7 @@ class Admin::TagsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def find_tag
|
||||
@tag = ActsAsTaggableOn::Tag.category.find(params[:id])
|
||||
@tag = Tag.category.find(params[:id])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -64,7 +64,7 @@ module Budgets
|
||||
end
|
||||
|
||||
def load_categories
|
||||
@categories = ActsAsTaggableOn::Tag.category.order(:name)
|
||||
@categories = Tag.category.order(:name)
|
||||
end
|
||||
|
||||
def load_ballot_referer
|
||||
|
||||
@@ -146,7 +146,7 @@ module Budgets
|
||||
end
|
||||
|
||||
def load_categories
|
||||
@categories = ActsAsTaggableOn::Tag.category.order(:name)
|
||||
@categories = Tag.category.order(:name)
|
||||
end
|
||||
|
||||
def load_content_blocks
|
||||
|
||||
@@ -110,12 +110,12 @@ module CommentableActions
|
||||
end
|
||||
|
||||
def load_categories
|
||||
@categories = ActsAsTaggableOn::Tag.category.order(:name)
|
||||
@categories = Tag.category.order(:name)
|
||||
end
|
||||
|
||||
def parse_tag_filter
|
||||
if params[:tag].present?
|
||||
@tag_filter = params[:tag] if ActsAsTaggableOn::Tag.named(params[:tag]).exists?
|
||||
@tag_filter = params[:tag] if Tag.named(params[:tag]).exists?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class Management::Budgets::InvestmentsController < Management::BaseController
|
||||
end
|
||||
|
||||
def load_categories
|
||||
@categories = ActsAsTaggableOn::Tag.category.order(:name)
|
||||
@categories = Tag.category.order(:name)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
class TagsController < ApplicationController
|
||||
|
||||
load_and_authorize_resource class: ActsAsTaggableOn::Tag
|
||||
load_and_authorize_resource
|
||||
respond_to :json
|
||||
|
||||
def suggest
|
||||
@tags = ActsAsTaggableOn::Tag.search(params[:search]).map(&:name)
|
||||
@tags = Tag.search(params[:search]).map(&:name)
|
||||
respond_with @tags
|
||||
end
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ module Abilities
|
||||
can :suggest, Debate
|
||||
can :suggest, Proposal
|
||||
can :suggest, Legislation::Proposal
|
||||
can :suggest, ActsAsTaggableOn::Tag
|
||||
can :suggest, Tag
|
||||
|
||||
can [:flag, :unflag], Comment
|
||||
cannot [:flag, :unflag], Comment, user_id: user.id
|
||||
|
||||
@@ -156,7 +156,7 @@ class Proposal < ApplicationRecord
|
||||
|
||||
def self.for_summary
|
||||
summary = {}
|
||||
categories = ActsAsTaggableOn::Tag.category_names.sort
|
||||
categories = Tag.category_names.sort
|
||||
geozones = Geozone.names.sort
|
||||
|
||||
groups = categories + geozones
|
||||
|
||||
@@ -16,7 +16,7 @@ class TagCloud
|
||||
end
|
||||
|
||||
def category_names
|
||||
ActsAsTaggableOn::Tag.category_names.map(&:downcase)
|
||||
Tag.category_names.map(&:downcase)
|
||||
end
|
||||
|
||||
def geozone_names
|
||||
|
||||
@@ -20,7 +20,7 @@ Debate:
|
||||
comments: [Comment]
|
||||
public_author: User
|
||||
votes_for: [Vote]
|
||||
tags: ["ActsAsTaggableOn::Tag"]
|
||||
tags: [Tag]
|
||||
Proposal:
|
||||
fields:
|
||||
id: integer
|
||||
@@ -42,7 +42,7 @@ Proposal:
|
||||
proposal_notifications: [ProposalNotification]
|
||||
public_author: User
|
||||
votes_for: [Vote]
|
||||
tags: ["ActsAsTaggableOn::Tag"]
|
||||
tags: [Tag]
|
||||
Comment:
|
||||
fields:
|
||||
id: integer
|
||||
@@ -68,7 +68,7 @@ ProposalNotification:
|
||||
proposal_id: integer
|
||||
public_created_at: string
|
||||
proposal: Proposal
|
||||
ActsAsTaggableOn::Tag:
|
||||
Tag:
|
||||
fields:
|
||||
id: integer
|
||||
name: string
|
||||
|
||||
@@ -19,7 +19,7 @@ section "Creating Debates" do
|
||||
end
|
||||
end
|
||||
|
||||
tags = ActsAsTaggableOn::Tag.where(kind: "category")
|
||||
tags = Tag.where(kind: "category")
|
||||
30.times do
|
||||
author = User.all.sample
|
||||
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
|
||||
|
||||
@@ -3,7 +3,7 @@ section "Creating comment notifications" do
|
||||
debate = Debate.create!(author: user,
|
||||
title: Faker::Lorem.sentence(3).truncate(60),
|
||||
description: "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>",
|
||||
tag_list: ActsAsTaggableOn::Tag.all.sample(3).join(","),
|
||||
tag_list: Tag.all.sample(3).join(","),
|
||||
geozone: Geozone.reorder("RANDOM()").first,
|
||||
terms_of_service: "1")
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ section "Creating Successful Proposals" do
|
||||
add_image_to proposal
|
||||
end
|
||||
|
||||
tags = ActsAsTaggableOn::Tag.where(kind: "category")
|
||||
tags = Tag.where(kind: "category")
|
||||
30.times do
|
||||
author = User.all.sample
|
||||
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
section "Creating Tags Categories" do
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.associations"))
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.culture"))
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.sports"))
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.social_rights"))
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.economy"))
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.employment"))
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.equity"))
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.sustainability"))
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.participation"))
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.mobility"))
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.media"))
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.health"))
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.transparency"))
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.security_emergencies"))
|
||||
ActsAsTaggableOn::Tag.category.create!(name: I18n.t("seeds.categories.environment"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.associations"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.culture"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.sports"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.social_rights"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.economy"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.employment"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.equity"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.sustainability"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.participation"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.mobility"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.media"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.health"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.transparency"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.security_emergencies"))
|
||||
Tag.category.create!(name: I18n.t("seeds.categories.environment"))
|
||||
end
|
||||
|
||||
@@ -134,7 +134,7 @@ The models are the following:
|
||||
| `Comment` | Comments on debates, proposals and other comments |
|
||||
| `Geozone` | Geozones (districts) |
|
||||
| `ProposalNotification` | Notifications related to proposals |
|
||||
| `ActsAsTaggableOn::Tag` | Tags on debates and proposals |
|
||||
| `Tag` | Tags on debates and proposals |
|
||||
| `Vote` | Information related to votes |
|
||||
|
||||
## Examples of queries
|
||||
|
||||
@@ -134,7 +134,7 @@ La lista de modelos es la siguiente:
|
||||
| `Comment` | Comentarios en debates, propuestas y otros comentarios |
|
||||
| `Geozone` | Geozonas (distritos) |
|
||||
| `ProposalNotification` | Notificaciones asociadas a propuestas |
|
||||
| `ActsAsTaggableOn::Tag` | Tags en debates y propuestas |
|
||||
| `Tag` | Tags en debates y propuestas |
|
||||
| `Vote` | Información sobre votos |
|
||||
|
||||
## Ejemplos de consultas
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
FactoryBot.define do
|
||||
factory :tag, class: "ActsAsTaggableOn::Tag" do
|
||||
factory :tag do
|
||||
sequence(:name) { |n| "Tag #{n} name" }
|
||||
|
||||
trait :category do
|
||||
|
||||
@@ -86,7 +86,7 @@ describe "Admin tags" do
|
||||
click_button "Create topic"
|
||||
end
|
||||
|
||||
expect(ActsAsTaggableOn::Tag.category.where(name: "wow_category")).to exist
|
||||
expect(Tag.category.where(name: "wow_category")).to exist
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ describe ActsAsTaggableOn do
|
||||
let(:debate) { create(:debate) }
|
||||
|
||||
it "increases and decreases the tag's custom counters" do
|
||||
tag = ActsAsTaggableOn::Tag.create(name: "foo")
|
||||
tag = Tag.create(name: "foo")
|
||||
|
||||
expect(tag.debates_count).to eq(0)
|
||||
expect(tag.proposals_count).to eq(0)
|
||||
@@ -47,7 +47,7 @@ describe ActsAsTaggableOn do
|
||||
describe "Tag" do
|
||||
describe "#recalculate_custom_counter_for" do
|
||||
it "updates the counters of proposals and debates, taking into account hidden ones" do
|
||||
tag = ActsAsTaggableOn::Tag.create(name: "foo")
|
||||
tag = Tag.create(name: "foo")
|
||||
|
||||
create(:proposal, tag_list: "foo")
|
||||
create(:proposal, :hidden, tag_list: "foo")
|
||||
@@ -73,7 +73,7 @@ describe ActsAsTaggableOn do
|
||||
proposal.tag_list.add(tag)
|
||||
proposal.save
|
||||
|
||||
expect(ActsAsTaggableOn::Tag.public_for_api).to eq [tag]
|
||||
expect(Tag.public_for_api).to eq [tag]
|
||||
end
|
||||
|
||||
it "returns tags whose kind is 'category' and have at least one tagging whose taggable is not hidden" do
|
||||
@@ -82,7 +82,7 @@ describe ActsAsTaggableOn do
|
||||
proposal.tag_list.add(tag)
|
||||
proposal.save
|
||||
|
||||
expect(ActsAsTaggableOn::Tag.public_for_api).to eq [tag]
|
||||
expect(Tag.public_for_api).to eq [tag]
|
||||
end
|
||||
|
||||
it "blocks other kinds of tags" do
|
||||
@@ -91,13 +91,13 @@ describe ActsAsTaggableOn do
|
||||
proposal.tag_list.add(tag)
|
||||
proposal.save
|
||||
|
||||
expect(ActsAsTaggableOn::Tag.public_for_api).to be_empty
|
||||
expect(Tag.public_for_api).to be_empty
|
||||
end
|
||||
|
||||
it "blocks tags that don't have at least one tagged element" do
|
||||
create(:tag)
|
||||
|
||||
expect(ActsAsTaggableOn::Tag.public_for_api).to be_empty
|
||||
expect(Tag.public_for_api).to be_empty
|
||||
end
|
||||
|
||||
it "only permits tags on proposals or debates" do
|
||||
@@ -117,7 +117,7 @@ describe ActsAsTaggableOn do
|
||||
budget_investment.save
|
||||
debate.save
|
||||
|
||||
expect(ActsAsTaggableOn::Tag.public_for_api).to match_array([tag_1, tag_3])
|
||||
expect(Tag.public_for_api).to match_array([tag_1, tag_3])
|
||||
end
|
||||
|
||||
it "blocks tags after its taggings became hidden" do
|
||||
@@ -126,11 +126,11 @@ describe ActsAsTaggableOn do
|
||||
proposal.tag_list.add(tag)
|
||||
proposal.save
|
||||
|
||||
expect(ActsAsTaggableOn::Tag.public_for_api).to eq [tag]
|
||||
expect(Tag.public_for_api).to eq [tag]
|
||||
|
||||
proposal.delete
|
||||
|
||||
expect(ActsAsTaggableOn::Tag.public_for_api).to be_empty
|
||||
expect(Tag.public_for_api).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
@@ -141,10 +141,10 @@ describe ActsAsTaggableOn do
|
||||
create(:tag, name: "Salud")
|
||||
create(:tag, name: "Famosos")
|
||||
|
||||
expect(ActsAsTaggableOn::Tag.pg_search("f").length).to eq(2)
|
||||
expect(ActsAsTaggableOn::Tag.search("cultura").first.name).to eq("Cultura")
|
||||
expect(ActsAsTaggableOn::Tag.search("sal").first.name).to eq("Salud")
|
||||
expect(ActsAsTaggableOn::Tag.search("fami").first.name).to eq("Familia")
|
||||
expect(Tag.pg_search("f").length).to eq(2)
|
||||
expect(Tag.search("cultura").first.name).to eq("Cultura")
|
||||
expect(Tag.search("sal").first.name).to eq("Salud")
|
||||
expect(Tag.search("fami").first.name).to eq("Familia")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ describe "Cache flow" do
|
||||
describe "Tag destroy" do
|
||||
it "invalidates Debate cache keys" do
|
||||
debate = create(:debate, tag_list: "Good, Bad")
|
||||
tag = ActsAsTaggableOn::Tag.find_by(name: "Bad")
|
||||
tag = Tag.find_by(name: "Bad")
|
||||
|
||||
expect { tag.destroy }.to change { debate.reload.cache_key }
|
||||
end
|
||||
|
||||
@@ -521,7 +521,7 @@ describe "Consul Schema" do
|
||||
|
||||
it "does not display tags for taggings that are not public" do
|
||||
create(:proposal, tag_list: "Health")
|
||||
allow(ActsAsTaggableOn::Tag).to receive(:public_for_api).and_return([])
|
||||
allow(Tag).to receive(:public_for_api).and_return([])
|
||||
|
||||
response = execute("{ tags { edges { node { name } } } }")
|
||||
received_tags = extract_fields(response, "tags", "name")
|
||||
|
||||
@@ -403,7 +403,7 @@ describe Debate do
|
||||
describe "custom tag counters when hiding/restoring" do
|
||||
it "decreases the tag counter when hiden, and increases it when restored" do
|
||||
debate = create(:debate, tag_list: "foo")
|
||||
tag = ActsAsTaggableOn::Tag.where(name: "foo").first
|
||||
tag = Tag.where(name: "foo").first
|
||||
expect(tag.debates_count).to eq(1)
|
||||
|
||||
debate.hide
|
||||
|
||||
@@ -346,7 +346,7 @@ describe Proposal do
|
||||
describe "custom tag counters when hiding/restoring" do
|
||||
it "decreases the tag counter when hiden, and increases it when restored" do
|
||||
proposal = create(:proposal, tag_list: "foo")
|
||||
tag = ActsAsTaggableOn::Tag.where(name: "foo").first
|
||||
tag = Tag.where(name: "foo").first
|
||||
expect(tag.proposals_count).to eq(1)
|
||||
|
||||
proposal.hide
|
||||
|
||||
Reference in New Issue
Block a user