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

@ -4,8 +4,8 @@ require 'rails_helper'
describe InvitesController do
context 'show' do
let(:invite) { Fabricate(:invite) }
let(:user) { Fabricate(:coding_horror) }
fab!(:invite) { Fabricate(:invite) }
fab!(:user) { Fabricate(:coding_horror) }
it "returns error if invite not found" do
get "/invites/nopeNOPEnope"
@ -49,7 +49,7 @@ describe InvitesController do
context 'while logged in' do
let!(:user) { sign_in(Fabricate(:user)) }
let!(:invite) { Fabricate(:invite, invited_by: user) }
let(:another_invite) { Fabricate(:invite, email: 'anotheremail@address.com') }
fab!(:another_invite) { Fabricate(:invite, email: 'anotheremail@address.com') }
it 'raises an error when the email is missing' do
delete "/invites.json"
@ -229,7 +229,7 @@ describe InvitesController do
end
context 'with a deleted invite' do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
let(:invite) do
Invite.invite_by_email("iceking@adventuretime.ooo", topic.user, topic)
@ -251,7 +251,7 @@ describe InvitesController do
end
context 'with a valid invite id' do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
let(:invite) do
Invite.invite_by_email("iceking@adventuretime.ooo", topic.user, topic)
end
@ -263,7 +263,7 @@ describe InvitesController do
end
context 'when redeem returns a user' do
let(:user) { Fabricate(:coding_horror) }
fab!(:user) { Fabricate(:coding_horror) }
context 'success' do
it 'logs in the user' do
@ -402,7 +402,7 @@ describe InvitesController do
end
context 'new registrations are disabled' do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
let(:invite) do
Invite.invite_by_email("iceking@adventuretime.ooo", topic.user, topic)
@ -421,7 +421,7 @@ describe InvitesController do
end
context 'user is already logged in' do
let(:topic) { Fabricate(:topic) }
fab!(:topic) { Fabricate(:topic) }
let(:invite) do
Invite.invite_by_email("iceking@adventuretime.ooo", topic.user, topic)
@ -449,7 +449,7 @@ describe InvitesController do
context 'while logged in' do
let!(:user) { sign_in(Fabricate(:user)) }
let!(:invite) { Fabricate(:invite, invited_by: user) }
let(:another_invite) { Fabricate(:invite, email: 'last_name@example.com') }
fab!(:another_invite) { Fabricate(:invite, email: 'last_name@example.com') }
it 'raises an error when the email is missing' do
post "/invites/reinvite.json"