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:
Javi Martín
2019-10-04 14:20:05 +02:00
parent f444533956
commit ad14636255
23 changed files with 56 additions and 56 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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")

View File

@@ -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

View File

@@ -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