FIX: Add missing unique index on user_id for user_profiles.

FIX: Add missing unique index on user_id for user_profiles.

diff --git a/app/models/user_profile.rb b/app/models/user_profile.rb
index a6453de..a5d1873 100644
--- a/app/models/user_profile.rb
+++ b/app/models/user_profile.rb
@@ -11,6 +11,7 @@ class UserProfile < ActiveRecord::Base
   belongs_to :card_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 :website, url: true, allow_blank: true, if: Proc.new { |c| c.new_record? || c.website_changed? }
   validates :user, presence: true
diff --git a/db/migrate/20190524040814_add_unique_index_user_id_on_user_profiles.rb b/db/migrate/20190524040814_add_unique_index_user_id_on_user_profiles.rb
new file mode 100644
index 0000000..ee07ffa
--- /dev/null
+++ b/db/migrate/20190524040814_add_unique_index_user_id_on_user_profiles.rb
@@ -0,0 +1,5 @@
+class AddUniqueIndexUserIdOnUserProfiles < ActiveRecord::Migration[5.2]
+  def change
+    add_index :user_profiles, :user_id, unique: true
+  end
+end
diff --git a/spec/models/user_profile_spec.rb b/spec/models/user_profile_spec.rb
index eb11213..aa9285d 100644
--- a/spec/models/user_profile_spec.rb
+++ b/spec/models/user_profile_spec.rb
@@ -40,7 +40,7 @@ describe UserProfile do
     end
 
     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
         user_profile.website = "http://https://google.com"

GitHub sha: 5478aa63

Revert "FIX: Add missing unique index on user_id for user_profiles."