diff --git a/Changelog.md b/Changelog.md index 08ebdaacb..ece7eae94 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,7 @@ ## Bug fixes * Don't link to deleted users in admin user stats [#8063](https://github.com/diaspora/diaspora/pull/8063) +* Properly validate a profile's gender field length instead of failing with a database error. [#8127](https://github.com/diaspora/diaspora/pull/8127) ## Features diff --git a/app/models/profile.rb b/app/models/profile.rb index 74ca9fec6..7a615ffae 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -21,6 +21,7 @@ class Profile < ApplicationRecord validates :first_name, :length => { :maximum => 32 } validates :last_name, :length => { :maximum => 32 } validates :location, :length => { :maximum =>255 } + validates :gender, length: {maximum: 255} validates_format_of :first_name, :with => /\A[^;]+\z/, :allow_blank => true validates_format_of :last_name, :with => /\A[^;]+\z/, :allow_blank => true diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index c1a83f13f..f0cafecf1 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -124,6 +124,18 @@ describe Profile, :type => :model do end end + describe "of gender" do + it "can be 255 characters long" do + profile = FactoryGirl.build(:profile, gender: "a" * 255) + expect(profile).to be_valid + end + + it "cannot be 256 characters" do + profile = FactoryGirl.build(:profile, gender: "a" * 256) + expect(profile).not_to be_valid + end + end + describe "image_url setters" do %i(image_url image_url_small image_url_medium).each do |method| describe "##{method}=" do