DEV: Fix new Rubocop offenses
This commit is contained in:
parent
e57fa3519d
commit
fa6fe4abbf
36
Gemfile.lock
36
Gemfile.lock
|
@ -1,11 +1,30 @@
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
activesupport (7.1.3.2)
|
||||
base64
|
||||
bigdecimal
|
||||
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||
connection_pool (>= 2.2.5)
|
||||
drb
|
||||
i18n (>= 1.6, < 2)
|
||||
minitest (>= 5.1)
|
||||
mutex_m
|
||||
tzinfo (~> 2.0)
|
||||
ast (2.4.2)
|
||||
base64 (0.2.0)
|
||||
bigdecimal (3.1.6)
|
||||
concurrent-ruby (1.2.3)
|
||||
connection_pool (2.4.1)
|
||||
drb (2.2.1)
|
||||
i18n (1.14.1)
|
||||
concurrent-ruby (~> 1.0)
|
||||
json (2.7.1)
|
||||
language_server-protocol (3.17.0.3)
|
||||
minitest (5.22.2)
|
||||
mutex_m (0.2.0)
|
||||
parallel (1.24.0)
|
||||
parser (3.3.0.4)
|
||||
parser (3.3.0.5)
|
||||
ast (~> 2.4.1)
|
||||
racc
|
||||
prettier_print (1.2.1)
|
||||
|
@ -13,7 +32,7 @@ GEM
|
|||
rainbow (3.1.1)
|
||||
regexp_parser (2.9.0)
|
||||
rexml (3.2.6)
|
||||
rubocop (1.60.0)
|
||||
rubocop (1.61.0)
|
||||
json (~> 2.3)
|
||||
language_server-protocol (>= 3.17.0)
|
||||
parallel (~> 1.10)
|
||||
|
@ -24,22 +43,27 @@ GEM
|
|||
rubocop-ast (>= 1.30.0, < 2.0)
|
||||
ruby-progressbar (~> 1.7)
|
||||
unicode-display_width (>= 2.4.0, < 3.0)
|
||||
rubocop-ast (1.30.0)
|
||||
parser (>= 3.2.1.0)
|
||||
rubocop-ast (1.31.1)
|
||||
parser (>= 3.3.0.4)
|
||||
rubocop-capybara (2.20.0)
|
||||
rubocop (~> 1.41)
|
||||
rubocop-discourse (3.6.0)
|
||||
rubocop-discourse (3.7.1)
|
||||
activesupport (>= 6.1)
|
||||
rubocop (>= 1.59.0)
|
||||
rubocop-capybara (>= 2.0.0)
|
||||
rubocop-factory_bot (>= 2.0.0)
|
||||
rubocop-rspec (>= 2.25.0)
|
||||
rubocop-factory_bot (2.25.1)
|
||||
rubocop (~> 1.41)
|
||||
rubocop-rspec (2.26.1)
|
||||
rubocop-rspec (2.27.1)
|
||||
rubocop (~> 1.40)
|
||||
rubocop-capybara (~> 2.17)
|
||||
rubocop-factory_bot (~> 2.22)
|
||||
ruby-progressbar (1.13.0)
|
||||
syntax_tree (6.2.0)
|
||||
prettier_print (>= 1.2.0)
|
||||
tzinfo (2.0.6)
|
||||
concurrent-ruby (~> 1.0)
|
||||
unicode-display_width (2.5.0)
|
||||
|
||||
PLATFORMS
|
||||
|
|
|
@ -2,29 +2,29 @@
|
|||
|
||||
module DiscourseTopicVoting
|
||||
module CategoryExtension
|
||||
def self.prepended(base)
|
||||
base.class_eval do
|
||||
has_one :discourse_topic_voting_category_setting,
|
||||
class_name: "DiscourseTopicVoting::CategorySetting",
|
||||
dependent: :destroy
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
accepts_nested_attributes_for :discourse_topic_voting_category_setting, allow_destroy: true
|
||||
prepended do
|
||||
has_one :discourse_topic_voting_category_setting,
|
||||
class_name: "DiscourseTopicVoting::CategorySetting",
|
||||
dependent: :destroy
|
||||
|
||||
after_save :reset_voting_cache
|
||||
accepts_nested_attributes_for :discourse_topic_voting_category_setting, allow_destroy: true
|
||||
|
||||
@allowed_voting_cache = DistributedCache.new("allowed_voting")
|
||||
after_save :reset_voting_cache, if: -> { SiteSetting.voting_enabled? }
|
||||
|
||||
def self.reset_voting_cache
|
||||
@allowed_voting_cache["allowed"] = DiscourseTopicVoting::CategorySetting.pluck(
|
||||
:category_id,
|
||||
)
|
||||
end
|
||||
@allowed_voting_cache = DistributedCache.new("allowed_voting")
|
||||
end
|
||||
|
||||
def self.can_vote?(category_id)
|
||||
return false if !SiteSetting.voting_enabled
|
||||
class_methods do
|
||||
def reset_voting_cache
|
||||
@allowed_voting_cache["allowed"] = DiscourseTopicVoting::CategorySetting.pluck(:category_id)
|
||||
end
|
||||
|
||||
(@allowed_voting_cache["allowed"] || reset_voting_cache).include?(category_id)
|
||||
end
|
||||
def can_vote?(category_id)
|
||||
return false if !SiteSetting.voting_enabled
|
||||
|
||||
(@allowed_voting_cache["allowed"] || reset_voting_cache).include?(category_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
module DiscourseTopicVoting
|
||||
module ListControllerExtension
|
||||
def self.prepended(base)
|
||||
base.class_eval do
|
||||
before_action :ensure_discourse_topic_voting, only: %i[voted_by votes_feed]
|
||||
skip_before_action :ensure_logged_in, only: %i[voted_by votes_feed]
|
||||
end
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
prepended do
|
||||
before_action :ensure_discourse_topic_voting, only: %i[voted_by votes_feed]
|
||||
skip_before_action :ensure_logged_in, only: %i[voted_by votes_feed]
|
||||
end
|
||||
|
||||
def voted_by
|
||||
|
|
|
@ -2,14 +2,15 @@
|
|||
|
||||
module DiscourseTopicVoting
|
||||
module TopicExtension
|
||||
def self.prepended(base)
|
||||
base.class_eval do
|
||||
has_one :topic_vote_count,
|
||||
class_name: "DiscourseTopicVoting::TopicVoteCount",
|
||||
dependent: :destroy
|
||||
has_many :votes, class_name: "DiscourseTopicVoting::Vote", dependent: :destroy
|
||||
attribute :current_user_voted
|
||||
end
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
prepended do
|
||||
has_one :topic_vote_count,
|
||||
class_name: "DiscourseTopicVoting::TopicVoteCount",
|
||||
dependent: :destroy
|
||||
has_many :votes, class_name: "DiscourseTopicVoting::Vote", dependent: :destroy
|
||||
|
||||
attribute :current_user_voted
|
||||
end
|
||||
|
||||
def can_vote?
|
||||
|
@ -46,7 +47,7 @@ module DiscourseTopicVoting
|
|||
end
|
||||
|
||||
def who_voted
|
||||
return nil if !SiteSetting.voting_show_who_voted
|
||||
return if !SiteSetting.voting_show_who_voted
|
||||
|
||||
self.votes.map(&:user)
|
||||
end
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
|
||||
module DiscourseTopicVoting
|
||||
module UserExtension
|
||||
def self.prepended(base)
|
||||
base.class_eval do
|
||||
has_many :votes, class_name: "DiscourseTopicVoting::Vote", dependent: :destroy
|
||||
end
|
||||
end
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
prepended { has_many :votes, class_name: "DiscourseTopicVoting::Vote", dependent: :destroy }
|
||||
|
||||
def vote_count
|
||||
topics_with_vote.length
|
||||
|
|
|
@ -2,18 +2,18 @@
|
|||
|
||||
module DiscourseTopicVoting
|
||||
module WebHookExtension
|
||||
def self.prepended(base)
|
||||
base.class_eval do
|
||||
def self.enqueue_topic_voting_hooks(event, topic, payload)
|
||||
if active_web_hooks(event).exists?
|
||||
WebHook.enqueue_hooks(
|
||||
:topic_voting,
|
||||
event,
|
||||
category_id: topic.category_id,
|
||||
tag_ids: topic.tags.pluck(:id),
|
||||
payload: payload,
|
||||
)
|
||||
end
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def enqueue_topic_voting_hooks(event, topic, payload)
|
||||
if active_web_hooks(event).exists?
|
||||
WebHook.enqueue_hooks(
|
||||
:topic_voting,
|
||||
event,
|
||||
category_id: topic.category_id,
|
||||
tag_ids: topic.tags.pluck(:id),
|
||||
payload: payload,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
14
plugin.rb
14
plugin.rb
|
@ -45,13 +45,13 @@ after_initialize do
|
|||
].each { |path| require_relative path }
|
||||
|
||||
reloadable_patch do
|
||||
CategoriesController.class_eval { prepend DiscourseTopicVoting::CategoriesControllerExtension }
|
||||
Category.class_eval { prepend DiscourseTopicVoting::CategoryExtension }
|
||||
ListController.class_eval { prepend DiscourseTopicVoting::ListControllerExtension }
|
||||
Topic.class_eval { prepend DiscourseTopicVoting::TopicExtension }
|
||||
TopicQuery.class_eval { prepend DiscourseTopicVoting::TopicQueryExtension }
|
||||
User.class_eval { prepend DiscourseTopicVoting::UserExtension }
|
||||
WebHook.class_eval { prepend DiscourseTopicVoting::WebHookExtension }
|
||||
CategoriesController.prepend(DiscourseTopicVoting::CategoriesControllerExtension)
|
||||
Category.prepend(DiscourseTopicVoting::CategoryExtension)
|
||||
ListController.prepend(DiscourseTopicVoting::ListControllerExtension)
|
||||
Topic.prepend(DiscourseTopicVoting::TopicExtension)
|
||||
TopicQuery.prepend(DiscourseTopicVoting::TopicQueryExtension)
|
||||
User.prepend(DiscourseTopicVoting::UserExtension)
|
||||
WebHook.prepend(DiscourseTopicVoting::WebHookExtension)
|
||||
end
|
||||
|
||||
add_to_serializer(:post, :can_vote, include_condition: -> { object.post_number == 1 }) do
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe CategoriesController do
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
fab!(:category)
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
fab!(:admin) { Fabricate(:user, admin: true) }
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe ListController do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
fab!(:user)
|
||||
fab!(:topic)
|
||||
# "topics/voted-by/:username"
|
||||
before { SiteSetting.voting_enabled = true }
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe SearchController do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:user)
|
||||
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
fab!(:category)
|
||||
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
fab!(:topic_2) { Fabricate(:topic, category: category) }
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe BasicCategorySerializer do
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
fab!(:category)
|
||||
|
||||
it "does not return can_vote when voting disabled" do
|
||||
SiteSetting.voting_enabled = false
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe CategorySerializer do
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
fab!(:category)
|
||||
|
||||
it "does not return enable_topic_voting voting disabled" do
|
||||
SiteSetting.voting_enabled = false
|
||||
|
|
|
@ -4,7 +4,7 @@ RSpec.describe CurrentUserSerializer do
|
|||
fab!(:user1) { Fabricate(:user, trust_level: 3) }
|
||||
let(:user2) { Fabricate(:user) }
|
||||
fab!(:guardian) { Guardian.new(user1) }
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
fab!(:category)
|
||||
fab!(:topic1) { Fabricate(:topic, category_id: category.id) }
|
||||
let(:topic2) { Fabricate(:topic, category_id: category.id) }
|
||||
let(:topic3) { Fabricate(:topic, category_id: category.id) }
|
||||
|
|
|
@ -16,4 +16,4 @@ module TopicVotingCategory
|
|||
end
|
||||
end
|
||||
|
||||
PageObjects::Pages::Category.class_eval { include TopicVotingCategory }
|
||||
PageObjects::Pages::Category.include(TopicVotingCategory)
|
||||
|
|
|
@ -27,4 +27,4 @@ module TopicVotingTopic
|
|||
end
|
||||
end
|
||||
|
||||
PageObjects::Pages::Topic.class_eval { include TopicVotingTopic }
|
||||
PageObjects::Pages::Topic.include(TopicVotingTopic)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe "Voting", type: :system, js: true do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
fab!(:user)
|
||||
fab!(:admin)
|
||||
fab!(:category1) { Fabricate(:category) }
|
||||
fab!(:category2) { Fabricate(:category) }
|
||||
fab!(:topic1) { Fabricate(:topic, category: category1) }
|
||||
|
|
Loading…
Reference in New Issue