Skip to content

GitLab Fabrication Guide

GitLab Fabrication Guide

This guide will help you understand how to fabricate GitLab Data Models.

Create a Model

You can create a model using create() method. The create() method accepts a Factory and a hash of attributes.

For example, this would create a group label with the title ‘bug’ and color ‘#FF0000’ under the top-level namespace:

class DataSeeder
def seed
create(:group_label, group: @group, title: 'bug', color: '#FF0000')
end
end

Create a List of Models

You can create a list of models using create_list() method. The create_list() method accepts a Factory, the number of models to create, and a hash of attributes.

For example, this would create 5 group labels with the title ‘bug’ and color ‘#FF0000’ under the top-level namespace:

class DataSeeder
def seed
create_list(:group_label, 5, group: @group, title: 'bug', color: '#FF0000')
end
end

Build a model and save it later

You can build a model using build() method. The build() method accepts a Factory and a hash of attributes.

In this example, we build the first label without saving, label 1 will be created, then label 2 is saved later, resulting in label 2 being created after label 1.

class DataSeeder
def seed
label = build(:group_label, title: 'label 2')
create(:group_label, title: 'label 1')
label.save
end
end

Build a model and bypass validation

You can build a model and bypass GitLab’s built-in validations by building a model and calling save(validate: false).

class DataSeeder
def seed
build(:group_label, title: 'label 2', color: 'invalid color').save(validate: false)
end
end

In this example, we are assuming that the color is validated by GitLab’s built-in record validations. We can bypass this validation by calling save(validate: false).