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:
Enabled: true
AllowAsExpressionSeparator: true
AllowAsExpressionSeparator: true

View File

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

View File

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

View File

@ -40,7 +40,7 @@ class SiteController < ApplicationController
logo_url: UrlHelper.absolute(SiteSetting.site_logo_url),
logo_small_url: UrlHelper.absolute(SiteSetting.site_logo_small_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,
description: SiteSetting.site_description,
header_primary_color: ColorScheme.hex_for_name('header_primary') || '333333',

View File

@ -10,16 +10,16 @@ module Jobs
sidekiq_options retry: false
HEADER_ATTRS_FOR ||= HashWithIndifferentAccess.new(
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_stats: ['topics_entered', 'posts_read_count', 'time_read', 'topic_count', 'post_count', 'likes_given', 'likes_received'],
user_profile: ['location', 'website', 'views'],
user_sso: ['external_id', 'external_email', 'external_username', 'external_name', 'external_avatar_url'],
staff_action: ['staff_user', 'action', 'subject', 'created_at', 'details', 'context'],
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_stats: ['topics_entered', 'posts_read_count', 'time_read', 'topic_count', 'post_count', 'likes_given', 'likes_received'],
user_profile: ['location', 'website', 'views'],
user_sso: ['external_id', 'external_email', 'external_username', 'external_name', 'external_avatar_url'],
staff_action: ['staff_user', 'action', 'subject', 'created_at', 'details', 'context'],
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_url: ['domain', 'action', 'match_count', 'last_match_at', 'created_at'],
report: ['date', 'value']
screened_ip: ['ip_address', 'action', 'match_count', 'last_match_at', 'created_at'],
screened_url: ['domain', 'action', 'match_count', 'last_match_at', 'created_at'],
report: ['date', 'value']
)
def execute(args)

View File

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

View File

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

View File

@ -435,12 +435,12 @@ class PostAction < ActiveRecord::Base
before_create do
post_action_type_ids = is_flag? ? PostActionType.notify_flag_types.values : post_action_type_id
raise AlreadyActed if PostAction.where(user_id: user_id)
.where(post_id: post_id)
.where(post_action_type_id: post_action_type_ids)
.where(deleted_at: nil)
.where(disagreed_at: nil)
.where(targets_topic: targets_topic)
.exists?
.where(post_id: post_id)
.where(post_action_type_id: post_action_type_ids)
.where(deleted_at: nil)
.where(disagreed_at: nil)
.where(targets_topic: targets_topic)
.exists?
end
# 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],
tracking: notification_levels[:tracking],
regular: notification_levels[:regular],
auto_watch_tag: TopicUser.notification_reasons[:auto_watch_tag])
auto_watch_tag: TopicUser.notification_reasons[:auto_watch_tag])
end
def self.auto_track(opts)
builder = DB.build <<~SQL
UPDATE topic_users
SET notification_level = :tracking, notifications_reason_id = :auto_track_tag
@ -147,7 +146,7 @@ class TagUser < ActiveRecord::Base
builder.exec(tracking: notification_levels[:tracking],
regular: notification_levels[:regular],
auto_track_tag: TopicUser.notification_reasons[:auto_track_tag])
auto_track_tag: TopicUser.notification_reasons[:auto_track_tag])
end
end

View File

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

View File

@ -49,7 +49,7 @@ class PushNotificationPusher
title: I18n.t("discourse_push_notifications.popup.confirm_title",
site_title: SiteSetting.title),
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,
tag: "#{Discourse.current_hostname}-subscription"
}

View File

@ -19,12 +19,12 @@ if ENV['RAILS_ENV'] != 'production' && ENV['RAILS_ENV'] != 'profile'
if defined? Bootsnap
Bootsnap.setup(
cache_dir: 'tmp/cache', # Path to your 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?
disable_trace: false, # Sets `RubyVM::InstructionSequence.compile_option = { trace_instruction: false }`
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
cache_dir: 'tmp/cache', # Path to your 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?
disable_trace: false, # Sets `RubyVM::InstructionSequence.compile_option = { trace_instruction: false }`
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
)
end
end

View File

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

View File

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

View File

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

View File

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

View File

@ -14,6 +14,8 @@ class BulkImport::Base
NOW ||= "now()".freeze
PRIVATE_OFFSET ||= 2**30
# rubocop:disable Layout/AlignHash
CHARSET_MAP = {
"armscii8" => nil,
"ascii" => Encoding::US_ASCII,
@ -53,6 +55,8 @@ class BulkImport::Base
"utf8" => Encoding::UTF_8,
}
# rubocop:enable Layout/AlignHash
def initialize
charset = ENV["DB_CHARSET"] || "utf8"
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|
{
id: user["id"],
username: user["username"],
email: user["email"] || (SecureRandom.hex << "@domain.com"),
admin: user["is_staff"],
created_at: Time.zone.at(@td.decode(user["date_joined"])),
id: user["id"],
username: user["username"],
email: user["email"] || (SecureRandom.hex << "@domain.com"),
admin: user["is_staff"],
created_at: Time.zone.at(@td.decode(user["date_joined"])),
last_seen_at: Time.zone.at(@td.decode(user["last_seen"])),
name: user["real_name"],
website: user["website"],
location: user["location"],
name: user["real_name"],
website: user["website"],
location: user["location"],
}
end
end

View File

@ -322,7 +322,7 @@ class ImportScripts::Lithium < ImportScripts::Base
create_categories(parent_categories) do |category|
{
id: category["node_id"],
name: category["name"],
name: category["name"],
position: category["position"],
post_create_action: lambda do |record|
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|
{
id: row["user_id"],
email: row["email"] || (SecureRandom.hex << "@domain.com"),
created_at: Time.zone.at(@td.decode(row["joined"])),
name: row["name"],
id: row["user_id"],
email: row["email"] || (SecureRandom.hex << "@domain.com"),
created_at: Time.zone.at(@td.decode(row["joined"])),
name: row["name"],
post_create_action: proc do |user|
import_avatar(user, row["user_id"])
end
@ -151,13 +151,15 @@ class ImportScripts::Nabble < ImportScripts::Base
raw = process_content(raw)
raw = process_attachments(raw, t['node_id'])
{ id: t['node_id'],
{
id: t['node_id'],
title: t['subject'],
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"])),
category: CATEGORY_ID,
raw: raw,
cook_method: Post.cook_methods[:regular] }
cook_method: Post.cook_methods[:regular]
}
end
end
end

View File

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

View File

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

View File

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