Skip to content

Commit

Permalink
improvement: Fix rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Vasquez authored and ChaelCodes committed Oct 8, 2021
1 parent fddff36 commit 93b695b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class Profile < ApplicationRecord
# Whether they are "buddy" or "friend"
has_many :buddyships, class_name: "Friendship", foreign_key: "buddy_id", dependent: :destroy, inverse_of: :buddy
has_many :friendships, class_name: "Friendship", foreign_key: "friend_id", dependent: :destroy, inverse_of: :friend
# rubocop:disable Rails/UniqueValidationWithoutIndex, Layout/LineLength
validates :handle, presence: true, format: { with: /\A[a-zA-Z0-9]+\z/, message: "Only letters and numbers are allowed" }, uniqueness: { case_sensitive: true }
# rubocop:enable Rails/UniqueValidationWithoutIndex, Layout/LineLength
validates :handle, presence: true,
format: { with: /\A[a-zA-Z0-9]+\z/, message: "Only letters and numbers are allowed" },
uniqueness: { case_sensitive: true }

def to_s
name
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20211006022040_change_handle_to_profiles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# Add index and unique to handle attribute in the profiles table
class ChangeHandleToProfiles < ActiveRecord::Migration[6.1]
def change
add_index :profiles, :handle, unique: true
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions spec/requests/profiles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@
end

describe "PATCH /update" do
subject(:patch_update) { patch profile_url(profile), params: { profile: attributes } }
subject(:patch_update) do
patch profile_url(profile), params: { profile: attributes }
end

context "with valid parameters" do
let(:attributes) do
Expand Down Expand Up @@ -138,7 +140,7 @@
it "does not update the profile" do
patch_update
profile.reload
expect(profile.handle).to_not eq "ChaelChats"
expect(profile.handle).not_to eq "ChaelChats"
end
end
end
Expand Down

0 comments on commit 93b695b

Please sign in to comment.