Monorepo with multiple rails apps

6 views
Skip to first unread message

Karlis Sergijevskis

unread,
May 11, 2021, 9:54:38 AMMay 11
to fabrication
Hello Paul,

I am looking for ideas how to use Fabrication gem across different Rails apps.
Soo imagine we have a monorepo which consists of 2 Rails apps:

- app_1
    ...
    - features
    - specs/fabricators
    ...
- app_2
    ...
    - features
    - specs/fabricators
    ...

Then we have cucumber tests that tests app_1 but for example tests needs some data on app_2 (for example when testing if redirection works correctly).

any tips on how it should be implemented ?( i.e. when tests are launched from app_1 - fabrication can also be done in app_2 db)?  

  

Paul Elliott

unread,
May 11, 2021, 10:00:58 AMMay 11
to fabrica...@googlegroups.com
Are you asking if you can load both fabricator folders when cucumber loads?

You can specify an array of custom load paths to Fabrication::Config.fabricator_path. 


--
You received this message because you are subscribed to the Google Groups "fabrication" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fabricationge...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fabricationgem/adc77cb8-091a-48b2-b2d3-1cbe68afd36dn%40googlegroups.com.

Karlis Sergijevskis

unread,
May 11, 2021, 10:37:01 AMMay 11
to fabrication
I was more considering situation when each app has its own database, would it work with `fabricator_path` ?

Paul Elliott

unread,
May 11, 2021, 10:38:35 AMMay 11
to fabrica...@googlegroups.com
The fabricator path config just let's you tell it where to load definitions from. Fabrication doesn't care about databases, only models tied to the fabricators. Can you explain the issue you have in a little more detail?

Karlis Sergijevskis

unread,
May 12, 2021, 9:11:46 AMMay 12
to fabrication
So imagine two Rails apps in same git repo (for the sake of an example - kinda in microservice manner):
```
apps/users
apps/shop
```
in order to login into shop - user needs to exist in users app
so when test is run for shop - gherkin scenario would look like this:
```
Feature: Shop cart

Scenario:  User can populate cart
  Given user exists
  And shop items exist:
  | name | price |
  | apple | 1        |
  | banana | 2    |
  When user adds item "apple" in cart
  Then cart total should be "1"
```
for brevity lets skip stepdefs for  user adds item "apple" in cart  and Then cart total should be "1"
These stepdefs would reside in apps/shop/features/fabrication_stepdefs.rb

```
Given("{string} exists") do |subject|
Fabricate(subject.to_sym) # should be fabricated in shop_test database
end

Given("shop {string} exist:") do |subject, table|
Fabricate(subject.to_sym, **table.rows_hash) # should be fabricated in users_test database
end
```

One approach would be to mock users app, but all these apps are in our possesion (no 3rd party) so we would like to test real integration.
I had an idea about gem that could manage multiple instances of Fabrication one per each app and then invoke it like :
```
any_fabricate(app: :user_app, :user)
or
any_fabricate(app: :shop, :item, **opts)
```
I noticed that there is a support for Rails engines, do you think I could apply this also with multiple apps ? 

Paul Elliott

unread,
May 12, 2021, 9:16:42 AMMay 12
to fabrica...@googlegroups.com
Is the shop app reading the users app's database directly or is it making an API call to the users app? If it is making an API call you should use something like webmock to stub that request.

-- Paul


Karlis Sergijevskis

unread,
May 13, 2021, 3:37:40 PMMay 13
to fabrication
But in case (for the sake of example) shop app would be using users database directly ? 
is there a way to configure multiple fabrication instances on demand ? or single instance that can recognize in which DB to fabricate in ?  

Paul Elliott

unread,
May 13, 2021, 5:23:29 PMMay 13
to fabrica...@googlegroups.com
Presumably you have a User model in the shop app that is capable of writing users, which you would use as the base for your user fabricator.

If both apps are using the same database directly you could have a third folder in the monorepo for shared items and put a fabricators folder in there. That could contain common definitions that you extend in the fabricators in each of your apps.

-- Paul


Reply all
Reply to author
Forward
0 new messages