user.rb: drop unused add_favorite!, delete_favorite! methods.
These methods were incorrect anyway, didn't upvote/downvote the post.
This commit is contained in:
@@ -108,6 +108,7 @@ class User < ApplicationRecord
|
|||||||
has_many :forum_posts, -> {order("forum_posts.created_at, forum_posts.id")}, :foreign_key => "creator_id"
|
has_many :forum_posts, -> {order("forum_posts.created_at, forum_posts.id")}, :foreign_key => "creator_id"
|
||||||
has_many :user_name_change_requests, -> {visible.order("user_name_change_requests.created_at desc")}
|
has_many :user_name_change_requests, -> {visible.order("user_name_change_requests.created_at desc")}
|
||||||
has_many :favorite_groups, -> {order(name: :asc)}, foreign_key: :creator_id
|
has_many :favorite_groups, -> {order(name: :asc)}, foreign_key: :creator_id
|
||||||
|
has_many :favorites, ->(rec) {where("user_id % 100 = #{rec.id % 100} and user_id = #{rec.id}").order("id desc")}
|
||||||
belongs_to :inviter, class_name: "User", optional: true
|
belongs_to :inviter, class_name: "User", optional: true
|
||||||
after_update :create_mod_action
|
after_update :create_mod_action
|
||||||
accepts_nested_attributes_for :dmail_filter
|
accepts_nested_attributes_for :dmail_filter
|
||||||
@@ -297,20 +298,6 @@ class User < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module FavoriteMethods
|
|
||||||
def favorites
|
|
||||||
Favorite.where("user_id % 100 = #{id % 100} and user_id = #{id}").order("id desc")
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_favorite!(post)
|
|
||||||
Favorite.add(post: post, user: self)
|
|
||||||
end
|
|
||||||
|
|
||||||
def remove_favorite!(post)
|
|
||||||
Favorite.remove(post: post, user: self)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module LevelMethods
|
module LevelMethods
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
@@ -917,7 +904,6 @@ class User < ApplicationRecord
|
|||||||
include NameMethods
|
include NameMethods
|
||||||
include PasswordMethods
|
include PasswordMethods
|
||||||
include AuthenticationMethods
|
include AuthenticationMethods
|
||||||
include FavoriteMethods
|
|
||||||
include LevelMethods
|
include LevelMethods
|
||||||
include EmailMethods
|
include EmailMethods
|
||||||
include BlacklistMethods
|
include BlacklistMethods
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class FavoriteTest < ActiveSupport::TestCase
|
|||||||
user1 = FactoryBot.create(:user)
|
user1 = FactoryBot.create(:user)
|
||||||
p1 = FactoryBot.create(:post)
|
p1 = FactoryBot.create(:post)
|
||||||
|
|
||||||
user1.add_favorite!(p1)
|
p1.add_favorite!(user1)
|
||||||
assert_equal(1, Favorite.count)
|
assert_equal(1, Favorite.count)
|
||||||
|
|
||||||
Favorite.where(:user_id => user1.id, :post_id => p1.id).delete_all
|
Favorite.where(:user_id => user1.id, :post_id => p1.id).delete_all
|
||||||
@@ -31,9 +31,9 @@ class FavoriteTest < ActiveSupport::TestCase
|
|||||||
p1 = FactoryBot.create(:post)
|
p1 = FactoryBot.create(:post)
|
||||||
p2 = FactoryBot.create(:post)
|
p2 = FactoryBot.create(:post)
|
||||||
|
|
||||||
user1.add_favorite!(p1)
|
p1.add_favorite!(user1)
|
||||||
user1.add_favorite!(p2)
|
p2.add_favorite!(user1)
|
||||||
user2.add_favorite!(p1)
|
p1.add_favorite!(user2)
|
||||||
|
|
||||||
favorites = user1.favorites.order("id desc")
|
favorites = user1.favorites.order("id desc")
|
||||||
assert_equal(2, favorites.count)
|
assert_equal(2, favorites.count)
|
||||||
@@ -49,8 +49,8 @@ class FavoriteTest < ActiveSupport::TestCase
|
|||||||
user1 = FactoryBot.create(:user)
|
user1 = FactoryBot.create(:user)
|
||||||
p1 = FactoryBot.create(:post)
|
p1 = FactoryBot.create(:post)
|
||||||
p2 = FactoryBot.create(:post)
|
p2 = FactoryBot.create(:post)
|
||||||
user1.add_favorite!(p1)
|
p1.add_favorite!(user1)
|
||||||
user1.add_favorite!(p1)
|
p1.add_favorite!(user1)
|
||||||
|
|
||||||
assert_equal(1, user1.favorites.count)
|
assert_equal(1, user1.favorites.count)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user