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

@@ -3,9 +3,9 @@
require 'rails_helper'
RSpec.describe EmailController do
let(:user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic) }
let(:private_topic) { Fabricate(:private_message_topic) }
fab!(:user) { Fabricate(:user) }
fab!(:topic) { Fabricate(:topic) }
fab!(:private_topic) { Fabricate(:private_message_topic) }
context '.perform unsubscribe' do
it 'raises not found on invalid key' do
@@ -13,7 +13,7 @@ RSpec.describe EmailController do
expect(response.status).to eq(404)
end
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:key) { UnsubscribeKey.create_key_for(user, "all") }
it 'can fully unsubscribe' do
@@ -192,7 +192,7 @@ RSpec.describe EmailController do
expect(response.body).to include(CGI.escapeHTML(I18n.t("unsubscribe.not_found_description")))
end
let(:user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) }
let(:unsubscribe_key) { UnsubscribeKey.create_key_for(user, key_type) }
context 'Unsubscribe from digest' do
@@ -259,7 +259,7 @@ RSpec.describe EmailController do
end
context 'Unsubscribe from a post' do
let(:post) { Fabricate(:post) }
fab!(:post) { Fabricate(:post) }
let(:user) { post.user }
let(:key_type) { post }