Rubocop: enable and fix Style/Send and Style/Next (#9366)
* Enable and fix Style/Send * Enable and fix Style/Next * Fix private cookies send * Fix merging indentation issues
This commit is contained in:
parent
c5cf8fa82a
commit
6cd64c4071
16 changed files with 119 additions and 117 deletions
16
.rubocop.yml
16
.rubocop.yml
|
|
@ -386,7 +386,7 @@ Style/ClassAndModuleChildren:
|
|||
Style/Next:
|
||||
Description: 'Use `next` to skip iteration instead of a condition at the end.'
|
||||
StyleGuide: '#no-nested-conditionals'
|
||||
Enabled: false
|
||||
Enabled: true
|
||||
|
||||
Style/RedundantAssignment:
|
||||
Description: 'Checks for redundant assignment before returning.'
|
||||
|
|
@ -423,10 +423,10 @@ Style/ReturnNil:
|
|||
Description: 'Use return instead of return nil.'
|
||||
Enabled: true
|
||||
|
||||
# Style/Send:
|
||||
# Description: 'Prefer `Object#__send__` or `Object#public_send` to `send`, as `send` may overlap with existing methods.'
|
||||
# StyleGuide: '#prefer-public-send'
|
||||
# Enabled: false
|
||||
Style/Send:
|
||||
Description: 'Prefer `Object#__send__` or `Object#public_send` to `send`, as `send` may overlap with existing methods.'
|
||||
StyleGuide: '#prefer-public-send'
|
||||
Enabled: true
|
||||
|
||||
Style/SingleLineBlockParams:
|
||||
Description: 'Enforces the names of some block params.'
|
||||
|
|
@ -455,9 +455,9 @@ Style/TrailingCommaInArrayLiteral:
|
|||
Enabled: true
|
||||
EnforcedStyleForMultiline: comma
|
||||
|
||||
# Style/TrailingCommaInBlockArgs:
|
||||
# Description: 'Checks for useless trailing commas in block arguments.'
|
||||
# Enabled: false
|
||||
Style/TrailingCommaInBlockArgs:
|
||||
Description: 'Checks for useless trailing commas in block arguments.'
|
||||
Enabled: true
|
||||
|
||||
# Performance cops from rubocop-performance
|
||||
# https://github.com/rubocop-hq/rubocop-performance/blob/master/config/default.yml
|
||||
|
|
|
|||
|
|
@ -26,17 +26,18 @@ class BufferUpdatesController < ApplicationController
|
|||
tags_names = @article.decorate.cached_tag_list_array
|
||||
tags_names.each do |name|
|
||||
tag = Tag.find_by(name: name)
|
||||
if tag&.buffer_profile_id_code.present?
|
||||
BufferUpdate.create(
|
||||
article_id: @article.id,
|
||||
composer_user_id: current_user.id,
|
||||
body_text: modified_body_text,
|
||||
social_service_name: "twitter",
|
||||
buffer_profile_id_code: tag.buffer_profile_id_code,
|
||||
tag_id: tag.id,
|
||||
status: "pending",
|
||||
)
|
||||
end
|
||||
|
||||
next if tag&.buffer_profile_id_code.blank?
|
||||
|
||||
BufferUpdate.create(
|
||||
article_id: @article.id,
|
||||
composer_user_id: current_user.id,
|
||||
body_text: modified_body_text,
|
||||
social_service_name: "twitter",
|
||||
buffer_profile_id_code: tag.buffer_profile_id_code,
|
||||
tag_id: tag.id,
|
||||
status: "pending",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -76,12 +76,12 @@ module CacheBuster
|
|||
bust("/videos?i=i")
|
||||
end
|
||||
TIMEFRAMES.each do |timestamp, interval|
|
||||
if Article.published.where("published_at > ?", timestamp)
|
||||
.order(public_reactions_count: :desc).limit(3).pluck(:id).include?(article.id)
|
||||
bust("/top/#{interval}")
|
||||
bust("/top/#{interval}?i=i")
|
||||
bust("/top/#{interval}/?i=i")
|
||||
end
|
||||
next unless Article.published.where("published_at > ?", timestamp)
|
||||
.order(public_reactions_count: :desc).limit(3).pluck(:id).include?(article.id)
|
||||
|
||||
bust("/top/#{interval}")
|
||||
bust("/top/#{interval}?i=i")
|
||||
bust("/top/#{interval}/?i=i")
|
||||
end
|
||||
if article.published && article.published_at > 1.hour.ago
|
||||
bust("/latest")
|
||||
|
|
@ -99,22 +99,23 @@ module CacheBuster
|
|||
bust("/t/#{tag}/latest?i=i")
|
||||
end
|
||||
TIMEFRAMES.each do |timestamp, interval|
|
||||
if Article.published.where("published_at > ?", timestamp).tagged_with(tag)
|
||||
.order(public_reactions_count: :desc).limit(3).pluck(:id).include?(article.id)
|
||||
bust("/top/#{interval}")
|
||||
bust("/top/#{interval}?i=i")
|
||||
bust("/top/#{interval}/?i=i")
|
||||
12.times do |i|
|
||||
bust("/api/articles?tag=#{tag}&top=#{i}")
|
||||
end
|
||||
next unless Article.published.where("published_at > ?", timestamp).tagged_with(tag)
|
||||
.order(public_reactions_count: :desc).limit(3).pluck(:id).include?(article.id)
|
||||
|
||||
bust("/top/#{interval}")
|
||||
bust("/top/#{interval}?i=i")
|
||||
bust("/top/#{interval}/?i=i")
|
||||
12.times do |i|
|
||||
bust("/api/articles?tag=#{tag}&top=#{i}")
|
||||
end
|
||||
end
|
||||
if rand(2) == 1 &&
|
||||
Article.published.tagged_with(tag)
|
||||
.order(hotness_score: :desc).limit(2).pluck(:id).include?(article.id)
|
||||
bust("/t/#{tag}")
|
||||
bust("/t/#{tag}?i=i")
|
||||
end
|
||||
|
||||
next unless rand(2) == 1 &&
|
||||
Article.published.tagged_with(tag)
|
||||
.order(hotness_score: :desc).limit(2).pluck(:id).include?(article.id)
|
||||
|
||||
bust("/t/#{tag}")
|
||||
bust("/t/#{tag}?i=i")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,17 +7,17 @@ class MarkdownFixer
|
|||
add_quotes_to_title add_quotes_to_description
|
||||
modify_hr_tags convert_new_lines split_tags underscores_in_usernames
|
||||
]
|
||||
methods.reduce(markdown) { |acc, elem| send(elem, acc) }
|
||||
methods.reduce(markdown) { |acc, elem| public_send(elem, acc) }
|
||||
end
|
||||
|
||||
def fix_for_preview(markdown)
|
||||
methods = %i[add_quotes_to_title add_quotes_to_description modify_hr_tags underscores_in_usernames]
|
||||
methods.reduce(markdown) { |acc, elem| send(elem, acc) }
|
||||
methods.reduce(markdown) { |acc, elem| public_send(elem, acc) }
|
||||
end
|
||||
|
||||
def fix_for_comment(markdown)
|
||||
methods = %I[modify_hr_tags underscores_in_usernames]
|
||||
methods.reduce(markdown) { |acc, elem| send(elem, acc) }
|
||||
methods.reduce(markdown) { |acc, elem| public_send(elem, acc) }
|
||||
end
|
||||
|
||||
def add_quotes_to_title(markdown)
|
||||
|
|
|
|||
|
|
@ -112,21 +112,21 @@ class PodcastEpisode < ApplicationRecord
|
|||
doc.css("img").each do |img|
|
||||
img_src = img.attr("src")
|
||||
|
||||
if img_src
|
||||
quality = "auto"
|
||||
quality = 66 if img_src.include?(".gif")
|
||||
next unless img_src
|
||||
|
||||
cloudinary_img_src = ActionController::Base.helpers
|
||||
.cl_image_path(img_src,
|
||||
type: "fetch",
|
||||
width: 725,
|
||||
crop: "limit",
|
||||
quality: quality,
|
||||
flags: "progressive",
|
||||
fetch_format: "auto",
|
||||
sign_url: true)
|
||||
self.processed_html = processed_html.gsub(img_src, cloudinary_img_src)
|
||||
end
|
||||
quality = "auto"
|
||||
quality = 66 if img_src.include?(".gif")
|
||||
|
||||
cloudinary_img_src = ActionController::Base.helpers
|
||||
.cl_image_path(img_src,
|
||||
type: "fetch",
|
||||
width: 725,
|
||||
crop: "limit",
|
||||
quality: quality,
|
||||
flags: "progressive",
|
||||
fetch_format: "auto",
|
||||
sign_url: true)
|
||||
self.processed_html = processed_html.gsub(img_src, cloudinary_img_src)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ module DataSync
|
|||
def sync_related_documents
|
||||
RELATED_DOCS.each do |relation_name|
|
||||
if updated_record.published
|
||||
send(relation_name).find_each(&:index_to_elasticsearch)
|
||||
__send__(relation_name).find_each(&:index_to_elasticsearch)
|
||||
elsif updated_fields.key?(:published)
|
||||
send(relation_name).find_each(&:remove_from_elasticsearch)
|
||||
__send__(relation_name).find_each(&:remove_from_elasticsearch)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ module DataSync
|
|||
|
||||
def sync_related_documents
|
||||
self.class::RELATED_DOCS.each do |relation_name|
|
||||
send(relation_name).find_each(&:index_to_elasticsearch)
|
||||
__send__(relation_name).find_each(&:index_to_elasticsearch)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class RateLimitChecker
|
|||
|
||||
def limit_by_action(action)
|
||||
check_method = "check_#{action}_limit"
|
||||
result = respond_to?(check_method, true) ? send(check_method) : false
|
||||
result = respond_to?(check_method, true) ? __send__(check_method) : false
|
||||
|
||||
if result
|
||||
@action = action
|
||||
|
|
|
|||
|
|
@ -77,14 +77,14 @@ class RssReader
|
|||
next if a_tag.empty?
|
||||
|
||||
possible_link = a_tag[0].inner_html
|
||||
if /medium\.com\/media\/.+\/href/.match?(possible_link)
|
||||
real_link = HTTParty.head(possible_link).request.last_uri.to_s
|
||||
return nil unless real_link.include?("gist.github.com")
|
||||
next unless /medium\.com\/media\/.+\/href/.match?(possible_link)
|
||||
|
||||
iframe.name = "p"
|
||||
iframe.keys.each { |attr| iframe.remove_attribute(attr) } # rubocop:disable Style/HashEachMethods
|
||||
iframe.inner_html = "{% gist #{real_link} %}"
|
||||
end
|
||||
real_link = HTTParty.head(possible_link).request.last_uri.to_s
|
||||
return nil unless real_link.include?("gist.github.com")
|
||||
|
||||
iframe.name = "p"
|
||||
iframe.keys.each { |attr| iframe.remove_attribute(attr) } # rubocop:disable Style/HashEachMethods
|
||||
iframe.inner_html = "{% gist #{real_link} %}"
|
||||
end
|
||||
html_doc
|
||||
end
|
||||
|
|
@ -94,14 +94,14 @@ class RssReader
|
|||
html_doc.search("script").remove
|
||||
html_doc.css("blockquote").each do |bq|
|
||||
bq_with_p = bq.css("p")
|
||||
next if bq_with_p.empty?
|
||||
|
||||
if (tweet_link = bq_with_p.css("a[href*='twitter.com']"))
|
||||
bq.name = "p"
|
||||
tweet_url = tweet_link.attribute("href").value
|
||||
tweet_id = tweet_url.split("/status/").last
|
||||
bq.inner_html = "{% tweet #{tweet_id} %}"
|
||||
end
|
||||
next if bq_with_p.empty?
|
||||
next unless (tweet_link = bq_with_p.css("a[href*='twitter.com']"))
|
||||
|
||||
bq.name = "p"
|
||||
tweet_url = tweet_link.attribute("href").value
|
||||
tweet_id = tweet_url.split("/status/").last
|
||||
bq.inner_html = "{% tweet #{tweet_id} %}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -115,12 +115,12 @@ class RssReader
|
|||
|
||||
def parse_and_translate_youtube_iframe!(html_doc)
|
||||
html_doc.css("iframe").each do |iframe|
|
||||
if /youtube\.com/.match?(iframe.attributes["src"].value)
|
||||
iframe.name = "p"
|
||||
youtube_id = iframe.attributes["src"].value.scan(/embed%2F(.{4,11})/).flatten.first
|
||||
iframe.keys.each { |attr| iframe.remove_attribute(attr) } # rubocop:disable Style/HashEachMethods
|
||||
iframe.inner_html = "{% youtube #{youtube_id} %}"
|
||||
end
|
||||
next unless /youtube\.com/.match?(iframe.attributes["src"].value)
|
||||
|
||||
iframe.name = "p"
|
||||
youtube_id = iframe.attributes["src"].value.scan(/embed%2F(.{4,11})/).flatten.first
|
||||
iframe.keys.each { |attr| iframe.remove_attribute(attr) } # rubocop:disable Style/HashEachMethods
|
||||
iframe.inner_html = "{% youtube #{youtube_id} %}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -64,11 +64,11 @@ module PracticalDeveloper
|
|||
top_routes = []
|
||||
Rails.application.routes.routes.each do |route|
|
||||
route = route.path.spec.to_s
|
||||
unless route.starts_with?("/:")
|
||||
route = route.split("/")[1]
|
||||
route = route.split("(")[0] if route&.include?("(")
|
||||
top_routes << route
|
||||
end
|
||||
next if route.starts_with?("/:")
|
||||
|
||||
route = route.split("/")[1]
|
||||
route = route.split("(")[0] if route&.include?("(")
|
||||
top_routes << route
|
||||
end
|
||||
ReservedWords.all = [ReservedWords::BASE_WORDS + top_routes].flatten.compact.uniq
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ class ApplicationConfig
|
|||
URI_REGEXP = %r{(?<scheme>https?://)?(?<host>.+?)(?<port>:\d+)?$}.freeze
|
||||
|
||||
def self.[](key)
|
||||
ENVied.send(key)
|
||||
ENVied.public_send(key)
|
||||
end
|
||||
|
||||
def self.app_domain_no_port
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ RSpec.describe "AsyncInfo", type: :request do
|
|||
it "requires remember_user_token cookie to be present" do
|
||||
get "/async_info/base_data"
|
||||
token = "a_token"
|
||||
controller.send("cookies")[:remember_user_token] = "a_token"
|
||||
controller.__send__("cookies")[:remember_user_token] = "a_token"
|
||||
expect(controller.remember_user_token).to eq(token)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ RSpec.describe "Follows #show", type: :request do
|
|||
|
||||
def get_following_status
|
||||
%w[User Organization Tag Podcast].map do |type|
|
||||
get "/follows/#{send(type.downcase).id}", params: { followable_type: type }
|
||||
get "/follows/#{__send__(type.downcase).id}", params: { followable_type: type }
|
||||
response.body
|
||||
end
|
||||
end
|
||||
|
|
@ -27,7 +27,7 @@ RSpec.describe "Follows #show", type: :request do
|
|||
end
|
||||
|
||||
it "returns true when is following" do
|
||||
%w[user organization tag].each { |followable| current_user.follow(send(followable)) }
|
||||
%w[user organization tag].each { |followable| current_user.follow(__send__(followable)) }
|
||||
expect(get_following_status.uniq[0]).to eq("true")
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -103,24 +103,24 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do
|
|||
|
||||
it "does not send a notification to a newly-created user" do
|
||||
user.update!(created_at: Time.zone.now)
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_welcome_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_welcome_notification) }
|
||||
expect(user.notifications.count).to eq(0)
|
||||
end
|
||||
|
||||
it "generates the correct broadcast type and sends the notification to the user" do
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_welcome_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_welcome_notification) }
|
||||
expect(user.notifications.first.notifiable).to eq(welcome_broadcast)
|
||||
end
|
||||
|
||||
it "does not send to a user who has commented in a welcome thread" do
|
||||
create(:comment, commentable: welcome_thread, commentable_type: "Article", user: user)
|
||||
expect do
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_welcome_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_welcome_notification) }
|
||||
end.not_to change(user.notifications, :count)
|
||||
end
|
||||
|
||||
it "does not send duplicate notifications" do
|
||||
2.times { sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_welcome_notification) } }
|
||||
2.times { sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_welcome_notification) } }
|
||||
expect(user.notifications.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
|
@ -128,32 +128,32 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do
|
|||
describe "#send_authentication_notification" do
|
||||
it "does not send notification if user is created less than a day ago" do
|
||||
user = create(:user, :with_identity, identities: ["github"])
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_authentication_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_authentication_notification) }
|
||||
expect(Notification).not_to have_received(:send_welcome_notification)
|
||||
end
|
||||
|
||||
it "generates and sends the appropriate broadcast (twitter)" do
|
||||
user = create(:user, :with_identity, identities: ["github"], created_at: 1.day.ago)
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_authentication_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_authentication_notification) }
|
||||
expect(user.notifications.first.notifiable).to eq(twitter_connect_broadcast)
|
||||
end
|
||||
|
||||
it "generates and sends the appropriate broadcast (github)" do
|
||||
user = create(:user, :with_identity, identities: ["twitter"], created_at: 1.day.ago)
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_authentication_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_authentication_notification) }
|
||||
expect(user.notifications.first.notifiable).to eq(github_connect_broadcast)
|
||||
end
|
||||
|
||||
it "does not send notification if user is authenticated with both services" do
|
||||
user = create(:user, :with_identity, identities: %w[twitter github], created_at: 1.day.ago)
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_authentication_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_authentication_notification) }
|
||||
expect(Notification).not_to have_received(:send_welcome_notification).with(user.id, github_connect_broadcast.id)
|
||||
end
|
||||
|
||||
it "does not send duplicate notifications (github)" do
|
||||
user = create(:user, :with_identity, identities: ["twitter"], created_at: 1.day.ago)
|
||||
2.times do
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_authentication_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_authentication_notification) }
|
||||
end
|
||||
expect(user.notifications.count).to eq(1)
|
||||
end
|
||||
|
|
@ -161,7 +161,7 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do
|
|||
it "does not send duplicate notifications (twitter)" do
|
||||
user = create(:user, :with_identity, identities: ["github"], created_at: 1.day.ago)
|
||||
2.times do
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_authentication_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_authentication_notification) }
|
||||
end
|
||||
expect(user.notifications.count).to eq(1)
|
||||
end
|
||||
|
|
@ -175,25 +175,25 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do
|
|||
|
||||
it "does not send a notification to a newly-created user" do
|
||||
user.update!(created_at: Time.current)
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_feed_customization_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_feed_customization_notification) }
|
||||
expect(Notification).not_to have_received(:send_welcome_notification)
|
||||
end
|
||||
|
||||
it "does not send a notification to a user that is following 2 tags" do
|
||||
2.times { user.follow(create(:tag)) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_feed_customization_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_feed_customization_notification) }
|
||||
expect(Notification).not_to have_received(:send_welcome_notification)
|
||||
end
|
||||
|
||||
it "sends a notification to a user with 0 tag follows" do
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_feed_customization_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_feed_customization_notification) }
|
||||
expect(user.notifications.count).to eq(1)
|
||||
expect(user.notifications.first.notifiable).to eq(customize_feed_broadcast)
|
||||
end
|
||||
|
||||
it "does not send duplicate notifications" do
|
||||
2.times do
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_feed_customization_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_feed_customization_notification) }
|
||||
end
|
||||
expect(user.notifications.count).to eq(1)
|
||||
end
|
||||
|
|
@ -204,19 +204,19 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do
|
|||
|
||||
it "does not send a notification to a newly-created user" do
|
||||
user.update!(created_at: Time.zone.now)
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_ux_customization_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_ux_customization_notification) }
|
||||
expect(Notification).not_to have_received(:send_welcome_notification)
|
||||
end
|
||||
|
||||
it "generates the correct broadcast type and sends the notification to the user" do
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_ux_customization_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_ux_customization_notification) }
|
||||
expect(user.notifications.count).to eq(1)
|
||||
expect(user.notifications.first.notifiable).to eq(customize_ux_broadcast)
|
||||
end
|
||||
|
||||
it "does not send duplicate notifications" do
|
||||
2.times do
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_ux_customization_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_ux_customization_notification) }
|
||||
end
|
||||
expect(user.notifications.count).to eq(1)
|
||||
end
|
||||
|
|
@ -232,7 +232,7 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do
|
|||
it "generates the correct broadcast type and sends the notification to the user" do
|
||||
create(:article, tags: "explainlikeimfive", user: user)
|
||||
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_discuss_and_ask_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_discuss_and_ask_notification) }
|
||||
expect(user.notifications.count).to eq(1)
|
||||
expect(user.notifications.first.notifiable).to eq(start_discussion_broadcast)
|
||||
end
|
||||
|
|
@ -242,7 +242,7 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do
|
|||
it "generates the correct broadcast type and sends the notification to the user" do
|
||||
create(:article, tags: "discuss", user: user)
|
||||
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_discuss_and_ask_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_discuss_and_ask_notification) }
|
||||
expect(user.notifications.count).to eq(1)
|
||||
expect(user.notifications.first.notifiable).to eq(ask_question_broadcast)
|
||||
end
|
||||
|
|
@ -250,7 +250,7 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do
|
|||
|
||||
context "with a user who has neither asked a question and started a discussion" do
|
||||
it "generates the correct broadcast type and sends the notification to the user" do
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_discuss_and_ask_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_discuss_and_ask_notification) }
|
||||
expect(user.notifications.count).to eq(1)
|
||||
expect(user.notifications.first.notifiable).to eq(discuss_and_ask_broadcast)
|
||||
end
|
||||
|
|
@ -261,20 +261,20 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do
|
|||
create(:article, tags: "discuss", user: user)
|
||||
create(:article, tags: "explainlikeimfive", user: user)
|
||||
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_discuss_and_ask_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_discuss_and_ask_notification) }
|
||||
expect(Notification).not_to have_received(:send_welcome_notification)
|
||||
end
|
||||
end
|
||||
|
||||
it "does not send a notification to a newly-created user" do
|
||||
user.update!(created_at: Time.zone.now)
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_discuss_and_ask_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_discuss_and_ask_notification) }
|
||||
expect(Notification).not_to have_received(:send_welcome_notification)
|
||||
end
|
||||
|
||||
it "does not send duplicate notifications" do
|
||||
2.times do
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_discuss_and_ask_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_discuss_and_ask_notification) }
|
||||
end
|
||||
expect(user.notifications.count).to eq(1)
|
||||
end
|
||||
|
|
@ -284,19 +284,19 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do
|
|||
|
||||
it "does not send a notification to a newly-created user" do
|
||||
user.update!(created_at: Time.zone.now)
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_download_app_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_download_app_notification) }
|
||||
expect(Notification).not_to have_received(:send_welcome_notification)
|
||||
end
|
||||
|
||||
it "generates the correct broadcast type and sends the notification to the user" do
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_download_app_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_download_app_notification) }
|
||||
expect(user.notifications.count).to eq(1)
|
||||
expect(user.notifications.first.notifiable).to eq(download_app_broadcast)
|
||||
end
|
||||
|
||||
it "does not send duplicate notifications" do
|
||||
2.times do
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_download_app_notification) }
|
||||
sidekiq_perform_enqueued_jobs { described_class.new(user.id).__send__(:send_download_app_notification) }
|
||||
end
|
||||
expect(user.notifications.count).to eq(1)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ RSpec.describe Notifications::NewComment::Send, type: :service do
|
|||
described_class.call(comment_sent)
|
||||
|
||||
channels = ["user-notifications-#{user2.id}", "user-notifications-#{user.id}"]
|
||||
payload = described_class.new(comment_sent).send(:push_notification_payload)
|
||||
payload = described_class.new(comment_sent).__send__(:push_notification_payload)
|
||||
expect(Pusher::PushNotifications).to have_received(:publish_to_interests).with(interests: channels,
|
||||
payload: payload)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ RSpec.describe RateLimitChecker, type: :service do
|
|||
let(:rate_limit_checker) { described_class.new(user) }
|
||||
|
||||
def cache_key(action)
|
||||
rate_limit_checker.send("limit_cache_key", action)
|
||||
rate_limit_checker.__send__("limit_cache_key", action)
|
||||
end
|
||||
|
||||
describe "#limit_by_action" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue