diff --git a/app/models/user.rb b/app/models/user.rb index 61a062878..2dcbbb1ad 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 @@ -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 diff --git a/app/models/user_ip_address.rb b/app/models/user_ip_address.rb index 172348f0f..7a8914e0d 100644 --- a/app/models/user_ip_address.rb +++ b/app/models/user_ip_address.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class UserIpAddress < ApplicationRecord +class UserIPAddress < ApplicationRecord belongs_to :user, optional: false validates :ip_address, presence: true diff --git a/app/policies/user_ip_address_policy.rb b/app/policies/user_ip_address_policy.rb index 54dca3cfa..7d213a55a 100644 --- a/app/policies/user_ip_address_policy.rb +++ b/app/policies/user_ip_address_policy.rb @@ -1,4 +1,6 @@ -class UserIpAddressPolicy < ApplicationPolicy +# frozen_string_literal: true + +class UserIPAddressPolicy < ApplicationPolicy administrated_by :community_mod def update? diff --git a/db/migrate/20170822072811_insert_existing_user_ip_address_and_remove_column_from_users.rb b/db/migrate/20170822072811_insert_existing_user_ip_address_and_remove_column_from_users.rb index 58d34586a..fc095c290 100644 --- a/db/migrate/20170822072811_insert_existing_user_ip_address_and_remove_column_from_users.rb +++ b/db/migrate/20170822072811_insert_existing_user_ip_address_and_remove_column_from_users.rb @@ -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 diff --git a/spec/models/user_ip_address_spec.rb b/spec/models/user_ip_address_spec.rb index 63ca625ca..33ea7661a 100644 --- a/spec/models/user_ip_address_spec.rb +++ b/spec/models/user_ip_address_spec.rb @@ -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