Upgrade Rubocop related gems and fix new violations (#3581) [ci skip]

This commit is contained in:
rhymes 2019-07-30 20:29:05 +02:00 committed by Mac Siri
parent bb6fe4495a
commit 816c062ea0
36 changed files with 201 additions and 202 deletions

View file

@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-07-01 18:50:42 +0200 using RuboCop version 0.72.0.
# on 2019-07-30 17:22:03 +0200 using RuboCop version 0.73.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@ -12,16 +12,16 @@
Metrics/BlockLength:
Max: 63
# Offense count: 24
# Offense count: 25
Metrics/PerceivedComplexity:
Max: 15
Max: 13
# Offense count: 1
RSpec/AnyInstance:
Exclude:
- 'spec/requests/stripe_cancellations_spec.rb'
# Offense count: 281
# Offense count: 343
# Configuration parameters: AggregateFailuresByDefault.
RSpec/MultipleExpectations:
Max: 8
@ -47,9 +47,8 @@ Rails/OutputSafety:
- 'app/models/message.rb'
- 'app/views/api/v0/articles/show.json.jbuilder'
- 'app/views/articles/feed.rss.builder'
- 'app/views/podcast_episodes/show.html.erb'
# Offense count: 17
# Offense count: 19
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle.
# SupportedStyles: nested, compact
@ -62,7 +61,7 @@ Style/GuardClause:
Exclude:
- 'app/models/article.rb'
# Offense count: 2463
# Offense count: 2642
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https

View file

@ -645,12 +645,12 @@ GEM
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
rubocop-performance (1.4.0)
rubocop-performance (1.4.1)
rubocop (>= 0.71.0)
rubocop-rails (2.2.0)
rubocop-rails (2.2.1)
rack (>= 1.1)
rubocop (>= 0.72.0)
rubocop-rspec (1.33.0)
rubocop-rspec (1.34.0)
rubocop (>= 0.60.0)
ruby-prof (0.18.0)
ruby-progressbar (1.10.1)

View file

@ -3,7 +3,7 @@ module Api
class FollowsController < ApplicationController
def create
return unless user_signed_in?
user_ids = params[:users].map { |h| h["id"] }
users = User.where(id: user_ids)
users.each do |user|

View file

@ -6,24 +6,24 @@ RSpec.describe UserSimilarity, vcr: {} do
let(:dissimilar_user) { create(:user, summary: "I like Haskell and functional programming") }
it "returns similar user" do
similar_score = UserSimilarity.new(user, similar_user).score
dissimilar_score = UserSimilarity.new(user, dissimilar_user).score
similar_score = described_class.new(user, similar_user).score
dissimilar_score = described_class.new(user, dissimilar_user).score
expect(similar_score).to be > dissimilar_score
end
it "Is not affected by stop words" do
user.summary = user.summary + " throughout yourself can indeed otherwise thru yourselves through yours by inc others"
dissimilar_user.summary = dissimilar_user.summary + " throughout yourself can indeed otherwise thru yourselves through yours by inc others"
similar_score = UserSimilarity.new(user, similar_user).score
dissimilar_score = UserSimilarity.new(user, dissimilar_user).score
similar_score = described_class.new(user, similar_user).score
dissimilar_score = described_class.new(user, dissimilar_user).score
expect(similar_score).to be > dissimilar_score
end
it "Is affected by non-stop words" do
user.summary = "Hot dogs languages punk rock hello"
dissimilar_user.summary = "Hot dogs languages punk rock hello "
similar_score = UserSimilarity.new(user, similar_user).score
dissimilar_score = UserSimilarity.new(user, dissimilar_user).score
similar_score = described_class.new(user, similar_user).score
dissimilar_score = described_class.new(user, dissimilar_user).score
expect(similar_score).to be < dissimilar_score
end
end

View file

@ -5,7 +5,7 @@ RSpec.describe DevCommentTag, type: :liquid_template do
let(:article) { create(:article) }
let(:comment) { create(:comment, commentable: article, body_markdown: "DevCommentTagTest", user: user) }
setup { Liquid::Template.register_tag("devcomment", DevCommentTag) }
setup { Liquid::Template.register_tag("devcomment", described_class) }
def generate_comment_tag(id_code)
Liquid::Template.parse("{% devcomment #{id_code} %}")

View file

@ -9,10 +9,10 @@ RSpec.describe LinkTag, type: :liquid_template do
let(:org_user) { create(:user, organization_id: org.id) }
let(:org_article) do
create(:article, user_id: org_user.id, title: "test this please", tags: "tag1 tag2 tag3",
organization_id: org.id)
organization_id: org.id)
end
let(:escaped_article) do
create(:article, user_id: user.id, title: "Hello & Hi <3 <script>", tags: "tag")
create(:article, user_id: user.id, title: "Hello & Hi <3 <script>", tags: "tag")
end
def generate_new_liquid(slug)

View file

@ -1,7 +1,7 @@
require "rails_helper"
RSpec.describe MediumTag, type: :liquid_template do
setup { Liquid::Template.register_tag("medium", MediumTag) }
setup { Liquid::Template.register_tag("medium", described_class) }
subject { Liquid::Template.parse("{% medium #{link} %}") }

View file

@ -4,7 +4,7 @@ RSpec.describe NullTag, type: :liquid_template do
describe "#initialize" do
tags = %w[assign capture case comment cycle for if ifchanged include unless]
setup { tags.each { |tag| Liquid::Template.register_tag(tag, NullTag) } }
setup { tags.each { |tag| Liquid::Template.register_tag(tag, described_class) } }
def generate_given_tag(tag)
Liquid::Template.parse("{% #{tag} %}")

View file

@ -3,7 +3,7 @@ require "rails_helper"
RSpec.describe OrganizationTag, type: :liquid_template do
let(:organization) { create(:organization) }
setup { Liquid::Template.register_tag("organization", OrganizationTag) }
setup { Liquid::Template.register_tag("organization", described_class) }
def generate_user_tag(id_code)
Liquid::Template.parse("{% organization #{id_code} %}")

View file

@ -5,7 +5,7 @@ RSpec.describe PodcastTag, type: :liquid_template do
let(:podcast_episode) { create(:podcast_episode, podcast_id: podcast.id) }
let(:valid_long_slug) { "/#{podcast.slug}/#{podcast_episode.slug}" }
before { Liquid::Template.register_tag("podcast", PodcastTag) }
before { Liquid::Template.register_tag("podcast", described_class) }
def generate_podcast_liquid_tag(link)
Liquid::Template.parse("{% podcast #{link} %}")

View file

@ -3,7 +3,7 @@ require "rails_helper"
RSpec.describe TagTag, type: :liquid_template do
let(:tag) { create(:tag) }
setup { Liquid::Template.register_tag("tag", TagTag) }
setup { Liquid::Template.register_tag("tag", described_class) }
def generate_tag_tag(id_code)
Liquid::Template.parse("{% tag #{id_code} %}")

View file

@ -6,7 +6,7 @@ RSpec.describe TweetTag, type: :liquid_template do
let(:name) { "The Practical Dev" }
let(:body) { "When GitHub goes down" }
setup { Liquid::Template.register_tag("tweet", TweetTag) }
setup { Liquid::Template.register_tag("tweet", described_class) }
def generate_tweet_liquid_tag(id)
Liquid::Template.parse("{% tweet #{id} %}")

View file

@ -3,7 +3,7 @@ require "rails_helper"
RSpec.describe UserTag, type: :liquid_template do
let(:user) { create(:user) }
setup { Liquid::Template.register_tag("user", UserTag) }
setup { Liquid::Template.register_tag("user", described_class) }
def generate_user_tag(id_code)
Liquid::Template.parse("{% user #{id_code} %}")

View file

@ -58,9 +58,9 @@ RSpec.describe Article, type: :model do
end
it "does not persist with invalid publish scoped data" do
article = Article.create(title: "hey",
body_html: "hey hey hey hey hey hey",
published: true)
article = described_class.create(title: "hey",
body_html: "hey hey hey hey hey hey",
published: true)
expect(article.persisted?).to eq(false)
end
@ -268,20 +268,20 @@ RSpec.describe Article, type: :model do
create(:article, score: 30)
create(:article, score: 30)
top_article = create(:article, organic_page_views_past_month_count: 20, score: 30)
articles = Article.seo_boostable
articles = described_class.seo_boostable
expect(articles.first[0]).to eq(top_article.path)
end
it "returns articles if within time frame" do
top_article = create(:article, organic_page_views_past_month_count: 20, score: 30)
articles = Article.seo_boostable(nil, 1.month.ago)
articles = described_class.seo_boostable(nil, 1.month.ago)
expect(articles.first[0]).to eq(top_article.path)
end
it "does not return articles outside of timeframe" do
top_article = create(:article, organic_page_views_past_month_count: 20, score: 30)
top_article.update_column(:published_at, 3.months.ago)
articles = Article.seo_boostable(nil, 1.month.ago)
articles = described_class.seo_boostable(nil, 1.month.ago)
expect(articles.first).to eq(nil)
end
@ -290,7 +290,7 @@ RSpec.describe Article, type: :model do
create(:article, organic_page_views_count: 30, score: 30)
top_article = create(:article, organic_page_views_past_month_count: 20, score: 30)
top_article.update_column(:cached_tag_list, "good, greatalicious")
articles = Article.seo_boostable("greatalicious")
articles = described_class.seo_boostable("greatalicious")
expect(articles.first[0]).to eq(top_article.path)
end
@ -299,7 +299,7 @@ RSpec.describe Article, type: :model do
create(:article, organic_page_views_count: 30)
top_article = create(:article, organic_page_views_past_month_count: 20, score: 30)
top_article.update_column(:cached_tag_list, "good, greatalicious")
articles = Article.seo_boostable("godsdsdsdsgoo")
articles = described_class.seo_boostable("godsdsdsdsgoo")
expect(articles.size).to eq(0)
end
end
@ -530,7 +530,7 @@ RSpec.describe Article, type: :model do
describe "published_timestamp" do
it "returns empty string if the article is new" do
expect(Article.new.published_timestamp).to eq("")
expect(described_class.new.published_timestamp).to eq("")
end
it "returns empty string if the article is not published" do
@ -557,7 +557,7 @@ RSpec.describe Article, type: :model do
describe "when algolia auto-indexing/removal is triggered" do
context "when article is saved" do
it "process background auto-indexing" do
expect { build(:article, user_id: user.id).save }.to have_enqueued_job.with(kind_of(Article), "index_or_remove_from_index_where_appropriate").on_queue("algoliasearch")
expect { build(:article, user_id: user.id).save }.to have_enqueued_job.with(kind_of(described_class), "index_or_remove_from_index_where_appropriate").on_queue("algoliasearch")
end
end

View file

@ -2,7 +2,7 @@ require "rails_helper"
RSpec.describe Block, type: :model do
let(:user) { create(:user) }
let(:block) { Block.new(user: user, input_html: "hello") }
let(:block) { described_class.new(user: user, input_html: "hello") }
it "creates processed_html after published!" do
user.add_role(:super_admin)

View file

