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

@@ -24,8 +24,8 @@ describe TopTopic do
context "refresh!" do
let!(:t1) { Fabricate(:topic) }
let!(:t2) { Fabricate(:topic) }
fab!(:t1) { Fabricate(:topic) }
fab!(:t2) { Fabricate(:topic) }
it "begins blank" do
expect(TopTopic.all).to be_blank
@@ -45,18 +45,18 @@ describe TopTopic do
describe "#compute_top_score_for" do
let(:user) { Fabricate(:user) }
let(:coding_horror) { Fabricate(:coding_horror) }
fab!(:user) { Fabricate(:user) }
fab!(:coding_horror) { Fabricate(:coding_horror) }
let!(:topic_1) { Fabricate(:topic, posts_count: 10, like_count: 28) }
let!(:t1_post_1) { Fabricate(:post, topic: topic_1, like_count: 28, post_number: 1) }
fab!(:topic_1) { Fabricate(:topic, posts_count: 10, like_count: 28) }
fab!(:t1_post_1) { Fabricate(:post, topic: topic_1, like_count: 28, post_number: 1) }
let!(:topic_2) { Fabricate(:topic, posts_count: 10, like_count: 20) }
let!(:t2_post_1) { Fabricate(:post, topic: topic_2, like_count: 10, post_number: 1) }
let!(:t2_post_2) { Fabricate(:post, topic: topic_2, like_count: 10) }
fab!(:topic_2) { Fabricate(:topic, posts_count: 10, like_count: 20) }
fab!(:t2_post_1) { Fabricate(:post, topic: topic_2, like_count: 10, post_number: 1) }
fab!(:t2_post_2) { Fabricate(:post, topic: topic_2, like_count: 10) }
let!(:topic_3) { Fabricate(:topic, posts_count: 10) }
let!(:t3_post_1) { Fabricate(:post, topic_id: topic_3.id) }
fab!(:topic_3) { Fabricate(:topic, posts_count: 10) }
fab!(:t3_post_1) { Fabricate(:post, topic_id: topic_3.id) }
let!(:t3_view_1) { TopicViewItem.add(topic_3.id, '127.0.0.1', user) }
let!(:t3_view_2) { TopicViewItem.add(topic_3.id, '127.0.0.2', coding_horror) }