Merge pull request #3264 from consul/tags-length
[Backport] Set tags max length to 160
This commit is contained in:
@@ -8,7 +8,7 @@ App.Tags =
|
||||
|
||||
unless $this.data('initialized') is 'yes'
|
||||
$this.on('click', ->
|
||||
name = $(this).text()
|
||||
name = '"' + $(this).text() + '"'
|
||||
current_tags = $tag_input.val().split(',').filter(Boolean)
|
||||
|
||||
if $.inArray(name, current_tags) >= 0
|
||||
|
||||
2
app/models/tag.rb
Normal file
2
app/models/tag.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class Tag < ActsAsTaggableOn::Tag
|
||||
end
|
||||
9
db/migrate/20190205131722_increase_tag_name_limit.rb
Normal file
9
db/migrate/20190205131722_increase_tag_name_limit.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class IncreaseTagNameLimit < ActiveRecord::Migration
|
||||
def up
|
||||
change_column :tags, :name, :string, limit: 160
|
||||
end
|
||||
|
||||
def down
|
||||
change_column :tags, :name, :string, limit: 40
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20190131122858) do
|
||||
ActiveRecord::Schema.define(version: 20190205131722) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -1311,7 +1311,7 @@ ActiveRecord::Schema.define(version: 20190131122858) do
|
||||
add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree
|
||||
|
||||
create_table "tags", force: :cascade do |t|
|
||||
t.string "name", limit: 40
|
||||
t.string "name", limit: 160
|
||||
t.integer "taggings_count", default: 0
|
||||
t.integer "debates_count", default: 0
|
||||
t.integer "proposals_count", default: 0
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
class TagSanitizer
|
||||
DISALLOWED_STRINGS = %w(? < > = /)
|
||||
DISALLOWED_STRINGS = %w[? < > = /]
|
||||
|
||||
def sanitize_tag(tag)
|
||||
tag = tag.dup
|
||||
DISALLOWED_STRINGS.each do |s|
|
||||
tag.gsub!(s, '')
|
||||
tag.gsub!(s, "")
|
||||
end
|
||||
tag.truncate(TagSanitizer.tag_max_length)
|
||||
end
|
||||
@@ -14,7 +14,7 @@ class TagSanitizer
|
||||
end
|
||||
|
||||
def self.tag_max_length
|
||||
40
|
||||
160
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
FactoryBot.define do
|
||||
factory :tag, class: 'ActsAsTaggableOn::Tag' do
|
||||
factory :tag, class: "ActsAsTaggableOn::Tag" do
|
||||
sequence(:name) { |n| "Tag #{n} name" }
|
||||
|
||||
trait :category do
|
||||
@@ -7,6 +7,12 @@ FactoryBot.define do
|
||||
end
|
||||
end
|
||||
|
||||
factory :tagging, class: "ActsAsTaggableOn::Tagging" do
|
||||
context "tags"
|
||||
association :taggable, factory: :proposal
|
||||
tag
|
||||
end
|
||||
|
||||
factory :topic do
|
||||
sequence(:title) { |n| "Topic title #{n}" }
|
||||
sequence(:description) { |n| "Description as comment #{n}" }
|
||||
|
||||
37
spec/models/tag_spec.rb
Normal file
37
spec/models/tag_spec.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Tag do
|
||||
|
||||
it "decreases tag_count when a debate is hidden" do
|
||||
debate = create(:debate)
|
||||
tag = create(:tag)
|
||||
tagging = create(:tagging, tag: tag, taggable: debate)
|
||||
|
||||
expect(tag.taggings_count).to eq(1)
|
||||
|
||||
debate.update(hidden_at: Time.now)
|
||||
|
||||
tag.reload
|
||||
expect(tag.taggings_count).to eq(0)
|
||||
end
|
||||
|
||||
it "decreases tag_count when a proposal is hidden" do
|
||||
proposal = create(:proposal)
|
||||
tag = create(:tag)
|
||||
tagging = create(:tagging, tag: tag, taggable: proposal)
|
||||
|
||||
expect(tag.taggings_count).to eq(1)
|
||||
|
||||
proposal.update(hidden_at: Time.now)
|
||||
|
||||
tag.reload
|
||||
expect(tag.taggings_count).to eq(0)
|
||||
end
|
||||
|
||||
describe "name validation" do
|
||||
it "160 char name should be valid" do
|
||||
tag = build(:tag, name: Faker::Lorem.characters(160))
|
||||
expect(tag).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user