fix too long tag name #5737
This commit is contained in:
parent
25e80fddc8
commit
18a1958ef8
6 changed files with 36 additions and 2 deletions
|
|
@ -93,7 +93,8 @@ class StatusMessagesController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.mobile { redirect_to stream_path }
|
||||
format.json { render :text => @status_message.errors.messages[:text].to_sentence, :status => 403 }
|
||||
#there are some errors, so we report the first one to the user
|
||||
format.json { render :text => @status_message.errors.messages.values.first.to_sentence, :status => 403 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ class Profile < ActiveRecord::Base
|
|||
belongs_to :person
|
||||
before_validation do
|
||||
self.tag_string = self.tag_string.split[0..4].join(' ')
|
||||
self.build_tags
|
||||
end
|
||||
|
||||
before_save do
|
||||
|
|
|
|||
|
|
@ -1253,6 +1253,8 @@ en:
|
|||
following: "Following #%{tag}"
|
||||
stop_following: "Stop following #%{tag}"
|
||||
none: "The empty tag does not exist!"
|
||||
name_too_long: "Please make your tag name fewer than %{count} characters. Right now it is %{current_length} characters"
|
||||
|
||||
tag_followings:
|
||||
create:
|
||||
success: "Hooray! You’re now following #%{name}."
|
||||
|
|
|
|||
|
|
@ -7,9 +7,20 @@ module Diaspora
|
|||
def self.included(model)
|
||||
model.class_eval do
|
||||
cattr_accessor :field_with_tags
|
||||
|
||||
# validate tag's name maximum length [tag's name should be less than or equal to 255 chars]
|
||||
validate :tag_name_max_length, on: :create
|
||||
|
||||
# tag's name is limited to 255 charchters according to ActsAsTaggableOn gem, so we check the length of the name for each tag
|
||||
def tag_name_max_length
|
||||
self.tag_list.each do |tag|
|
||||
errors[:tags] << I18n.t('tags.name_too_long', :count => 255, :current_length => tag.length) if tag.length > 255
|
||||
end
|
||||
end
|
||||
protected :tag_name_max_length
|
||||
end
|
||||
model.instance_eval do
|
||||
before_create :build_tags
|
||||
before_validation :build_tags # build tags before validation fixs the too long tag name issue #5737
|
||||
|
||||
def extract_tags_from sym
|
||||
self.field_with_tags = sym
|
||||
|
|
|
|||
|
|
@ -272,6 +272,11 @@ describe Profile, :type => :model do
|
|||
@object.save
|
||||
expect(@object.tags.count).to eq(5)
|
||||
end
|
||||
it 'should require tag name not be more than 255 characters long' do
|
||||
@object.tag_string = "##{'a' * (255+1)}"
|
||||
@object.save
|
||||
expect(@object).not_to be_valid
|
||||
end
|
||||
it_should_behave_like 'it is taggable'
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -70,6 +70,14 @@ describe StatusMessage, :type => :model do
|
|||
expect(guids).to eq([sm1.guid])
|
||||
end
|
||||
end
|
||||
|
||||
describe '.before_validation' do
|
||||
it 'calls build_tags' do
|
||||
status = FactoryGirl.build(:status_message)
|
||||
expect(status).to receive(:build_tags)
|
||||
status.save
|
||||
end
|
||||
end
|
||||
|
||||
describe '.before_create' do
|
||||
it 'calls build_tags' do
|
||||
|
|
@ -255,6 +263,12 @@ STR
|
|||
expect(msg_uc.tags).to match_array(tag_array)
|
||||
expect(msg_cp.tags).to match_array(tag_array)
|
||||
end
|
||||
|
||||
it 'should require tag name not be more than 255 characters long' do
|
||||
message = "##{'a' * (255+1)}"
|
||||
status_message = FactoryGirl.build(:status_message, :text => message)
|
||||
expect(status_message).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "XML" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue