Update Rubocop to 0.60

This commit is contained in:
Régis Hanol 2018-12-04 10:48:16 +01:00
parent 72bd388ff7
commit 3c9c95ac83
23 changed files with 141 additions and 126 deletions

View File

@ -120,4 +120,4 @@ Style/SingleLineMethods:
Style/Semicolon: Style/Semicolon:
Enabled: true Enabled: true
AllowAsExpressionSeparator: true AllowAsExpressionSeparator: true

View File

@ -270,7 +270,7 @@ GEM
redis redis
ruby-openid ruby-openid
parallel (1.12.1) parallel (1.12.1)
parser (2.5.1.0) parser (2.5.3.0)
ast (~> 2.4.0) ast (~> 2.4.0)
pg (1.1.3) pg (1.1.3)
powerpack (0.1.2) powerpack (0.1.2)
@ -357,17 +357,17 @@ GEM
rspec-support (~> 3.7.0) rspec-support (~> 3.7.0)
rspec-support (3.7.1) rspec-support (3.7.1)
rtlit (0.0.5) rtlit (0.0.5)
rubocop (0.57.2) rubocop (0.60.0)
jaro_winkler (~> 1.5.1) jaro_winkler (~> 1.5.1)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 2.5) parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1) powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0) rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1) unicode-display_width (~> 1.4.0)
ruby-openid (2.7.0) ruby-openid (2.7.0)
ruby-prof (0.17.0) ruby-prof (0.17.0)
ruby-progressbar (1.9.0) ruby-progressbar (1.10.0)
ruby-readability (0.7.0) ruby-readability (0.7.0)
guess_html_encoding (>= 0.0.4) guess_html_encoding (>= 0.0.4)
nokogiri (>= 1.6.0) nokogiri (>= 1.6.0)

View File

@ -54,8 +54,8 @@ class QueuedPostsController < ApplicationController
def user_deletion_opts def user_deletion_opts
base = { base = {
context: I18n.t('queue.delete_reason', performed_by: current_user.username), context: I18n.t('queue.delete_reason', performed_by: current_user.username),
delete_posts: true, delete_posts: true,
delete_as_spammer: true delete_as_spammer: true
} }

View File

@ -40,7 +40,7 @@ class SiteController < ApplicationController
logo_url: UrlHelper.absolute(SiteSetting.site_logo_url), logo_url: UrlHelper.absolute(SiteSetting.site_logo_url),
logo_small_url: UrlHelper.absolute(SiteSetting.site_logo_small_url), logo_small_url: UrlHelper.absolute(SiteSetting.site_logo_small_url),
apple_touch_icon_url: UrlHelper.absolute(SiteSetting.site_apple_touch_icon_url), apple_touch_icon_url: UrlHelper.absolute(SiteSetting.site_apple_touch_icon_url),
favicon_url: UrlHelper.absolute(SiteSetting.site_favicon_url), favicon_url: UrlHelper.absolute(SiteSetting.site_favicon_url),
title: SiteSetting.title, title: SiteSetting.title,
description: SiteSetting.site_description, description: SiteSetting.site_description,
header_primary_color: ColorScheme.hex_for_name('header_primary') || '333333', header_primary_color: ColorScheme.hex_for_name('header_primary') || '333333',

View File

@ -10,16 +10,16 @@ module Jobs
sidekiq_options retry: false sidekiq_options retry: false
HEADER_ATTRS_FOR ||= HashWithIndifferentAccess.new( HEADER_ATTRS_FOR ||= HashWithIndifferentAccess.new(
user_archive: ['topic_title', 'category', 'sub_category', 'is_pm', 'post', 'like_count', 'reply_count', 'url', 'created_at'], user_archive: ['topic_title', 'category', 'sub_category', 'is_pm', 'post', 'like_count', 'reply_count', 'url', 'created_at'],
user_list: ['id', 'name', 'username', 'email', 'title', 'created_at', 'last_seen_at', 'last_posted_at', 'last_emailed_at', 'trust_level', 'approved', 'suspended_at', 'suspended_till', 'silenced_till', 'active', 'admin', 'moderator', 'ip_address', 'staged'], user_list: ['id', 'name', 'username', 'email', 'title', 'created_at', 'last_seen_at', 'last_posted_at', 'last_emailed_at', 'trust_level', 'approved', 'suspended_at', 'suspended_till', 'silenced_till', 'active', 'admin', 'moderator', 'ip_address', 'staged'],
user_stats: ['topics_entered', 'posts_read_count', 'time_read', 'topic_count', 'post_count', 'likes_given', 'likes_received'], user_stats: ['topics_entered', 'posts_read_count', 'time_read', 'topic_count', 'post_count', 'likes_given', 'likes_received'],
user_profile: ['location', 'website', 'views'], user_profile: ['location', 'website', 'views'],
user_sso: ['external_id', 'external_email', 'external_username', 'external_name', 'external_avatar_url'], user_sso: ['external_id', 'external_email', 'external_username', 'external_name', 'external_avatar_url'],
staff_action: ['staff_user', 'action', 'subject', 'created_at', 'details', 'context'], staff_action: ['staff_user', 'action', 'subject', 'created_at', 'details', 'context'],
screened_email: ['email', 'action', 'match_count', 'last_match_at', 'created_at', 'ip_address'], screened_email: ['email', 'action', 'match_count', 'last_match_at', 'created_at', 'ip_address'],
screened_ip: ['ip_address', 'action', 'match_count', 'last_match_at', 'created_at'], screened_ip: ['ip_address', 'action', 'match_count', 'last_match_at', 'created_at'],
screened_url: ['domain', 'action', 'match_count', 'last_match_at', 'created_at'], screened_url: ['domain', 'action', 'match_count', 'last_match_at', 'created_at'],
report: ['date', 'value'] report: ['date', 'value']
) )
def execute(args) def execute(args)

View File

@ -97,7 +97,7 @@ class CategoryUser < ActiveRecord::Base
builder.exec( builder.exec(
tracking: notification_levels[:tracking], tracking: notification_levels[:tracking],
regular: notification_levels[:regular], regular: notification_levels[:regular],
auto_track_category: TopicUser.notification_reasons[:auto_track_category] auto_track_category: TopicUser.notification_reasons[:auto_track_category]
) )
end end
@ -157,7 +157,7 @@ class CategoryUser < ActiveRecord::Base
watching: notification_levels[:watching], watching: notification_levels[:watching],
tracking: notification_levels[:tracking], tracking: notification_levels[:tracking],
regular: notification_levels[:regular], regular: notification_levels[:regular],
auto_watch_category: TopicUser.notification_reasons[:auto_watch_category] auto_watch_category: TopicUser.notification_reasons[:auto_watch_category]
) )
end end

View File

@ -4,6 +4,8 @@ require_dependency 'distributed_cache'
class ColorScheme < ActiveRecord::Base class ColorScheme < ActiveRecord::Base
# rubocop:disable Layout/AlignHash
CUSTOM_SCHEMES = { CUSTOM_SCHEMES = {
'Dark': { 'Dark': {
"primary" => 'dddddd', "primary" => 'dddddd',
@ -97,8 +99,11 @@ class ColorScheme < ActiveRecord::Base
} }
} }
# rubocop:enable Layout/AlignHash
def self.base_color_scheme_colors def self.base_color_scheme_colors
base_with_hash = {} base_with_hash = {}
base_colors.each do |name, color| base_colors.each do |name, color|
base_with_hash[name] = "#{color}" base_with_hash[name] = "#{color}"
end end
@ -110,6 +115,7 @@ class ColorScheme < ActiveRecord::Base
CUSTOM_SCHEMES.each do |k, v| CUSTOM_SCHEMES.each do |k, v|
list.push(id: k.to_s, colors: v) list.push(id: k.to_s, colors: v)
end end
list list
end end
@ -208,6 +214,7 @@ class ColorScheme < ActiveRecord::Base
def colors_by_name def colors_by_name
@colors_by_name ||= self.colors.inject({}) { |sum, c| sum[c.name] = c; sum; } @colors_by_name ||= self.colors.inject({}) { |sum, c| sum[c.name] = c; sum; }
end end
def clear_colors_cache def clear_colors_cache
@colors_by_name = nil @colors_by_name = nil
end end

View File

@ -435,12 +435,12 @@ class PostAction < ActiveRecord::Base
before_create do before_create do
post_action_type_ids = is_flag? ? PostActionType.notify_flag_types.values : post_action_type_id post_action_type_ids = is_flag? ? PostActionType.notify_flag_types.values : post_action_type_id
raise AlreadyActed if PostAction.where(user_id: user_id) raise AlreadyActed if PostAction.where(user_id: user_id)
.where(post_id: post_id) .where(post_id: post_id)
.where(post_action_type_id: post_action_type_ids) .where(post_action_type_id: post_action_type_ids)
.where(deleted_at: nil) .where(deleted_at: nil)
.where(disagreed_at: nil) .where(disagreed_at: nil)
.where(targets_topic: targets_topic) .where(targets_topic: targets_topic)
.exists? .exists?
end end
# Returns the flag counts for a post, taking into account that some users # Returns the flag counts for a post, taking into account that some users

View File

@ -113,12 +113,11 @@ class TagUser < ActiveRecord::Base
builder.exec(watching: notification_levels[:watching], builder.exec(watching: notification_levels[:watching],
tracking: notification_levels[:tracking], tracking: notification_levels[:tracking],
regular: notification_levels[:regular], regular: notification_levels[:regular],
auto_watch_tag: TopicUser.notification_reasons[:auto_watch_tag]) auto_watch_tag: TopicUser.notification_reasons[:auto_watch_tag])
end end
def self.auto_track(opts) def self.auto_track(opts)
builder = DB.build <<~SQL builder = DB.build <<~SQL
UPDATE topic_users UPDATE topic_users
SET notification_level = :tracking, notifications_reason_id = :auto_track_tag SET notification_level = :tracking, notifications_reason_id = :auto_track_tag
@ -147,7 +146,7 @@ class TagUser < ActiveRecord::Base
builder.exec(tracking: notification_levels[:tracking], builder.exec(tracking: notification_levels[:tracking],
regular: notification_levels[:regular], regular: notification_levels[:regular],
auto_track_tag: TopicUser.notification_reasons[:auto_track_tag]) auto_track_tag: TopicUser.notification_reasons[:auto_track_tag])
end end
end end

View File

@ -478,7 +478,7 @@ class User < ActiveRecord::Base
DB.query_single(sql, DB.query_single(sql,
user_id: id, user_id: id,
seen_notification_id: seen_notification_id, seen_notification_id: seen_notification_id,
pm: Notification.types[:private_message], pm: Notification.types[:private_message],
limit: User.max_unread_notifications limit: User.max_unread_notifications
)[0].to_i )[0].to_i
end end

View File

@ -49,7 +49,7 @@ class PushNotificationPusher
title: I18n.t("discourse_push_notifications.popup.confirm_title", title: I18n.t("discourse_push_notifications.popup.confirm_title",
site_title: SiteSetting.title), site_title: SiteSetting.title),
body: I18n.t("discourse_push_notifications.popup.confirm_body"), body: I18n.t("discourse_push_notifications.popup.confirm_body"),
icon: ActionController::Base.helpers.image_url("push-notifications/check.png"), icon: ActionController::Base.helpers.image_url("push-notifications/check.png"),
badge: get_badge, badge: get_badge,
tag: "#{Discourse.current_hostname}-subscription" tag: "#{Discourse.current_hostname}-subscription"
} }

View File

@ -19,12 +19,12 @@ if ENV['RAILS_ENV'] != 'production' && ENV['RAILS_ENV'] != 'profile'
if defined? Bootsnap if defined? Bootsnap
Bootsnap.setup( Bootsnap.setup(
cache_dir: 'tmp/cache', # Path to your cache cache_dir: 'tmp/cache', # Path to your cache
load_path_cache: true, # Should we optimize the LOAD_PATH with a cache? load_path_cache: true, # Should we optimize the LOAD_PATH with a cache?
autoload_paths_cache: true, # Should we optimize ActiveSupport autoloads with cache? autoload_paths_cache: true, # Should we optimize ActiveSupport autoloads with cache?
disable_trace: false, # Sets `RubyVM::InstructionSequence.compile_option = { trace_instruction: false }` disable_trace: false, # Sets `RubyVM::InstructionSequence.compile_option = { trace_instruction: false }`
compile_cache_iseq: true, # Should compile Ruby code into ISeq cache? compile_cache_iseq: true, # Should compile Ruby code into ISeq cache?
compile_cache_yaml: false # Skip YAML cache for now, cause we were seeing issues with it compile_cache_yaml: false # Skip YAML cache for now, cause we were seeing issues with it
) )
end end
end end

View File

@ -24,12 +24,12 @@ Discourse::Application.configure do
if GlobalSetting.smtp_address if GlobalSetting.smtp_address
settings = { settings = {
address: GlobalSetting.smtp_address, address: GlobalSetting.smtp_address,
port: GlobalSetting.smtp_port, port: GlobalSetting.smtp_port,
domain: GlobalSetting.smtp_domain, domain: GlobalSetting.smtp_domain,
user_name: GlobalSetting.smtp_user_name, user_name: GlobalSetting.smtp_user_name,
password: GlobalSetting.smtp_password, password: GlobalSetting.smtp_password,
authentication: GlobalSetting.smtp_authentication, authentication: GlobalSetting.smtp_authentication,
enable_starttls_auto: GlobalSetting.smtp_enable_start_tls enable_starttls_auto: GlobalSetting.smtp_enable_start_tls
} }

View File

@ -366,17 +366,17 @@ class HtmlPrettify < String
def default_entities def default_entities
{ {
single_left_quote: "&lsquo;", single_left_quote: "&lsquo;",
double_left_quote: "&ldquo;", double_left_quote: "&ldquo;",
single_right_quote: "&rsquo;", single_right_quote: "&rsquo;",
double_right_quote: "&rdquo;", double_right_quote: "&rdquo;",
em_dash: "&mdash;", em_dash: "&mdash;",
en_dash: "&ndash;", en_dash: "&ndash;",
ellipsis: "&hellip;", ellipsis: "&hellip;",
html_quote: "&quot;", html_quote: "&quot;",
frac12: "&frac12;", frac12: "&frac12;",
frac14: "&frac14;", frac14: "&frac14;",
frac34: "&frac34;", frac34: "&frac34;",
} }
end end

View File

@ -5,30 +5,32 @@ if (Rails.env.development? || Rails.env.test?)
task :set_annotation_options do task :set_annotation_options do
# You can override any of these by setting an environment variable of the # You can override any of these by setting an environment variable of the
# same name. # same name.
Annotate.set_defaults('position_in_routes' => "before", Annotate.set_defaults(
'position_in_class' => "after", 'position_in_routes' => "before",
'position_in_test' => "before", 'position_in_class' => "after",
'position_in_fixture' => "before", 'position_in_test' => "before",
'position_in_factory' => "before", 'position_in_fixture' => "before",
'show_indexes' => "true", 'position_in_factory' => "before",
'simple_indexes' => "false", 'show_indexes' => "true",
'model_dir' => "app/models", 'simple_indexes' => "false",
'include_version' => "false", 'model_dir' => "app/models",
'require' => "", 'include_version' => "false",
'exclude_tests' => "true", 'require' => "",
'exclude_fixtures' => "true", 'exclude_tests' => "true",
'exclude_helpers' => "true", 'exclude_fixtures' => "true",
'exclude_factories' => "true", 'exclude_helpers' => "true",
'exclude_serializers' => "true", 'exclude_factories' => "true",
'exclude_controllers' => "true", 'exclude_serializers' => "true",
'ignore_model_sub_dir' => "false", 'exclude_controllers' => "true",
'skip_on_db_migrate' => "true", 'ignore_model_sub_dir' => "false",
'format_bare' => "true", 'skip_on_db_migrate' => "true",
'format_rdoc' => "false", 'format_bare' => "true",
'format_markdown' => "false", 'format_rdoc' => "false",
'sort' => "false", 'format_markdown' => "false",
'force' => "false", 'sort' => "false",
'trace' => "false") 'force' => "false",
'trace' => "false"
)
end end
end end

View File

