Enable random order for specs (#2466) [ci skip]
This commit is contained in:
parent
3d12535272
commit
7d3fb0c0b5
18 changed files with 138 additions and 105 deletions
|
|
@ -52,6 +52,8 @@ Rails.application.configure do
|
|||
# Raises error for missing translations
|
||||
# config.action_view.raise_on_missing_translations = true
|
||||
|
||||
config.active_job.queue_adapter = :test
|
||||
|
||||
# Install the Timber.io logger, but do not send logs.
|
||||
logger = Timber::Logger.new(nil)
|
||||
logger.level = config.log_level
|
||||
|
|
|
|||
|
|
@ -10,6 +10,12 @@ RSpec.describe Follows::CreateChatChannelJob, type: :job do
|
|||
|
||||
it "creates a chat channel when mutual followers" do
|
||||
follow2 = create(:follow, follower: user2, followable: user)
|
||||
|
||||
# Follow has an after_create callback that creates a channel between the two users,
|
||||
# so to make sure this test is correct, we delete all channels right after
|
||||
ChatChannelMembership.delete_all
|
||||
ChatChannel.delete_all
|
||||
|
||||
expect do
|
||||
described_class.perform_now(follow2.id)
|
||||
end.to change(ChatChannel, :count).by(1)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
RSpec.shared_examples "#enqueues_job" do |queue_name, args|
|
||||
describe "#perform_later" do
|
||||
it "enqueues the job" do
|
||||
ActiveJob::Base.queue_adapter = :test
|
||||
expect do
|
||||
described_class.perform_later(*args)
|
||||
end.to have_enqueued_job.with(*args).on_queue(queue_name)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ require "rails_helper"
|
|||
RSpec.describe Users::TouchJob, type: :job do
|
||||
describe "#perform_later" do
|
||||
it "enqueues the job" do
|
||||
ActiveJob::Base.queue_adapter = :test
|
||||
expect do
|
||||
described_class.perform_later(3)
|
||||
end.to have_enqueued_job.with(3).on_queue("touch_user")
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Article, type: :model do
|
||||
before { ActiveJob::Base.queue_adapter = :test }
|
||||
|
||||
context "when no organization" do
|
||||
let(:article) { create(:article) }
|
||||
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ RSpec.describe Article, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe "queries" do
|
||||
describe ".seo_boostable" do
|
||||
it "returns articles ordered by organic_page_views_count" do
|
||||
create(:article, score: 30)
|
||||
create(:article, score: 30)
|
||||
|
|
@ -245,17 +245,20 @@ RSpec.describe Article, type: :model do
|
|||
articles = Article.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)
|
||||
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)
|
||||
expect(articles.first).to eq(nil)
|
||||
end
|
||||
|
||||
it "returns articles ordered by organic_page_views_count by tag" do
|
||||
create(:article, score: 30)
|
||||
create(:article, organic_page_views_count: 30, score: 30)
|
||||
|
|
@ -264,6 +267,7 @@ RSpec.describe Article, type: :model do
|
|||
articles = Article.seo_boostable("greatalicious")
|
||||
expect(articles.first[0]).to eq(top_article.path)
|
||||
end
|
||||
|
||||
it "returns nothing if no tagged articles" do
|
||||
create(:article, score: 30)
|
||||
create(:article, organic_page_views_count: 30)
|
||||
|
|
@ -401,20 +405,21 @@ RSpec.describe Article, type: :model do
|
|||
|
||||
describe "#async_score_calc" do
|
||||
context "when published" do
|
||||
before { ActiveJob::Base.queue_adapter = :inline }
|
||||
|
||||
let(:article) { build(:article) }
|
||||
|
||||
it "updates the hotness score" do
|
||||
article.save
|
||||
article.reload
|
||||
expect(article.hotness_score > 0).to eq(true)
|
||||
perform_enqueued_jobs do
|
||||
article.save
|
||||
expect(article.reload.hotness_score.positive?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
it "updates the spaminess score" do
|
||||
article.spaminess_rating = -1
|
||||
article.save
|
||||
expect(article.spaminess_rating).to eq(0)
|
||||
it "updates the spaminess rating" do
|
||||
perform_enqueued_jobs do
|
||||
article.spaminess_rating = -1
|
||||
article.save
|
||||
expect(article.reload.spaminess_rating).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -422,14 +427,18 @@ RSpec.describe Article, type: :model do
|
|||
let(:article) { create(:article, published: false) }
|
||||
|
||||
it "does not update the hotness score" do
|
||||
article.save
|
||||
expect(article.hotness_score).to eq(0)
|
||||
perform_enqueued_jobs do
|
||||
article.save
|
||||
expect(article.reload.hotness_score).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
it "does not update the spaminess score" do
|
||||
article.update_column(:spaminess_rating, -1)
|
||||
article.save
|
||||
expect(article.spaminess_rating).to eq(-1)
|
||||
it "does not update the spaminess rating" do
|
||||
perform_enqueued_jobs do
|
||||
article.spaminess_rating = -1
|
||||
article.save
|
||||
expect(article.reload.spaminess_rating).to eq(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ RSpec.describe Follow, type: :model do
|
|||
end
|
||||
|
||||
context "when enqueuing jobs" do
|
||||
before { ActiveJob::Base.queue_adapter = :test }
|
||||
|
||||
it "enqueues touch follower job on creation" do
|
||||
expect do
|
||||
Follow.create(follower: user, followable: user_2)
|
||||
|
|
@ -32,12 +30,12 @@ RSpec.describe Follow, type: :model do
|
|||
end
|
||||
|
||||
context "when creating and inline" do
|
||||
before { ActiveJob::Base.queue_adapter = :inline }
|
||||
|
||||
it "touches the follower user while creating" do
|
||||
timestamp = 1.day.ago
|
||||
user.update_columns(updated_at: timestamp, last_followed_at: timestamp)
|
||||
Follow.create!(follower: user, followable: user_2)
|
||||
perform_enqueued_jobs do
|
||||
Follow.create!(follower: user, followable: user_2)
|
||||
end
|
||||
user.reload
|
||||
expect(user.updated_at).to be > timestamp
|
||||
expect(user.last_followed_at).to be > timestamp
|
||||
|
|
@ -45,27 +43,33 @@ RSpec.describe Follow, type: :model do
|
|||
|
||||
it "doesn't create a channel when a followable is an org" do
|
||||
expect do
|
||||
Follow.create!(follower: user, followable: create(:organization))
|
||||
perform_enqueued_jobs do
|
||||
Follow.create!(follower: user, followable: create(:organization))
|
||||
end
|
||||
end.not_to change(ChatChannel, :count)
|
||||
end
|
||||
|
||||
it "doesn't create a chat channel when users don't follow mutually" do
|
||||
expect do
|
||||
Follow.create!(follower: user, followable: user_2)
|
||||
perform_enqueued_jobs do
|
||||
Follow.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)
|
||||
expect do
|
||||
Follow.create!(follower: user, followable: user_2)
|
||||
perform_enqueued_jobs do
|
||||
Follow.create!(follower: user, followable: user_2)
|
||||
end
|
||||
end.to change(ChatChannel, :count).by(1)
|
||||
end
|
||||
|
||||
it "sends an email notification" do
|
||||
user_2.update_column(:email_follower_notifications, true)
|
||||
expect do
|
||||
run_background_jobs_immediately do
|
||||
perform_enqueued_jobs do
|
||||
Follow.create!(follower: user, followable: user_2)
|
||||
end
|
||||
end.to change(EmailMessage, :count).by(1)
|
||||
|
|
|
|||
|
|
@ -29,8 +29,9 @@ RSpec.describe Notification, type: :model do
|
|||
|
||||
describe "#send_new_follower_notification" do
|
||||
before do
|
||||
ActiveJob::Base.queue_adapter = :inline
|
||||
Notification.send_new_follower_notification(follow_instance)
|
||||
perform_enqueued_jobs do
|
||||
Notification.send_new_follower_notification(follow_instance)
|
||||
end
|
||||
end
|
||||
|
||||
it "sets the notifiable_at column upon creation" do
|
||||
|
|
@ -70,8 +71,9 @@ RSpec.describe Notification, type: :model do
|
|||
context "when a user unfollows another user" do
|
||||
it "destroys the follow notification" do
|
||||
follow_instance = user.stop_following(user2)
|
||||
ActiveJob::Base.queue_adapter = :inline
|
||||
Notification.send_new_follower_notification(follow_instance)
|
||||
perform_enqueued_jobs do
|
||||
Notification.send_new_follower_notification(follow_instance)
|
||||
end
|
||||
expect(Notification.count).to eq 0
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,11 +3,8 @@ require "rails_helper"
|
|||
RSpec.describe Reaction, type: :model do
|
||||
let(:article) { create(:article, featured: true) }
|
||||
let(:user) { create(:user) }
|
||||
# let!(:reaction) { build(:reaction, reactable: article) }
|
||||
|
||||
context "when creating and enqueueing" do
|
||||
before { ActiveJob::Base.queue_adapter = :test }
|
||||
|
||||
it "enqueues the Users::TouchJob" do
|
||||
expect do
|
||||
create(:reaction, reactable: article, user: user)
|
||||
|
|
@ -33,21 +30,23 @@ RSpec.describe Reaction, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
context "when creating and inline" do
|
||||
before { ActiveJob::Base.queue_adapter = :inline }
|
||||
|
||||
context "when creating and performing jobs" do
|
||||
it "updates the reactable Comment" do
|
||||
updated_at = 1.day.ago
|
||||
comment = create(:comment, commentable: article, updated_at: updated_at)
|
||||
create(:reaction, reactable: comment, user: user)
|
||||
expect(comment.reload.updated_at).to be > updated_at
|
||||
perform_enqueued_jobs do
|
||||
updated_at = 1.day.ago
|
||||
comment = create(:comment, commentable: article, updated_at: updated_at)
|
||||
create(:reaction, reactable: comment, user: user)
|
||||
expect(comment.reload.updated_at).to be > updated_at
|
||||
end
|
||||
end
|
||||
|
||||
it "touches the user" do
|
||||
updated_at = 1.day.ago
|
||||
user.update_columns(updated_at: updated_at)
|
||||
create(:reaction, reactable: article, user: user)
|
||||
expect(user.reload.updated_at).to be > updated_at
|
||||
perform_enqueued_jobs do
|
||||
updated_at = 1.day.ago
|
||||
user.update_columns(updated_at: updated_at)
|
||||
create(:reaction, reactable: article, user: user)
|
||||
expect(user.reload.updated_at).to be > updated_at
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ RSpec.describe Reaction, type: :model do
|
|||
let!(:reaction) { create(:reaction, reactable: article) }
|
||||
|
||||
it "creates a ScoreCalcJob on article reaction destroy" do
|
||||
ActiveJob::Base.queue_adapter = :test
|
||||
expect { reaction.destroy }.to have_enqueued_job(Articles::ScoreCalcJob).exactly(:once)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -379,31 +379,35 @@ RSpec.describe User, type: :model do
|
|||
expect(new_user.identities.size).to eq(2)
|
||||
end
|
||||
|
||||
context "with active jobs" do
|
||||
before { ActiveJob::Base.queue_adapter = :inline }
|
||||
|
||||
context "when estimating the default language" do
|
||||
it "estimates default language to be nil" do
|
||||
user.estimate_default_language!
|
||||
expect(user.estimated_default_language).to eq(nil)
|
||||
perform_enqueued_jobs do
|
||||
user.estimate_default_language!
|
||||
end
|
||||
expect(user.reload.estimated_default_language).to eq(nil)
|
||||
end
|
||||
|
||||
it "estimates default language to be japan with jp email" do
|
||||
user.update_column(:email, "ben@hello.jp")
|
||||
user.estimate_default_language!
|
||||
user.reload
|
||||
expect(user.estimated_default_language).to eq("ja")
|
||||
perform_enqueued_jobs do
|
||||
user.update_column(:email, "ben@hello.jp")
|
||||
user.estimate_default_language!
|
||||
end
|
||||
expect(user.reload.estimated_default_language).to eq("ja")
|
||||
end
|
||||
|
||||
it "estimates default language based on ID dump" do
|
||||
new_user = user_from_authorization_service(:twitter, nil, "navbar_basic")
|
||||
new_user.estimate_default_language!
|
||||
perform_enqueued_jobs do
|
||||
new_user = user_from_authorization_service(:twitter, nil, "navbar_basic")
|
||||
new_user.estimate_default_language!
|
||||
end
|
||||
end
|
||||
|
||||
it "returns proper preferred_languages_array" do
|
||||
user.update_column(:email, "ben@hello.jp")
|
||||
user.estimate_default_language!
|
||||
user.reload
|
||||
expect(user.decorate.preferred_languages_array).to include("ja")
|
||||
perform_enqueued_jobs do
|
||||
user.update_column(:email, "ben@hello.jp")
|
||||
user.estimate_default_language!
|
||||
end
|
||||
expect(user.reload.decorate.preferred_languages_array).to include("ja")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,11 +9,12 @@ RSpec.describe CommentObserver, type: :observer do
|
|||
end
|
||||
|
||||
it "pings slack if user with warned role creates a comment" do
|
||||
ActiveJob::Base.queue_adapter = :inline
|
||||
user.add_role :warned
|
||||
Comment.observers.enable :comment_observer do
|
||||
run_background_jobs_immediately do
|
||||
create(:comment, user: user, commentable: article)
|
||||
perform_enqueued_jobs do
|
||||
user.add_role :warned
|
||||
Comment.observers.enable :comment_observer do
|
||||
run_background_jobs_immediately do
|
||||
create(:comment, user: user, commentable: article)
|
||||
end
|
||||
end
|
||||
end
|
||||
expect(SlackBot).to have_received(:ping).twice
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ RSpec.configure do |config|
|
|||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
|
||||
config.include ApplicationHelper
|
||||
config.include ActiveJob::TestHelper
|
||||
config.include Devise::Test::ControllerHelpers, type: :view
|
||||
config.include Devise::Test::IntegrationHelpers, type: :system
|
||||
config.include Devise::Test::IntegrationHelpers, type: :request
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Internal::Users", type: :request do
|
||||
let(:user) { create(:user, twitter_username: nil) }
|
||||
let(:user2) { create(:user, twitter_username: "Twitter") }
|
||||
let!(:user) { create(:user, twitter_username: nil) }
|
||||
let!(:user2) { create(:user, twitter_username: "Twitter") }
|
||||
let(:user3) { create(:user) }
|
||||
let(:super_admin) { create(:user, :super_admin) }
|
||||
let(:article) { create(:article, user: user) }
|
||||
|
|
@ -11,8 +11,6 @@ RSpec.describe "Internal::Users", type: :request do
|
|||
|
||||
before do
|
||||
sign_in super_admin
|
||||
user
|
||||
user2
|
||||
Delayed::Worker.new(quiet: true).work_off
|
||||
dependents_for_offending_user_article
|
||||
offender_activity_on_other_content
|
||||
|
|
@ -66,35 +64,50 @@ RSpec.describe "Internal::Users", type: :request do
|
|||
context "when merging users" do
|
||||
before do
|
||||
full_profile
|
||||
post "/internal/users/#{user.id}/merge", params: { user: { merge_user_id: user2.id } }
|
||||
Delayed::Worker.new(quiet: true).work_off
|
||||
end
|
||||
|
||||
it "deletes duplicate user" do
|
||||
post "/internal/users/#{user.id}/merge", params: { user: { merge_user_id: user2.id } }
|
||||
|
||||
expect { User.find(user2.id) }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it "merges all content" do
|
||||
expect(user.comments.count).to eq(2)
|
||||
expect(user.articles.count).to eq(2)
|
||||
expect(user.reactions.count).to eq(4)
|
||||
expected_articles_count = user.articles.count + user2.articles.count
|
||||
expected_comments_count = user.comments.count + user2.comments.count
|
||||
expected_reactions_count = user.reactions.count + user2.reactions.count
|
||||
|
||||
post "/internal/users/#{user.id}/merge", params: { user: { merge_user_id: user2.id } }
|
||||
|
||||
expect(user.comments.count).to eq(expected_articles_count)
|
||||
expect(user.articles.count).to eq(expected_comments_count)
|
||||
expect(user.reactions.count).to eq(expected_reactions_count)
|
||||
end
|
||||
|
||||
it "merges all relationships" do
|
||||
expect(user.follows.count).to eq(2)
|
||||
expected_follows_count = user.follows.count + user2.follows.count
|
||||
expected_channel_memberships_count = user.chat_channel_memberships.count + user2.chat_channel_memberships.count
|
||||
expected_mentions_count = user.mentions.count + user2.mentions.count
|
||||
|
||||
post "/internal/users/#{user.id}/merge", params: { user: { merge_user_id: user2.id } }
|
||||
|
||||
expect(user.follows.count).to eq(expected_follows_count)
|
||||
expect(Follow.where(followable_id: user.id, followable_type: "User").count).to eq(1)
|
||||
expect(user.chat_channel_memberships.count).to eq(1)
|
||||
expect(user.mentions.count).to eq(1)
|
||||
expect(user.chat_channel_memberships.count).to eq(expected_channel_memberships_count)
|
||||
expect(user.mentions.count).to eq(expected_mentions_count)
|
||||
end
|
||||
|
||||
it "merges misc profile info" do
|
||||
post "/internal/users/#{user.id}/merge", params: { user: { merge_user_id: user2.id } }
|
||||
|
||||
expect(user.github_repos.any?).to be true
|
||||
expect(user.badge_achievements.any?).to be true
|
||||
end
|
||||
|
||||
it "merges social identities and usernames" do
|
||||
user.reload
|
||||
expect(user.twitter_username).to eq("Twitter")
|
||||
post "/internal/users/#{user.id}/merge", params: { user: { merge_user_id: user2.id } }
|
||||
|
||||
expect(user.reload.twitter_username).to eq("Twitter")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -70,10 +70,6 @@ RSpec.describe "UserSettings", type: :request do
|
|||
end
|
||||
|
||||
context "when requesting an export of the articles" do
|
||||
before do
|
||||
ActiveJob::Base.queue_adapter = :test
|
||||
end
|
||||
|
||||
def send_request(flag = true)
|
||||
put "/users/#{user.id}", params: {
|
||||
user: { tab: "misc", export_requested: flag }
|
||||
|
|
@ -103,13 +99,15 @@ RSpec.describe "UserSettings", type: :request do
|
|||
end
|
||||
|
||||
it "sends an email" do
|
||||
ActiveJob::Base.queue_adapter = :inline
|
||||
expect { send_request }.to change { ActionMailer::Base.deliveries.count }.by(1)
|
||||
perform_enqueued_jobs do
|
||||
expect { send_request }.to change { ActionMailer::Base.deliveries.count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
it "does not send an email if there was no request" do
|
||||
ActiveJob::Base.queue_adapter = :inline
|
||||
expect { send_request(false) }.not_to(change { ActionMailer::Base.deliveries.count })
|
||||
perform_enqueued_jobs do
|
||||
expect { send_request(false) }.not_to(change { ActionMailer::Base.deliveries.count })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -93,15 +93,15 @@ RSpec.configure do |config|
|
|||
# # particularly slow.
|
||||
# config.profile_examples = 10
|
||||
#
|
||||
# # Run specs in random order to surface order dependencies. If you find an
|
||||
# # order dependency and want to debug it, you can fix the order by providing
|
||||
# # the seed, which is printed after each run.
|
||||
# # --seed 1234
|
||||
# config.order = :random
|
||||
#
|
||||
# # Seed global randomization in this process using the `--seed` CLI option.
|
||||
# # Setting this allows you to use `--seed` to deterministically reproduce
|
||||
# # test failures related to randomization by passing the same `--seed` value
|
||||
# # as the one that triggered the failure.
|
||||
# Kernel.srand config.seed
|
||||
# Run specs in random order to surface order dependencies. If you find an
|
||||
# order dependency and want to debug it, you can fix the order by providing
|
||||
# the seed, which is printed after each run.
|
||||
# --seed 1234
|
||||
config.order = :random
|
||||
|
||||
# Seed global randomization in this process using the `--seed` CLI option.
|
||||
# Setting this allows you to use `--seed` to deterministically reproduce
|
||||
# test failures related to randomization by passing the same `--seed` value
|
||||
# as the one that triggered the failure.
|
||||
Kernel.srand config.seed
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ require "rails_helper"
|
|||
RSpec.describe "Creating Comment", type: :system, js: true do
|
||||
let(:user) { create(:user) }
|
||||
let(:raw_comment) { Faker::Lorem.paragraph }
|
||||
let(:article) do
|
||||
create(:article, user_id: user.id, show_comments: true)
|
||||
end
|
||||
# the article should be created before signing in
|
||||
let!(:article) { create(:article, user_id: user.id, show_comments: true) }
|
||||
|
||||
before do
|
||||
sign_in user
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ RSpec.describe "Sorting Dashboard Articles", type: :system, js: true do
|
|||
let(:article3) { create(:article, user_id: user.id, published_at: 5.minutes.ago, created_at: 3.days.ago, positive_reactions_count: 0, page_views_count: 1000, comments_count: 50) }
|
||||
|
||||
before do
|
||||
sign_in user
|
||||
article1
|
||||
article2
|
||||
article3
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it "shows articles sorted by default in created_at DESC" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue