Skip to content

Commit

Permalink
Fix UserIpAddresses class name for inflection
Browse files Browse the repository at this point in the history
  • Loading branch information
NuckChorris committed Nov 10, 2024
1 parent a9d8bc2 commit c6f4837
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class User < ApplicationRecord
has_many :notification_settings, dependent: :delete_all
has_many :one_signal_players, dependent: :delete_all
has_many :reposts, dependent: :destroy
has_many :ip_addresses, dependent: :delete_all, class_name: 'UserIpAddress'
has_many :ip_addresses, dependent: :delete_all, class_name: 'UserIPAddress'
has_many :category_favorites, dependent: :delete_all
has_many :quotes, dependent: :nullify
has_many :wiki_submissions
Expand Down Expand Up @@ -360,8 +360,8 @@ def alts
alts = {}
user_ips = ip_addresses.select(:ip_address)
user_ip_count = user_ips.count
shared_ips = UserIpAddress.where(ip_address: user_ips).where.not(user: self).includes(:user)
alt_ip_counts = UserIpAddress.where(user_id: shared_ips.select(:user_id)).group(:user_id).count
shared_ips = UserIPAddress.where(ip_address: user_ips).where.not(user: self).includes(:user)
alt_ip_counts = UserIPAddress.where(user_id: shared_ips.select(:user_id)).group(:user_id).count

shared_ips.group(:user).count.each do |alt, shared_ips_count|
alts[alt] = shared_ips_count.to_f / [[user_ip_count, alt_ip_counts[alt.id]].min, 2].max
Expand Down
2 changes: 1 addition & 1 deletion app/models/user_ip_address.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class UserIpAddress < ApplicationRecord
class UserIPAddress < ApplicationRecord
belongs_to :user, optional: false

validates :ip_address, presence: true
Expand Down
4 changes: 3 additions & 1 deletion app/policies/user_ip_address_policy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class UserIpAddressPolicy < ApplicationPolicy
# frozen_string_literal: true

class UserIPAddressPolicy < ApplicationPolicy
administrated_by :community_mod

def update?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def change
return puts "BAD IP: #{ip} for #{user.id}" unless ip.is_a?(IPAddr)
{ip_address: ip, user_id: user.id}
end
UserIpAddress.create!(ips.compact)
UserIPAddress.create!(ips.compact)
end
remove_column :users, :ip_addresses, :inet
end
Expand Down
7 changes: 5 additions & 2 deletions spec/models/user_ip_address_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe UserIpAddress, type: :model do
RSpec.describe UserIPAddress, type: :model do
subject { build(:user_ip_address) }
it { should belong_to(:user).required }

it { is_expected.to belong_to(:user).required }
end

0 comments on commit c6f4837

Please sign in to comment.