remove constants / replace by class methods
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
class Organization < ActiveRecord::Base
|
class Organization < ActiveRecord::Base
|
||||||
NAME_LENGTH = {maximum: Organization.columns.find { |c| c.name == 'name' }.limit || 60}
|
|
||||||
|
|
||||||
belongs_to :user, touch: true
|
belongs_to :user, touch: true
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
class TagSanitizer
|
class TagSanitizer
|
||||||
TAG_MAX_LENGTH = 40
|
|
||||||
|
|
||||||
DISALLOWED_STRINGS = %w(? < > = /)
|
DISALLOWED_STRINGS = %w(? < > = /)
|
||||||
|
|
||||||
def sanitize_tag(tag)
|
def sanitize_tag(tag)
|
||||||
@@ -8,11 +6,15 @@ class TagSanitizer
|
|||||||
DISALLOWED_STRINGS.each do |s|
|
DISALLOWED_STRINGS.each do |s|
|
||||||
tag.gsub!(s, '')
|
tag.gsub!(s, '')
|
||||||
end
|
end
|
||||||
tag.truncate(TAG_MAX_LENGTH)
|
tag.truncate(TagSanitizer.tag_max_length)
|
||||||
end
|
end
|
||||||
|
|
||||||
def sanitize_tag_list(tag_list)
|
def sanitize_tag_list(tag_list)
|
||||||
tag_list.map { |tag| sanitize_tag(tag) }
|
tag_list.map { |tag| sanitize_tag(tag) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.tag_max_length
|
||||||
|
40
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ describe TagSanitizer do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'sets up a max length for each tag' do
|
it 'sets up a max length for each tag' do
|
||||||
long_tag = '1' * (TagSanitizer::TAG_MAX_LENGTH + 100)
|
long_tag = '1' * (TagSanitizer.tag_max_length + 100)
|
||||||
|
|
||||||
expect(subject.sanitize_tag(long_tag).size).to eq(TagSanitizer::TAG_MAX_LENGTH)
|
expect(subject.sanitize_tag(long_tag).size).to eq(TagSanitizer.tag_max_length)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user