- Docker Setup
- GDK Setup
- List of Awesome Companies
AwesomeCo is a test data seeding harness, that can seed test data into a user or group namespace.
AwesomeCo uses FactoryBot in the backend which makes maintenance extremely easy. When a Model is changed, FactoryBot will already be reflected to account for the change.
$ gdk start db ok: run: services/postgresql: (pid n) 0s, normally down ok: run: services/redis: (pid n) 74s, normally down $ bundle install Bundle complete! $ bundle exec rake db:migrate main: migrated ci: migrated
ee:gitlab:seed:awesome_co Rake task takes two arguments.
$ bundle exec rake "ee:gitlab:seed:awesome_co[awesome_co,1]" Seeding AwesomeCo for Administrator
:name is the name of the AwesomeCo. (This will reflect .rb files located in db/seeds/awesome_co/*.rb)
:namespace_id is the ID of the User or Group Namespace
Each company (i.e. test data template) is represented as a Ruby file (.rb) in
$ bundle exec rake "ee:gitlab:seed:awesome_co[awesome_co,:namespace_id]" Seeding AwesomeCo for :namespace_id
AwesomeCo is an automated seeding of this demo repository.
AwesomeCo seeding uses FactoryBot definitions from
spec/factories which …
- Saves time on development
- Are easy-to-read
- Are easy to maintain
- Do not rely on an API that may change in the future
- Are always up-to-date
- Execute on the lowest-level (
ActiveRecord) possible to create data as quickly as possible
From the FactoryBot README :
factory_botis a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class, including factory inheritance
Factories reside in
spec/factories/* and are fixtures for Rails models found in
app/models/*. For example, For a model named
app/models/issue.rb, the factory will
spec/factories/issues.rb. For a model named
app/models/project.rb, the factory will be named
Factories consist of three main parts - the Name of the factory, the Traits and the Attributes.
create(:iteration, :with_title, :current, title: 'My Iteration')
|:iteration||This is the Name of the factory. The file name will be the plural form of this Name and reside under either |
|:with_title||This is a Trait of the factory. See how it’s defined.|
|:current||This is a Trait of the factory. See how it’s defined.|
|title: ‘My Iteration’||This is an Attribute of the factory that will be passed to the Model for creation.|
In these examples, you will see an instance variable
@owner. This is the
root user (
my_group = create(:group, name: 'My Group', path: 'my-group-path')
# create a Project belonging to a Group my_project = create(:project, :public, name: 'My Project', namespace: my_group, creator: @owner)
# create an Issue belonging to a Project my_issue = create(:issue, title: 'My Issue', project: my_project, weight: 2)
# create an Iteration under a Group my_iteration = create(:iteration, :with_title, :current, title: 'My Iteration', group: my_group)
ActiveRecord::RecordInvalid: Validation failed: Email has already been taken, Username has already been taken
This is because, by default, our factories are written to backfill any data that is missing. For instance, when a project is created, the project must have somebody that created it. If the owner is not specified, the factory attempts to create it.
How to fix
Check the respective Factory to find out what key is required. Usually
# This throws ActiveRecord::RecordInvalid create(:project, name: 'Throws Error', namespace: create(:group, name: 'Some Group')) # Specify the user where @owner is a [User] record create(:project, name: 'No longer throws error', owner: @owner, namespace: create(:group, name: 'Some Group')) create(:epic, group: create(:group), author: @owner)