@ -5,42 +5,42 @@ RSpec.describe BufferUpdate, type: :model do
let(:article) { create(:article, user_id: user.id) }
it "creates update" do
BufferUpdate.buff!(article.id, "twitter_buffer_text", "CODE", "twitter")
expect(BufferUpdate.all.size).to eq(1)
described_class.buff!(article.id, "twitter_buffer_text", "CODE", "twitter")
expect(described_class.all.size).to eq(1)
end
it "does not allow duplicate updates" do
BufferUpdate.buff!(article.id, "twitter_buffer_text", "CODE", "twitter")
BufferUpdate.buff!(article.id, "twitter_buffer_text", "CODE", "twitter")
expect(BufferUpdate.all.size).to eq(1)
described_class.buff!(article.id, "twitter_buffer_text", "CODE", "twitter")
described_class.buff!(article.id, "twitter_buffer_text", "CODE", "twitter")
expect(described_class.all.size).to eq(1)
end
it "does not allow duplicate updates if the first one was a little while ago" do
b1 = BufferUpdate.buff!(article.id, "twitter_buffer_text", "CODE", "twitter")
b1 = described_class.buff!(article.id, "twitter_buffer_text", "CODE", "twitter")
b1.update_column(:created_at, 5.minutes.ago)
BufferUpdate.buff!(article.id, "twitter_buffer_text", "CODE", "twitter")
expect(BufferUpdate.all.size).to eq(2)
BufferUpdate.buff!(article.id, "twitter_buffer_text", "CODE", "twitter")
expect(BufferUpdate.all.size).to eq(2)
BufferUpdate.buff!(article.id, "twitter_buffer_text yoyo", "CODE", "twitter")
expect(BufferUpdate.all.size).to eq(3)
described_class.buff!(article.id, "twitter_buffer_text", "CODE", "twitter")
expect(described_class.all.size).to eq(2)
described_class.buff!(article.id, "twitter_buffer_text", "CODE", "twitter")
expect(described_class.all.size).to eq(2)
described_class.buff!(article.id, "twitter_buffer_text yoyo", "CODE", "twitter")
expect(described_class.all.size).to eq(3)
end
it "allows same text across different social platforms" do
BufferUpdate.buff!(article.id, "twitter_buffer_text", "CODE", "facebook")
BufferUpdate.buff!(article.id, "twitter_buffer_text", "CODE", "twitter")
expect(BufferUpdate.all.size).to eq(2)
described_class.buff!(article.id, "twitter_buffer_text", "CODE", "facebook")
described_class.buff!(article.id, "twitter_buffer_text", "CODE", "twitter")
expect(described_class.all.size).to eq(2)
end
it "allows same text across different tags" do
BufferUpdate.buff!(article.id, "twitter_buffer_text", "CODE", "twitter", 1)
BufferUpdate.buff!(article.id, "twitter_buffer_text", "CODE", "twitter", 2)
expect(BufferUpdate.all.size).to eq(2)
described_class.buff!(article.id, "twitter_buffer_text", "CODE", "twitter", 1)
described_class.buff!(article.id, "twitter_buffer_text", "CODE", "twitter", 2)
expect(described_class.all.size).to eq(2)
end
it "allows same text across different articles with the same tag" do
BufferUpdate.buff!(article.id, "twitter_buffer_text", "CODE", "twitter", 1)
BufferUpdate.buff!(create(:article).id, "twitter_buffer_text", "CODE", "twitter", 1)
expect(BufferUpdate.all.size).to eq(2)
described_class.buff!(article.id, "twitter_buffer_text", "CODE", "twitter", 1)
described_class.buff!(create(:article).id, "twitter_buffer_text", "CODE", "twitter", 1)
expect(described_class.all.size).to eq(2)
end
end

View file

@ -14,19 +14,19 @@ RSpec.describe ChatChannel, type: :model do
end
it "creates channel with users" do
chat_channel = ChatChannel.create_with_users([create(:user), create(:user)])
chat_channel = described_class.create_with_users([create(:user), create(:user)])
expect(chat_channel.users.size).to eq(2)
expect(chat_channel.has_member?(User.first)).to eq(true)
end
it "lists active memberships" do
chat_channel = ChatChannel.create_with_users([create(:user), create(:user)])
chat_channel = described_class.create_with_users([create(:user), create(:user)])
expect(chat_channel.active_users.size).to eq(2)
expect(chat_channel.channel_users.size).to eq(2)
end
it "decreases active users if one leaves" do
chat_channel = ChatChannel.create_with_users([create(:user), create(:user)])
chat_channel = described_class.create_with_users([create(:user), create(:user)])
ChatChannelMembership.last.update(status: "left_channel")
expect(chat_channel.active_users.size).to eq(1)
expect(chat_channel.channel_users.size).to eq(1)

View file

@ -13,7 +13,7 @@ RSpec.describe Comment, type: :model do
end
describe "validations" do
subject { Comment.new(commentable: article) }
subject { described_class.new(commentable: article) }
let(:article) { Article.new }
@ -36,7 +36,7 @@ RSpec.describe Comment, type: :model do
end
it "gets proper generated ID code" do
comment = Comment.new(id: 1)
comment = described_class.new(id: 1)
expect(comment.id_code_generated).to eq(comment.id.to_s(26))
end
@ -273,7 +273,7 @@ RSpec.describe Comment, type: :model do
it "checks auto-indexing" do
expect do
create(:comment, user_id: user2.id, commentable_id: article.id)
end.to have_enqueued_job.with(kind_of(Comment), "index!").on_queue("algoliasearch")
end.to have_enqueued_job.with(kind_of(described_class), "index!").on_queue("algoliasearch")
end
end
@ -282,7 +282,7 @@ RSpec.describe Comment, type: :model do
comment.deleted = true
expect do
comment.save!
end.to have_enqueued_job.with(kind_of(Comment), "remove_algolia_index").on_queue("algoliasearch")
end.to have_enqueued_job.with(kind_of(described_class), "remove_algolia_index").on_queue("algoliasearch")
end
end
end

View file

@ -13,13 +13,13 @@ RSpec.describe Credit, type: :model do
# See https://github.com/magnusvk/counter_culture/issues/259
create_list(:credit, random_number, user: user)
Credit.counter_culture_fix_counts
described_class.counter_culture_fix_counts
expect(user.reload.credits_count).to eq(random_number)
end
it "counts credits for organization" do
create_list(:credit, random_number, organization: organization)
Credit.counter_culture_fix_counts
described_class.counter_culture_fix_counts
expect(organization.reload.credits_count).to eq(random_number)
end

View file

@ -6,7 +6,7 @@ RSpec.describe FeedbackMessage, type: :model do
describe "validations for an abuse report" do
subject(:feedback_message) do
FeedbackMessage.new(
described_class.new(
feedback_type: "abuse-reports",
reported_url: "https://dev.to",
category: "spam",
@ -26,7 +26,7 @@ RSpec.describe FeedbackMessage, type: :model do
describe "validations for a bug report" do
subject(:feedback_message) do
FeedbackMessage.new(
described_class.new(
feedback_type: "bug-reports",
category: "bug",
message: "something",

View file

@ -16,19 +16,19 @@ RSpec.describe Follow, type: :model do
context "when enqueuing jobs" do
it "enqueues touch follower job on creation" do
expect do
Follow.create(follower: user, followable: user_2)
described_class.create(follower: user, followable: user_2)
end.to have_enqueued_job(Follows::TouchFollowerJob)
end
it "enqueues create channel job" do
expect do
Follow.create(follower: user, followable: user_2)
described_class.create(follower: user, followable: user_2)
end.to have_enqueued_job(Follows::CreateChatChannelJob)
end
it "enqueues send notification job" do
expect do
Follow.create(follower: user, followable: user_2)
described_class.create(follower: user, followable: user_2)
end.to have_enqueued_job(Follows::SendEmailNotificationJob)
end
end
@ -38,7 +38,7 @@ RSpec.describe Follow, type: :model do
timestamp = 1.day.ago
user.update_columns(updated_at: timestamp, last_followed_at: timestamp)
perform_enqueued_jobs do
Follow.create!(follower: user, followable: user_2)
described_class.create!(follower: user, followable: user_2)
end
user.reload
expect(user.updated_at).to be > timestamp
@ -48,7 +48,7 @@ RSpec.describe Follow, type: :model do
it "doesn't create a channel when a followable is an org" do
expect do
perform_enqueued_jobs do
Follow.create!(follower: user, followable: create(:organization))
described_class.create!(follower: user, followable: create(:organization))
end
end.not_to change(ChatChannel, :count)
end
@ -56,16 +56,16 @@ RSpec.describe Follow, type: :model do
it "doesn't create a chat channel when users don't follow mutually" do
expect do
perform_enqueued_jobs do
Follow.create!(follower: user, followable: user_2)
described_class.create!(follower: user, followable: user_2)
end
end.not_to change(ChatChannel, :count)
end
it "creates a chat channel when users follow mutually" do
Follow.create!(follower: user_2, followable: user)
described_class.create!(follower: user_2, followable: user)
expect do
perform_enqueued_jobs do
Follow.create!(follower: user, followable: user_2)
described_class.create!(follower: user, followable: user_2)
end
end.to change(ChatChannel, :count).by(1)
end
@ -74,7 +74,7 @@ RSpec.describe Follow, type: :model do
user_2.update_column(:email_follower_notifications, true)
expect do
perform_enqueued_jobs do
Follow.create!(follower: user, followable: user_2)
described_class.create!(follower: user, followable: user_2)
end
end.to change(EmailMessage, :count).by(1)
end

View file

@ -51,7 +51,7 @@ RSpec.describe GithubRepo, type: :model do
old_updated_at = repo.updated_at
Timecop.freeze(3.days.from_now) do
described_class.update_to_latest
expect(old_updated_at).not_to eq(GithubRepo.find(repo.id).updated_at)
expect(old_updated_at).not_to eq(described_class.find(repo.id).updated_at)
end
end
end

View file

@ -19,21 +19,21 @@ RSpec.describe HtmlVariant, type: :model do
it "finds for test without tag" do
html_variant.save!
expect(HtmlVariant.find_for_test.id).to eq(html_variant.id)
expect(described_class.find_for_test.id).to eq(html_variant.id)
end
it "finds for test with tag given" do
html_variant.target_tag = "hello"
html_variant.save!
expect(HtmlVariant.find_for_test(["hello"]).id).to eq(html_variant.id)
expect(described_class.find_for_test(["hello"]).id).to eq(html_variant.id)
end
it "does not find if different tag targeted" do
html_variant.target_tag = "different_tag_yolo"
html_variant.save!
expect(HtmlVariant.find_for_test(["hello"])).to eq(nil)
expect(described_class.find_for_test(["hello"])).to eq(nil)
end
it "finds if no tag targeted and tag given" do
html_variant.save!
expect(HtmlVariant.find_for_test(["hello"]).id).to eq(html_variant.id)
expect(described_class.find_for_test(["hello"]).id).to eq(html_variant.id)
end
it "creates an html variant with img in it" do
html_variant = create(:html_variant, approved: false, published: true)

View file

@ -11,10 +11,10 @@ RSpec.describe Identity, type: :model do
describe ".find_for_oauth" do
it "works" do
allow(Identity).to receive(:find_or_create_by)
allow(described_class).to receive(:find_or_create_by)
auth = { uid: 0, provider: "github" }
described_class.find_for_oauth(instance_double("request", auth))
expect(Identity).to have_received(:find_or_create_by).with(auth)
expect(described_class).to have_received(:find_or_create_by).with(auth)
end
end
end

View file

@ -2,7 +2,7 @@ require "rails_helper"
RSpec.describe JobOpportunity, type: :model do
it "returns remoteness in words for remoteness" do
jo = JobOpportunity.new
jo = described_class.new
jo.remoteness = "on_premise"
expect(jo.remoteness_in_words).to eq("In Office")
end

View file

@ -16,6 +16,6 @@ RSpec.describe Mention, type: :model do
end
it "doesn't raise undefined method for NilClass on valid?" do
expect(Mention.new.valid?).to eq(false)
expect(described_class.new.valid?).to eq(false)
end
end

View file

@ -17,24 +17,24 @@ RSpec.describe Notification, type: :model do
create(:notification, user: user, notifiable: article, action: "Reaction")
duplicate_notification = build(:notification, user: user, notifiable: article, action: "Reaction")
expect do
Notification.import([duplicate_notification],
on_duplicate_key_update: {
conflict_target: %i[notifiable_id notifiable_type user_id action],
index_predicate: "action IS NOT NULL",
columns: %i[json_data notified_at read]
})
end.not_to change(Notification, :count)
described_class.import([duplicate_notification],
on_duplicate_key_update: {
conflict_target: %i[notifiable_id notifiable_type user_id action],
index_predicate: "action IS NOT NULL",
columns: %i[json_data notified_at read]
})
end.not_to change(described_class, :count)
end
it "updates when trying to create a duplicate notification via import" do
notification = create(:notification, user: user, notifiable: article, action: "Reaction", json_data: { "user_id" => 1 })
duplicate_notification = build(:notification, user: user, notifiable: article, action: "Reaction", json_data: { "user_id" => 2 })
Notification.import([duplicate_notification],
on_duplicate_key_update: {
conflict_target: %i[notifiable_id notifiable_type user_id action],
index_predicate: "action IS NOT NULL",
columns: %i[json_data notified_at read]
})
described_class.import([duplicate_notification],
on_duplicate_key_update: {
conflict_target: %i[notifiable_id notifiable_type user_id action],
index_predicate: "action IS NOT NULL",
columns: %i[json_data notified_at read]
})
notification.reload
expect(notification.json_data["user_id"]).to eq(2)
end
@ -43,13 +43,13 @@ RSpec.describe Notification, type: :model do
create(:notification, organization: organization, notifiable: article, action: "Reaction")
duplicate_notification = build(:notification, organization: organization, notifiable: article, action: "Reaction")
expect do
Notification.import([duplicate_notification],
on_duplicate_key_update: {
conflict_target: %i[notifiable_id notifiable_type organization_id action],
index_predicate: "action IS NOT NULL",
columns: %i[json_data notified_at read]
})
end.not_to change(Notification, :count)
described_class.import([duplicate_notification],
on_duplicate_key_update: {
conflict_target: %i[notifiable_id notifiable_type organization_id action],
index_predicate: "action IS NOT NULL",
columns: %i[json_data notified_at read]
})
end.not_to change(described_class, :count)
end
describe "when notifiable is a Comment" do
@ -61,13 +61,13 @@ RSpec.describe Notification, type: :model do
create(:notification, notification_attributes)
duplicate_notification = build(:notification, notification_attributes)
expect do
Notification.import([duplicate_notification],
on_duplicate_key_update: {
conflict_target: %i[notifiable_id notifiable_type user_id],
index_predicate: "action IS NULL",
columns: %i[json_data notified_at read]
})
end.not_to change(Notification, :count)
described_class.import([duplicate_notification],
on_duplicate_key_update: {
conflict_target: %i[notifiable_id notifiable_type user_id],
index_predicate: "action IS NULL",
columns: %i[json_data notified_at read]
})
end.not_to change(described_class, :count)
end
it "doesn't allow to create a duplicate org notification via import when action is nil" do
@ -75,13 +75,13 @@ RSpec.describe Notification, type: :model do
create(:notification, notification_attributes)
duplicate_notification = build(:notification, notification_attributes)
expect do
Notification.import([duplicate_notification],
on_duplicate_key_update: {
conflict_target: %i[notifiable_id notifiable_type organization_id],
index_predicate: "action IS NULL",
columns: %i[json_data notified_at read]
})
end.not_to change(Notification, :count)
described_class.import([duplicate_notification],
on_duplicate_key_update: {
conflict_target: %i[notifiable_id notifiable_type organization_id],
index_predicate: "action IS NULL",
columns: %i[json_data notified_at read]
})
end.not_to change(described_class, :count)
end
# rubocop:enable RSpec/ExampleLength
end
@ -93,15 +93,15 @@ RSpec.describe Notification, type: :model do
it "runs fine" do
run_background_jobs_immediately do
Notification.send_new_follower_notification(tag_follow)
described_class.send_new_follower_notification(tag_follow)
end
end
it "doesn't create a notification" do
run_background_jobs_immediately do
expect do
Notification.send_new_follower_notification(tag_follow)
end.not_to change(Notification, :count)
described_class.send_new_follower_notification(tag_follow)
end.not_to change(described_class, :count)
end
end
end
@ -109,21 +109,21 @@ RSpec.describe Notification, type: :model do
describe "#send_new_follower_notification" do
before do
perform_enqueued_jobs do
Notification.send_new_follower_notification(follow_instance)
described_class.send_new_follower_notification(follow_instance)
end
end
it "sets the notifiable_at column upon creation" do
expect(Notification.last.notified_at).not_to eq nil
expect(described_class.last.notified_at).not_to eq nil
end
context "when a user follows another user" do
it "creates a notification belonging to the person being followed" do
expect(Notification.first.user_id).to eq user2.id
expect(described_class.first.user_id).to eq user2.id
end
it "creates a notification from the follow instance" do
notifiable_data = { notifiable_id: Notification.first.notifiable_id, notifiable_type: Notification.first.notifiable_type }
notifiable_data = { notifiable_id: described_class.first.notifiable_id, notifiable_type: described_class.first.notifiable_type }
follow_data = { notifiable_id: follow_instance.id, notifiable_type: follow_instance.class.name }
expect(notifiable_data).to eq follow_data
end
@ -133,15 +133,15 @@ RSpec.describe Notification, type: :model do
let(:follow_instance) { user.follow(organization) }
it "creates a notification belonging to the organization" do
expect(Notification.first.organization_id).to eq organization.id
expect(described_class.first.organization_id).to eq organization.id
end
it "does not create a notification belonging to a user" do
expect(Notification.first.user_id).to eq nil
expect(described_class.first.user_id).to eq nil
end
it "creates a notification from the follow instance" do
notifiable_data = { notifiable_id: Notification.first.notifiable_id, notifiable_type: Notification.first.notifiable_type }
notifiable_data = { notifiable_id: described_class.first.notifiable_id, notifiable_type: described_class.first.notifiable_type }
follow_data = { notifiable_id: follow_instance.id, notifiable_type: follow_instance.class.name }
expect(notifiable_data).to eq follow_data
end
@ -151,9 +151,9 @@ RSpec.describe Notification, type: :model do
it "destroys the follow notification" do
follow_instance = user.stop_following(user2)
perform_enqueued_jobs do
Notification.send_new_follower_notification(follow_instance)
described_class.send_new_follower_notification(follow_instance)
end
expect(Notification.count).to eq 0
expect(described_class.count).to eq 0
end
end
end
@ -162,26 +162,26 @@ RSpec.describe Notification, type: :model do
context "when all commenters are subscribed" do
it "sends a notification to the author of the article" do
comment = create(:comment, user: user2, commentable: article)
Notification.send_new_comment_notifications_without_delay(comment)
described_class.send_new_comment_notifications_without_delay(comment)
expect(user.notifications.count).to eq 1
end
it "does not send a notification to the author of the article if the commenter is the author" do
comment = create(:comment, user: user, commentable: article)
Notification.send_new_comment_notifications_without_delay(comment)
described_class.send_new_comment_notifications_without_delay(comment)
expect(user.notifications.count).to eq 0
end
it "does not send a notification to the author of the comment" do
comment = create(:comment, user: user2, commentable: article)
Notification.send_new_comment_notifications_without_delay(comment)
described_class.send_new_comment_notifications_without_delay(comment)
expect(user2.notifications.count).to eq 0
end
it "sends a notification to the author of the article about the child comment" do
parent_comment = create(:comment, user: user2, commentable: article)
child_comment = create(:comment, user: user3, commentable: article, ancestry: parent_comment.id.to_s)
Notification.send_new_comment_notifications_without_delay(child_comment)
described_class.send_new_comment_notifications_without_delay(child_comment)
expect(user.notifications.count).to eq(1)
end
@ -190,7 +190,7 @@ RSpec.describe Notification, type: :model do
create(:organization_membership, user: user, organization: org)
article.update(organization: org)
comment = create(:comment, user: user2, commentable: article)
Notification.send_new_comment_notifications_without_delay(comment)
described_class.send_new_comment_notifications_without_delay(comment)
expect(org.notifications.count).to eq 1
end
end
@ -204,13 +204,13 @@ RSpec.describe Notification, type: :model do
end
it "does not send a notification to the author of the article" do
Notification.send_new_comment_notifications_without_delay(comment)
described_class.send_new_comment_notifications_without_delay(comment)
expect(user.notifications.count).to eq 0
end
it "doesn't send a notification to the author of the article about the child comment" do
child_comment = create(:comment, user: user3, commentable: article, ancestry: comment.id.to_s)
Notification.send_new_comment_notifications_without_delay(child_comment)
described_class.send_new_comment_notifications_without_delay(child_comment)
expect(user.notifications.count).to eq 0
end
end
@ -224,12 +224,12 @@ RSpec.describe Notification, type: :model do
end
it "does not send a notification to the author of the comment" do
Notification.send_new_comment_notifications_without_delay(child_comment)
described_class.send_new_comment_notifications_without_delay(child_comment)
expect(user2.notifications.count).to eq 0
end
it "sends a notification to the author of the article" do
Notification.send_new_comment_notifications_without_delay(child_comment)
described_class.send_new_comment_notifications_without_delay(child_comment)
expect(user.notifications.count).to eq(1)
end
end
@ -241,7 +241,7 @@ RSpec.describe Notification, type: :model do
comment = create(:comment, user: user2, commentable: article)
reaction = create(:reaction, reactable: comment, user: user)
perform_enqueued_jobs do
Notification.send_reaction_notification(reaction, reaction.reactable.user)
described_class.send_reaction_notification(reaction, reaction.reactable.user)
expect(user2.notifications.count).to eq 1
end
end
@ -249,7 +249,7 @@ RSpec.describe Notification, type: :model do
it "sends a notification to the author of an article" do
reaction = create(:reaction, reactable: article, user: user2)
perform_enqueued_jobs do
Notification.send_reaction_notification(reaction, reaction.reactable.user)
described_class.send_reaction_notification(reaction, reaction.reactable.user)
expect(user.notifications.count).to eq 1
end
end
@ -262,15 +262,15 @@ RSpec.describe Notification, type: :model do
it "destroys the notification if it exists" do
reaction = create(:reaction, reactable: comment, user: user)
reaction.destroy
Notification.send_reaction_notification_without_delay(reaction, article.user)
expect(Notification.where(id: notification.id)).not_to be_any
described_class.send_reaction_notification_without_delay(reaction, article.user)
expect(described_class.where(id: notification.id)).not_to be_any
end
it "keeps the notification if siblings exist" do
reaction = create(:reaction, reactable: comment, user: user)
create(:reaction, reactable: comment, user: user3)
reaction.destroy
Notification.send_reaction_notification_without_delay(reaction, article.user)
described_class.send_reaction_notification_without_delay(reaction, article.user)
notification.reload
expect(notification).to be_persisted
end
@ -279,7 +279,7 @@ RSpec.describe Notification, type: :model do
reaction = create(:reaction, reactable: comment, user: user)
create(:reaction, reactable: comment, user: user3)
reaction.destroy
Notification.send_reaction_notification_without_delay(reaction, article.user)
described_class.send_reaction_notification_without_delay(reaction, article.user)
notification.reload
expect(notification.json_data["reaction"]["aggregated_siblings"].map { |s| s["user"]["id"] }).to eq([user3.id])
# not the user of the destroyed reaction!
@ -292,14 +292,14 @@ RSpec.describe Notification, type: :model do
comment = create(:comment, user: user2, commentable: article)
comment.update(receive_notifications: false)
reaction = create(:reaction, reactable: comment, user: user)
Notification.send_reaction_notification_without_delay(reaction, reaction.reactable.user)
described_class.send_reaction_notification_without_delay(reaction, reaction.reactable.user)
expect(user2.notifications.count).to eq 0
end
it "does not send a notification to the author of an article" do
article.update(receive_notifications: false)
reaction = create(:reaction, reactable: article, user: user2)
Notification.send_reaction_notification_without_delay(reaction, reaction.reactable.user)
described_class.send_reaction_notification_without_delay(reaction, reaction.reactable.user)
expect(user.notifications.count).to eq 0
end
end
@ -314,7 +314,7 @@ RSpec.describe Notification, type: :model do
it "creates a notification with the organization's ID" do
reaction = create(:reaction, reactable: article, user: user2)
Notification.send_reaction_notification_without_delay(reaction, reaction.reactable.organization)
described_class.send_reaction_notification_without_delay(reaction, reaction.reactable.organization)
expect(org.notifications.count).to eq 1
end
end
@ -326,8 +326,8 @@ RSpec.describe Notification, type: :model do
)
perform_enqueued_jobs do
expect do
Notification.send_reaction_notification(reaction, reaction.reactable.user)
end.to change(Notification, :count).by(1)
described_class.send_reaction_notification(reaction, reaction.reactable.user)
end.to change(described_class, :count).by(1)
end
end
@ -339,18 +339,18 @@ RSpec.describe Notification, type: :model do
)
perform_enqueued_jobs do
expect do
Notification.send_reaction_notification(reaction, reaction.reactable.user)
end.not_to change(Notification, :count)
described_class.send_reaction_notification(reaction, reaction.reactable.user)
end.not_to change(described_class, :count)
end
end
it "destroys the notification properly" do
reaction = create(:reaction, user: user2, reactable: article, category: "like")
perform_enqueued_jobs do
Notification.send_reaction_notification(reaction, reaction.reactable.user)
described_class.send_reaction_notification(reaction, reaction.reactable.user)
reaction.destroy!
Notification.send_reaction_notification(reaction, reaction.reactable.user)
expect(Notification.count).to eq 0
described_class.send_reaction_notification(reaction, reaction.reactable.user)
expect(described_class.count).to eq 0
end
end
end
@ -359,11 +359,11 @@ RSpec.describe Notification, type: :model do
context "when the notifiable is an article from a user" do
before do
user2.follow(user)
perform_enqueued_jobs { Notification.send_to_followers(article, "Published") }
perform_enqueued_jobs { described_class.send_to_followers(article, "Published") }
end
it "sends a notification to the author's followers" do
expect(Notification.first.user_id).to eq user2.id
expect(described_class.first.user_id).to eq user2.id
end
end
@ -373,7 +373,7 @@ RSpec.describe Notification, type: :model do
before do
user2.follow(user)
user3.follow(organization)
perform_enqueued_jobs { Notification.send_to_followers(article, "Published") }
perform_enqueued_jobs { described_class.send_to_followers(article, "Published") }
end
it "sends a notification to author's followers" do
@ -390,7 +390,7 @@ RSpec.describe Notification, type: :model do
context "when there are article notifications to update" do
before do
user2.follow(user)
Notification.send_to_followers_without_delay(article, "Published")
described_class.send_to_followers_without_delay(article, "Published")
end
it "updates the notification with the new article title" do
@ -398,8 +398,8 @@ RSpec.describe Notification, type: :model do
article.update_column(:title, new_title)
article.reload
perform_enqueued_jobs do
Notification.update_notifications(article, "Published")
first_notification_article_title = Notification.first.json_data["article"]["title"]
described_class.update_notifications(article, "Published")
first_notification_article_title = described_class.first.json_data["article"]["title"]
expect(first_notification_article_title).to eq new_title
end
end
@ -408,8 +408,8 @@ RSpec.describe Notification, type: :model do
article.update_column(:organization_id, organization.id)
article.reload
perform_enqueued_jobs do
Notification.update_notifications(article.reload, "Published")
first_notification_organization_id = Notification.first.json_data["organization"]["id"]
described_class.update_notifications(article.reload, "Published")
first_notification_organization_id = described_class.first.json_data["organization"]["id"]
expect(first_notification_organization_id).to eq organization.id
end
end
@ -436,7 +436,7 @@ RSpec.describe Notification, type: :model do
describe "#send_new_badge_achievement_notification" do
it "enqueues a new badge achievement job" do
assert_enqueued_with(job: Notifications::NewBadgeAchievementJob, args: [badge_achievement.id]) do
Notification.send_new_badge_achievement_notification(badge_achievement)
described_class.send_new_badge_achievement_notification(badge_achievement)
end
end
end
@ -444,7 +444,7 @@ RSpec.describe Notification, type: :model do
describe "#send_new_badge_notification (deprecated)" do
it "enqueues a new badge achievement job" do
assert_enqueued_with(job: Notifications::NewBadgeAchievementJob, args: [badge_achievement.id]) do
Notification.send_new_badge_notification(badge_achievement)
described_class.send_new_badge_notification(badge_achievement)
end
end
end
@ -452,8 +452,8 @@ RSpec.describe Notification, type: :model do
describe "#send_new_badge_notification_without_delay (deprecated)" do
it "creates a notification" do
expect do
Notification.send_new_badge_notification_without_delay(badge_achievement)
end.to change(Notification, :count).by(1)
described_class.send_new_badge_notification_without_delay(badge_achievement)
end.to change(described_class, :count).by(1)
end
end
@ -469,8 +469,8 @@ RSpec.describe Notification, type: :model do
it "removes each mention related notifiable" do
perform_enqueued_jobs do
expect do
Notification.remove_each(notifiable_collection)
end.to change(Notification, :count).by(-1)
described_class.remove_each(notifiable_collection)
end.to change(described_class, :count).by(-1)
end
end
end

View file

@ -78,7 +78,7 @@ RSpec.describe Podcast, type: :model do
end
it "is reachable when the feed is unreachable but the podcast has reachable podcasts" do
reachable_ids = Podcast.reachable.pluck(:id)
reachable_ids = described_class.reachable.pluck(:id)
expect(reachable_ids).to include(podcast.id)
expect(reachable_ids).to include(cool_podcast.id)
expect(reachable_ids).not_to include(unpodcast.id)

View file

@ -5,11 +5,11 @@ RSpec.describe PollOption, type: :model do
let(:poll) { create(:poll, article_id: article.id) }
it "allows up to 128 markdown characters" do
poll_option = PollOption.create(markdown: "0" * 30, poll_id: poll.id)
poll_option = described_class.create(markdown: "0" * 30, poll_id: poll.id)
expect(poll_option).to be_valid
end
it "disallows over 128 markdown characters" do
poll_option = PollOption.create(markdown: "0" * 200, poll_id: poll.id)
poll_option = described_class.create(markdown: "0" * 200, poll_id: poll.id)
expect(poll_option).not_to be_valid
end
end

View file

@ -6,30 +6,30 @@ RSpec.describe PollSkip, type: :model do
let(:poll) { create(:poll, article_id: article.id) }
it "is unique across poll and user" do
PollSkip.create(user_id: user.id, poll_id: poll.id)
PollSkip.create(user_id: user.id, poll_id: poll.id)
PollSkip.create(user_id: user.id, poll_id: poll.id)
expect(PollSkip.all.size).to eq(1)
described_class.create(user_id: user.id, poll_id: poll.id)
described_class.create(user_id: user.id, poll_id: poll.id)
described_class.create(user_id: user.id, poll_id: poll.id)
expect(described_class.all.size).to eq(1)
second_poll = create(:poll, article_id: article.id)
PollSkip.create(user_id: user.id, poll_id: second_poll.id)
expect(PollSkip.all.size).to eq(2)
described_class.create(user_id: user.id, poll_id: second_poll.id)
expect(described_class.all.size).to eq(2)
end
it "is unique across user and poll votes for the poll" do
PollVote.create(user_id: user.id, poll_id: poll.id, poll_option_id: poll.poll_options.last.id)
PollSkip.create(user_id: user.id, poll_id: poll.id)
PollSkip.create(user_id: user.id, poll_id: poll.id)
expect(PollSkip.all.size).to eq(0)
described_class.create(user_id: user.id, poll_id: poll.id)
described_class.create(user_id: user.id, poll_id: poll.id)
expect(described_class.all.size).to eq(0)
second_poll = create(:poll, article_id: article.id)
PollSkip.create(user_id: user.id, poll_id: second_poll.id)
expect(PollSkip.all.size).to eq(1)
described_class.create(user_id: user.id, poll_id: second_poll.id)
expect(described_class.all.size).to eq(1)
end
it "is prevents a poll vote from being cast" do
PollSkip.create(user_id: user.id, poll_id: poll.id)
PollSkip.create(user_id: user.id, poll_id: poll.id)
described_class.create(user_id: user.id, poll_id: poll.id)
described_class.create(user_id: user.id, poll_id: poll.id)
PollVote.create(user_id: user.id, poll_id: poll.id, poll_option_id: poll.poll_options.last.id)
expect(PollSkip.all.size).to eq(1)
expect(described_class.all.size).to eq(1)
expect(PollVote.all.size).to eq(0)
end
end

View file

@ -6,13 +6,13 @@ RSpec.describe PollVote, type: :model do
let(:poll) { create(:poll, article_id: article.id) }
it "is not valid as a new object" do
expect(PollVote.new.valid?).to be(false)
expect(described_class.new.valid?).to be(false)
end
it "limits one vote per user per poll" do
create(:poll_vote, poll_option_id: poll.poll_options.last.id, user_id: user.id, poll_id: poll.id)
PollVote.create(poll_option_id: poll.poll_options.first.id, user_id: user.id, poll_id: poll.id)
PollVote.create(poll_option_id: poll.poll_options.last.id, user_id: user.id, poll_id: poll.id)
described_class.create(poll_option_id: poll.poll_options.first.id, user_id: user.id, poll_id: poll.id)
described_class.create(poll_option_id: poll.poll_options.last.id, user_id: user.id, poll_id: poll.id)
expect(user.poll_votes.size).to eq(1)
end
@ -39,7 +39,7 @@ RSpec.describe PollVote, type: :model do
it "disallows a vote after skipping" do
PollSkip.create(poll_id: poll.id, user_id: user.id)
PollVote.create(poll_option_id: poll.poll_options.last.id, user_id: user.id, poll_id: poll.id)
described_class.create(poll_option_id: poll.poll_options.last.id, user_id: user.id, poll_id: poll.id)
expect(user.poll_votes.size).to eq(0)
end

View file

@ -3,9 +3,9 @@ require "rails_helper"
RSpec.describe PushNotificationSubscription, type: :model do
describe "validation" do
subject do
PushNotificationSubscription.create(user: create(:user),
auth_key: "asdf123",
endpoint: "asdf123")
described_class.create(user: create(:user),
auth_key: "asdf123",
endpoint: "asdf123")
end
it { is_expected.to validate_presence_of(:endpoint) }

View file

@ -7,7 +7,7 @@ RSpec.describe Reaction, type: :model do
let(:reaction) { build(:reaction, reactable: comment) }
describe "actual validation" do
subject { Reaction.new(reactable: article, reactable_type: "Article", user: user) }
subject { described_class.new(reactable: article, reactable_type: "Article", user: user) }
before { user.add_role(:trusted) }

View file

@ -40,7 +40,7 @@ RSpec.describe Tag, type: :model do
end
it "knows class valid categories" do
expect(Tag.valid_categories).to include("tool")
expect(described_class.valid_categories).to include("tool")
end
it "triggers cache busting on save" do

View file

@ -9,12 +9,12 @@ RSpec.describe Tweet, type: :model, vcr: vcr_option do
let(:tweet_id) { "1018911886862057472" }
it "fetches a tweet" do
tweet = Tweet.fetch(tweet_id)
tweet = described_class.fetch(tweet_id)
expect(tweet.class).to eq(described_class)
end
it "renders processed text" do
tweet = Tweet.fetch(tweet_id)
tweet = described_class.fetch(tweet_id)
expect(tweet.processed_text).not_to be_nil
end
end

View file

@ -83,7 +83,7 @@ RSpec.describe "Api::V0::Articles", type: :request do
get "/api/articles/#{article.id}"
expect(json_response["title"]).to eq(article.title)
end
it "contains article markdown content" do
get "/api/articles/#{article.id}"
expect(json_response["body_markdown"]).to eq(article.body_markdown)