Enable Rubocop 0.89 cops and fix Lint/ violations (#9709)
* Enable new Lint/ cops and run rubocop -a * Fixing last remaining things with rubocop -a * Enable and fix Style/ExplicitBlockArgument and Style/GlobalStdStream * Forgot parenthesis
This commit is contained in:
parent
edd0f2c630
commit
cc8bfcb5c0
26 changed files with 163 additions and 90 deletions
65
.rubocop.yml
65
.rubocop.yml
|
|
@ -134,6 +134,10 @@ Lint/AmbiguousBlockAssociation:
|
|||
Exclude:
|
||||
- "spec/**/*"
|
||||
|
||||
Lint/BinaryOperatorWithIdenticalOperands:
|
||||
Description: 'This cop checks for places where binary operator has identical operands.'
|
||||
Enabled: true
|
||||
|
||||
Lint/ConstantResolution:
|
||||
Description: 'Check that constants are fully qualified with `::`.'
|
||||
Enabled: false
|
||||
|
|
@ -146,12 +150,31 @@ Lint/DuplicateElsifCondition:
|
|||
Description: 'Do not repeat conditions used in if `elsif`.'
|
||||
Enabled: true
|
||||
|
||||
Lint/DuplicateRescueException:
|
||||
Description: 'Checks that there are no repeated exceptions used in `rescue` expressions.'
|
||||
Enabled: true
|
||||
|
||||
Lint/EmptyConditionalBody:
|
||||
Description: 'This cop checks for the presence of `if`, `elsif` and `unless` branches without a body.'
|
||||
Enabled: true
|
||||
|
||||
Lint/FloatComparison:
|
||||
Description: 'Checks for the presence of precise comparison of floating point numbers.'
|
||||
StyleGuide: '#float-comparison'
|
||||
Enabled: true
|
||||
|
||||
# Lint/HeredocMethodCallPosition:
|
||||
# Description: >-
|
||||
# Checks for the ordering of a method call where
|
||||
# the receiver of the call is a HEREDOC.
|
||||
# Enabled: false
|
||||
|
||||
Lint/MissingSuper:
|
||||
Description: >-
|
||||
This cop checks for the presence of constructors and lifecycle callbacks
|
||||
without calls to `super`'.
|
||||
Enabled: true
|
||||
|
||||
Lint/MixedRegexpCaptureTypes:
|
||||
Description: 'Do not mix named captures and numbered captures in a Regexp literal.'
|
||||
Enabled: true
|
||||
|
|
@ -160,15 +183,31 @@ Lint/MixedRegexpCaptureTypes:
|
|||
# Description: 'Checks unsafe usage of number conversion methods.'
|
||||
# Enabled: false
|
||||
|
||||
Lint/OutOfRangeRegexpRef:
|
||||
Description: 'Checks for out of range reference for Regexp because it always returns nil.'
|
||||
Enabled: true
|
||||
|
||||
Lint/RaiseException:
|
||||
Description: Checks for `raise` or `fail` statements which are raising `Exception` class.
|
||||
StyleGuide: '#raise-exception'
|
||||
Enabled: true
|
||||
|
||||
Lint/SelfAssignment:
|
||||
Description: 'Checks for self-assignments.'
|
||||
Enabled: true
|
||||
|
||||
Lint/StructNewOverride:
|
||||
Description: 'Disallow overriding the `Struct` built-in methods via `Struct.new`.'
|
||||
Enabled: true
|
||||
|
||||
Lint/TopLevelReturnWithArgument:
|
||||
Description: 'This cop detects top level return statements with argument.'
|
||||
Enabled: true
|
||||
|
||||
Lint/UnreachableLoop:
|
||||
Description: 'This cop checks for loops that will have at most one iteration.'
|
||||
Enabled: true
|
||||
|
||||
#################### Metrics ###############################
|
||||
|
||||
Metrics/AbcSize:
|
||||
|
|
@ -292,6 +331,13 @@ Style/Encoding:
|
|||
Description: 'Use UTF-8 as the source file encoding.'
|
||||
Enabled: false
|
||||
|
||||
Style/ExplicitBlockArgument:
|
||||
Description: >-
|
||||
Consider using explicit block argument to avoid writing block literal
|
||||
that just passes its arguments to another block.
|
||||
StyleGuide: '#block-argument'
|
||||
Enabled: true
|
||||
|
||||
Style/ExponentialNotation:
|
||||
Description: 'When using exponential notation, favor a mantissa between 1 (inclusive) and 10 (exclusive).'
|
||||
StyleGuide: '#exponential-notation'
|
||||
|
|
@ -305,6 +351,11 @@ Style/FrozenStringLiteralComment:
|
|||
Enabled: true
|
||||
EnforcedStyle: never
|
||||
|
||||
Style/GlobalStdStream:
|
||||
Description: 'Enforces the use of `$stdout/$stderr/$stdin` instead of `STDOUT/STDERR/STDIN`.'
|
||||
StyleGuide: '#global-stdout'
|
||||
Enabled: true
|
||||
|
||||
Style/HashAsLastArrayItem:
|
||||
Description: >-
|
||||
Checks for presence or absence of braces around hash literal as a last
|
||||
|
|
@ -379,6 +430,11 @@ Style/ClassAndModuleChildren:
|
|||
Enabled: true
|
||||
SafeAutoCorrect: true
|
||||
|
||||
Style/OptionalBooleanParameter:
|
||||
Description: 'Use keyword arguments when defining method with boolean argument.'
|
||||
StyleGuide: '#boolean-keyword-arguments'
|
||||
Enabled: pending
|
||||
|
||||
Style/OptionHash:
|
||||
Description: "Don't use option hashes when you can use keyword arguments."
|
||||
Enabled: true
|
||||
|
|
@ -423,6 +479,10 @@ Style/Send:
|
|||
StyleGuide: '#prefer-public-send'
|
||||
Enabled: true
|
||||
|
||||
Style/SingleArgumentDig:
|
||||
Description: 'Avoid using single argument dig method.'
|
||||
Enabled: pending
|
||||
|
||||
Style/SingleLineBlockParams:
|
||||
Description: 'Enforces the names of some block params.'
|
||||
Enabled: true
|
||||
|
|
@ -431,6 +491,11 @@ Style/SlicingWithRange:
|
|||
Description: 'Checks array slicing is done with endless ranges when suitable.'
|
||||
Enabled: true
|
||||
|
||||
Style/StringConcatenation:
|
||||
Description: 'Checks for places where string concatenation can be replaced with string interpolation.'
|
||||
StyleGuide: '#string-interpolation'
|
||||
Enabled: pending
|
||||
|
||||
Style/StringLiterals:
|
||||
Description: 'Checks if uses of quotes match the configured preference.'
|
||||
StyleGuide: '#consistent-string-literals'
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ class CommentsController < ApplicationController
|
|||
# GET /comments
|
||||
# GET /comments.json
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
def index
|
||||
skip_authorization
|
||||
@on_comments_page = true
|
||||
|
|
@ -39,6 +40,7 @@ class CommentsController < ApplicationController
|
|||
render :deleted_commentable_comment unless @commentable
|
||||
end
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
|
||||
# GET /comments/1
|
||||
# GET /comments/1.json
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
class NotificationsController < ApplicationController
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
# No authorization required because we provide authentication on notifications page
|
||||
def index
|
||||
return unless user_signed_in?
|
||||
|
|
@ -49,6 +50,7 @@ class NotificationsController < ApplicationController
|
|||
render partial: "notifications_list" if notified_at_offset
|
||||
end
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
|
||||
private
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ class VideoChatsController < ApplicationController
|
|||
grant.room = params[:id]
|
||||
token.add_grant(grant)
|
||||
|
||||
@username = @username
|
||||
@token = token.to_jwt
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class NullTag < Liquid::Block
|
||||
def initialize(tag_name, _markup, _options)
|
||||
def initialize(tag_name, _markup, _options) # rubocop:disable Lint/MissingSuper
|
||||
raise StandardError, "Liquid##{tag_name} tag is disabled"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
module Moderator
|
||||
class BanishUser < ManageActivityAndRoles
|
||||
attr_reader :user, :admin
|
||||
|
||||
def self.call(admin:, user:)
|
||||
new(user: user, admin: admin).banish
|
||||
end
|
||||
|
||||
attr_reader :user, :admin
|
||||
|
||||
def initialize(admin:, user:)
|
||||
@user = user
|
||||
@admin = admin
|
||||
super(user: user, admin: admin, user_params: {})
|
||||
end
|
||||
|
||||
def banish
|
||||
|
|
|
|||
|
|
@ -10,12 +10,6 @@ module Moderator
|
|||
end
|
||||
end
|
||||
|
||||
def initialize(admin:, user:, user_params:)
|
||||
@user = user
|
||||
@admin = admin
|
||||
@user_params = user_params
|
||||
end
|
||||
|
||||
def ghostify
|
||||
@ghost = User.find_by(username: "ghost")
|
||||
reassign_articles
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ module Moderator
|
|||
|
||||
attr_reader :keep_user, :admin, :delete_user_id
|
||||
|
||||
def initialize(admin:, keep_user:, delete_user_id:)
|
||||
def initialize(admin:, keep_user:, delete_user_id:) # rubocop:disable Lint/MissingSuper
|
||||
@keep_user = keep_user
|
||||
@admin = admin
|
||||
@delete_user = User.find(delete_user_id.to_i)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class RateLimitChecker
|
|||
class LimitReached < StandardError
|
||||
attr_reader :retry_after
|
||||
|
||||
def initialize(retry_after)
|
||||
def initialize(retry_after) # rubocop:disable Lint/MissingSuper
|
||||
@retry_after = retry_after
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ module Search
|
|||
}.freeze
|
||||
|
||||
def initialize(params:)
|
||||
super()
|
||||
|
||||
@params = params.deep_symbolize_keys
|
||||
@params[:viewable_by] = @params[:user_id]
|
||||
|
||||
|
|
|
|||
|
|
@ -67,6 +67,8 @@ module Search
|
|||
attr_accessor :params, :body
|
||||
|
||||
def initialize(params:)
|
||||
super()
|
||||
|
||||
@params = params.deep_symbolize_keys
|
||||
|
||||
# Default to only showing published articles to start
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ module Search
|
|||
}.freeze
|
||||
|
||||
def initialize(params:)
|
||||
super()
|
||||
|
||||
@params = params.deep_symbolize_keys
|
||||
|
||||
# For now, we're not allowing searches for Listings that are
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ module Search
|
|||
attr_accessor :params, :body
|
||||
|
||||
def initialize(params:)
|
||||
super()
|
||||
|
||||
@params = params.deep_symbolize_keys
|
||||
|
||||
# Default to only readinglist reactions
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ module Search
|
|||
}.freeze
|
||||
|
||||
def initialize(params:)
|
||||
super()
|
||||
|
||||
@params = params.deep_symbolize_keys
|
||||
|
||||
# default to excluding users who are banned
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ Rails.application.configure do
|
|||
config.log_level = :debug
|
||||
|
||||
if ENV["RAILS_LOG_TO_STDOUT"].present?
|
||||
logger = ActiveSupport::Logger.new(STDOUT)
|
||||
logger = ActiveSupport::Logger.new($stdout)
|
||||
logger.formatter = config.log_formatter
|
||||
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ Rails.application.configure do
|
|||
# require 'syslog/logger'
|
||||
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
||||
|
||||
logger = ActiveSupport::Logger.new(STDOUT)
|
||||
logger = ActiveSupport::Logger.new($stdout)
|
||||
logger.formatter = config.log_formatter
|
||||
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,17 +26,18 @@ CarrierWave.configure do |config|
|
|||
region: "us-east-2"
|
||||
}
|
||||
config.asset_host = "https://#{ApplicationConfig['APP_DOMAIN']}/images"
|
||||
config.fog_public = false
|
||||
config.fog_public = false
|
||||
else
|
||||
region = ApplicationConfig["AWS_UPLOAD_REGION"].presence || ApplicationConfig["AWS_DEFAULT_REGION"]
|
||||
config.fog_credentials = {
|
||||
provider: "AWS",
|
||||
aws_access_key_id: ApplicationConfig["AWS_ID"],
|
||||
aws_secret_access_key: ApplicationConfig["AWS_SECRET"],
|
||||
region: region
|
||||
}
|
||||
provider: "AWS",
|
||||
aws_access_key_id: ApplicationConfig["AWS_ID"],
|
||||
aws_secret_access_key: ApplicationConfig["AWS_SECRET"],
|
||||
region: region
|
||||
}
|
||||
end
|
||||
config.fog_directory = ApplicationConfig["AWS_BUCKET_NAME"]
|
||||
config.storage = :fog
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/BlockLength
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
if Rails.env.development? && File.file?("/.dockerenv")
|
||||
# Using shell tools so we don't need to require Socket and IPAddr
|
||||
host_ip = `ip route|awk '/default/ { print $3 }'`.strip
|
||||
logger = Logger.new(STDOUT)
|
||||
logger = Logger.new($stdout)
|
||||
logger.info "Allowing #{host_ip} for BetterErrors and Web Console"
|
||||
|
||||
if defined?(BetterErrors::Middleware)
|
||||
|
|
|
|||
|
|
@ -67,7 +67,8 @@ describe SocialImageHelper do
|
|||
it "returns correct manipulation of cloudinary links" do
|
||||
article.update_column(
|
||||
:main_image,
|
||||
"https://res.cloudinary.com/practicaldev/image/fetch/s--A-gun7rr--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://res.cloudinary.com/practicaldev/image/fetch/s--hcD8ZkbP--/c_imagga_scale%2Cf_auto%2Cfl_progressive%2Ch_420%2Cq_auto%2Cw_1000/https://dev-to-uploads.s3.amazonaws.com/i/th93d625o27nuz63oeen.png")
|
||||
"https://res.cloudinary.com/practicaldev/image/fetch/s--A-gun7rr--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://res.cloudinary.com/practicaldev/image/fetch/s--hcD8ZkbP--/c_imagga_scale%2Cf_auto%2Cfl_progressive%2Ch_420%2Cq_auto%2Cw_1000/https://dev-to-uploads.s3.amazonaws.com/i/th93d625o27nuz63oeen.png", # rubocop:disable Layout/LineLength
|
||||
)
|
||||
url = helper.article_social_image_url(article.decorate, width: 1600, height: 900)
|
||||
|
||||
expect(url.scan(/res.cloudinary.com/).length).to be 1
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ RSpec.describe HtmlVariant, type: :model do
|
|||
it "prefixes an image with cloudinary" do
|
||||
html = "<div><img src='https://devimages.com/image.jpg' /></div>"
|
||||
html_variant.update(approved: false, html: html)
|
||||
expect(html_variant.html).to include("/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_420/https://devimages.com/image.jpg")
|
||||
cloudinary_string = "/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_420/https://devimages.com/image.jpg"
|
||||
expect(html_variant.html).to include(cloudinary_string)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe "/admin/chat_channels", type: :request do
|
||||
|
||||
let(:user) { create(:user) }
|
||||
let(:chat_channel) { create(:chat_channel) }
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
expect do
|
||||
post "/admin/config", params: { site_config: { favicon_url: expected_image_url },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
end.to raise_error Pundit::NotAuthorizedError
|
||||
end
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
expect do
|
||||
post "/admin/config", params: { site_config: { favicon_url: expected_image_url },
|
||||
confirmation: "Not proper" }
|
||||
confirmation: "Not proper" }
|
||||
end.to raise_error Pundit::NotAuthorizedError
|
||||
end
|
||||
end
|
||||
|
|
@ -51,7 +51,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
it "updates the health_check_token" do
|
||||
token = rand(20).to_s
|
||||
post "/admin/config", params: { site_config: { health_check_token: token },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.health_check_token).to eq token
|
||||
end
|
||||
end
|
||||
|
|
@ -60,7 +60,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
it "updates enabled authentication providers" do
|
||||
enabled = Array.wrap(Authentication::Providers.available.first.to_s)
|
||||
post "/admin/config", params: { site_config: { authentication_providers: enabled },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.authentication_providers).to eq(enabled)
|
||||
end
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
provider = Authentication::Providers.available.first.to_s
|
||||
enabled = [provider, "", nil]
|
||||
post "/admin/config", params: { site_config: { authentication_providers: enabled },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.authentication_providers).to eq([provider])
|
||||
end
|
||||
end
|
||||
|
|
@ -78,21 +78,21 @@ RSpec.describe "/admin/config", type: :request do
|
|||
allow(SiteConfig).to receive(:community_description).and_call_original
|
||||
description = "Hey hey #{rand(100)}"
|
||||
post "/admin/config", params: { site_config: { community_description: description },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.community_description).to eq(description)
|
||||
end
|
||||
|
||||
it "updates the community_member_label" do
|
||||
name = "developer"
|
||||
post "/admin/config", params: { site_config: { community_member_label: name },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.community_member_label).to eq(name)
|
||||
end
|
||||
|
||||
it "updates the community_action" do
|
||||
action = "reading"
|
||||
post "/admin/config", params: { site_config: { community_member_label: action },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.community_member_label).to eq(action)
|
||||
end
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
members: "members@example.com"
|
||||
}
|
||||
post "/admin/config", params: { site_config: { email_addresses: expected_email_addresses },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.email_addresses[:privacy]).to eq("privacy@example.com")
|
||||
expect(SiteConfig.email_addresses[:business]).to eq("partners@example.com")
|
||||
expect(SiteConfig.email_addresses[:members]).to eq("members@example.com")
|
||||
|
|
@ -122,20 +122,20 @@ RSpec.describe "/admin/config", type: :request do
|
|||
describe "Email digest frequency" do
|
||||
it "updates periodic_email_digest_max" do
|
||||
post "/admin/config", params: { site_config: { periodic_email_digest_max: 1 },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.periodic_email_digest_max).to eq(1)
|
||||
end
|
||||
|
||||
it "updates periodic_email_digest_min" do
|
||||
post "/admin/config", params: { site_config: { periodic_email_digest_min: 3 },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.periodic_email_digest_min).to eq(3)
|
||||
end
|
||||
|
||||
it "rejects update without proper confirmation" do
|
||||
expect do
|
||||
post "/admin/config", params: { site_config: { periodic_email_digest_min: 6 },
|
||||
confirmation: "Incorrect yo!" }
|
||||
confirmation: "Incorrect yo!" }
|
||||
end.to raise_error Pundit::NotAuthorizedError
|
||||
expect(SiteConfig.periodic_email_digest_min).not_to eq(6)
|
||||
end
|
||||
|
|
@ -144,13 +144,13 @@ RSpec.describe "/admin/config", type: :request do
|
|||
describe "Jobs" do
|
||||
it "updates jobs_url" do
|
||||
post "/admin/config", params: { site_config: { jobs_url: "www.jobs.com" },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.jobs_url).to eq("www.jobs.com")
|
||||
end
|
||||
|
||||
it "updates display_jobs_banner" do
|
||||
post "/admin/config", params: { site_config: { display_jobs_banner: true },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.display_jobs_banner).to eq(true)
|
||||
end
|
||||
end
|
||||
|
|
@ -171,35 +171,35 @@ RSpec.describe "/admin/config", type: :request do
|
|||
it "updates main_social_image" do
|
||||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
post "/admin/config", params: { site_config: { main_social_image: expected_image_url },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.main_social_image).to eq(expected_image_url)
|
||||
end
|
||||
|
||||
it "updates favicon_url" do
|
||||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
post "/admin/config", params: { site_config: { favicon_url: expected_image_url },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.favicon_url).to eq(expected_image_url)
|
||||
end
|
||||
|
||||
it "updates logo_png" do
|
||||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
post "/admin/config", params: { site_config: { logo_png: expected_image_url },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.logo_png).to eq(expected_image_url)
|
||||
end
|
||||
|
||||
it "updates logo_svg" do
|
||||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
post "/admin/config", params: { site_config: { logo_svg: expected_image_url },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.logo_svg).to eq(expected_image_url)
|
||||
end
|
||||
|
||||
it "updates secondary_logo_url" do
|
||||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
post "/admin/config", params: { site_config: { secondary_logo_url: expected_image_url },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.secondary_logo_url).to eq(expected_image_url)
|
||||
end
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
expected_svg = "<svg height='100' width='100'><circle cx='50' cy='50' r='40' " \
|
||||
"stroke='black' stroke-width='3'/></svg>"
|
||||
post "/admin/config", params: { site_config: { left_navbar_svg_icon: expected_svg },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.left_navbar_svg_icon).to eq(expected_svg)
|
||||
end
|
||||
|
||||
|
|
@ -215,7 +215,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
expected_svg = "<svg height='100' width='100'><circle cx='50' cy='50' r='40' " \
|
||||
"stroke='black' stroke-width='1'/></svg>"
|
||||
post "/admin/config", params: { site_config: { right_navbar_svg_icon: expected_svg },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.right_navbar_svg_icon).to eq(expected_svg)
|
||||
end
|
||||
|
||||
|
|
@ -223,7 +223,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
expect do
|
||||
post "/admin/config", params: { site_config: { logo_svg: expected_image_url },
|
||||
confirmation: "Incorrect yo!" }
|
||||
confirmation: "Incorrect yo!" }
|
||||
end.to raise_error Pundit::NotAuthorizedError
|
||||
end
|
||||
end
|
||||
|
|
@ -232,28 +232,28 @@ RSpec.describe "/admin/config", type: :request do
|
|||
it "updates the mascot_user_id" do
|
||||
expected_mascot_user_id = 2
|
||||
post "/admin/config", params: { site_config: { mascot_user_id: expected_mascot_user_id },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.mascot_user_id).to eq(expected_mascot_user_id)
|
||||
end
|
||||
|
||||
it "updates mascot_image_url" do
|
||||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
post "/admin/config", params: { site_config: { mascot_image_url: expected_image_url },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.mascot_image_url).to eq(expected_image_url)
|
||||
end
|
||||
|
||||
it "updates mascot_footer_image_url" do
|
||||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
post "/admin/config", params: { site_config: { mascot_footer_image_url: expected_image_url },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.mascot_footer_image_url).to eq(expected_image_url)
|
||||
end
|
||||
|
||||
it "updates mascot_image_description" do
|
||||
description = "Hey hey #{rand(100)}"
|
||||
post "/admin/config", params: { site_config: { mascot_image_description: description },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.mascot_image_description).to eq(description)
|
||||
end
|
||||
end
|
||||
|
|
@ -262,7 +262,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
it "updates meta keywords" do
|
||||
expected_keywords = { "default" => "software, people", "article" => "user, experience", "tag" => "bye" }
|
||||
post "/admin/config", params: { site_config: { meta_keywords: expected_keywords },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.meta_keywords[:default]).to eq("software, people")
|
||||
expect(SiteConfig.meta_keywords[:article]).to eq("user, experience")
|
||||
expect(SiteConfig.meta_keywords[:tag]).to eq("bye")
|
||||
|
|
@ -272,7 +272,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
describe "Monetization" do
|
||||
it "updates payment pointer" do
|
||||
post "/admin/config", params: { site_config: { payment_pointer: "$pay.yo" },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.payment_pointer).to eq("$pay.yo")
|
||||
end
|
||||
|
||||
|
|
@ -300,7 +300,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
it "updates shop url" do
|
||||
expected_shop_url = "https://qshop.dev.to"
|
||||
post "/admin/config", params: { site_config: { shop_url: expected_shop_url },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.shop_url).to eq(expected_shop_url)
|
||||
get "/privacy"
|
||||
expect(response.body).to include(expected_shop_url)
|
||||
|
|
@ -312,25 +312,25 @@ RSpec.describe "/admin/config", type: :request do
|
|||
describe "Newsletter" do
|
||||
it "updates mailchimp_newsletter_id" do
|
||||
post "/admin/config", params: { site_config: { mailchimp_newsletter_id: "abc" },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.mailchimp_newsletter_id).to eq("abc")
|
||||
end
|
||||
|
||||
it "updates mailchimp_sustaining_members_id" do
|
||||
post "/admin/config", params: { site_config: { mailchimp_sustaining_members_id: "abc" },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.mailchimp_sustaining_members_id).to eq("abc")
|
||||
end
|
||||
|
||||
it "updates mailchimp_tag_moderators_id" do
|
||||
post "/admin/config", params: { site_config: { mailchimp_tag_moderators_id: "abc" },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.mailchimp_tag_moderators_id).to eq("abc")
|
||||
end
|
||||
|
||||
it "updates mailchimp_community_moderators_id" do
|
||||
post "/admin/config", params: { site_config: { mailchimp_community_moderators_id: "abc" },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.mailchimp_community_moderators_id).to eq("abc")
|
||||
end
|
||||
end
|
||||
|
|
@ -339,33 +339,33 @@ RSpec.describe "/admin/config", type: :request do
|
|||
it "updates onboarding_taskcard_image" do
|
||||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
post "/admin/config", params: { site_config: { onboarding_taskcard_image: expected_image_url },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.onboarding_taskcard_image).to eq(expected_image_url)
|
||||
end
|
||||
|
||||
it "updates onboarding_logo_image" do
|
||||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
post "/admin/config", params: { site_config: { onboarding_logo_image: expected_image_url },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.onboarding_logo_image).to eq(expected_image_url)
|
||||
end
|
||||
|
||||
it "updates onboarding_background_image" do
|
||||
expected_image_url = "https://dummyimage.com/300x300"
|
||||
post "/admin/config", params: { site_config: { onboarding_background_image: expected_image_url },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.onboarding_background_image).to eq(expected_image_url)
|
||||
end
|
||||
|
||||
it "removes space suggested_tags" do
|
||||
post "/admin/config", params: { site_config: { suggested_tags: "hey, haha,hoho, bobo fofo" },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.suggested_tags).to eq(%w[hey haha hoho bobofofo])
|
||||
end
|
||||
|
||||
it "downcases suggested_tags" do
|
||||
post "/admin/config", params: { site_config: { suggested_tags: "hey, haha,hoHo, Bobo Fofo" },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.suggested_tags).to eq(%w[hey haha hoho bobofofo])
|
||||
end
|
||||
|
||||
|
|
@ -390,49 +390,49 @@ RSpec.describe "/admin/config", type: :request do
|
|||
it "updates rate_limit_follow_count_daily" do
|
||||
expect do
|
||||
post "/admin/config", params: { site_config: { rate_limit_follow_count_daily: 3 },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
end.to change(SiteConfig, :rate_limit_follow_count_daily).from(500).to(3)
|
||||
end
|
||||
|
||||
it "updates rate_limit_comment_creation" do
|
||||
expect do
|
||||
post "/admin/config", params: { site_config: { rate_limit_comment_creation: 3 },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
end.to change(SiteConfig, :rate_limit_comment_creation).from(9).to(3)
|
||||
end
|
||||
|
||||
it "updates rate_limit_published_article_creation" do
|
||||
expect do
|
||||
post "/admin/config", params: { site_config: { rate_limit_published_article_creation: 3 },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
end.to change(SiteConfig, :rate_limit_published_article_creation).from(9).to(3)
|
||||
end
|
||||
|
||||
it "updates rate_limit_organization_creation" do
|
||||
expect do
|
||||
post "/admin/config", params: { site_config: { rate_limit_organization_creation: 3 },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
end.to change(SiteConfig, :rate_limit_organization_creation).from(1).to(3)
|
||||
end
|
||||
|
||||
it "updates rate_limit_image_upload" do
|
||||
expect do
|
||||
post "/admin/config", params: { site_config: { rate_limit_image_upload: 3 },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
end.to change(SiteConfig, :rate_limit_image_upload).from(9).to(3)
|
||||
end
|
||||
|
||||
it "updates rate_limit_email_recipient" do
|
||||
expect do
|
||||
post "/admin/config", params: { site_config: { rate_limit_email_recipient: 3 },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
end.to change(SiteConfig, :rate_limit_email_recipient).from(5).to(3)
|
||||
end
|
||||
|
||||
it "updates rate_limit_user_subscription_creation" do
|
||||
expect do
|
||||
post "/admin/config", params: { site_config: { rate_limit_user_subscription_creation: 1 },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
end.to change(SiteConfig, :rate_limit_user_subscription_creation).from(3).to(1)
|
||||
end
|
||||
end
|
||||
|
|
@ -447,7 +447,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
it "updates social_media_handles" do
|
||||
expected_handle = { "facebook" => "tpd", "github" => "", "instagram" => "", "twitch" => "", "twitter" => "" }
|
||||
post "/admin/config", params: { site_config: { social_media_handles: expected_handle },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.social_media_handles[:facebook]).to eq("tpd")
|
||||
expect(SiteConfig.social_media_handles[:github]).to eq("")
|
||||
end
|
||||
|
|
@ -472,7 +472,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
it "updates the sponsor_headline" do
|
||||
headline = "basic"
|
||||
post "/admin/config", params: { site_config: { sponsor_headline: headline },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.sponsor_headline).to eq(headline)
|
||||
end
|
||||
end
|
||||
|
|
@ -480,13 +480,13 @@ RSpec.describe "/admin/config", type: :request do
|
|||
describe "Tags" do
|
||||
it "removes space sidebar_tags" do
|
||||
post "/admin/config", params: { site_config: { sidebar_tags: "hey, haha,hoho, bobo fofo" },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.sidebar_tags).to eq(%w[hey haha hoho bobofofo])
|
||||
end
|
||||
|
||||
it "downcases sidebar_tags" do
|
||||
post "/admin/config", params: { site_config: { sidebar_tags: "hey, haha,hoHo, Bobo Fofo" },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.sidebar_tags).to eq(%w[hey haha hoho bobofofo])
|
||||
end
|
||||
end
|
||||
|
|
@ -495,21 +495,21 @@ RSpec.describe "/admin/config", type: :request do
|
|||
it "updates the feed_style" do
|
||||
feed_style = "basic"
|
||||
post "/admin/config", params: { site_config: { mascot_user_id: feed_style },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.feed_style).to eq(feed_style)
|
||||
end
|
||||
|
||||
it "updates public to true" do
|
||||
is_public = true
|
||||
post "/admin/config", params: { site_config: { public: is_public },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.public).to eq(is_public)
|
||||
end
|
||||
|
||||
it "updates public to false" do
|
||||
is_public = false
|
||||
post "/admin/config", params: { site_config: { public: is_public },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.public).to eq(is_public)
|
||||
end
|
||||
end
|
||||
|
|
@ -528,7 +528,7 @@ RSpec.describe "/admin/config", type: :request do
|
|||
new_prices = original_prices.merge(size => 123)
|
||||
expect do
|
||||
post "/admin/config", params: { site_config: { credit_prices_in_cents: new_prices },
|
||||
confirmation: confirmation_message }
|
||||
confirmation: confirmation_message }
|
||||
end.to change { SiteConfig.credit_prices_in_cents[size] }.from(original_prices[size.to_sym]).to(123)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ RSpec.describe "/admin/podcasts", type: :request do
|
|||
describe "Updating" do
|
||||
it "updates" do
|
||||
put admin_podcast_path(podcast), params: { podcast: { title: "hello",
|
||||
feed_url: "https://pod.example.com/rss.rss" } }
|
||||
feed_url: "https://pod.example.com/rss.rss" } }
|
||||
podcast.reload
|
||||
expect(podcast.title).to eq("hello")
|
||||
expect(podcast.feed_url).to eq("https://pod.example.com/rss.rss")
|
||||
|
|
@ -70,7 +70,7 @@ RSpec.describe "/admin/podcasts", type: :request do
|
|||
|
||||
it "redirects after update" do
|
||||
put admin_podcast_path(podcast), params: { podcast: { title: "hello",
|
||||
feed_url: "https://pod.example.com/rss.rss" } }
|
||||
feed_url: "https://pod.example.com/rss.rss" } }
|
||||
expect(response).to redirect_to(admin_podcasts_path)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ RSpec.describe "/admin/profile_fields", type: :request do
|
|||
end
|
||||
|
||||
describe "GET /admin/profile_fields" do
|
||||
|
||||
it "renders successfully" do
|
||||
get admin_profile_fields_path
|
||||
expect(response).to be_successful
|
||||
|
|
@ -27,7 +26,6 @@ RSpec.describe "/admin/profile_fields", type: :request do
|
|||
end
|
||||
|
||||
describe "POST /admin/profile_fields" do
|
||||
|
||||
let(:new_profile_field) do
|
||||
{
|
||||
label: "Location",
|
||||
|
|
@ -62,13 +60,13 @@ RSpec.describe "/admin/profile_fields", type: :request do
|
|||
|
||||
it "redirects successfully" do
|
||||
put "#{admin_profile_fields_path}/#{profile_field.id}",
|
||||
params: { profile_field: { active: false }}
|
||||
params: { profile_field: { active: false } }
|
||||
expect(response).to redirect_to admin_profile_fields_path
|
||||
end
|
||||
|
||||
it "updates the profile field values" do
|
||||
put "#{admin_profile_fields_path}/#{profile_field.id}",
|
||||
params: { profile_field: { active: false }}
|
||||
params: { profile_field: { active: false } }
|
||||
|
||||
changed_profile_record = ProfileField.find(profile_field.id)
|
||||
expect(changed_profile_record.active).to be(false)
|
||||
|
|
|
|||
|
|
@ -112,6 +112,6 @@ RSpec.describe "admin/users", type: :request do
|
|||
expect do
|
||||
patch unlock_access_admin_user_path(user)
|
||||
end.to change { user.reload.access_locked? }.from(true).to(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,20 +11,22 @@ RSpec.describe CloudCoverUrl, type: :view_object do
|
|||
end
|
||||
|
||||
it "returns proper url when nested cloudinary" do
|
||||
image_url = "https://res.cloudinary.com/practicaldev/image/fetch/s--A-gun7rr--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://res.cloudinary.com/practicaldev/image/fetch/s--hcD8ZkbP--/c_imagga_scale%2Cf_auto%2Cfl_progressive%2Ch_420%2Cq_auto%2Cw_1000/https://dev-to-uploads.s3.amazonaws.com/i/th93d625o27nuz63oeen.png"
|
||||
image_url = "https://res.cloudinary.com/practicaldev/image/fetch/s--A-gun7rr--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://res.cloudinary.com/practicaldev/image/fetch/s--hcD8ZkbP--/c_imagga_scale%2Cf_auto%2Cfl_progressive%2Ch_420%2Cq_auto%2Cw_1000/https://dev-to-uploads.s3.amazonaws.com/i/th93d625o27nuz63oeen.png" # rubocop:disable Layout/LineLength
|
||||
cloudinary_string = "/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/i/th93d625o27nuz63oeen.png" # rubocop:disable Layout/LineLength
|
||||
|
||||
article.update_column(:main_image, image_url)
|
||||
expect(described_class.new(article.main_image).call)
|
||||
.to start_with(cloudinary_prefix)
|
||||
.and end_with("/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/i/th93d625o27nuz63oeen.png")
|
||||
.and end_with(cloudinary_string)
|
||||
end
|
||||
|
||||
it "returns proper url when single cloudinary" do
|
||||
image_url = "https://res.cloudinary.com/practicaldev/image/fetch/s--hcD8ZkbP--/c_imagga_scale%2Cf_auto%2Cfl_progressive%2Ch_420%2Cq_auto%2Cw_1000/https://dev-to-uploads.s3.amazonaws.com/i/th93d625o27nuz63oeen.png"
|
||||
image_url = "https://res.cloudinary.com/practicaldev/image/fetch/s--hcD8ZkbP--/c_imagga_scale%2Cf_auto%2Cfl_progressive%2Ch_420%2Cq_auto%2Cw_1000/https://dev-to-uploads.s3.amazonaws.com/i/th93d625o27nuz63oeen.png" # rubocop:disable Layout/LineLength
|
||||
cloudinary_string = "/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/i/th93d625o27nuz63oeen.png" # rubocop:disable Layout/LineLength
|
||||
|
||||
article.update_column(:main_image, image_url)
|
||||
expect(described_class.new(article.main_image).call)
|
||||
.to start_with(cloudinary_prefix)
|
||||
.and end_with("/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/i/th93d625o27nuz63oeen.png")
|
||||
.and end_with(cloudinary_string)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue