DEV: Prefabrication (test optimization) (#7414)

* Introduced fab!, a helper that creates database state for a group

It's almost identical to let_it_be, except:

 1. It creates a new object for each test by default,
 2. You can disable it using PREFABRICATION=0
This commit is contained in:
Daniel Waterworth 2019-05-07 03:12:20 +00:00 committed by Sam
parent 329969ea20
commit e219588142
258 changed files with 1402 additions and 1364 deletions

View File

@ -5,8 +5,8 @@ require 'rails_helper'
describe AdminConfirmation do
let(:admin) { Fabricate(:admin) }
let(:user) { Fabricate(:user) }
fab!(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
describe "create_confirmation" do
it "raises an error for non-admins" do

View File

@ -93,8 +93,8 @@ describe AdminUserIndexQuery do
end
describe 'with a suspected user' do
let(:user) { Fabricate(:active_user, created_at: 1.day.ago) }
let(:bot) { Fabricate(:active_user, id: -10, created_at: 1.day.ago) }
fab!(:user) { Fabricate(:active_user, created_at: 1.day.ago) }
fab!(:bot) { Fabricate(:active_user, id: -10, created_at: 1.day.ago) }
it 'finds the suspected user' do
bot
@ -106,8 +106,8 @@ describe AdminUserIndexQuery do
describe "with a pending user" do
let!(:user) { Fabricate(:user, active: true, approved: false) }
let!(:inactive_user) { Fabricate(:user, approved: false, active: false) }
fab!(:user) { Fabricate(:user, active: true, approved: false) }
fab!(:inactive_user) { Fabricate(:user, approved: false, active: false) }
it "finds the unapproved user" do
query = ::AdminUserIndexQuery.new(query: 'pending')
@ -116,7 +116,7 @@ describe AdminUserIndexQuery do
end
context 'and a suspended pending user' do
let!(:suspended_user) { Fabricate(:user, approved: false, suspended_at: 1.hour.ago, suspended_till: 20.years.from_now) }
fab!(:suspended_user) { Fabricate(:user, approved: false, suspended_at: 1.hour.ago, suspended_till: 20.years.from_now) }
it "doesn't return the suspended user" do
query = ::AdminUserIndexQuery.new(query: 'pending')
expect(query.find_users).not_to include(suspended_user)
@ -149,8 +149,8 @@ describe AdminUserIndexQuery do
describe "with an admin user" do
let!(:user) { Fabricate(:user, admin: true) }
let!(:user2) { Fabricate(:user, admin: false) }
fab!(:user) { Fabricate(:user, admin: true) }
fab!(:user2) { Fabricate(:user, admin: false) }
it "finds the admin" do
query = ::AdminUserIndexQuery.new(query: 'admins')
@ -161,8 +161,8 @@ describe AdminUserIndexQuery do
describe "with a moderator" do
let!(:user) { Fabricate(:user, moderator: true) }
let!(:user2) { Fabricate(:user, moderator: false) }
fab!(:user) { Fabricate(:user, moderator: true) }
fab!(:user2) { Fabricate(:user, moderator: false) }
it "finds the moderator" do
query = ::AdminUserIndexQuery.new(query: 'moderators')
@ -173,8 +173,8 @@ describe AdminUserIndexQuery do
describe "with a silenced user" do
let!(:user) { Fabricate(:user, silenced_till: 1.year.from_now) }
let!(:user2) { Fabricate(:user) }
fab!(:user) { Fabricate(:user, silenced_till: 1.year.from_now) }
fab!(:user2) { Fabricate(:user) }
it "finds the silenced user" do
query = ::AdminUserIndexQuery.new(query: 'silenced')
@ -185,8 +185,8 @@ describe AdminUserIndexQuery do
describe "with a staged user" do
let!(:user) { Fabricate(:user, staged: true) }
let!(:user2) { Fabricate(:user, staged: false) }
fab!(:user) { Fabricate(:user, staged: true) }
fab!(:user2) { Fabricate(:user, staged: false) }
it "finds the staged user" do
query = ::AdminUserIndexQuery.new(query: 'staged')
@ -256,7 +256,7 @@ describe AdminUserIndexQuery do
context "by ip address fragment" do
let!(:user) { Fabricate(:user, ip_address: "117.207.94.9") }
fab!(:user) { Fabricate(:user, ip_address: "117.207.94.9") }
it "matches the ip address" do
query = ::AdminUserIndexQuery.new(filter: " 117.207.94.9 ")

View File

@ -368,7 +368,7 @@ describe Auth::DefaultCurrentUserProvider do
end
describe "#current_user" do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:unhashed_token) do
new_provider = provider('/')
@ -605,7 +605,7 @@ describe Auth::DefaultCurrentUserProvider do
end
context "user api" do
let :user do
fab! :user do
Fabricate(:user)
end

View File

@ -49,7 +49,7 @@ describe Auth::FacebookAuthenticator do
end
context 'description_for_user' do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
it 'returns empty string if no entry for user' do
expect(authenticator.description_for_user(user)).to eq("")
@ -62,7 +62,7 @@ describe Auth::FacebookAuthenticator do
end
context 'revoke' do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:authenticator) { Auth::FacebookAuthenticator.new }
it 'raises exception if no entry for user' do

View File

@ -23,7 +23,7 @@ end
describe Auth::GithubAuthenticator do
let(:authenticator) { described_class.new }
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
context 'after_authenticate' do
let(:data) do
@ -251,7 +251,7 @@ describe Auth::GithubAuthenticator do
end
context 'revoke' do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:authenticator) { Auth::GithubAuthenticator.new }
it 'raises exception if no entry for user' do
@ -271,8 +271,8 @@ describe Auth::GithubAuthenticator do
let(:job_klass) { Jobs::DownloadAvatarFromUrl }
context 'when user has a custom avatar' do
let(:user_avatar) { Fabricate(:user_avatar, custom_upload: Fabricate(:upload)) }
let(:user_with_custom_avatar) { Fabricate(:user, user_avatar: user_avatar) }
fab!(:user_avatar) { Fabricate(:user_avatar, custom_upload: Fabricate(:upload)) }
fab!(:user_with_custom_avatar) { Fabricate(:user, user_avatar: user_avatar) }
it 'does not enqueue a download_avatar_from_url job' do
expect {

View File

@ -116,7 +116,7 @@ describe Auth::GoogleOAuth2Authenticator do
end
context 'revoke' do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:authenticator) { Auth::GoogleOAuth2Authenticator.new }
it 'raises exception if no entry for user' do

View File

@ -42,7 +42,7 @@ describe Auth::InstagramAuthenticator do
end
context 'revoke' do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:authenticator) { Auth::InstagramAuthenticator.new }
it 'raises exception if no entry for user' do

View File

@ -54,8 +54,8 @@ describe Auth::ManagedAuthenticator do
end
describe 'connecting to another user account' do
let(:user1) { Fabricate(:user) }
let(:user2) { Fabricate(:user) }
fab!(:user1) { Fabricate(:user) }
fab!(:user2) { Fabricate(:user) }
before { UserAssociatedAccount.create!(user: user1, provider_name: 'myauth', provider_uid: "1234") }
it 'works by default' do
@ -138,7 +138,7 @@ describe Auth::ManagedAuthenticator do
end
describe "avatar on update" do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let!(:associated) { UserAssociatedAccount.create!(user: user, provider_name: 'myauth', provider_uid: "1234") }
it "schedules the job upon update correctly" do
@ -159,7 +159,7 @@ describe Auth::ManagedAuthenticator do
end
describe "profile on update" do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let!(:associated) { UserAssociatedAccount.create!(user: user, provider_name: 'myauth', provider_uid: "1234") }
it "updates the user's location and bio, unless already set" do
@ -183,7 +183,7 @@ describe Auth::ManagedAuthenticator do
end
describe "email update" do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let!(:associated) { UserAssociatedAccount.create!(user: user, provider_name: 'myauth', provider_uid: "1234") }
it "updates the user's email if currently invalid" do
@ -212,7 +212,7 @@ describe Auth::ManagedAuthenticator do
end
describe "avatar on create" do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let!(:association) { UserAssociatedAccount.create!(provider_name: 'myauth', provider_uid: "1234") }
it "doesn't schedule with no image" do
@ -229,7 +229,7 @@ describe Auth::ManagedAuthenticator do
end
describe "profile on create" do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let!(:association) { UserAssociatedAccount.create!(provider_name: 'myauth', provider_uid: "1234") }
it "doesn't explode without profile" do
@ -248,7 +248,7 @@ describe Auth::ManagedAuthenticator do
end
describe 'description_for_user' do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
it 'returns empty string if no entry for user' do
expect(authenticator.description_for_user(user)).to eq("")
@ -265,7 +265,7 @@ describe Auth::ManagedAuthenticator do
end
describe 'revoke' do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
it 'raises exception if no entry for user' do
expect { authenticator.revoke(user) }.to raise_error(Discourse::NotFound)

View File

@ -38,7 +38,7 @@ describe Auth::OpenIdAuthenticator do
end
context 'revoke' do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:authenticator) { Auth::OpenIdAuthenticator.new("test", "id", "enable_yahoo_logins", trusted: true) }
it 'raises exception if no entry for user' do

View File

@ -54,7 +54,7 @@ describe Auth::TwitterAuthenticator do
end
context 'revoke' do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:authenticator) { Auth::TwitterAuthenticator.new }
it 'raises exception if no entry for user' do

View File

@ -5,7 +5,7 @@ require 'rails_helper'
require_dependency 'avatar_lookup'
describe AvatarLookup do
let!(:user) { Fabricate(:user, username: "john_doe", name: "John Doe") }
fab!(:user) { Fabricate(:user, username: "john_doe", name: "John Doe") }
describe '#[]' do
before do

View File

@ -45,7 +45,7 @@ describe ComposerMessagesFinder do
end
context 'private message' do
let(:topic) { Fabricate(:private_message_topic) }
fab!(:topic) { Fabricate(:private_message_topic) }
context 'starting a new private message' do
let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'createTopic', topic_id: topic.id) }
@ -104,7 +104,7 @@ describe ComposerMessagesFinder do
context '.check_avatar_notification' do
let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'createTopic') }
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
context "success" do
let!(:message) { finder.check_avatar_notification }
@ -150,8 +150,8 @@ describe ComposerMessagesFinder do
end
context '.check_sequential_replies' do
let(:user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic) }
fab!(:user) { Fabricate(:user) }
fab!(:topic) { Fabricate(:topic) }
before do
SiteSetting.educate_until_posts = 10
@ -223,8 +223,8 @@ describe ComposerMessagesFinder do
end
context '.check_dominating_topic' do
let(:user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic) }
fab!(:user) { Fabricate(:user) }
fab!(:topic) { Fabricate(:topic) }
before do
SiteSetting.educate_until_posts = 10
@ -308,21 +308,21 @@ describe ComposerMessagesFinder do
end
context '.check_get_a_room' do
let(:user) { Fabricate(:user) }
let(:other_user) { Fabricate(:user) }
let(:third_user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic, user: other_user) }
let(:op) { Fabricate(:post, topic_id: topic.id, user: other_user) }
fab!(:user) { Fabricate(:user) }
fab!(:other_user) { Fabricate(:user) }
fab!(:third_user) { Fabricate(:user) }
fab!(:topic) { Fabricate(:topic, user: other_user) }
fab!(:op) { Fabricate(:post, topic_id: topic.id, user: other_user) }
let!(:other_user_reply) do
fab!(:other_user_reply) do
Fabricate(:post, topic: topic, user: third_user, reply_to_user_id: op.user_id)
end
let!(:first_reply) do
fab!(:first_reply) do
Fabricate(:post, topic: topic, user: user, reply_to_user_id: op.user_id)
end
let!(:second_reply) do
fab!(:second_reply) do
Fabricate(:post, topic: topic, user: user, reply_to_user_id: op.user_id)
end
@ -424,8 +424,8 @@ describe ComposerMessagesFinder do
end
context '.check_reviving_old_topic' do
let(:user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic) }
fab!(:user) { Fabricate(:user) }
fab!(:topic) { Fabricate(:topic) }
it "does not give a message without a topic id" do
expect(described_class.new(user, composer_action: 'createTopic').check_reviving_old_topic).to be_blank
@ -470,8 +470,8 @@ describe ComposerMessagesFinder do
end
context 'when editing a post' do
let(:user) { Fabricate(:user) }
let(:topic) { Fabricate(:post).topic }
fab!(:user) { Fabricate(:user) }
fab!(:topic) { Fabricate(:post).topic }
let!(:post) do
PostCreator.create!(

View File

@ -4,8 +4,8 @@ require 'rails_helper'
describe CategoryHashtag do
describe '#query_from_hashtag_slug' do
let(:parent_category) { Fabricate(:category) }
let(:child_category) { Fabricate(:category, parent_category: parent_category) }
fab!(:parent_category) { Fabricate(:category) }
fab!(:child_category) { Fabricate(:category, parent_category: parent_category) }
it "should return the right result for a parent category slug" do
expect(Category.query_from_hashtag_slug(parent_category.slug))

View File

@ -3,11 +3,11 @@
require 'rails_helper'
RSpec.describe SecondFactorManager do
let(:user_second_factor_totp) { Fabricate(:user_second_factor_totp) }
fab!(:user_second_factor_totp) { Fabricate(:user_second_factor_totp) }
let(:user) { user_second_factor_totp.user }
let(:another_user) { Fabricate(:user) }
fab!(:another_user) { Fabricate(:user) }
let(:user_second_factor_backup) { Fabricate(:user_second_factor_backup) }
fab!(:user_second_factor_backup) { Fabricate(:user_second_factor_backup) }
let(:user_backup) { user_second_factor_backup.user }
describe '#totp' do

View File

@ -6,13 +6,13 @@ require "file_store/s3_store"
describe CookedPostProcessor do
context "#post_process" do
let(:upload) do
fab!(:upload) do
Fabricate(:upload,
url: '/uploads/default/original/1X/1/1234567890123456.jpg'
)
end
let(:post) do
fab!(:post) do
Fabricate(:post, raw: <<~RAW)
<img src="#{upload.url}">
RAW
@ -132,9 +132,9 @@ describe CookedPostProcessor do
end
describe 'internal links' do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
fab!(:post) { Fabricate(:post, raw: "Hello #{topic.url}") }
let(:url) { topic.url }
let(:post) { Fabricate(:post, raw: "Hello #{url}") }
it "includes the topic title" do
cpp.post_process
@ -364,7 +364,7 @@ describe CookedPostProcessor do
end
context "with image_sizes" do
let(:post) { Fabricate(:post_with_image_urls) }
fab!(:post) { Fabricate(:post_with_image_urls) }
let(:cpp) { CookedPostProcessor.new(post, image_sizes: image_sizes) }
before do
@ -401,7 +401,7 @@ describe CookedPostProcessor do
context "with unsized images" do
let(:post) { Fabricate(:post_with_unsized_images) }
fab!(:post) { Fabricate(:post_with_unsized_images) }
let(:cpp) { CookedPostProcessor.new(post) }
it "adds the width and height to images that don't have them" do
@ -415,8 +415,8 @@ describe CookedPostProcessor do
context "with large images" do
let(:upload) { Fabricate(:upload) }
let(:post) { Fabricate(:post_with_large_image) }
fab!(:upload) { Fabricate(:upload) }
fab!(:post) { Fabricate(:post_with_large_image) }
let(:cpp) { CookedPostProcessor.new(post, disable_loading_image: true) }
before do
@ -463,7 +463,7 @@ describe CookedPostProcessor do
end
describe 'when image is an svg' do
let(:post) do
fab!(:post) do
Fabricate(:post, raw: '<img src="/uploads/default/original/1X/1234567890123456.svg">')
end
@ -552,8 +552,8 @@ describe CookedPostProcessor do
context "with large images when using subfolders" do
let(:upload) { Fabricate(:upload) }
let(:post) { Fabricate(:post_with_large_image_on_subfolder) }
fab!(:upload) { Fabricate(:upload) }
fab!(:post) { Fabricate(:post_with_large_image_on_subfolder) }
let(:cpp) { CookedPostProcessor.new(post, disable_loading_image: true) }
let(:base_url) { "http://test.localhost/subfolder" }
let(:base_uri) { "/subfolder" }
@ -1281,7 +1281,7 @@ describe CookedPostProcessor do
end
context "remove direct reply full quote" do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
let!(:post) { Fabricate(:post, topic: topic, raw: "this is the first post") }
let(:raw) do

View File

@ -111,8 +111,8 @@ describe Discourse do
context '#site_contact_user' do
let!(:admin) { Fabricate(:admin) }
let!(:another_admin) { Fabricate(:admin) }
fab!(:admin) { Fabricate(:admin) }
fab!(:another_admin) { Fabricate(:admin) }
it 'returns the user specified by the site setting site_contact_username' do
SiteSetting.site_contact_username = another_admin.username

View File

@ -8,13 +8,13 @@ require 'discourse_tagging'
describe DiscourseTagging do
let(:admin) { Fabricate(:admin) }
let(:user) { Fabricate(:user) }
fab!(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
let(:guardian) { Guardian.new(user) }
let!(:tag1) { Fabricate(:tag, name: "fun") }
let!(:tag2) { Fabricate(:tag, name: "fun2") }
let!(:tag3) { Fabricate(:tag, name: "Fun3") }
fab!(:tag1) { Fabricate(:tag, name: "fun") }
fab!(:tag2) { Fabricate(:tag, name: "fun2") }
fab!(:tag3) { Fabricate(:tag, name: "Fun3") }
before do
SiteSetting.tagging_enabled = true
@ -42,7 +42,7 @@ describe DiscourseTagging do
end
context 'with tags visible only to staff' do
let(:hidden_tag) { Fabricate(:tag) }
fab!(:hidden_tag) { Fabricate(:tag) }
let!(:staff_tag_group) { Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name]) }
it 'should return all tags to staff' do
@ -61,9 +61,9 @@ describe DiscourseTagging do
end
describe 'filter_visible' do
let(:hidden_tag) { Fabricate(:tag) }
fab!(:hidden_tag) { Fabricate(:tag) }
let!(:staff_tag_group) { Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name]) }
let(:topic) { Fabricate(:topic, tags: [tag1, tag2, tag3, hidden_tag]) }
fab!(:topic) { Fabricate(:topic, tags: [tag1, tag2, tag3, hidden_tag]) }
it 'returns all tags to staff' do
tags = DiscourseTagging.filter_visible(topic.tags, Guardian.new(admin))
@ -89,7 +89,7 @@ describe DiscourseTagging do
describe 'tag_topic_by_names' do
context 'staff-only tags' do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
before do
create_staff_tags(['alpha'])
@ -109,8 +109,8 @@ describe DiscourseTagging do
end
context 'respects category minimum_required_tags setting' do
let(:category) { Fabricate(:category, minimum_required_tags: 2) }
let(:topic) { Fabricate(:topic, category: category) }
fab!(:category) { Fabricate(:category, minimum_required_tags: 2) }
fab!(:topic) { Fabricate(:topic, category: category) }
it 'when tags are not present' do
valid = DiscourseTagging.tag_topic_by_names(topic, Guardian.new(user), [])
@ -138,10 +138,10 @@ describe DiscourseTagging do
end
context 'hidden tags' do
let(:hidden_tag) { Fabricate(:tag) }
fab!(:hidden_tag) { Fabricate(:tag) }
let!(:staff_tag_group) { Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name]) }
let(:topic) { Fabricate(:topic, user: user) }
let(:post) { Fabricate(:post, user: user, topic: topic, post_number: 1) }
fab!(:topic) { Fabricate(:topic, user: user) }
fab!(:post) { Fabricate(:post, user: user, topic: topic, post_number: 1) }
it 'user cannot add hidden tag by knowing its name' do
expect(PostRevisor.new(post).revise!(topic.user, raw: post.raw + " edit", tags: [hidden_tag.name])).to be_falsey
@ -252,10 +252,10 @@ describe DiscourseTagging do
end
describe "staff_tag_names" do
let(:tag) { Fabricate(:tag) }
fab!(:tag) { Fabricate(:tag) }
let(:staff_tag) { Fabricate(:tag) }
let(:other_staff_tag) { Fabricate(:tag) }
fab!(:staff_tag) { Fabricate(:tag) }
fab!(:other_staff_tag) { Fabricate(:tag) }
let!(:staff_tag_group) {
Fabricate(

View File

@ -12,10 +12,10 @@ describe Email::Processor do
context "when reply via email is too short" do
let(:mail) { file_from_fixtures("chinese_reply.eml", "emails").read }
let(:post) { Fabricate(:post) }
let(:user) { Fabricate(:user, email: 'discourse@bar.com') }
fab!(:post) { Fabricate(:post) }
fab!(:user) { Fabricate(:user, email: 'discourse@bar.com') }
let!(:post_reply_key) do
fab!(:post_reply_key) do
Fabricate(:post_reply_key,
user: user,
post: post,
@ -179,7 +179,7 @@ describe Email::Processor do
describe 'when replying to a post that is too old' do
let(:mail) { file_from_fixtures("old_destination.eml", "emails").read }
let!(:user) { Fabricate(:user, email: "discourse@bar.com") }
fab!(:user) { Fabricate(:user, email: "discourse@bar.com") }
it 'rejects the email with the right response' do
SiteSetting.disallow_reply_by_email_after_days = 2

View File

@ -119,8 +119,8 @@ describe Email::Receiver do
describe "creating whisper post in PMs for staged users" do
let(:email_address) { "linux-admin@b-s-c.co.jp" }
let(:user1) { user1 = Fabricate(:user) }
let(:user2) { user2 = Fabricate(:staged, email: email_address) }
fab!(:user1) { Fabricate(:user) }
let(:user2) { Fabricate(:staged, email: email_address) }
let(:topic) { Fabricate(:topic, archetype: 'private_message', category_id: nil, user: user1, allowed_users: [user1, user2]) }
let(:post) { create_post(topic: topic, user: user1) }
@ -186,7 +186,7 @@ describe Email::Receiver do
let(:bounce_key) { "14b08c855160d67f2e0c2f8ef36e251e" }
let(:bounce_key_2) { "b542fb5a9bacda6d28cc061d18e4eb83" }
let!(:user) { Fabricate(:user, email: "linux-admin@b-s-c.co.jp") }
fab!(:user) { Fabricate(:user, email: "linux-admin@b-s-c.co.jp") }
let!(:email_log) { Fabricate(:email_log, to_address: user.email, user: user, bounce_key: bounce_key) }
let!(:email_log_2) { Fabricate(:email_log, to_address: user.email, user: user, bounce_key: bounce_key_2) }
@ -251,10 +251,10 @@ describe Email::Receiver do
context "reply" do
let(:reply_key) { "4f97315cc828096c9cb34c6f1a0d6fe8" }
let(:category) { Fabricate(:category) }
let(:user) { Fabricate(:user, email: "discourse@bar.com") }
let(:topic) { create_topic(category: category, user: user) }
let(:post) { create_post(topic: topic) }
fab!(:category) { Fabricate(:category) }
fab!(:user) { Fabricate(:user, email: "discourse@bar.com") }
fab!(:topic) { create_topic(category: category, user: user) }
fab!(:post) { create_post(topic: topic) }
let!(:post_reply_key) do
Fabricate(:post_reply_key,
@ -661,7 +661,7 @@ describe Email::Receiver do
context "new message to a group" do
let!(:group) { Fabricate(:group, incoming_email: "team@bar.com|meat@bar.com") }
fab!(:group) { Fabricate(:group, incoming_email: "team@bar.com|meat@bar.com") }
it "handles encoded display names" do
expect { process(:encoded_display_name) }.to change(Topic, :count)
@ -833,7 +833,7 @@ describe Email::Receiver do
context "new topic in a category" do
let!(:category) { Fabricate(:category, email_in: "category@bar.com|category@foo.com", email_in_allow_strangers: false) }
fab!(:category) { Fabricate(:category, email_in: "category@bar.com|category@foo.com", email_in_allow_strangers: false) }
it "raises a StrangersNotAllowedError when 'email_in_allow_strangers' is disabled" do
expect { process(:new_user) }.to raise_error(Email::Receiver::StrangersNotAllowedError)
@ -960,7 +960,7 @@ describe Email::Receiver do
context "new topic in a category that allows strangers" do
let!(:category) { Fabricate(:category, email_in: "category@bar.com|category@foo.com", email_in_allow_strangers: true) }
fab!(:category) { Fabricate(:category, email_in: "category@bar.com|category@foo.com", email_in_allow_strangers: true) }
it "lets an email in from a stranger" do
expect { process(:new_user) }.to change(Topic, :count)
@ -1128,13 +1128,13 @@ describe Email::Receiver do
context "when email is sent to category" do
context "when email is sent by a new user and category does not allow strangers" do
let!(:category) { Fabricate(:category, email_in: "category@foo.com", email_in_allow_strangers: false) }
fab!(:category) { Fabricate(:category, email_in: "category@foo.com", email_in_allow_strangers: false) }
include_examples "does not create staged users", :new_user, Email::Receiver::StrangersNotAllowedError
end
context "when email has no date" do
let!(:category) { Fabricate(:category, email_in: "category@foo.com", email_in_allow_strangers: true) }
fab!(:category) { Fabricate(:category, email_in: "category@foo.com", email_in_allow_strangers: true) }
it "includes the translated string in the error" do
expect { process(:no_date) }.to raise_error(Email::Receiver::InvalidPost).with_message(I18n.t("system_messages.email_reject_invalid_post_specified.date_invalid"))
@ -1146,11 +1146,11 @@ describe Email::Receiver do
context "email is a reply" do
let(:reply_key) { "4f97315cc828096c9cb34c6f1a0d6fe8" }
let(:category) { Fabricate(:category) }
let(:user) { Fabricate(:user, email: "discourse@bar.com") }
let!(:user2) { Fabricate(:user, email: "someone_else@bar.com") }
let(:topic) { create_topic(category: category, user: user) }
let(:post) { create_post(topic: topic, user: user) }
fab!(:category) { Fabricate(:category) }
fab!(:user) { Fabricate(:user, email: "discourse@bar.com") }
fab!(:user2) { Fabricate(:user, email: "someone_else@bar.com") }
fab!(:topic) { create_topic(category: category, user: user) }
fab!(:post) { create_post(topic: topic, user: user) }
let!(:post_reply_key) do
Fabricate(:post_reply_key, reply_key: reply_key, user: user, post: post)
@ -1162,7 +1162,7 @@ describe Email::Receiver do
end
context "replying without key is allowed" do
let!(:group) { Fabricate(:group, incoming_email: "team@bar.com") }
fab!(:group) { Fabricate(:group, incoming_email: "team@bar.com") }
let!(:topic) do
SiteSetting.find_related_post_with_key = false
process(:email_reply_1)
@ -1202,7 +1202,7 @@ describe Email::Receiver do
end
context "mailing list mirror" do
let!(:category) { Fabricate(:mailinglist_mirror_category) }
fab!(:category) { Fabricate(:mailinglist_mirror_category) }
before do
SiteSetting.block_auto_generated_emails = true

View File

@ -4,11 +4,11 @@ require 'rails_helper'
require 'email/sender'
describe Email::Sender do
let(:post) { Fabricate(:post) }
fab!(:post) { Fabricate(:post) }
context "disable_emails is enabled" do
let(:user) { Fabricate(:user) }
let(:moderator) { Fabricate(:moderator) }
fab!(:user) { Fabricate(:user) }
fab!(:moderator) { Fabricate(:moderator) }
context "disable_emails is enabled for everyone" do
before { SiteSetting.disable_emails = "yes" }
@ -138,9 +138,9 @@ describe Email::Sender do
end
context "adds a List-ID header to identify the forum" do
let(:category) { Fabricate(:category, name: 'Name With Space') }
let(:topic) { Fabricate(:topic, category: category) }
let(:post) { Fabricate(:post, topic: topic) }
fab!(:category) { Fabricate(:category, name: 'Name With Space') }
fab!(:topic) { Fabricate(:topic, category: category) }
fab!(:post) { Fabricate(:post, topic: topic) }
before do
message.header['X-Discourse-Post-Id'] = post.id
@ -165,8 +165,8 @@ describe Email::Sender do
end
context "adds Precedence header" do
let(:topic) { Fabricate(:topic) }
let(:post) { Fabricate(:post, topic: topic) }
fab!(:topic) { Fabricate(:topic) }
fab!(:post) { Fabricate(:post, topic: topic) }
before do
message.header['X-Discourse-Post-Id'] = post.id
@ -180,8 +180,8 @@ describe Email::Sender do
end
context "removes custom Discourse headers from topic notification mails" do
let(:topic) { Fabricate(:topic) }
let(:post) { Fabricate(:post, topic: topic) }
fab!(:topic) { Fabricate(:topic) }
fab!(:post) { Fabricate(:post, topic: topic) }
before do
message.header['X-Discourse-Post-Id'] = post.id
@ -206,12 +206,12 @@ describe Email::Sender do
end
context "email threading" do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
let(:post_1) { Fabricate(:post, topic: topic, post_number: 1) }
let(:post_2) { Fabricate(:post, topic: topic, post_number: 2) }
let(:post_3) { Fabricate(:post, topic: topic, post_number: 3) }
let(:post_4) { Fabricate(:post, topic: topic, post_number: 4) }
fab!(:post_1) { Fabricate(:post, topic: topic, post_number: 1) }
fab!(:post_2) { Fabricate(:post, topic: topic, post_number: 2) }
fab!(:post_3) { Fabricate(:post, topic: topic, post_number: 3) }
fab!(:post_4) { Fabricate(:post, topic: topic, post_number: 4) }
let!(:post_reply_1_4) { PostReply.create(post: post_1, reply: post_4) }
let!(:post_reply_2_4) { PostReply.create(post: post_2, reply: post_4) }
@ -377,7 +377,7 @@ describe Email::Sender do
message
end
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:email_sender) { Email::Sender.new(message, :valid_type, user) }
before do
@ -390,7 +390,7 @@ describe Email::Sender do
end
describe "post reply keys" do
let(:post) { Fabricate(:post) }
fab!(:post) { Fabricate(:post) }
before do
message.header['X-Discourse-Post-Id'] = post.id

View File

@ -4,7 +4,7 @@ require 'rails_helper'
require_dependency 'file_store/base_store'
RSpec.describe FileStore::BaseStore do
let(:upload) { Fabricate(:upload, id: 9999, sha1: Digest::SHA1.hexdigest('9999')) }
fab!(:upload) { Fabricate(:upload, id: 9999, sha1: Digest::SHA1.hexdigest('9999')) }
describe '#get_path_for_upload' do
it 'should return the right path' do

View File

@ -7,10 +7,10 @@ describe FileStore::LocalStore do
let(:store) { FileStore::LocalStore.new }
let(:upload) { Fabricate(:upload) }
fab!(:upload) { Fabricate(:upload) }
let(:uploaded_file) { file_from_fixtures("logo.png") }
let(:optimized_image) { Fabricate(:optimized_image) }
fab!(:optimized_image) { Fabricate(:optimized_image) }
describe "#store_upload" do

View File

@ -8,10 +8,10 @@ describe FileStore::S3Store do
let(:store) { FileStore::S3Store.new }
let(:s3_helper) { store.instance_variable_get(:@s3_helper) }
let(:upload) { Fabricate(:upload) }
fab!(:upload) { Fabricate(:upload) }
let(:uploaded_file) { file_from_fixtures("logo.png") }
let(:optimized_image) { Fabricate(:optimized_image) }
fab!(:optimized_image) { Fabricate(:optimized_image) }
let(:optimized_image_file) { file_from_fixtures("logo.png") }
before(:each) do
@ -22,7 +22,7 @@ describe FileStore::S3Store do
end
shared_context 's3 helpers' do
let(:upload) do
fab!(:upload) do
Fabricate(:upload, sha1: Digest::SHA1.hexdigest('secreet image string'))
end
@ -199,7 +199,7 @@ describe FileStore::S3Store do
end
describe "#remove_optimized_image" do
let(:optimized_image) { Fabricate(:optimized_image, upload: upload) }
fab!(:optimized_image) { Fabricate(:optimized_image, upload: upload) }
let(:image_path) do
FileStore::BaseStore.new.get_path_for_optimized_image(optimized_image)

View File

@ -6,16 +6,16 @@ require 'topic_view'
describe FilterBestPosts do
let(:topic) { Fabricate(:topic) }
let(:coding_horror) { Fabricate(:coding_horror) }
let(:first_poster) { topic.user }
fab!(:topic) { Fabricate(:topic) }
fab!(:coding_horror) { Fabricate(:coding_horror) }
fab!(:first_poster) { topic.user }
let!(:p1) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 1) }
let!(:p2) { Fabricate(:post, topic: topic, user: coding_horror, percent_rank: 0.5) }
let!(:p3) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 0) }
fab!(:p1) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 1) }
fab!(:p2) { Fabricate(:post, topic: topic, user: coding_horror, percent_rank: 0.5) }
fab!(:p3) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 0) }
let(:moderator) { Fabricate(:moderator) }
let(:admin) { Fabricate(:admin) }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:admin) { Fabricate(:admin) }
it "can find the best responses" do

View File

@ -5,7 +5,7 @@ require_dependency 'flag_query'
describe FlagQuery do
let(:codinghorror) { Fabricate(:coding_horror) }
fab!(:codinghorror) { Fabricate(:coding_horror) }
describe "flagged_topics" do
it "respects `min_score_default_visibility`" do

View File

@ -3,9 +3,9 @@
require 'rails_helper'
RSpec.describe CategoryGuardian do
let(:admin) { Fabricate(:admin) }
fab!(:admin) { Fabricate(:admin) }
let(:guardian) { Guardian.new(admin) }
let(:category) { Fabricate(:category) }
fab!(:category) { Fabricate(:category) }
describe '#cannot_delete_category_reason' do
describe 'when category is uncategorized' do

View File

@ -116,7 +116,7 @@ describe UserGuardian do
context "hidden profile" do
# Mixing Fabricate.build() and Fabricate() could cause ID clashes, so override :user
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:hidden_user) do
result = Fabricate(:user)

View File

@ -8,10 +8,10 @@ require_dependency 'post_locker'
describe Guardian do
let(:user) { Fabricate(:user) }
let(:moderator) { Fabricate(:moderator) }
let(:admin) { Fabricate(:admin) }
let(:anonymous_user) { Fabricate(:anonymous) }
fab!(:user) { Fabricate(:user) }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:admin) { Fabricate(:admin) }
fab!(:anonymous_user) { Fabricate(:anonymous) }
let(:trust_level_1) { build(:user, trust_level: 1) }
let(:trust_level_2) { build(:user, trust_level: 2) }
let(:trust_level_3) { build(:user, trust_level: 3) }
@ -132,7 +132,7 @@ describe Guardian do
end
describe 'when allow_flagging_staff is false' do
let(:staff_post) { Fabricate(:post, user: Fabricate(:moderator)) }
fab!(:staff_post) { Fabricate(:post, user: Fabricate(:moderator)) }
before do
SiteSetting.allow_flagging_staff = false
@ -250,9 +250,9 @@ describe Guardian do
end
describe 'can_send_private_message' do
let(:user) { Fabricate(:user) }
let(:another_user) { Fabricate(:user) }
let(:suspended_user) { Fabricate(:user, suspended_till: 1.week.from_now, suspended_at: 1.day.ago) }
fab!(:user) { Fabricate(:user) }
fab!(:another_user) { Fabricate(:user) }
fab!(:suspended_user) { Fabricate(:user, suspended_till: 1.week.from_now, suspended_at: 1.day.ago) }
it "returns false when the user is nil" do
expect(Guardian.new(nil).can_send_private_message?(user)).to be_falsey
@ -371,9 +371,9 @@ describe Guardian do
end
describe 'can_reply_as_new_topic' do
let(:user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic) }
let(:private_message) { Fabricate(:private_message_topic) }
fab!(:user) { Fabricate(:user) }
fab!(:topic) { Fabricate(:topic) }
fab!(:private_message) { Fabricate(:private_message_topic) }
it "returns false for a non logged in user" do
expect(Guardian.new(nil).can_reply_as_new_topic?(topic)).to be_falsey
@ -478,8 +478,8 @@ describe Guardian do
end
context 'with groups' do
let(:group) { Fabricate(:group) }
let(:another_group) { Fabricate(:group) }
fab!(:group) { Fabricate(:group) }
fab!(:another_group) { Fabricate(:group) }
let(:groups) { [group, another_group] }
before do
@ -505,17 +505,17 @@ describe Guardian do
describe 'can_invite_to?' do
describe "regular topics" do
let(:group) { Fabricate(:group) }
let(:category) { Fabricate(:category, read_restricted: true) }
let(:topic) { Fabricate(:topic) }
let(:private_topic) { Fabricate(:topic, category: category) }
let(:user) { topic.user }
let(:moderator) { Fabricate(:moderator) }
let(:admin) { Fabricate(:admin) }
fab!(:group) { Fabricate(:group) }
fab!(:category) { Fabricate(:category, read_restricted: true) }
fab!(:topic) { Fabricate(:topic) }
fab!(:private_topic) { Fabricate(:topic, category: category) }
fab!(:user) { topic.user }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:admin) { Fabricate(:admin) }
let(:private_category) { Fabricate(:private_category, group: group) }
let(:group_private_topic) { Fabricate(:topic, category: private_category) }
let(:group_owner) { group_private_topic.user.tap { |u| group.add_owner(u) } }
let(:pm) { Fabricate(:topic) }
fab!(:pm) { Fabricate(:topic) }
it 'handles invitation correctly' do
expect(Guardian.new(nil).can_invite_to?(topic)).to be_falsey
@ -548,8 +548,8 @@ describe Guardian do
end
describe 'for a private category for automatic and non-automatic group' do
let(:automatic_group) { Fabricate(:group, automatic: true) }
let(:group) { Fabricate(:group) }
fab!(:automatic_group) { Fabricate(:group, automatic: true) }
fab!(:group) { Fabricate(:group) }
let(:category) do
Fabricate(:category, read_restricted: true).tap do |category|
@ -592,10 +592,10 @@ describe Guardian do
end
describe "private messages" do
let(:user) { Fabricate(:user, trust_level: TrustLevel[2]) }
let!(:pm) { Fabricate(:private_message_topic, user: user) }
let(:admin) { Fabricate(:admin) }
let(:moderator) { Fabricate(:moderator) }
fab!(:user) { Fabricate(:user, trust_level: TrustLevel[2]) }
fab!(:pm) { Fabricate(:private_message_topic, user: user) }
fab!(:admin) { Fabricate(:admin) }
fab!(:moderator) { Fabricate(:moderator) }
context "when private messages are disabled" do
it "allows an admin to invite to the pm" do
@ -796,7 +796,7 @@ describe Guardian do
end
describe 'a Post' do
let(:another_admin) { Fabricate(:admin) }
fab!(:another_admin) { Fabricate(:admin) }
it 'correctly handles post visibility' do
post = Fabricate(:post)
topic = post.topic
@ -844,7 +844,7 @@ describe Guardian do
end
describe 'a PostRevision' do
let(:post_revision) { Fabricate(:post_revision) }
fab!(:post_revision) { Fabricate(:post_revision) }
context 'edit_history_visible_to_public is true' do
before { SiteSetting.edit_history_visible_to_public = true }
@ -1030,7 +1030,7 @@ describe Guardian do
end
context "system message" do
let(:private_message) {
fab!(:private_message) {
Fabricate(
:topic,
archetype: Archetype.private_message,
@ -1049,7 +1049,7 @@ describe Guardian do
end
context "private message" do
let(:private_message) { Fabricate(:topic, archetype: Archetype.private_message, category_id: nil) }
fab!(:private_message) { Fabricate(:topic, archetype: Archetype.private_message, category_id: nil) }
before { user.save! }
@ -1542,7 +1542,7 @@ describe Guardian do
describe 'a Category' do
let(:category) { Fabricate(:category) }
fab!(:category) { Fabricate(:category) }
it 'returns false when not logged in' do
expect(Guardian.new.can_edit?(category)).to be_falsey
@ -1700,7 +1700,7 @@ describe Guardian do
end
context "can_delete_post_action?" do
let(:post) { Fabricate(:post) }
fab!(:post) { Fabricate(:post) }
it "allows us to remove a bookmark" do
pa = PostActionCreator.bookmark(user, post).post_action
@ -2138,7 +2138,7 @@ describe Guardian do
end
context "delete myself" do
let(:myself) { Fabricate(:user, created_at: 6.months.ago) }
fab!(:myself) { Fabricate(:user, created_at: 6.months.ago) }
subject { Guardian.new(myself).can_delete_user?(myself) }
it "is true to delete myself and I have never made a post" do
@ -2332,9 +2332,9 @@ describe Guardian do
end
context 'with title argument' do
let(:title_badge) { Fabricate(:badge, name: 'Helper', allow_title: true) }
let(:no_title_badge) { Fabricate(:badge, name: 'Writer', allow_title: false) }
let(:group) { Fabricate(:group, title: 'Groupie') }
fab!(:title_badge) { Fabricate(:badge, name: 'Helper', allow_title: true) }
fab!(:no_title_badge) { Fabricate(:badge, name: 'Writer', allow_title: false) }
fab!(:group) { Fabricate(:group, title: 'Groupie') }
it 'returns true if title belongs to a badge that user has' do
BadgeGranter.grant(title_badge, user)
@ -2418,7 +2418,7 @@ describe Guardian do
end
context 'for a new user' do
let(:target_user) { Fabricate(:user, created_at: 1.minute.ago) }
fab!(:target_user) { Fabricate(:user, created_at: 1.minute.ago) }
include_examples "staff can always change usernames"
it "is true for the user to change their own username" do
@ -2818,8 +2818,8 @@ describe Guardian do
end
describe "#allow_themes?" do
let(:theme) { Fabricate(:theme) }
let(:theme2) { Fabricate(:theme) }
let!(:theme) { Fabricate(:theme) }
let!(:theme2) { Fabricate(:theme) }
it "allows staff to use any themes" do
expect(Guardian.new(moderator).allow_themes?([theme.id, theme2.id])).to eq(false)
@ -3074,7 +3074,7 @@ describe Guardian do
let(:uncategorized) { Category.find(SiteSetting.uncategorized_category_id) }
context "uncategorized" do
let!(:link_category) { Fabricate(:link_category) }
fab!(:link_category) { Fabricate(:link_category) }
it "allows featured links if uncategorized allows it" do
uncategorized.topic_featured_link_allowed = true
@ -3090,8 +3090,8 @@ describe Guardian do
end
context 'when exist' do
let!(:category) { Fabricate(:category, topic_featured_link_allowed: false) }
let!(:link_category) { Fabricate(:link_category) }
fab!(:category) { Fabricate(:category, topic_featured_link_allowed: false) }
fab!(:link_category) { Fabricate(:link_category) }
it 'returns true if the category is listed' do
expect(guardian.can_edit_featured_link?(link_category.id)).to eq(true)
@ -3104,14 +3104,14 @@ describe Guardian do
end
context "suspension reasons" do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
it "will be shown by default" do
expect(Guardian.new.can_see_suspension_reason?(user)).to eq(true)
end
context "with hide suspension reason enabled" do
let(:moderator) { Fabricate(:moderator) }
fab!(:moderator) { Fabricate(:moderator) }
before do
SiteSetting.hide_suspension_reasons = true
@ -3140,8 +3140,8 @@ describe Guardian do
end
context 'normal user' do
let(:topic) { Fabricate(:topic, user: Fabricate(:user)) }
let(:another_user) { Fabricate(:user) }
fab!(:topic) { Fabricate(:topic, user: Fabricate(:user)) }
fab!(:another_user) { Fabricate(:user) }
before do
topic.allowed_users << user

View File

@ -24,7 +24,7 @@ describe InlineOneboxer do
end
context "caching" do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
before do
InlineOneboxer.purge(topic.url)

View File

@ -5,7 +5,7 @@ require 'new_post_manager'
describe NewPostManager do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
context "default action" do
it "creates the post by default" do
@ -20,7 +20,7 @@ describe NewPostManager do
end
context "default action" do
let(:other_user) { Fabricate(:user) }
fab!(:other_user) { Fabricate(:user) }
it "doesn't enqueue private messages" do
SiteSetting.approve_unless_trust_level = 4
@ -355,8 +355,8 @@ describe NewPostManager do
end
context 'when posting in the category requires approval' do
let(:user) { Fabricate(:user) }
let(:category) { Fabricate(:category) }
fab!(:user) { Fabricate(:user) }
fab!(:category) { Fabricate(:category) }
context 'when new topics require approval' do
before do
@ -379,7 +379,7 @@ describe NewPostManager do
end
context 'when new posts require approval' do
let(:topic) { Fabricate(:topic, category: category) }
fab!(:topic) { Fabricate(:topic, category: category) }
before do
category.custom_fields[Category::REQUIRE_REPLY_APPROVAL] = true

View File

@ -3,8 +3,8 @@
require 'rails_helper'
describe PostActionCreator do
let(:user) { Fabricate(:user) }
let(:post) { Fabricate(:post) }
fab!(:user) { Fabricate(:user) }
fab!(:post) { Fabricate(:post) }
let(:like_type_id) { PostActionType.types[:like] }
describe "rate limits" do

View File

@ -6,11 +6,11 @@ require 'topic_subtype'
describe PostCreator do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic, user: user) }
context "new topic" do
let(:category) { Fabricate(:category, user: user) }
fab!(:category) { Fabricate(:category, user: user) }
let(:basic_topic_params) { { title: "hello world topic", raw: "my name is fred", archetype_id: 1 } }
let(:image_sizes) { { 'http://an.image.host/image.jpg' => { "width" => 111, "height" => 222 } } }
@ -350,7 +350,7 @@ describe PostCreator do
end
describe "topic's auto close based on last post" do
let(:topic_timer) do
fab!(:topic_timer) do
Fabricate(:topic_timer,
based_on_last_post: true,
execute_at: Time.zone.now - 12.hours,
@ -360,8 +360,8 @@ describe PostCreator do
let(:topic) { topic_timer.topic }
let(:post) do
Fabricate(:post, topic: topic)
fab!(:post) do
Fabricate(:post, topic: topic_timer.topic)
end
it "updates topic's auto close date" do
@ -475,7 +475,7 @@ describe PostCreator do
end
context 'whisper' do
let!(:topic) { Fabricate(:topic, user: user) }
fab!(:topic) { Fabricate(:topic, user: user) }
it 'whispers do not mess up the public view' do
first = PostCreator.new(user,
@ -544,7 +544,7 @@ describe PostCreator do
context 'uniqueness' do
let!(:topic) { Fabricate(:topic, user: user) }
fab!(:topic) { Fabricate(:topic, user: user) }
let(:basic_topic_params) { { raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4 } }
let(:creator) { PostCreator.new(user, basic_topic_params) }
@ -606,7 +606,7 @@ describe PostCreator do
context "host spam" do
let!(:topic) { Fabricate(:topic, user: user) }
fab!(:topic) { Fabricate(:topic, user: user) }
let(:basic_topic_params) { { raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4 } }
let(:creator) { PostCreator.new(user, basic_topic_params) }
@ -633,7 +633,7 @@ describe PostCreator do
# more integration testing ... maximise our testing
context 'existing topic' do
let(:topic) { Fabricate(:topic, user: user, title: 'topic title with 25 chars') }
fab!(:topic) { Fabricate(:topic, user: user, title: 'topic title with 25 chars') }
let(:creator) { PostCreator.new(user, raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4) }
it 'ensures the user can create the post' do
@ -686,7 +686,7 @@ describe PostCreator do
end
context 'closed topic' do
let!(:topic) { Fabricate(:topic, user: user, closed: true) }
fab!(:topic) { Fabricate(:topic, user: user, closed: true) }
let(:creator) { PostCreator.new(user, raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4) }
it 'responds with an error message' do
@ -698,7 +698,7 @@ describe PostCreator do
end
context 'missing topic' do
let!(:topic) { Fabricate(:topic, user: user, deleted_at: 5.minutes.ago) }
let(:topic) { Fabricate(:topic, user: user, deleted_at: 5.minutes.ago) }
let(:creator) { PostCreator.new(user, raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4) }
it 'responds with an error message' do
@ -726,8 +726,8 @@ describe PostCreator do
# integration test ... minimise db work
context 'private message' do
let(:target_user1) { Fabricate(:coding_horror) }
let(:target_user2) { Fabricate(:moderator) }
let(:unrelated) { Fabricate(:user) }
fab!(:target_user2) { Fabricate(:moderator) }
fab!(:unrelated) { Fabricate(:user) }
let(:post) do
PostCreator.create(user, title: 'hi there welcome to my topic',
raw: "this is my awesome message @#{unrelated.username_lower}",
@ -804,7 +804,7 @@ describe PostCreator do
context "warnings" do
let(:target_user1) { Fabricate(:coding_horror) }
let(:target_user2) { Fabricate(:moderator) }
fab!(:target_user2) { Fabricate(:moderator) }
let(:base_args) do
{ title: 'you need a warning buddy!',
raw: "you did something bad and I'm telling you about it!",
@ -885,7 +885,7 @@ describe PostCreator do
context 'private message to group' do
let(:target_user1) { Fabricate(:coding_horror) }
let(:target_user2) { Fabricate(:moderator) }
fab!(:target_user2) { Fabricate(:moderator) }
let(:group) do
g = Fabricate.build(:group, messageable_level: Group::ALIAS_LEVELS[:everyone])
g.add(target_user1)
@ -893,7 +893,7 @@ describe PostCreator do
g.save
g
end
let(:unrelated) { Fabricate(:user) }
fab!(:unrelated) { Fabricate(:user) }
let(:post) do
PostCreator.create!(user,
title: 'hi there welcome to my topic',
@ -1044,7 +1044,7 @@ describe PostCreator do
end
context "staged users" do
let(:staged) { Fabricate(:staged) }
fab!(:staged) { Fabricate(:staged) }
it "automatically watches all messages it participates in" do
post = PostCreator.create(staged,
@ -1171,7 +1171,7 @@ describe PostCreator do
end
context 'private message to a user that has disabled private messages' do
let(:another_user) { Fabricate(:user) }
fab!(:another_user) { Fabricate(:user) }
before do
another_user.user_option.update!(allow_private_messages: false)
@ -1195,8 +1195,8 @@ describe PostCreator do
end
context "private message to a muted user" do
let(:muted_me) { Fabricate(:evil_trout) }
let(:another_user) { Fabricate(:user) }
fab!(:muted_me) { Fabricate(:evil_trout) }
fab!(:another_user) { Fabricate(:user) }
it 'should fail' do
updater = UserUpdater.new(muted_me, muted_me)
@ -1217,7 +1217,7 @@ describe PostCreator do
)
end
let(:staff_user) { Fabricate(:admin) }
fab!(:staff_user) { Fabricate(:admin) }
it 'succeeds if the user is staff' do
updater = UserUpdater.new(muted_me, muted_me)
@ -1236,8 +1236,8 @@ describe PostCreator do
end
context "private message to an ignored user" do
let(:ignorer) { Fabricate(:evil_trout) }
let(:another_user) { Fabricate(:user) }
fab!(:ignorer) { Fabricate(:evil_trout) }
fab!(:another_user) { Fabricate(:user) }
context "when post author is ignored" do
let!(:ignored_user) { Fabricate(:ignored_user, user: ignorer, ignored_user: user) }
@ -1259,8 +1259,8 @@ describe PostCreator do
end
context "when post author is admin who is ignored" do
let(:staff_user) { Fabricate(:admin) }
let!(:ignored_user) { Fabricate(:ignored_user, user: ignorer, ignored_user: staff_user) }
fab!(:staff_user) { Fabricate(:admin) }
fab!(:ignored_user) { Fabricate(:ignored_user, user: ignorer, ignored_user: staff_user) }
it 'succeeds if the user is staff' do
pc = PostCreator.new(
@ -1278,9 +1278,9 @@ describe PostCreator do
end
context "private message recipients limit (max_allowed_message_recipients) reached" do
let(:target_user1) { Fabricate(:coding_horror) }
let(:target_user2) { Fabricate(:evil_trout) }
let(:target_user3) { Fabricate(:walter_white) }
fab!(:target_user1) { Fabricate(:coding_horror) }
fab!(:target_user2) { Fabricate(:evil_trout) }
fab!(:target_user3) { Fabricate(:walter_white) }
before do
SiteSetting.max_allowed_message_recipients = 2
@ -1314,7 +1314,7 @@ describe PostCreator do
end
context "always succeeds if the user is staff" do
let(:staff_user) { Fabricate(:admin) }
fab!(:staff_user) { Fabricate(:admin) }
it 'when sending message to multiple recipients' do
pc = PostCreator.new(
@ -1331,9 +1331,9 @@ describe PostCreator do
end
context "#create_post_notice" do
let(:user) { Fabricate(:user) }
let(:staged) { Fabricate(:staged) }
let(:anonymous) { Fabricate(:anonymous) }
fab!(:user) { Fabricate(:user) }
fab!(:staged) { Fabricate(:staged) }
fab!(:anonymous) { Fabricate(:anonymous) }
it "generates post notices for new users" do
post = PostCreator.create!(user, title: "one of my first topics", raw: "one of my first posts")

View File

@ -9,8 +9,8 @@ describe PostDestroyer do
UserActionManager.enable
end
let(:moderator) { Fabricate(:moderator) }
let(:admin) { Fabricate(:admin) }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:admin) { Fabricate(:admin) }
let(:post) { create_post }
describe "destroy_old_hidden_posts" do
@ -251,7 +251,7 @@ describe PostDestroyer do
end
describe "recovery and post actions" do
let(:codinghorror) { Fabricate(:coding_horror) }
fab!(:codinghorror) { Fabricate(:coding_horror) }
let!(:like) { PostActionCreator.like(codinghorror, post).post_action }
let!(:another_like) { PostActionCreator.like(moderator, post).post_action }
@ -436,10 +436,10 @@ describe PostDestroyer do
end
context 'private message' do
let(:author) { Fabricate(:user) }
let(:private_message) { Fabricate(:private_message_topic, user: author) }
let!(:first_post) { Fabricate(:post, topic: private_message, user: author) }
let!(:second_post) { Fabricate(:post, topic: private_message, user: author, post_number: 2) }
fab!(:author) { Fabricate(:user) }
fab!(:private_message) { Fabricate(:private_message_topic, user: author) }
fab!(:first_post) { Fabricate(:post, topic: private_message, user: author) }
fab!(:second_post) { Fabricate(:post, topic: private_message, user: author, post_number: 2) }
it "doesn't update post_count for a reply" do
expect {
@ -473,10 +473,10 @@ describe PostDestroyer do
context 'deleting the second post in a topic' do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let!(:post) { create_post(user: user) }
let(:topic) { post.topic }
let(:second_user) { Fabricate(:coding_horror) }
fab!(:second_user) { Fabricate(:coding_horror) }
let!(:second_post) { create_post(topic: topic, user: second_user) }
before do
@ -613,8 +613,8 @@ describe PostDestroyer do
describe 'after delete' do
let!(:coding_horror) { Fabricate(:coding_horror) }
let!(:post) { Fabricate(:post, raw: "Hello @CodingHorror") }
fab!(:coding_horror) { Fabricate(:coding_horror) }
fab!(:post) { Fabricate(:post, raw: "Hello @CodingHorror") }
it "should feature the users again (in case they've changed)" do
Jobs.expects(:enqueue).with(:feature_topic_users, has_entries(topic_id: post.topic_id))
@ -623,7 +623,7 @@ describe PostDestroyer do
describe 'with a reply' do
let!(:reply) { Fabricate(:basic_reply, user: coding_horror, topic: post.topic) }
fab!(:reply) { Fabricate(:basic_reply, user: coding_horror, topic: post.topic) }
let!(:post_reply) { PostReply.create(post_id: post.id, reply_id: reply.id) }
it 'changes the post count of the topic' do
@ -766,7 +766,7 @@ describe PostDestroyer do
end
describe 'topic links' do
let!(:first_post) { Fabricate(:post) }
fab!(:first_post) { Fabricate(:post) }
let!(:topic) { first_post.topic }
let!(:second_post) { Fabricate(:post_with_external_links, topic: topic) }

View File

@ -4,8 +4,8 @@ require 'rails_helper'
require_dependency 'post_locker'
describe PostLocker do
let(:moderator) { Fabricate(:moderator) }
let(:post) { Fabricate(:post) }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:post) { Fabricate(:post) }
it "doesn't allow regular users to lock posts" do
expect {

View File

@ -4,9 +4,9 @@ require 'rails_helper'
require 'post_merger'
describe PostMerger do
let(:moderator) { Fabricate(:moderator) }
let(:admin) { Fabricate(:admin) }
let(:user) { Fabricate(:user) }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
let(:post) { create_post }
let(:topic) { post.topic }

View File

@ -5,8 +5,8 @@ require 'post_revisor'
describe PostRevisor do
let(:topic) { Fabricate(:topic) }
let(:newuser) { Fabricate(:newuser) }
fab!(:topic) { Fabricate(:topic) }
fab!(:newuser) { Fabricate(:newuser) }
let(:post_args) { { user: newuser, topic: topic } }
context 'TopicChanges' do
@ -336,7 +336,7 @@ describe PostRevisor do
end
describe 'rate limiter' do
let(:changed_by) { Fabricate(:coding_horror) }
fab!(:changed_by) { Fabricate(:coding_horror) }
it "triggers a rate limiter" do
EditRateLimiter.any_instance.expects(:performed!)
@ -345,7 +345,7 @@ describe PostRevisor do
end
describe "admin editing a new user's post" do
let(:changed_by) { Fabricate(:admin) }
fab!(:changed_by) { Fabricate(:admin) }
before do
SiteSetting.newuser_max_images = 0
@ -383,7 +383,7 @@ describe PostRevisor do
SiteSetting.editing_grace_period_max_diff = 1000
end
let(:changed_by) { Fabricate(:coding_horror) }
fab!(:changed_by) { Fabricate(:coding_horror) }
let!(:result) { subject.revise!(changed_by, raw: "lets update the body. Здравствуйте") }
it 'correctly updates raw' do
@ -466,7 +466,7 @@ describe PostRevisor do
end
context "logging staff edits" do
let(:moderator) { Fabricate(:moderator) }
fab!(:moderator) { Fabricate(:moderator) }
it "doesn't log when a regular user revises a post" do
subject.revise!(
@ -513,7 +513,7 @@ describe PostRevisor do
context "staff_edit_locks_post" do
context "disabled" do
let(:moderator) { Fabricate(:moderator) }
fab!(:moderator) { Fabricate(:moderator) }
before do
SiteSetting.staff_edit_locks_post = false
@ -532,7 +532,7 @@ describe PostRevisor do
end
context "enabled" do
let(:moderator) { Fabricate(:moderator) }
fab!(:moderator) { Fabricate(:moderator) }
before do
SiteSetting.staff_edit_locks_post = true
@ -607,7 +607,7 @@ describe PostRevisor do
context "alerts" do
let(:mentioned_user) { Fabricate(:user) }
fab!(:mentioned_user) { Fabricate(:user) }
before do
Jobs.run_immediately!

View File

@ -23,7 +23,7 @@ describe PrettyText do
describe "with avatar" do
let(:default_avatar) { "//test.localhost/uploads/default/avatars/42d/57c/46ce7ee487/{size}.png" }
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
before do
User.stubs(:default_template).returns(default_avatar)
@ -134,8 +134,8 @@ describe PrettyText do
describe "with primary user group" do
let(:default_avatar) { "//test.localhost/uploads/default/avatars/42d/57c/46ce7ee487/{size}.png" }
let(:group) { Fabricate(:group) }
let!(:user) { Fabricate(:user, primary_group: group) }
fab!(:group) { Fabricate(:group) }
fab!(:user) { Fabricate(:user, primary_group: group) }
before do
User.stubs(:default_template).returns(default_avatar)
@ -202,7 +202,7 @@ describe PrettyText do
end
describe "with letter avatar" do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
context "subfolder" do
before do
@ -713,7 +713,7 @@ describe PrettyText do
describe 'format_for_email' do
let(:base_url) { "http://baseurl.net" }
let(:post) { Fabricate(:post) }
fab!(:post) { Fabricate(:post) }
before do
Discourse.stubs(:base_url).returns(base_url)

View File

@ -17,7 +17,7 @@ describe Promotion do
context "newuser" do
let(:user) { Fabricate(:user, trust_level: TrustLevel[0], created_at: 2.days.ago) }
fab!(:user) { Fabricate(:user, trust_level: TrustLevel[0], created_at: 2.days.ago) }
let(:promotion) { Promotion.new(user) }
it "doesn't raise an error with a nil user" do
@ -106,7 +106,7 @@ describe Promotion do
context "basic" do
let(:user) { Fabricate(:user, trust_level: TrustLevel[1], created_at: 2.days.ago) }
fab!(:user) { Fabricate(:user, trust_level: TrustLevel[1], created_at: 2.days.ago) }
let(:promotion) { Promotion.new(user) }
context 'that has done nothing' do
@ -167,7 +167,7 @@ describe Promotion do
end
context "regular" do
let(:user) { Fabricate(:user, trust_level: TrustLevel[2]) }
fab!(:user) { Fabricate(:user, trust_level: TrustLevel[2]) }
let(:promotion) { Promotion.new(user) }
context "doesn't qualify for promotion" do

View File

@ -6,7 +6,7 @@ require 'quote_comparer'
describe QuoteComparer do
describe "#modified?" do
let(:post) { Fabricate(:post, raw: "This has **text** we _are_ matching") }
fab!(:post) { Fabricate(:post, raw: "This has **text** we _are_ matching") }
def qc(text)
QuoteComparer.new(post.topic_id, post.post_number, text)

View File

@ -5,7 +5,7 @@ require 'rate_limiter'
describe RateLimiter do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:rate_limiter) { RateLimiter.new(user, "peppermint-butler", 2, 60) }
context 'disabled' do

View File

@ -5,8 +5,8 @@ require 'score_calculator'
describe ScoreCalculator do
let!(:post) { Fabricate(:post, reads: 111) }
let!(:another_post) { Fabricate(:post, topic: post.topic, reads: 222) }
fab!(:post) { Fabricate(:post, reads: 111) }
fab!(:another_post) { Fabricate(:post, topic: post.topic, reads: 222) }
let(:topic) { post.topic }
context 'with weightings' do

View File

@ -840,8 +840,8 @@ describe SiteSettingExtension do
describe '.setup_methods' do
describe 'for uploads site settings' do
let(:upload) { Fabricate(:upload) }
let(:upload2) { Fabricate(:upload) }
fab!(:upload) { Fabricate(:upload) }
fab!(:upload2) { Fabricate(:upload) }
it 'should return the upload record' do
settings.setting(:some_upload, upload.id.to_s, type: :upload)

View File

@ -37,15 +37,15 @@ describe Stylesheet::Importer do
context "#theme_variables" do
let(:theme) { Fabricate(:theme) }
let!(:theme) { Fabricate(:theme) }
let(:importer) { described_class.new(theme: theme) }
let(:upload) { Fabricate(:upload) }
let(:upload_s3) { Fabricate(:upload_s3) }
fab!(:upload) { Fabricate(:upload) }
fab!(:upload_s3) { Fabricate(:upload_s3) }
let(:theme_field) { ThemeField.create!(theme: theme, target_id: 0, name: "var", upload: upload, value: "", type_id: ThemeField.types[:theme_upload_var]) }
let(:theme_field_s3) { ThemeField.create!(theme: theme, target_id: 1, name: "var_s3", upload: upload_s3, value: "", type_id: ThemeField.types[:theme_upload_var]) }
let!(:theme_field) { ThemeField.create!(theme: theme, target_id: 0, name: "var", upload: upload, value: "", type_id: ThemeField.types[:theme_upload_var]) }
let!(:theme_field_s3) { ThemeField.create!(theme: theme, target_id: 1, name: "var_s3", upload: upload_s3, value: "", type_id: ThemeField.types[:theme_upload_var]) }
it "should contain the URL" do
theme_field.save!

View File

@ -5,7 +5,7 @@ require 'suggested_topics_builder'
describe SuggestedTopicsBuilder do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
let(:builder) { SuggestedTopicsBuilder.new(topic) }
before do
@ -68,7 +68,7 @@ describe SuggestedTopicsBuilder do
end
context "adding topics" do
let!(:other_topic) { Fabricate(:topic) }
fab!(:other_topic) { Fabricate(:topic) }
before do
# Add all topics
@ -86,9 +86,9 @@ describe SuggestedTopicsBuilder do
end
context "adding topics that are not open" do
let!(:archived_topic) { Fabricate(:topic, archived: true) }
let!(:closed_topic) { Fabricate(:topic, closed: true) }
let!(:invisible_topic) { Fabricate(:topic, visible: false) }
fab!(:archived_topic) { Fabricate(:topic, archived: true) }
fab!(:closed_topic) { Fabricate(:topic, closed: true) }
fab!(:invisible_topic) { Fabricate(:topic, visible: false) }
it "adds archived and closed, but not invisible topics" do
builder.add_results(Topic)
@ -98,7 +98,7 @@ describe SuggestedTopicsBuilder do
end
context "category definition topics" do
let!(:category) { Fabricate(:category) }
fab!(:category) { Fabricate(:category) }
it "doesn't add a category definition topic" do
expect(category.topic_id).to be_present

View File

@ -8,8 +8,8 @@ describe SystemMessage do
context 'send' do
let(:admin) { Fabricate(:admin) }
let(:user) { Fabricate(:user) }
fab!(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
before do
SiteSetting.site_contact_username = admin.username

View File

@ -5,7 +5,7 @@ require 'theme_settings_manager'
describe ThemeSettingsManager do
let(:theme) { Fabricate(:theme) }
let!(:theme) { Fabricate(:theme) }
let(:theme_settings) do
yaml = File.read("#{Rails.root}/spec/fixtures/theme_settings/valid_settings.yaml")
theme.set_field(target: :settings, name: "yaml", value: yaml)

View File

@ -4,7 +4,7 @@ require 'rails_helper'
require 'theme_store/tgz_exporter'
describe ThemeStore::TgzExporter do
let(:theme) do
let!(:theme) do
Fabricate(:theme, name: "Header Icons").tap do |theme|
theme.set_field(target: :common, name: :body_tag, value: "<b>testtheme1</b>")
theme.set_field(target: :settings, name: :yaml, value: "somesetting: test")

View File

@ -4,9 +4,9 @@ require 'rails_helper'
describe TopicCreator do
let(:user) { Fabricate(:user, trust_level: TrustLevel[2]) }
let(:moderator) { Fabricate(:moderator) }
let(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user, trust_level: TrustLevel[2]) }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:admin) { Fabricate(:admin) }
let(:valid_attrs) { Fabricate.attributes_for(:topic) }
let(:pm_valid_attrs) { { raw: 'this is a new post', title: 'this is a new title', archetype: Archetype.private_message, target_usernames: moderator.username } }
@ -63,8 +63,8 @@ describe TopicCreator do
end
context 'tags' do
let!(:tag1) { Fabricate(:tag, name: "fun") }
let!(:tag2) { Fabricate(:tag, name: "fun2") }
fab!(:tag1) { Fabricate(:tag, name: "fun") }
fab!(:tag2) { Fabricate(:tag, name: "fun2") }
before do
SiteSetting.tagging_enabled = true
@ -99,7 +99,7 @@ describe TopicCreator do
end
context 'minimum_required_tags is present' do
let!(:category) { Fabricate(:category, name: "beta", minimum_required_tags: 2) }
fab!(:category) { Fabricate(:category, name: "beta", minimum_required_tags: 2) }
it "fails for regular user if minimum_required_tags is not satisfied" do
expect do

View File

@ -6,18 +6,18 @@ require 'rails_helper'
describe TopicPublisher do
context "shared drafts" do
let(:shared_drafts_category) { Fabricate(:category) }
let(:category) { Fabricate(:category) }
fab!(:shared_drafts_category) { Fabricate(:category) }
fab!(:category) { Fabricate(:category) }
before do
SiteSetting.shared_drafts_category = shared_drafts_category.id
end
context "publishing" do
let(:topic) { Fabricate(:topic, category: shared_drafts_category, visible: false) }
let(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) }
let(:moderator) { Fabricate(:moderator) }
let(:op) { Fabricate(:post, topic: topic) }
fab!(:topic) { Fabricate(:topic, category: shared_drafts_category, visible: false) }
fab!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:op) { Fabricate(:post, topic: topic) }
before do
# Create a revision

View File

@ -11,11 +11,11 @@ describe TopicQuery do
# we should remove the let! here and use freeze time to communicate how the clock moves
let!(:user) { Fabricate(:coding_horror) }
let(:creator) { Fabricate(:user) }
fab!(:creator) { Fabricate(:user) }
let(:topic_query) { TopicQuery.new(user) }
let(:moderator) { Fabricate(:moderator) }
let(:admin) { Fabricate(:admin) }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:admin) { Fabricate(:admin) }
context 'secure category' do
it "filters categories out correctly" do
@ -165,20 +165,20 @@ describe TopicQuery do
end
context 'tag filter' do
let(:tag) { Fabricate(:tag) }
let(:other_tag) { Fabricate(:tag) }
let(:uppercase_tag) { Fabricate(:tag, name: "HeLlO") }
fab!(:tag) { Fabricate(:tag) }
fab!(:other_tag) { Fabricate(:tag) }
fab!(:uppercase_tag) { Fabricate(:tag, name: "HeLlO") }
before do
SiteSetting.tagging_enabled = true
end
context "no category filter" do
let!(:tagged_topic1) { Fabricate(:topic, tags: [tag]) }
let!(:tagged_topic2) { Fabricate(:topic, tags: [other_tag]) }
let!(:tagged_topic3) { Fabricate(:topic, tags: [tag, other_tag]) }
let!(:tagged_topic4) { Fabricate(:topic, tags: [uppercase_tag]) }
let!(:no_tags_topic) { Fabricate(:topic) }
fab!(:tagged_topic1) { Fabricate(:topic, tags: [tag]) }
fab!(:tagged_topic2) { Fabricate(:topic, tags: [other_tag]) }
fab!(:tagged_topic3) { Fabricate(:topic, tags: [tag, other_tag]) }
fab!(:tagged_topic4) { Fabricate(:topic, tags: [uppercase_tag]) }
fab!(:no_tags_topic) { Fabricate(:topic) }
it "returns topics with the tag when filtered to it" do
expect(TopicQuery.new(moderator, tags: tag.name).list_latest.topics)
@ -269,7 +269,7 @@ describe TopicQuery do
end
context 'a bunch of topics' do
let!(:regular_topic) do
fab!(:regular_topic) do
Fabricate(:topic, title: 'this is a regular topic',
user: creator,
views: 100,
@ -278,7 +278,7 @@ describe TopicQuery do
participant_count: 11,
bumped_at: 15.minutes.ago)
end
let!(:pinned_topic) do
fab!(:pinned_topic) do
Fabricate(:topic, title: 'this is a pinned topic',
user: creator,
views: 10,
@ -289,7 +289,7 @@ describe TopicQuery do
pinned_globally: true,
bumped_at: 10.minutes.ago)
end
let!(:archived_topic) do
fab!(:archived_topic) do
Fabricate(:topic, title: 'this is an archived topic',
user: creator,
views: 50,
@ -299,7 +299,7 @@ describe TopicQuery do
participant_count: 1,
bumped_at: 6.minutes.ago)
end
let!(:invisible_topic) do
fab!(:invisible_topic) do
Fabricate(:topic, title: 'this is an invisible topic',
user: creator,
views: 1,
@ -309,7 +309,7 @@ describe TopicQuery do
participant_count: 3,
bumped_at: 5.minutes.ago)
end
let!(:closed_topic) do
fab!(:closed_topic) do
Fabricate(:topic, title: 'this is a closed topic',
user: creator,
views: 2,
@ -319,7 +319,7 @@ describe TopicQuery do
participant_count: 2,
bumped_at: 1.minute.ago)
end
let!(:future_topic) do
fab!(:future_topic) do
Fabricate(:topic, title: 'this is a topic in far future',
user: creator,
views: 30,
@ -417,13 +417,13 @@ describe TopicQuery do
end
context 'categorized' do
let(:category) { Fabricate(:category) }
fab!(:category) { Fabricate(:category) }
let(:topic_category) { category.topic }
let!(:topic_no_cat) { Fabricate(:topic) }
let!(:topic_in_cat1) { Fabricate(:topic, category: category,
fab!(:topic_no_cat) { Fabricate(:topic) }
fab!(:topic_in_cat1) { Fabricate(:topic, category: category,
bumped_at: 10.minutes.ago,
created_at: 10.minutes.ago) }
let!(:topic_in_cat2) { Fabricate(:topic, category: category) }
fab!(:topic_in_cat2) { Fabricate(:topic, category: category) }
describe '#list_new_in_category' do
it 'returns the topic category and the categorized topic' do
@ -486,8 +486,8 @@ describe TopicQuery do
end
context 'with read data' do
let!(:partially_read) { Fabricate(:post, user: creator).topic }
let!(:fully_read) { Fabricate(:post, user: creator).topic }
fab!(:partially_read) { Fabricate(:post, user: creator).topic }
fab!(:fully_read) { Fabricate(:post, user: creator).topic }
before do
TopicUser.update_last_read(user, partially_read.id, 0, 0, 0)
@ -918,7 +918,7 @@ describe TopicQuery do
end
describe '#list_group_topics' do
let(:group) { Fabricate(:group) }
fab!(:group) { Fabricate(:group) }
let(:user) do
user = Fabricate(:user)
@ -932,9 +932,9 @@ describe TopicQuery do
user
end
let(:user3) { Fabricate(:user) }
fab!(:user3) { Fabricate(:user) }
let(:private_category) do
fab!(:private_category) do
Fabricate(:private_category, group: group)
end
@ -970,7 +970,7 @@ describe TopicQuery do
end
describe '#list_private_messages_group' do
let(:group) { Fabricate(:group) }
fab!(:group) { Fabricate(:group) }
let!(:group_message) do
Fabricate(:private_message_topic,
@ -1011,13 +1011,13 @@ describe TopicQuery do
end
context "shared drafts" do
let(:category) { Fabricate(:category) }
let(:shared_drafts_category) { Fabricate(:category) }
let!(:topic) { Fabricate(:topic, category: shared_drafts_category) }
let!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) }
let(:admin) { Fabricate(:admin) }
let(:user) { Fabricate(:user) }
let(:group) { Fabricate(:group) }
fab!(:category) { Fabricate(:category) }
fab!(:shared_drafts_category) { Fabricate(:category) }
fab!(:topic) { Fabricate(:topic, category: shared_drafts_category) }
fab!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) }
fab!(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
fab!(:group) { Fabricate(:group) }
before do
shared_drafts_category.set_permissions(group => :full)

View File

@ -6,7 +6,7 @@ require 'topic_view'
describe TopicView do
let(:topic) { create_topic }
let(:evil_trout) { Fabricate(:evil_trout) }
fab!(:evil_trout) { Fabricate(:evil_trout) }
let(:first_poster) { topic.user }
let(:topic_view) { TopicView.new(topic.id, evil_trout) }
@ -35,8 +35,8 @@ describe TopicView do
context "setup_filtered_posts" do
describe "filters posts with ignored users" do
let!(:user) { Fabricate(:user) }
let!(:ignored_user) { Fabricate(:ignored_user, user: evil_trout, ignored_user: user) }
fab!(:user) { Fabricate(:user) }
fab!(:ignored_user) { Fabricate(:ignored_user, user: evil_trout, ignored_user: user) }
let!(:post) { Fabricate(:post, topic: topic, user: first_poster) }
let!(:post2) { Fabricate(:post, topic: topic, user: evil_trout) }
let!(:post3) { Fabricate(:post, topic: topic, user: user) }
@ -104,8 +104,8 @@ describe TopicView do
let!(:p2) { Fabricate(:post, topic: topic, user: evil_trout, percent_rank: 0.5) }
let!(:p3) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 0) }
let(:moderator) { Fabricate(:moderator) }
let(:admin) { Fabricate(:admin) }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:admin) { Fabricate(:admin) }
it "it can find the best responses" do
@ -167,8 +167,8 @@ describe TopicView do
end
context 'log_check_personal_message is enabled' do
let(:group) { Fabricate(:group) }
let(:private_message) { Fabricate(:private_message_topic, allowed_groups: [group]) }
fab!(:group) { Fabricate(:group) }
fab!(:private_message) { Fabricate(:private_message_topic, allowed_groups: [group]) }
before do
SiteSetting.log_personal_messages_views = true
@ -232,8 +232,8 @@ describe TopicView do
end
describe "#get_canonical_path" do
let(:user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic) }
fab!(:user) { Fabricate(:user) }
fab!(:topic) { Fabricate(:topic) }
let(:path) { "/1234" }
before do
@ -574,8 +574,8 @@ describe TopicView do
end
context "page_title" do
let(:tag1) { Fabricate(:tag) }
let(:tag2) { Fabricate(:tag, topic_count: 2) }
fab!(:tag1) { Fabricate(:tag) }
fab!(:tag2) { Fabricate(:tag, topic_count: 2) }
subject { TopicView.new(topic.id, evil_trout).page_title }

View File

@ -32,8 +32,8 @@ describe TopicsBulkAction do
end
describe "change_category" do
let(:topic) { Fabricate(:topic) }
let(:category) { Fabricate(:category) }
fab!(:topic) { Fabricate(:topic) }
fab!(:category) { Fabricate(:category) }
context "when the user can edit the topic" do
it "changes the category and returns the topic_id" do
@ -58,7 +58,7 @@ describe TopicsBulkAction do
end
describe "reset_read" do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
it "delegates to PostTiming.destroy_for" do
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'reset_read')
@ -68,8 +68,8 @@ describe TopicsBulkAction do
end
describe "delete" do
let(:topic) { Fabricate(:post).topic }
let(:moderator) { Fabricate(:moderator) }
fab!(:topic) { Fabricate(:post).topic }
fab!(:moderator) { Fabricate(:moderator) }
it "deletes the topic" do
tba = TopicsBulkAction.new(moderator, [topic.id], type: 'delete')
@ -80,7 +80,7 @@ describe TopicsBulkAction do
end
describe "change_notification_level" do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
context "when the user can see the topic" do
it "updates the notification level" do
@ -103,7 +103,7 @@ describe TopicsBulkAction do
end
describe "close" do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
context "when the user can moderate the topic" do
it "closes the topic and returns the topic_id" do
@ -130,7 +130,7 @@ describe TopicsBulkAction do
end
describe "archive" do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
context "when the user can moderate the topic" do
it "archives the topic and returns the topic_id" do
@ -157,7 +157,7 @@ describe TopicsBulkAction do
end
describe "unlist" do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
context "when the user can moderate the topic" do
it "unlists the topic and returns the topic_id" do
@ -184,9 +184,9 @@ describe TopicsBulkAction do
end
describe "change_tags" do
let(:topic) { Fabricate(:topic) }
let(:tag1) { Fabricate(:tag) }
let(:tag2) { Fabricate(:tag) }
fab!(:topic) { Fabricate(:topic) }
fab!(:tag1) { Fabricate(:tag) }
fab!(:tag2) { Fabricate(:tag) }
before do
SiteSetting.tagging_enabled = true
@ -236,10 +236,10 @@ describe TopicsBulkAction do
end
describe "append tags" do
let(:topic) { Fabricate(:topic) }
let(:tag1) { Fabricate(:tag) }
let(:tag2) { Fabricate(:tag) }
let(:tag3) { Fabricate(:tag) }
fab!(:topic) { Fabricate(:topic) }
fab!(:tag1) { Fabricate(:tag) }
fab!(:tag2) { Fabricate(:tag) }
fab!(:tag3) { Fabricate(:tag) }
before do
SiteSetting.tagging_enabled = true

View File

@ -4,7 +4,7 @@ require 'rails_helper'
require_dependency 'validators/post_validator'
describe Validators::PostValidator do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
let(:post) { build(:post, topic: topic) }
let(:validator) { Validators::PostValidator.new({}) }
@ -26,8 +26,8 @@ describe Validators::PostValidator do
end
describe "when post's topic is a PM between a human and a non human user" do
let(:robot) { Fabricate(:user, id: -3) }
let(:user) { Fabricate(:user) }
fab!(:robot) { Fabricate(:user, id: -3) }
fab!(:user) { Fabricate(:user) }
let(:topic) do
Fabricate(:private_message_topic, topic_allowed_users: [
@ -189,8 +189,8 @@ describe Validators::PostValidator do
end
describe "unique_post_validator" do
let(:user) { Fabricate(:user, id: 999) }
let(:post) { Fabricate(:post, user: user, topic: topic) }
fab!(:user) { Fabricate(:user, id: 999) }
fab!(:post) { Fabricate(:post, user: user, topic: topic) }
before do
SiteSetting.unique_posts_mins = 5
@ -240,9 +240,9 @@ describe Validators::PostValidator do
context "force_edit_last_validator" do
let(:user) { Fabricate(:user) }
let(:other_user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic) }
fab!(:user) { Fabricate(:user) }
fab!(:other_user) { Fabricate(:user) }
fab!(:topic) { Fabricate(:topic) }
before do
SiteSetting.max_consecutive_replies = 2

View File

@ -7,7 +7,7 @@ describe Validators::UploadValidator do
subject(:validator) { described_class.new }
describe 'validate' do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:filename) { "discourse.csv" }
let(:csv_file) { file_from_fixtures(filename, "csv") }
@ -57,7 +57,7 @@ describe Validators::UploadValidator do
end
describe 'upload for site settings' do
let(:user) { Fabricate(:admin) }
fab!(:user) { Fabricate(:admin) }
let(:upload) do
Fabricate.build(:upload,
@ -85,7 +85,7 @@ describe Validators::UploadValidator do
end
describe 'for normal user' do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
it 'should not allow the upload' do
expect(subject.validate(upload)).to eq(nil)

View File

@ -21,8 +21,8 @@ describe UsernameSettingValidator do
end
context "regex support" do
let!(:darthvader) { Fabricate(:user, username: 'darthvader') }
let!(:luke) { Fabricate(:user, username: 'luke') }
fab!(:darthvader) { Fabricate(:user, username: 'darthvader') }
fab!(:luke) { Fabricate(:user, username: 'luke') }
it "returns false if regex doesn't match" do
v = described_class.new(regex: 'darth')

View File

@ -10,7 +10,7 @@ describe Wizard::StepUpdater do
SiteSetting.wizard_enabled = true
end
let(:user) { Fabricate(:admin) }
fab!(:user) { Fabricate(:admin) }
let(:wizard) { Wizard::Builder.new(user).build }
context "locale" do
@ -171,7 +171,7 @@ describe Wizard::StepUpdater do
context "colors step" do
context "with an existing color scheme" do
let!(:color_scheme) { Fabricate(:color_scheme, name: 'existing', via_wizard: true) }
fab!(:color_scheme) { Fabricate(:color_scheme, name: 'existing', via_wizard: true) }
it "updates the scheme" do
updater = wizard.create_updater('colors', theme_previews: 'Dark')

View File

@ -166,7 +166,7 @@ describe ApplicationHelper do
end
describe '#html_classes' do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
it "includes 'rtl' when the I18n.locale is rtl" do
I18n.stubs(:locale).returns(:he)

View File

@ -5,11 +5,11 @@ require "import_export/category_exporter"
describe ImportExport::CategoryExporter do
let(:category) { Fabricate(:category) }
let(:group) { Fabricate(:group) }
let(:user) { Fabricate(:user) }
let(:user2) { Fabricate(:user) }
let(:user3) { Fabricate(:user) }
fab!(:category) { Fabricate(:category) }
fab!(:group) { Fabricate(:group) }
fab!(:user) { Fabricate(:user) }
fab!(:user2) { Fabricate(:user) }
fab!(:user3) { Fabricate(:user) }
before do
STDOUT.stubs(:write)

View File

@ -9,9 +9,9 @@ describe ImportExport::TopicExporter do
STDOUT.stubs(:write)
end
let(:user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic, user: user) }
let!(:post) { Fabricate(:post, topic: topic, user: user) }
fab!(:user) { Fabricate(:user) }
fab!(:topic) { Fabricate(:topic, user: user) }
fab!(:post) { Fabricate(:post, topic: topic, user: user) }
context '.perform' do
it 'export a single topic' do

View File

@ -14,13 +14,13 @@ describe "category tag restrictions" do
DiscourseTagging.filter_allowed_tags(Tag.all, Guardian.new(user), opts)
end
let!(:tag1) { Fabricate(:tag, name: 'tag1') }
let!(:tag2) { Fabricate(:tag, name: 'tag2') }
let!(:tag3) { Fabricate(:tag, name: 'tag3') }
let!(:tag4) { Fabricate(:tag, name: 'tag4') }
fab!(:tag1) { Fabricate(:tag, name: 'tag1') }
fab!(:tag2) { Fabricate(:tag, name: 'tag2') }
fab!(:tag3) { Fabricate(:tag, name: 'tag3') }
fab!(:tag4) { Fabricate(:tag, name: 'tag4') }
let(:user) { Fabricate(:user) }
let(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
fab!(:admin) { Fabricate(:admin) }
before do
SiteSetting.tagging_enabled = true
@ -29,8 +29,8 @@ describe "category tag restrictions" do
end
context "tags restricted to one category" do
let!(:category_with_tags) { Fabricate(:category) }
let!(:other_category) { Fabricate(:category) }
fab!(:category_with_tags) { Fabricate(:category) }
fab!(:other_category) { Fabricate(:category) }
before do
category_with_tags.tags = [tag1, tag2]
@ -98,9 +98,9 @@ describe "category tag restrictions" do
end
context "tag groups restricted to a category" do
let!(:tag_group1) { Fabricate(:tag_group) }
let!(:category) { Fabricate(:category) }
let!(:other_category) { Fabricate(:category) }
fab!(:tag_group1) { Fabricate(:tag_group) }
fab!(:category) { Fabricate(:category) }
fab!(:other_category) { Fabricate(:category) }
before do
tag_group1.tags = [tag1, tag2]
@ -156,8 +156,8 @@ describe "category tag restrictions" do
end
context 'another category has restricted tags using groups' do
let(:category2) { Fabricate(:category) }
let(:tag_group2) { Fabricate(:tag_group) }
fab!(:category2) { Fabricate(:category) }
fab!(:tag_group2) { Fabricate(:tag_group) }
before do
tag_group2.tags = [tag2, tag3]
@ -183,7 +183,7 @@ describe "category tag restrictions" do
end
context 'another category has restricted tags' do
let(:category2) { Fabricate(:category) }
fab!(:category2) { Fabricate(:category) }
it "doesn't filter tags that are also restricted in another category" do
category2.tags = [tag2, tag3]
@ -214,11 +214,11 @@ describe "category tag restrictions" do
end
context "and category restrictions" do
let(:car_category) { Fabricate(:category) }
let(:other_category) { Fabricate(:category) }
let(:makes) { Fabricate(:tag_group, name: "Makes") }
let(:honda_group) { Fabricate(:tag_group, name: "Honda Models") }
let(:ford_group) { Fabricate(:tag_group, name: "Ford Models") }
fab!(:car_category) { Fabricate(:category) }
fab!(:other_category) { Fabricate(:category) }
fab!(:makes) { Fabricate(:tag_group, name: "Makes") }
fab!(:honda_group) { Fabricate(:tag_group, name: "Honda Models") }
fab!(:ford_group) { Fabricate(:tag_group, name: "Ford Models") }
before do
@tags = {}
@ -290,12 +290,12 @@ describe "category tag restrictions" do
end
describe "tag topic counts per category" do
let(:admin) { Fabricate(:admin) }
let(:category) { Fabricate(:category) }
let(:category2) { Fabricate(:category) }
let(:tag1) { Fabricate(:tag) }
let(:tag2) { Fabricate(:tag) }
let(:tag3) { Fabricate(:tag) }
fab!(:admin) { Fabricate(:admin) }
fab!(:category) { Fabricate(:category) }
fab!(:category2) { Fabricate(:category) }
fab!(:tag1) { Fabricate(:tag) }
fab!(:tag2) { Fabricate(:tag) }
fab!(:tag3) { Fabricate(:tag) }
before do
SiteSetting.tagging_enabled = true
@ -323,8 +323,8 @@ describe "tag topic counts per category" do
end
context "topic with 2 tags" do
let(:topic) { Fabricate(:topic, category: category, tags: [tag1, tag2]) }
let(:post) { Fabricate(:post, user: topic.user, topic: topic) }
fab!(:topic) { Fabricate(:topic, category: category, tags: [tag1, tag2]) }
fab!(:post) { Fabricate(:post, user: topic.user, topic: topic) }
it "has correct counts after tag is removed from a topic" do
post
@ -355,8 +355,8 @@ describe "tag topic counts per category" do
end
context "topic with one tag" do
let(:topic) { Fabricate(:topic, tags: [tag1], category: category) }
let(:post) { Fabricate(:post, user: topic.user, topic: topic) }
fab!(:topic) { Fabricate(:topic, tags: [tag1], category: category) }
fab!(:post) { Fabricate(:post, user: topic.user, topic: topic) }
it "counts after topic becomes uncategorized" do
PostRevisor.new(post).revise!(topic.user, raw: post.raw, tags: [tag1.name], category_id: SiteSetting.uncategorized_category_id)

View File

@ -6,10 +6,10 @@ require 'rails_helper'
describe "spam rules for users" do
describe 'auto-silence users based on flagging' do
let!(:admin) { Fabricate(:admin) } # needed to send a system message
let!(:moderator) { Fabricate(:moderator) }
let(:user1) { Fabricate(:user) }
let(:user2) { Fabricate(:user) }
fab!(:admin) { Fabricate(:admin) } # needed to send a system message
fab!(:moderator) { Fabricate(:moderator) }
fab!(:user1) { Fabricate(:user) }
fab!(:user2) { Fabricate(:user) }
before do
SiteSetting.score_required_to_hide_post = 0
@ -18,7 +18,7 @@ describe "spam rules for users" do
end
context 'spammer is a new user' do
let(:spammer) { Fabricate(:user, trust_level: TrustLevel[0]) }
fab!(:spammer) { Fabricate(:user, trust_level: TrustLevel[0]) }
context 'spammer post is not flagged enough times' do
let!(:spam_post) { create_post(user: spammer) }
@ -43,7 +43,7 @@ describe "spam rules for users" do
end
context 'one spam post is flagged enough times by enough users' do
let!(:another_topic) { Fabricate(:topic) }
fab!(:another_topic) { Fabricate(:topic) }
let!(:private_messages_count) { spammer.private_topics_count }
let!(:mod_pm_count) { moderator.private_topics_count }
let!(:reviewable) { PostActionCreator.spam(user2, spam_post).reviewable }

View File

@ -4,7 +4,7 @@ require 'rails_helper'
describe 'user api keys integration' do
let(:user_api_key) { Fabricate(:readonly_user_api_key) }
fab!(:user_api_key) { Fabricate(:readonly_user_api_key) }
it 'updates last used time on use' do
user_api_key.update_columns(last_used_at: 7.days.ago)

View File

@ -3,12 +3,12 @@
require 'rails_helper'
describe WatchedWord do
let(:tl2_user) { Fabricate(:user, trust_level: TrustLevel[2]) }
let(:admin) { Fabricate(:admin) }
let(:moderator) { Fabricate(:moderator) }
fab!(:tl2_user) { Fabricate(:user, trust_level: TrustLevel[2]) }
fab!(:admin) { Fabricate(:admin) }
fab!(:moderator) { Fabricate(:moderator) }
let(:topic) { Fabricate(:topic) }
let(:first_post) { Fabricate(:post, topic: topic) }
fab!(:topic) { Fabricate(:topic) }
fab!(:first_post) { Fabricate(:post, topic: topic) }
let(:require_approval_word) { Fabricate(:watched_word, action: WatchedWord.actions[:require_approval]) }
let(:flag_word) { Fabricate(:watched_word, action: WatchedWord.actions[:flag]) }

View File

@ -3,8 +3,8 @@
require 'rails_helper'
RSpec.describe Jobs::AutoExpireUserApiKeys do
let(:key1) { Fabricate(:readonly_user_api_key) }
let(:key2) { Fabricate(:readonly_user_api_key) }
fab!(:key1) { Fabricate(:readonly_user_api_key) }
fab!(:key2) { Fabricate(:readonly_user_api_key) }
context 'when user api key is unused in last 1 days' do

View File

@ -7,8 +7,8 @@ describe Jobs::AutoQueueHandler do
subject { Jobs::AutoQueueHandler.new.execute({}) }
context "old flag" do
let!(:old) { Fabricate(:reviewable_flagged_post, created_at: 61.days.ago) }
let!(:not_old) { Fabricate(:reviewable_flagged_post, created_at: 59.days.ago) }
fab!(:old) { Fabricate(:reviewable_flagged_post, created_at: 61.days.ago) }
fab!(:not_old) { Fabricate(:reviewable_flagged_post, created_at: 59.days.ago) }
it "defers the old flag if auto_handle_queued_age is 60" do
SiteSetting.auto_handle_queued_age = 60
@ -26,10 +26,10 @@ describe Jobs::AutoQueueHandler do
end
context "reviewables" do
let!(:new_post) { Fabricate(:reviewable_queued_post, created_at: 59.days.ago) }
let!(:old_post) { Fabricate(:reviewable_queued_post, created_at: 61.days.ago) }
let!(:new_user) { Fabricate(:reviewable, created_at: 10.days.ago) }
let!(:old_user) { Fabricate(:reviewable, created_at: 80.days.ago) }
fab!(:new_post) { Fabricate(:reviewable_queued_post, created_at: 59.days.ago) }
fab!(:old_post) { Fabricate(:reviewable_queued_post, created_at: 61.days.ago) }
fab!(:new_user) { Fabricate(:reviewable, created_at: 10.days.ago) }
fab!(:old_user) { Fabricate(:reviewable, created_at: 80.days.ago) }
it "rejects the post when auto_handle_queued_age is 60" do
SiteSetting.auto_handle_queued_age = 60

View File

@ -4,11 +4,11 @@ require 'rails_helper'
describe Jobs::BulkInvite do
describe '#execute' do
let(:user) { Fabricate(:user) }
let(:admin) { Fabricate(:admin) }
let!(:group1) { Fabricate(:group, name: 'group1') }
let!(:group2) { Fabricate(:group, name: 'group2') }
let!(:topic) { Fabricate(:topic, id: 999) }
fab!(:user) { Fabricate(:user) }
fab!(:admin) { Fabricate(:admin) }
fab!(:group1) { Fabricate(:group, name: 'group1') }
fab!(:group2) { Fabricate(:group, name: 'group2') }
fab!(:topic) { Fabricate(:topic, id: 999) }
let(:email) { "test@discourse.org" }
let(:basename) { "bulk_invite.csv" }
let(:filename) { "#{Invite.base_directory}/#{basename}" }

View File

@ -3,8 +3,8 @@
require 'rails_helper'
describe Jobs::BumpTopic do
let(:admin) { Fabricate(:admin) }
let(:user) { Fabricate(:user) }
fab!(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
it "can bump a topic" do
topic = Fabricate(:topic_timer, user: admin).topic

View File

@ -3,15 +3,15 @@
require 'rails_helper'
describe Jobs::CleanUpEmailLogs do
let!(:email_log) { Fabricate(:email_log, created_at: 2.years.ago) }
let!(:email_log2) { Fabricate(:email_log, created_at: 2.weeks.ago) }
let!(:email_log3) { Fabricate(:email_log, created_at: 2.days.ago) }
fab!(:email_log) { Fabricate(:email_log, created_at: 2.years.ago) }
fab!(:email_log2) { Fabricate(:email_log, created_at: 2.weeks.ago) }
fab!(:email_log3) { Fabricate(:email_log, created_at: 2.days.ago) }
let!(:skipped_email_log) do
Fabricate(:skipped_email_log, created_at: 2.years.ago)
end
let!(:skipped_email_log2) { Fabricate(:skipped_email_log) }
fab!(:skipped_email_log2) { Fabricate(:skipped_email_log) }
it "removes old email logs" do
Jobs::CleanUpEmailLogs.new.execute({})

View File

@ -3,8 +3,8 @@
require 'rails_helper'
RSpec.describe Jobs::CleanUpUnusedStagedUsers do
let(:user) { Fabricate(:user) }
let(:staged_user) { Fabricate(:user, staged: true) }
fab!(:user) { Fabricate(:user) }
fab!(:staged_user) { Fabricate(:user, staged: true) }
context 'when staged user is unused' do
it 'should clean up the staged user' do

View File

@ -3,9 +3,9 @@
require 'rails_helper'
describe Jobs::DeleteTopic do
let(:admin) { Fabricate(:admin) }
fab!(:admin) { Fabricate(:admin) }
let(:topic) do
fab!(:topic) do
Fabricate(:topic_timer, user: admin).topic
end

View File

@ -5,7 +5,7 @@ require 'rails_helper'
describe Jobs::DisableBootstrapMode do
context '.execute' do
let(:admin) { Fabricate(:admin) }
fab!(:admin) { Fabricate(:admin) }
before do
SiteSetting.bootstrap_mode_enabled = true

View File

@ -3,7 +3,7 @@
require 'rails_helper'
RSpec.describe Jobs::DownloadAvatarFromUrl do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
describe 'when url is invalid' do
it 'should not raise any error' do

View File

@ -3,7 +3,7 @@
require 'rails_helper'
RSpec.describe Jobs::DownloadBackupEmail do
let(:user) { Fabricate(:admin) }
fab!(:user) { Fabricate(:admin) }
it "should work" do
described_class.new.execute(

View File

@ -3,7 +3,7 @@
require 'rails_helper'
RSpec.describe Jobs::DownloadProfileBackgroundFromUrl do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
describe 'when url is invalid' do
it 'should not raise any error' do

View File

@ -4,10 +4,10 @@ require 'rails_helper'
require 'excon'
describe Jobs::EmitWebHookEvent do
let(:post_hook) { Fabricate(:web_hook) }
let(:inactive_hook) { Fabricate(:inactive_web_hook) }
let(:post) { Fabricate(:post) }
let(:user) { Fabricate(:user) }
fab!(:post_hook) { Fabricate(:web_hook) }
fab!(:inactive_hook) { Fabricate(:inactive_web_hook) }
fab!(:post) { Fabricate(:post) }
fab!(:user) { Fabricate(:user) }
it 'raises an error when there is no web hook record' do
expect do
@ -157,10 +157,10 @@ describe Jobs::EmitWebHookEvent do
end
context 'with category filters' do
let(:category) { Fabricate(:category) }
let(:topic) { Fabricate(:topic) }
let(:topic_with_category) { Fabricate(:topic, category_id: category.id) }
let(:topic_hook) { Fabricate(:topic_web_hook, categories: [category]) }
fab!(:category) { Fabricate(:category) }
fab!(:topic) { Fabricate(:topic) }
fab!(:topic_with_category) { Fabricate(:topic, category_id: category.id) }
fab!(:topic_hook) { Fabricate(:topic_web_hook, categories: [category]) }
it "doesn't emit when event is not related with defined categories" do
subject.execute(
@ -186,9 +186,9 @@ describe Jobs::EmitWebHookEvent do
end
context 'with tag filters' do
let(:tag) { Fabricate(:tag) }
let(:topic) { Fabricate(:topic, tags: [tag]) }
let(:topic_hook) { Fabricate(:topic_web_hook, tags: [tag]) }
fab!(:tag) { Fabricate(:tag) }
fab!(:topic) { Fabricate(:topic, tags: [tag]) }
fab!(:topic_hook) { Fabricate(:topic_web_hook, tags: [tag]) }
it "doesn't emit when event is not included any tags" do
subject.execute(

View File

@ -5,7 +5,7 @@ require 'rails_helper'
describe Jobs::EnableBootstrapMode do
context '.execute' do
let(:admin) { Fabricate(:admin) }
fab!(:admin) { Fabricate(:admin) }
before do
SiteSetting.bootstrap_mode_enabled = false

View File

@ -5,7 +5,7 @@ require 'rails_helper'
describe Jobs::ExportCsvFile do
context '.execute' do
let(:user) { Fabricate(:user, username: "john_doe") }
fab!(:user) { Fabricate(:user, username: "john_doe") }
it 'raises an error when the entity is missing' do
expect { Jobs::ExportCsvFile.new.execute(user_id: user.id) }.to raise_error(Discourse::InvalidParameters)

View File

@ -17,8 +17,8 @@ describe Jobs::FeatureTopicUsers do
context 'with a topic' do
let!(:post) { create_post }
let(:topic) { post.topic }
let!(:coding_horror) { Fabricate(:coding_horror) }
let!(:evil_trout) { Fabricate(:evil_trout) }
fab!(:coding_horror) { Fabricate(:coding_horror) }
fab!(:evil_trout) { Fabricate(:evil_trout) }
let!(:second_post) { create_post(topic: topic, user: coding_horror) }
let!(:third_post) { create_post(topic: topic, user: evil_trout) }

View File

@ -20,9 +20,9 @@ describe Jobs::IgnoredUsersSummary do
end
context "when some ignored users exist" do
let(:tarek) { Fabricate(:user, username: "tarek") }
let(:matt) { Fabricate(:user, username: "matt") }
let(:john) { Fabricate(:user, username: "john") }
fab!(:tarek) { Fabricate(:user, username: "tarek") }
fab!(:matt) { Fabricate(:user, username: "matt") }
fab!(:john) { Fabricate(:user, username: "john") }
before do
Fabricate(:ignored_user, user: tarek, ignored_user: matt)

View File

@ -5,7 +5,7 @@ require 'rails_helper'
require_dependency 'jobs/scheduled/invalidate_inactive_admins'
describe Jobs::InvalidateInactiveAdmins do
let!(:active_admin) { Fabricate(:admin, last_seen_at: 1.hour.ago) }
fab!(:active_admin) { Fabricate(:admin, last_seen_at: 1.hour.ago) }
before { active_admin.email_tokens.update_all(confirmed: true) }
subject { Jobs::InvalidateInactiveAdmins.new.execute({}) }
@ -18,7 +18,7 @@ describe Jobs::InvalidateInactiveAdmins do
end
context "with an admin who hasn't been seen recently" do
let!(:not_seen_admin) { Fabricate(:admin, last_seen_at: 370.days.ago) }
fab!(:not_seen_admin) { Fabricate(:admin, last_seen_at: 370.days.ago) }
before { not_seen_admin.email_tokens.update_all(confirmed: true) }
context 'invalidate_inactive_admin_email_after_days = 365' do

View File

@ -14,7 +14,7 @@ describe Jobs::InviteEmail do
context 'with an invite id' do
let (:mailer) { Mail::Message.new(to: 'eviltrout@test.domain') }
let (:invite) { Fabricate(:invite) }
fab!(:invite) { Fabricate(:invite) }
it 'delegates to the test mailer' do
Email::Sender.any_instance.expects(:send)

View File

@ -4,12 +4,12 @@ require "rails_helper"
describe Jobs::NotifyMailingListSubscribers do
let(:mailing_list_user) { Fabricate(:user) }
fab!(:mailing_list_user) { Fabricate(:user) }
before { mailing_list_user.user_option.update(mailing_list_mode: true, mailing_list_mode_frequency: 1) }
let(:user) { Fabricate(:user) }
let(:post) { Fabricate(:post, user: user) }
fab!(:user) { Fabricate(:user) }
fab!(:post) { Fabricate(:post, user: user) }
shared_examples "no emails" do
it "doesn't send any emails" do
@ -88,7 +88,7 @@ describe Jobs::NotifyMailingListSubscribers do
end
context "to an anonymous user" do
let(:mailing_list_user) { Fabricate(:anonymous) }
fab!(:mailing_list_user) { Fabricate(:anonymous) }
include_examples "no emails"
end
@ -195,7 +195,7 @@ describe Jobs::NotifyMailingListSubscribers do
end
context "with a valid post from same user" do
let(:post) { Fabricate(:post, user: mailing_list_user) }
fab!(:post) { Fabricate(:post, user: mailing_list_user) }
context "to an user who has frequency set to 'daily'" do
before { mailing_list_user.user_option.update(mailing_list_mode_frequency: 0) }

View File

@ -15,10 +15,10 @@ describe Jobs::NotifyMovedPosts do
end
context 'with post ids' do
let!(:p1) { Fabricate(:post) }
let!(:p2) { Fabricate(:post, user: Fabricate(:evil_trout), topic: p1.topic) }
let!(:p3) { Fabricate(:post, user: p1.user, topic: p1.topic) }
let(:admin) { Fabricate(:admin) }
fab!(:p1) { Fabricate(:post) }
fab!(:p2) { Fabricate(:post, user: Fabricate(:evil_trout), topic: p1.topic) }
fab!(:p3) { Fabricate(:post, user: p1.user, topic: p1.topic) }
fab!(:admin) { Fabricate(:admin) }
let(:moved_post_notifications) { Notification.where(notification_type: Notification.types[:moved_post]) }

View File

@ -4,9 +4,9 @@ require 'rails_helper'
describe Jobs::NotifyReviewable do
describe '.execute' do
let!(:admin) { Fabricate(:admin, moderator: true) }
let!(:moderator) { Fabricate(:moderator) }
let!(:group_user) { Fabricate(:group_user) }
fab!(:admin) { Fabricate(:admin, moderator: true) }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:group_user) { Fabricate(:group_user) }
let(:user) { group_user.user }
let(:group) { group_user.group }

View File

@ -46,8 +46,8 @@ describe Jobs::PollFeed do
describe '#poll_feed' do
let(:embed_by_username) { 'eviltrout' }
let(:embed_username_key_from_feed) { 'discourse:username' }
let!(:default_user) { Fabricate(:evil_trout) }
let!(:feed_author) { Fabricate(:user, username: 'xrav3nz', email: 'hi@bye.com') }
fab!(:default_user) { Fabricate(:evil_trout) }
fab!(:feed_author) { Fabricate(:user, username: 'xrav3nz', email: 'hi@bye.com') }
shared_examples 'topic creation based on the the feed' do
describe 'author username parsing' do

View File

@ -11,7 +11,7 @@ describe Jobs::ProcessPost do
context 'with a post' do
let(:post) { Fabricate(:post) }
fab!(:post) { Fabricate(:post) }
it 'does not erase posts when CookedPostProcessor malfunctions' do
# Look kids, an actual reason why you want to use mocks

View File

@ -3,8 +3,8 @@
require 'rails_helper'
RSpec.describe Jobs::PublishTopicToCategory do
let(:category) { Fabricate(:category) }
let(:another_category) { Fabricate(:category) }
fab!(:category) { Fabricate(:category) }
fab!(:another_category) { Fabricate(:category) }
let(:topic) do
topic = Fabricate(:topic, category: category)

View File

@ -171,7 +171,7 @@ describe Jobs::PullHotlinkedImages do
end
describe "with a lightboxed image" do
let(:upload) { Fabricate(:upload) }
fab!(:upload) { Fabricate(:upload) }
before do
FastImage.expects(:size).returns([1750, 2000])

View File

@ -14,9 +14,9 @@ describe Jobs::PurgeExpiredIgnoredUsers do
end
context "when some ignored users exist" do
let(:tarek) { Fabricate(:user, username: "tarek") }
let(:matt) { Fabricate(:user, username: "matt") }
let(:john) { Fabricate(:user, username: "john") }
fab!(:tarek) { Fabricate(:user, username: "tarek") }
fab!(:matt) { Fabricate(:user, username: "matt") }
fab!(:john) { Fabricate(:user, username: "john") }
before do
Fabricate(:ignored_user, user: tarek, ignored_user: matt)
@ -30,7 +30,7 @@ describe Jobs::PurgeExpiredIgnoredUsers do
end
context "when there are expired ignored users" do
let(:fred) { Fabricate(:user, username: "fred") }
fab!(:fred) { Fabricate(:user, username: "fred") }
it "purges expired ignored users" do
freeze_time(5.months.ago) do
@ -43,7 +43,7 @@ describe Jobs::PurgeExpiredIgnoredUsers do
end
context "when there are expired ignored users by expiring_at" do
let(:fred) { Fabricate(:user, username: "fred") }
fab!(:fred) { Fabricate(:user, username: "fred") }
it "purges expired ignored users" do
Fabricate(:ignored_user, user: tarek, ignored_user: fred, expiring_at: 1.month.from_now)

View File

@ -15,7 +15,7 @@ describe Jobs::SendSystemMessage do
context 'with valid parameters' do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
it "should call SystemMessage.create" do
SystemMessage.any_instance.expects(:create).with('welcome_invite', {})

View File

@ -4,7 +4,7 @@ require 'rails_helper'
describe Jobs::SuspiciousLogin do
let(:user) { Fabricate(:moderator) }
fab!(:user) { Fabricate(:moderator) }
let(:zurich) { { latitude: 47.3686498, longitude: 8.5391825 } } # Zurich, Switzerland
let(:bern) { { latitude: 46.947922, longitude: 7.444608 } } # Bern, Switzerland

View File

@ -3,9 +3,9 @@
require 'rails_helper'
describe Jobs::ToggleTopicClosed do
let(:admin) { Fabricate(:admin) }
fab!(:admin) { Fabricate(:admin) }
let(:topic) do
fab!(:topic) do
Fabricate(:topic_timer, user: admin).topic
end
@ -45,8 +45,8 @@ describe Jobs::ToggleTopicClosed do
end
describe 'when category has auto close configured' do
let(:category) { Fabricate(:category, auto_close_hours: 5) }
let(:topic) { Fabricate(:topic, category: category, closed: true) }
fab!(:category) { Fabricate(:category, auto_close_hours: 5) }
fab!(:topic) { Fabricate(:topic, category: category, closed: true) }
it "should restore the category's auto close timer" do
Fabricate(:topic_timer,
@ -86,7 +86,7 @@ describe Jobs::ToggleTopicClosed do
end
describe 'when user is not authorized to close topics' do
let(:topic) do
fab!(:topic) do
Fabricate(:topic_timer, execute_at: 2.hours.from_now).topic
end

View File

@ -3,9 +3,9 @@
require 'rails_helper'
describe Jobs::TopicReminder do
let(:admin) { Fabricate(:admin) }
fab!(:admin) { Fabricate(:admin) }
let(:topic) do
fab!(:topic) do
Fabricate(:topic_timer,
user: admin,
status_type: TopicTimer.types[:reminder]

View File

@ -3,8 +3,8 @@
require 'rails_helper'
describe Jobs::TruncateUserFlagStats do
let(:user) { Fabricate(:user) }
let(:other_user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
fab!(:other_user) { Fabricate(:user) }
before do
# We might make this a site setting eventually

View File

@ -9,10 +9,10 @@ describe Jobs::UserEmail do
SiteSetting.email_time_window_mins = 10
end
let(:user) { Fabricate(:user, last_seen_at: 11.minutes.ago) }
let(:staged) { Fabricate(:user, staged: true, last_seen_at: 11.minutes.ago) }
let(:suspended) { Fabricate(:user, last_seen_at: 10.minutes.ago, suspended_at: 5.minutes.ago, suspended_till: 7.days.from_now) }
let(:anonymous) { Fabricate(:anonymous, last_seen_at: 11.minutes.ago) }
fab!(:user) { Fabricate(:user, last_seen_at: 11.minutes.ago) }
fab!(:staged) { Fabricate(:user, staged: true, last_seen_at: 11.minutes.ago) }
fab!(:suspended) { Fabricate(:user, last_seen_at: 10.minutes.ago, suspended_at: 5.minutes.ago, suspended_till: 7.days.from_now) }
fab!(:anonymous) { Fabricate(:anonymous, last_seen_at: 11.minutes.ago) }
it "raises an error when there is no user" do
expect { Jobs::UserEmail.new.execute(type: :digest) }.to raise_error(Discourse::InvalidParameters)
@ -27,8 +27,8 @@ describe Jobs::UserEmail do
end
context 'digest can be generated' do
let(:user) { Fabricate(:user, last_seen_at: 8.days.ago, last_emailed_at: 8.days.ago) }
let!(:popular_topic) { Fabricate(:topic, user: Fabricate(:admin), created_at: 1.hour.ago) }
fab!(:user) { Fabricate(:user, last_seen_at: 8.days.ago, last_emailed_at: 8.days.ago) }
fab!(:popular_topic) { Fabricate(:topic, user: Fabricate(:admin), created_at: 1.hour.ago) }
it "doesn't call the mailer when the user is missing" do
Jobs::UserEmail.new.execute(type: :digest, user_id: 1234)
@ -112,8 +112,8 @@ describe Jobs::UserEmail do
end
context "recently seen" do
let(:post) { Fabricate(:post, user: user) }
let(:notification) { Fabricate(
fab!(:post) { Fabricate(:post, user: user) }
fab!(:notification) { Fabricate(
:notification,
user: user,
topic: post.topic,
@ -177,7 +177,7 @@ describe Jobs::UserEmail do
end
context "email_log" do
let(:post) { Fabricate(:post) }
fab!(:post) { Fabricate(:post) }
before do
SiteSetting.editing_grace_period = 0
@ -233,7 +233,7 @@ describe Jobs::UserEmail do
end
context "post" do
let(:post) { Fabricate(:post, user: user) }
fab!(:post) { Fabricate(:post, user: user) }
it "doesn't send the email if you've seen the post" do
PostTiming.record_timing(topic_id: post.topic_id, user_id: user.id, post_number: post.post_number, msecs: 6666)
@ -307,8 +307,8 @@ describe Jobs::UserEmail do
end
context 'notification' do
let(:post) { Fabricate(:post, user: user) }
let!(:notification) {
fab!(:post) { Fabricate(:post, user: user) }
fab!(:notification) {
Fabricate(:notification,
user: user,
topic: post.topic,

View File

@ -4,7 +4,7 @@ require 'rails_helper'
require 'file_store/s3_store'
RSpec.describe UploadCreator do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
describe '#create_for' do
describe 'when upload is not an image' do

View File

@ -4,7 +4,7 @@ require 'rails_helper'
require_dependency "upload_recovery"
RSpec.describe UploadRecovery do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:upload) do
UploadCreator.new(

View File

@ -9,7 +9,7 @@ describe InviteMailer do
context "invite to site" do
context "default invite message" do
let(:invite) { Fabricate(:invite) }
fab!(:invite) { Fabricate(:invite) }
let(:invite_mail) { InviteMailer.send_invite(invite) }
it 'renders the invitee email' do
@ -38,7 +38,7 @@ describe InviteMailer do
end
context "custom invite message" do
let(:invite) { Fabricate(:invite, custom_message: "Hey, you should join this forum!") }
fab!(:invite) { Fabricate(:invite, custom_message: "Hey, you should join this forum!") }
context "custom message includes invite link" do
let(:custom_invite_mail) { InviteMailer.send_invite(invite) }

View File

@ -7,7 +7,7 @@ describe RejectionMailer do
describe "send_rejection" do
context 'sends rejection email' do
let (:user) { Fabricate(:user) }
fab! (:user) { Fabricate(:user) }
let (:template_args) { { former_title: "Mail Subject", destination: user.email, site_name: SiteSetting.title } }
let (:reject_mail) { RejectionMailer.send_rejection("email_reject_topic_not_found", user.email, template_args) }

View File

@ -5,7 +5,7 @@ require 'rails_helper'
require_dependency 'api_key'
describe ApiKey do
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
it { is_expected.to belong_to :user }
it { is_expected.to belong_to :created_by }

Some files were not shown because too many files have changed in this diff Show More