Skip to content
Extraits de code Groupes Projets
Valider 18a1958e rédigé par Sayed's avatar Sayed
Parcourir les fichiers

fix too long tag name #5737

parent 25e80fdd
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -93,7 +93,8 @@ class StatusMessagesController < ApplicationController ...@@ -93,7 +93,8 @@ class StatusMessagesController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { redirect_to :back } format.html { redirect_to :back }
format.mobile { redirect_to stream_path } 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 end
end end
......
...@@ -42,6 +42,7 @@ class Profile < ActiveRecord::Base ...@@ -42,6 +42,7 @@ class Profile < ActiveRecord::Base
belongs_to :person belongs_to :person
before_validation do before_validation do
self.tag_string = self.tag_string.split[0..4].join(' ') self.tag_string = self.tag_string.split[0..4].join(' ')
self.build_tags
end end
before_save do before_save do
......
...@@ -1253,6 +1253,8 @@ en: ...@@ -1253,6 +1253,8 @@ en:
following: "Following #%{tag}" following: "Following #%{tag}"
stop_following: "Stop following #%{tag}" stop_following: "Stop following #%{tag}"
none: "The empty tag does not exist!" 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: tag_followings:
create: create:
success: "Hooray! You’re now following #%{name}." success: "Hooray! You’re now following #%{name}."
......
...@@ -7,9 +7,20 @@ module Diaspora ...@@ -7,9 +7,20 @@ module Diaspora
def self.included(model) def self.included(model)
model.class_eval do model.class_eval do
cattr_accessor :field_with_tags 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 end
model.instance_eval do 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 def extract_tags_from sym
self.field_with_tags = sym self.field_with_tags = sym
......
...@@ -272,6 +272,11 @@ describe Profile, :type => :model do ...@@ -272,6 +272,11 @@ describe Profile, :type => :model do
@object.save @object.save
expect(@object.tags.count).to eq(5) expect(@object.tags.count).to eq(5)
end 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' it_should_behave_like 'it is taggable'
end end
......
...@@ -70,6 +70,14 @@ describe StatusMessage, :type => :model do ...@@ -70,6 +70,14 @@ describe StatusMessage, :type => :model do
expect(guids).to eq([sm1.guid]) expect(guids).to eq([sm1.guid])
end end
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 describe '.before_create' do
it 'calls build_tags' do it 'calls build_tags' do
...@@ -255,6 +263,12 @@ STR ...@@ -255,6 +263,12 @@ STR
expect(msg_uc.tags).to match_array(tag_array) expect(msg_uc.tags).to match_array(tag_array)
expect(msg_cp.tags).to match_array(tag_array) expect(msg_cp.tags).to match_array(tag_array)
end 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 end
describe "XML" do describe "XML" do
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter