FIX: Add missing unique index on user_id for user_profiles.

This commit is contained in:
Guo Xiang Tan
2019-05-24 12:10:53 +08:00
parent 4f5c9bb8d3
commit 5478aa63ab
3 changed files with 7 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ class UserProfile < ActiveRecord::Base
belongs_to :card_background_upload, class_name: "Upload" belongs_to :card_background_upload, class_name: "Upload"
belongs_to :profile_background_upload, class_name: "Upload" belongs_to :profile_background_upload, class_name: "Upload"
validates :user_id, uniqueness: true
validates :bio_raw, length: { maximum: 3000 } validates :bio_raw, length: { maximum: 3000 }
validates :website, url: true, allow_blank: true, if: Proc.new { |c| c.new_record? || c.website_changed? } validates :website, url: true, allow_blank: true, if: Proc.new { |c| c.new_record? || c.website_changed? }
validates :user, presence: true validates :user, presence: true

View File

@@ -0,0 +1,5 @@
class AddUniqueIndexUserIdOnUserProfiles < ActiveRecord::Migration[5.2]
def change
add_index :user_profiles, :user_id, unique: true
end
end

View File

@@ -40,7 +40,7 @@ describe UserProfile do
end end
context "website validation" do context "website validation" do
let(:user_profile) { Fabricate.build(:user_profile, user: Fabricate(:user)) } let(:user_profile) { Fabricate.build(:user_profile) }
it "should not allow invalid URLs" do it "should not allow invalid URLs" do
user_profile.website = "http://https://google.com" user_profile.website = "http://https://google.com"