@ -219,7 +219,7 @@ RSpec.describe MigratePollsData do
"type" => "regular" "type" => "regular"
}, },
"poll" => { "poll" => {
"options" => [ "options" => [
{ {
"id" => "edeee5dae4802ab24185d41039efb545", "id" => "edeee5dae4802ab24185d41039efb545",
"html" => "Yes", "html" => "Yes",

View File

@ -14,6 +14,8 @@ class BulkImport::Base
NOW ||= "now()".freeze NOW ||= "now()".freeze
PRIVATE_OFFSET ||= 2**30 PRIVATE_OFFSET ||= 2**30
# rubocop:disable Layout/AlignHash
CHARSET_MAP = { CHARSET_MAP = {
"armscii8" => nil, "armscii8" => nil,
"ascii" => Encoding::US_ASCII, "ascii" => Encoding::US_ASCII,
@ -53,6 +55,8 @@ class BulkImport::Base
"utf8" => Encoding::UTF_8, "utf8" => Encoding::UTF_8,
} }
# rubocop:enable Layout/AlignHash
def initialize def initialize
charset = ENV["DB_CHARSET"] || "utf8" charset = ENV["DB_CHARSET"] || "utf8"
db = ActiveRecord::Base.connection_config db = ActiveRecord::Base.connection_config

View File

@ -114,15 +114,15 @@ class ImportScripts::MyAskBot < ImportScripts::Base
create_users(users, total: total_count, offset: offset) do |user| create_users(users, total: total_count, offset: offset) do |user|
{ {
id: user["id"], id: user["id"],
username: user["username"], username: user["username"],
email: user["email"] || (SecureRandom.hex << "@domain.com"), email: user["email"] || (SecureRandom.hex << "@domain.com"),
admin: user["is_staff"], admin: user["is_staff"],
created_at: Time.zone.at(@td.decode(user["date_joined"])), created_at: Time.zone.at(@td.decode(user["date_joined"])),
last_seen_at: Time.zone.at(@td.decode(user["last_seen"])), last_seen_at: Time.zone.at(@td.decode(user["last_seen"])),
name: user["real_name"], name: user["real_name"],
website: user["website"], website: user["website"],
location: user["location"], location: user["location"],
} }
end end
end end

View File

@ -322,7 +322,7 @@ class ImportScripts::Lithium < ImportScripts::Base
create_categories(parent_categories) do |category| create_categories(parent_categories) do |category|
{ {
id: category["node_id"], id: category["node_id"],
name: category["name"], name: category["name"],
position: category["position"], position: category["position"],
post_create_action: lambda do |record| post_create_action: lambda do |record|
after_category_create(record, category) after_category_create(record, category)

View File

@ -77,10 +77,10 @@ class ImportScripts::Nabble < ImportScripts::Base
create_users(users, total: total_count, offset: offset) do |row| create_users(users, total: total_count, offset: offset) do |row|
{ {
id: row["user_id"], id: row["user_id"],
email: row["email"] || (SecureRandom.hex << "@domain.com"), email: row["email"] || (SecureRandom.hex << "@domain.com"),
created_at: Time.zone.at(@td.decode(row["joined"])), created_at: Time.zone.at(@td.decode(row["joined"])),
name: row["name"], name: row["name"],
post_create_action: proc do |user| post_create_action: proc do |user|
import_avatar(user, row["user_id"]) import_avatar(user, row["user_id"])
end end
@ -151,13 +151,15 @@ class ImportScripts::Nabble < ImportScripts::Base
raw = process_content(raw) raw = process_content(raw)
raw = process_attachments(raw, t['node_id']) raw = process_attachments(raw, t['node_id'])
{ id: t['node_id'], {
id: t['node_id'],
title: t['subject'], title: t['subject'],
user_id: user_id_from_imported_user_id(t["owner_id"]) || Discourse::SYSTEM_USER_ID, user_id: user_id_from_imported_user_id(t["owner_id"]) || Discourse::SYSTEM_USER_ID,
created_at: Time.zone.at(@td.decode(t["when_created"])), created_at: Time.zone.at(@td.decode(t["when_created"])),
category: CATEGORY_ID, category: CATEGORY_ID,
raw: raw, raw: raw,
cook_method: Post.cook_methods[:regular] } cook_method: Post.cook_methods[:regular]
}
end end
end end
end end

View File

@ -20,10 +20,11 @@ MAILTO = YOUR_EMAIL
### You shouldn't need to change anything below here ### You shouldn't need to change anything below here
$delivery_options = { $delivery_options = {
user_name: @DISCOURSE_SMTP_USER_NAME || nil, user_name: @DISCOURSE_SMTP_USER_NAME || nil,
password: @DISCOURSE_SMTP_PASSWORD || nil, password: @DISCOURSE_SMTP_PASSWORD || nil,
address: DISCOURSE_SMTP_ADDRESS, address: DISCOURSE_SMTP_ADDRESS,
port: @DISCOURSE_SMTP_PORT || nil, port: @DISCOURSE_SMTP_PORT || nil,
openssl_verify_mode: @DISCOURSE_SMTP_OPENSSL_VERIFY_MODE || nil } openssl_verify_mode: @DISCOURSE_SMTP_OPENSSL_VERIFY_MODE || nil
}
class EmailTestMailer < ActionMailer::Base class EmailTestMailer < ActionMailer::Base
def email_test(mailfrom, mailto) def email_test(mailfrom, mailto)

View File

@ -121,42 +121,42 @@ describe JsLocaleHelper do
end end
it 'performs fallbacks to english if a translation is not available' do it 'performs fallbacks to english if a translation is not available' do
JsLocaleHelper.set_translations('en', "en" => { JsLocaleHelper.set_translations('en', "en" => {
"js" => { "js" => {
"only_english" => "1-en", "only_english" => "1-en",
"english_and_site" => "3-en", "english_and_site" => "3-en",
"english_and_user" => "5-en", "english_and_user" => "5-en",
"all_three" => "7-en", "all_three" => "7-en",
} }
}) })
JsLocaleHelper.set_translations('ru', "ru" => { JsLocaleHelper.set_translations('ru', "ru" => {
"js" => { "js" => {
"only_site" => "2-ru", "only_site" => "2-ru",
"english_and_site" => "3-ru", "english_and_site" => "3-ru",
"site_and_user" => "6-ru", "site_and_user" => "6-ru",
"all_three" => "7-ru", "all_three" => "7-ru",
} }
}) })
JsLocaleHelper.set_translations('uk', "uk" => { JsLocaleHelper.set_translations('uk', "uk" => {
"js" => { "js" => {
"only_user" => "4-uk", "only_user" => "4-uk",
"english_and_user" => "5-uk", "english_and_user" => "5-uk",
"site_and_user" => "6-uk", "site_and_user" => "6-uk",
"all_three" => "7-uk", "all_three" => "7-uk",
} }
}) })
expected = { expected = {
"none" => "[uk.js.none]", "none" => "[uk.js.none]",
"only_english" => "1-en", "only_english" => "1-en",
"only_site" => "2-ru", "only_site" => "2-ru",
"english_and_site" => "3-ru", "english_and_site" => "3-ru",
"only_user" => "4-uk", "only_user" => "4-uk",
"english_and_user" => "5-uk", "english_and_user" => "5-uk",
"site_and_user" => "6-uk", "site_and_user" => "6-uk",
"all_three" => "7-uk", "all_three" => "7-uk",
} }
SiteSetting.default_locale = 'ru' SiteSetting.default_locale = 'ru'

View File

@ -43,10 +43,10 @@ describe WebhooksController do
post "/webhooks/sendgrid.json", params: { post "/webhooks/sendgrid.json", params: {
"_json" => [ "_json" => [
{ {
"email" => email, "email" => email,
"smtp-id" => "<12345@il.com>", "smtp-id" => "<12345@il.com>",
"event" => "bounce", "event" => "bounce",
"status" => "5.0.0" "status" => "5.0.0"
} }
] ]
} }
@ -66,9 +66,9 @@ describe WebhooksController do
post "/webhooks/mailjet.json", params: { post "/webhooks/mailjet.json", params: {
"event" => "bounce", "event" => "bounce",
"email" => email, "email" => email,
"hard_bounce" => true, "hard_bounce" => true,
"CustomID" => message_id "CustomID" => message_id
} }
expect(response.status).to eq(200) expect(response.status).to eq(200)