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