DEV: Use describe for methods in specs

This commit is contained in:
Loïc Guitaut
2022-07-27 12:21:10 +02:00
committed by Loïc Guitaut
parent f1c3670d74
commit 296aad430a
69 changed files with 214 additions and 214 deletions

View File

@@ -221,7 +221,7 @@ describe Badge do
end
end
context "#seed" do
describe "#seed" do
let(:regular_badge) do
Badge.find(Badge::Regular)

View File

@@ -1089,13 +1089,13 @@ describe Category do
SQL
end
context "#depth_of_descendants" do
describe "#depth_of_descendants" do
it "should produce max_depth" do
expect(category.depth_of_descendants(3)).to eq(3)
end
end
context "#height_of_ancestors" do
describe "#height_of_ancestors" do
it "should produce max_height" do
expect(category.height_of_ancestors(3)).to eq(3)
end
@@ -1107,13 +1107,13 @@ describe Category do
category.parent_category_id = category.id
end
context "#depth_of_descendants" do
describe "#depth_of_descendants" do
it "should produce max_depth" do
expect(category.depth_of_descendants(3)).to eq(3)
end
end
context "#height_of_ancestors" do
describe "#height_of_ancestors" do
it "should produce max_height" do
expect(category.height_of_ancestors(3)).to eq(3)
end
@@ -1125,20 +1125,20 @@ describe Category do
category.parent_category_id = subcategory.id
end
context "#depth_of_descendants" do
describe "#depth_of_descendants" do
it "should produce max_depth" do
expect(category.depth_of_descendants(3)).to eq(3)
end
end
context "#height_of_ancestors" do
describe "#height_of_ancestors" do
it "should produce max_height" do
expect(category.height_of_ancestors(3)).to eq(3)
end
end
end
context "#depth_of_descendants" do
describe "#depth_of_descendants" do
it "should be 0 when the category has no descendants" do
expect(subcategory.depth_of_descendants).to eq(0)
end
@@ -1148,7 +1148,7 @@ describe Category do
end
end
context "#height_of_ancestors" do
describe "#height_of_ancestors" do
it "should be 0 when the category has no ancestors" do
expect(category.height_of_ancestors).to eq(0)
end

View File

@@ -12,7 +12,7 @@ describe CategoryUser do
CategoryUser.notification_levels[:regular]
end
context '#batch_set' do
describe '#batch_set' do
fab!(:category) { Fabricate(:category) }
def category_ids_at_level(level)

View File

@@ -5,7 +5,7 @@ describe EmailToken do
it { is_expected.to validate_presence_of :email }
it { is_expected.to belong_to :user }
context '#create' do
describe '#create' do
fab!(:user) { Fabricate(:user, active: false) }
let!(:original_token) { user.email_tokens.first }
let!(:email_token) { Fabricate(:email_token, user: user, email: 'bubblegum@adventuretime.ooo') }
@@ -41,7 +41,7 @@ describe EmailToken do
end
end
context '#confirm' do
describe '#confirm' do
fab!(:user) { Fabricate(:user, active: false) }
let!(:email_token) { Fabricate(:email_token, user: user) }

View File

@@ -65,7 +65,7 @@ describe Invite do
end
end
context '.generate' do
describe '.generate' do
it 'saves an invites' do
invite = Invite.generate(user, email: 'TEST@EXAMPLE.COM')
expect(invite.invite_key).to be_present
@@ -201,7 +201,7 @@ describe Invite do
end
end
context '#redeem' do
describe '#redeem' do
fab!(:invite) { Fabricate(:invite) }
it 'works' do

View File

@@ -1491,7 +1491,7 @@ describe Post do
expect(UploadReference.count).to eq(0)
end
context "#link_post_uploads" do
describe "#link_post_uploads" do
it "finds all the uploads in the post" do
post.link_post_uploads
@@ -1547,7 +1547,7 @@ describe Post do
end
end
context '#update_uploads_secure_status' do
describe '#update_uploads_secure_status' do
fab!(:user) { Fabricate(:user, trust_level: 0) }
let(:raw) do

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe RemoteTheme do
context '#import_remote' do
describe '#import_remote' do
def about_json(love_color: "FAFAFA", tertiary_low_color: "FFFFFF", color_scheme_name: "Amazing", about_url: "https://www.site.com/about")
<<~JSON
{
@@ -201,7 +201,7 @@ describe RemoteTheme do
)
end
context "#github_diff_link" do
describe "#github_diff_link" do
it "is blank for non-github repos" do
expect(gitlab_repo.github_diff_link).to be_blank
end
@@ -218,7 +218,7 @@ describe RemoteTheme do
end
end
context ".joined_remotes" do
describe ".joined_remotes" do
it "finds records that are associated with themes" do
github_repo
gitlab_repo
@@ -232,7 +232,7 @@ describe RemoteTheme do
end
end
context ".out_of_date_themes" do
describe ".out_of_date_themes" do
let(:remote) { RemoteTheme.create!(remote_url: "https://github.com/org/testtheme") }
let!(:theme) { Fabricate(:theme, remote_theme: remote) }
@@ -252,7 +252,7 @@ describe RemoteTheme do
end
context ".unreachable_themes" do
describe ".unreachable_themes" do
let(:remote) { RemoteTheme.create!(remote_url: "https://github.com/org/testtheme", last_error_text: "can't contact this repo :(") }
let!(:theme) { Fabricate(:theme, remote_theme: remote) }

View File

@@ -2,7 +2,7 @@
RSpec.describe Reviewable, type: :model do
context ".create" do
describe ".create" do
fab!(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
@@ -31,7 +31,7 @@ RSpec.describe Reviewable, type: :model do
end
end
context ".needs_review!" do
describe ".needs_review!" do
fab!(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
@@ -86,7 +86,7 @@ RSpec.describe Reviewable, type: :model do
end
end
context ".list_for" do
describe ".list_for" do
fab!(:user) { Fabricate(:user) }
it "returns an empty list for nil user" do
@@ -381,7 +381,7 @@ RSpec.describe Reviewable, type: :model do
end
end
context ".score_required_to_hide_post" do
describe ".score_required_to_hide_post" do
it "will return the default visibility if it's higher" do
Reviewable.set_priorities(low: 40.0, high: 100.0)
@@ -411,7 +411,7 @@ RSpec.describe Reviewable, type: :model do
end
end
context ".spam_score_to_silence_new_user" do
describe ".spam_score_to_silence_new_user" do
it "returns a default value if we can't calculated any percentiles" do
SiteSetting.silence_new_user_sensitivity = Reviewable.sensitivity[:low]
expect(Reviewable.spam_score_to_silence_new_user).to eq(7.5)
@@ -434,7 +434,7 @@ RSpec.describe Reviewable, type: :model do
end
end
context ".score_to_auto_close_topic" do
describe ".score_to_auto_close_topic" do
it "returns the default if we can't calculated any percentiles" do
SiteSetting.auto_close_topic_sensitivity = Reviewable.sensitivity[:low]

View File

@@ -55,7 +55,7 @@ RSpec.describe ReviewableUser, type: :model do
end
end
context "#update_fields" do
describe "#update_fields" do
fab!(:moderator) { Fabricate(:moderator) }
fab!(:reviewable) { Fabricate(:reviewable) }

View File

@@ -8,7 +8,7 @@ describe TopicEmbed do
it { is_expected.to belong_to :post }
it { is_expected.to validate_presence_of :embed_url }
context '.import' do
describe '.import' do
fab!(:user) { Fabricate(:user) }
let(:title) { "How to turn a fish from good to evil in 30 seconds" }
@@ -173,7 +173,7 @@ describe TopicEmbed do
end
end
context '.topic_id_for_embed' do
describe '.topic_id_for_embed' do
it "returns correct topic id irrespective of url protocol" do
topic_embed = Fabricate(:topic_embed, embed_url: "http://example.com/post/248")
@@ -195,7 +195,7 @@ describe TopicEmbed do
describe '.find_remote' do
fab!(:embeddable_host) { Fabricate(:embeddable_host) }
context ".title_scrub" do
describe ".title_scrub" do
let(:url) { 'http://eviltrout.com/123' }
let(:contents) { "<title>Through the Looking Glass - Classic Books</title><body>some content here</body>" }

View File

@@ -17,7 +17,7 @@ describe Topic do
context 'validations' do
let(:topic) { Fabricate.build(:topic) }
context "#featured_link" do
describe "#featured_link" do
describe 'when featured_link contains more than a URL' do
it 'should not be valid' do
topic.featured_link = 'http://meta.discourse.org TEST'
@@ -33,7 +33,7 @@ describe Topic do
end
end
context "#external_id" do
describe "#external_id" do
describe 'when external_id is too long' do
it 'should not be valid' do
topic.external_id = 'a' * (Topic::EXTERNAL_ID_MAX_LENGTH + 1)
@@ -78,7 +78,7 @@ describe Topic do
end
end
context "#title" do
describe "#title" do
it { is_expected.to validate_presence_of :title }
describe 'censored words' do
@@ -165,7 +165,7 @@ describe Topic do
it { is_expected.to rate_limit }
context '#visible_post_types' do
describe '#visible_post_types' do
let(:types) { Post.types }
before do
@@ -260,7 +260,7 @@ describe Topic do
end
end
context '#ascii_generator' do
describe '#ascii_generator' do
before { SiteSetting.slug_generation_method = 'ascii' }
context 'with ascii letters' do
@@ -613,7 +613,7 @@ describe Topic do
end
end
context '.similar_to' do
describe '.similar_to' do
fab!(:category) { Fabricate(:category_with_definition) }
it 'returns an empty array with nil params' do

View File

@@ -6,7 +6,7 @@ describe TopicTag do
fab!(:tag) { Fabricate(:tag) }
let(:topic_tag) { Fabricate(:topic_tag, topic: topic, tag: tag) }
context '#after_create' do
describe '#after_create' do
it "tag topic_count should be increased" do
expect {
@@ -24,7 +24,7 @@ describe TopicTag do
end
context '#after_destroy' do
describe '#after_destroy' do
it "tag topic_count should be decreased" do
topic_tag

View File

@@ -43,7 +43,7 @@ describe Upload do
end
end
context ".create_thumbnail!" do
describe ".create_thumbnail!" do
it "does not create a thumbnail when disabled" do
SiteSetting.create_thumbnails = false
OptimizedImage.expects(:create_for).never
@@ -118,7 +118,7 @@ describe Upload do
expect(created_upload.valid?).to eq(false)
end
context ".extract_url" do
describe ".extract_url" do
let(:url) { 'https://example.com/uploads/default/original/1X/d1c2d40ab994e8410c.png' }
it 'should return the right part of url' do
@@ -126,7 +126,7 @@ describe Upload do
end
end
context ".get_from_url" do
describe ".get_from_url" do
let(:sha1) { "10f73034616a796dfd70177dc54b6def44c4ba6f" }
let(:upload) { Fabricate(:upload, sha1: sha1) }
@@ -258,7 +258,7 @@ describe Upload do
end
end
context ".get_from_urls" do
describe ".get_from_urls" do
let(:upload) { Fabricate(:upload, sha1: "10f73034616a796dfd70177dc54b6def44c4ba6f") }
let(:upload2) { Fabricate(:upload, sha1: "2a7081e615f9075befd87a9a6d273935c0262cd5") }
@@ -549,7 +549,7 @@ describe Upload do
stub_upload(upload)
end
context '.destroy' do
describe '.destroy' do
it "can correctly clear information when destroying an upload" do
upload = Fabricate(:upload)
user = Fabricate(:user)
@@ -568,7 +568,7 @@ describe Upload do
end
end
context ".signed_url_from_secure_media_url" do
describe ".signed_url_from_secure_media_url" do
before do
# must be done so signed_url_for_path exists
enable_secure_media
@@ -589,7 +589,7 @@ describe Upload do
end
end
context ".secure_media_url_from_upload_url" do
describe ".secure_media_url_from_upload_url" do
before do
# must be done so signed_url_for_path exists
enable_secure_media
@@ -603,7 +603,7 @@ describe Upload do
end
end
context ".secure_media_url?" do
describe ".secure_media_url?" do
it "works for a secure media url with or without schema + host" do
url = "//localhost:3000/secure-media-uploads/original/2X/f/f62055931bb702c7fd8f552fb901f977e0289a18.png"
expect(Upload.secure_media_url?(url)).to eq(true)

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
describe UserApiKey do
context "#allow?" do
describe "#allow?" do
def request_env(method, path, **path_parameters)
ActionDispatch::TestRequest.create.tap do |request|
request.request_method = method

View File

@@ -120,7 +120,7 @@ describe UserAvatar do
end
end
context '.import_url_for_user' do
describe '.import_url_for_user' do
it 'creates user_avatar record if missing' do
user = Fabricate(:user)

View File

@@ -261,7 +261,7 @@ RSpec.describe UserProfile do
end
end
context '.import_url_for_user' do
describe '.import_url_for_user' do
fab!(:user) { Fabricate(:user) }
before do

View File

@@ -289,7 +289,7 @@ RSpec.describe User do
end
end
context '.enqueue_welcome_message' do
describe '.enqueue_welcome_message' do
fab!(:user) { Fabricate(:user) }
it 'enqueues the system message' do
@@ -333,7 +333,7 @@ RSpec.describe User do
end
end
context '.set_default_tags_preferences' do
describe '.set_default_tags_preferences' do
let(:tag) { Fabricate(:tag) }
it "should set default tag preferences when new user created" do
@@ -2450,7 +2450,7 @@ RSpec.describe User do
end
end
context "#destroy!" do
describe "#destroy!" do
it 'clears up associated data on destroy!' do
user = Fabricate(:user)
post = Fabricate(:post)

View File

@@ -10,7 +10,7 @@ describe UserStat do
expect(user.user_stat.new_since).to be_present
end
context '#update_view_counts' do
describe '#update_view_counts' do
let(:user) { Fabricate(:user) }
let(:stat) { user.user_stat }