rom-factory 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef868642e36f9a4e7b18c91925f378a2c0da27bd4c7ac6d048650c0c739ce3d9
4
- data.tar.gz: 8815cd6d8318b35298ff341e5308e7b76692be6d6af58b076a9c5ddd23688bd2
3
+ metadata.gz: 946c06da46cc1d12ac8e90fc8b79661ce43e9ed2ab2ba0e3ffd93f5c1ac7e419
4
+ data.tar.gz: fa2c475a578ba75f7574ed5d883a4432fc4f2328849fc4be74813b854a0c6dba
5
5
  SHA512:
6
- metadata.gz: fb80a101f1b6c380ee4660d49756c02a0af58ed60d8c53d7a97ba5f94b5a04b37255a11018c7f47fe0665b71ba4a47ee70c65b1c6418c0d642b7e662bc5beffa
7
- data.tar.gz: 9f74c1af825e6927a2f1926963c39ac41b7b74471e2795cd6e8b28d1aca839c8fe1a1c688d4116e371a759ababa0b5df3147fcf8ae6b15fc0aaa5418fc4af9db
6
+ metadata.gz: b1dea330b287e3b56c2acaea898c9139317b0de709098c0c7525d05215db34571dfa41447337ca39b39f7d1d5ace98fde9f442854a725870fa6496c24d00eee3
7
+ data.tar.gz: 6279eb190440aeb10dc03c26fe18cfcc67f846e8d0981b7822746172f564936f5d2fd7cbf41a68336be1865516afda03947302804db8d6a1e05040198137beb9
@@ -2,20 +2,10 @@
2
2
  name: ci
3
3
  on:
4
4
  push:
5
- paths:
6
- - ".github/workflows/ci.yml"
7
- - lib/**
8
- - "*.gemspec"
9
- - spec/**
10
- - Rakefile
11
- - Gemfile
12
- - Gemfile.devtools
13
- - ".rubocop.yml"
14
- - project.yml
15
5
  pull_request:
16
- branches:
17
- - master
18
6
  create:
7
+ schedule:
8
+ - cron: "30 4 * * *"
19
9
  jobs:
20
10
  tests:
21
11
  runs-on: ubuntu-latest
@@ -23,13 +13,15 @@ jobs:
23
13
  fail-fast: false
24
14
  matrix:
25
15
  ruby:
16
+ - '3.4'
17
+ - '3.3'
18
+ - '3.2'
26
19
  - '3.1'
27
- - '3.0'
28
- - '2.7'
29
20
  env:
30
21
  COVERAGE: "${{matrix.coverage}}"
31
22
  COVERAGE_TOKEN: "${{secrets.CODACY_PROJECT_TOKEN}}"
32
23
  APT_DEPS: libpq-dev libmysqlclient-dev libsqlite3-dev
24
+ DATABASE_URL: "postgres://rom-factory:rom-factory@localhost:5432/rom_factory"
33
25
  steps:
34
26
  - name: Checkout
35
27
  uses: actions/checkout@v1
@@ -55,10 +47,10 @@ jobs:
55
47
  coverage-reports: coverage/coverage.xml
56
48
  services:
57
49
  db:
58
- image: postgres:10.8
50
+ image: postgres:16.1
59
51
  env:
60
- POSTGRES_USER: runner
61
- POSTGRES_PASSWORD: ''
52
+ POSTGRES_USER: rom-factory
53
+ POSTGRES_PASSWORD: rom-factory
62
54
  POSTGRES_DB: rom_factory
63
55
  ports:
64
56
  - 5432:5432
@@ -78,10 +70,18 @@ jobs:
78
70
  - name: Set up Ruby
79
71
  uses: ruby/setup-ruby@v1
80
72
  with:
81
- ruby-version: 2.6
73
+ ruby-version: "3.1"
82
74
  - name: Install dependencies
83
75
  run: gem install ossy --no-document
84
76
  - name: Trigger release workflow
85
77
  run: |
86
78
  tag=$(echo $GITHUB_REF | cut -d / -f 3)
87
79
  ossy gh w rom-rb/devtools release --payload "{\"tag\":\"$tag\",\"sha\":\"${{github.sha}}\",\"tag_creator\":\"$GITHUB_ACTOR\",\"repo\":\"$GITHUB_REPOSITORY\",\"repo_name\":\"${{github.event.repository.name}}\"}"
80
+
81
+ workflow-keepalive:
82
+ if: github.event_name == 'schedule'
83
+ runs-on: ubuntu-latest
84
+ permissions:
85
+ actions: write
86
+ steps:
87
+ - uses: liskin/gh-workflow-keepalive@v1
@@ -22,9 +22,9 @@ jobs:
22
22
  - run: |
23
23
  git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
24
24
  - name: Set up Ruby
25
- uses: actions/setup-ruby@v1
25
+ uses: ruby/setup-ruby@v1
26
26
  with:
27
- ruby-version: "2.6.x"
27
+ ruby-version: "3.1"
28
28
  - name: Set up git user
29
29
  run: |
30
30
  git config --local user.email "rom-bot@rom-rb.org"
@@ -60,4 +60,3 @@ jobs:
60
60
  GITHUB_LOGIN: rom-bot
61
61
  GITHUB_TOKEN: ${{secrets.GH_PAT}}
62
62
  run: ossy github workflow rom-rb/rom-rb.org ci
63
-
@@ -1,31 +1,25 @@
1
1
  # This file is synced from rom-rb/template-gem repo
2
2
 
3
- name: Changelog
3
+ name: sync
4
4
 
5
5
  on:
6
+ repository_dispatch:
6
7
  push:
7
- paths:
8
- - "changelog.yml"
9
8
  branches:
10
9
  - "main"
11
- pull_request:
12
- branches:
13
- - "main"
14
- types: [closed]
15
10
 
16
11
  jobs:
17
- sync:
12
+ main:
18
13
  runs-on: ubuntu-latest
19
- if: github.event.pull_request.merged == true
20
- name: Update
14
+ if: (github.event_name == 'repository_dispatch' && github.event.action == 'sync_configs') || github.event_name != 'repository_dispatch'
21
15
  env:
22
16
  GITHUB_LOGIN: rom-bot
23
17
  GITHUB_TOKEN: ${{ secrets.GH_PAT }}
24
18
  steps:
25
19
  - name: Checkout ${{github.repository}}
26
- uses: actions/checkout@v1
20
+ uses: actions/checkout@v3
27
21
  - name: Checkout devtools
28
- uses: actions/checkout@v2
22
+ uses: actions/checkout@v3
29
23
  with:
30
24
  repository: rom-rb/devtools
31
25
  path: tmp/devtools
@@ -34,9 +28,9 @@ jobs:
34
28
  git config --local user.email "rom-bot@rom-rb.org"
35
29
  git config --local user.name "rom-bot"
36
30
  - name: Set up Ruby
37
- uses: actions/setup-ruby@v1
31
+ uses: ruby/setup-ruby@v1
38
32
  with:
39
- ruby-version: "2.6"
33
+ ruby-version: "3.1"
40
34
  - name: Install dependencies
41
35
  run: gem install ossy --no-document
42
36
  - name: Update changelog.yml from commit
@@ -46,7 +40,7 @@ jobs:
46
40
  - name: Commit
47
41
  run: |
48
42
  git add -A
49
- git commit -m "Update CHANGELOG.md" || echo "nothing to commit"
43
+ git commit -m "[devtools] sync" || echo "nothing to commit"
50
44
  - name: Push changes
51
45
  run: |
52
46
  git pull --rebase origin main
data/.postgres.env ADDED
@@ -0,0 +1,4 @@
1
+ POSTGRES_USER="rom"
2
+ POSTGRES_PASSWORD="password"
3
+ POSTGRES_DATABASE="rom_factory"
4
+ POSTGRES_HOST_AUTH_METHOD="trust"
@@ -1,12 +1,17 @@
1
+ ###########################################################
2
+ # DO NOT EDIT THIS FILE
3
+ #
1
4
  # This is a config synced from rom-rb/template-gem repo
5
+ ###########################################################
2
6
 
3
7
  sources:
4
8
  - repo: rom-rb/template-gem
5
9
  sync:
6
- - "!.github/workflows/ci.yml.erb"
7
- - ".action_hero.yml.erb"
10
+ - ".repobot.yml.erb"
8
11
  - ".devtools/templates/*.sync:${{dir}}/${{name}}"
9
12
  - ".github/**/*.*"
13
+ - ".rspec"
14
+ - ".rubocop.yml"
10
15
  - "spec/support/*"
11
16
  - "CODE_OF_CONDUCT.md"
12
17
  - "CONTRIBUTING.md"
@@ -14,8 +19,6 @@ sources:
14
19
  - "LICENSE.erb"
15
20
  - "README.erb"
16
21
  - "Gemfile.devtools"
17
- - ".rspec"
18
- - ".rubocop.yml"
19
- - repo: action-hero/workflows
22
+ - repo: repobot-app/workflows
20
23
  sync:
21
24
  - ".github/workflows/*.yml"
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  # This is a config synced from rom-rb/template-gem repo
2
2
  AllCops:
3
- TargetRubyVersion: 2.7
4
- NewCops: disable
3
+ TargetRubyVersion: 3.1
4
+ NewCops: enable
5
5
  SuggestExtensions: false
6
6
  Exclude:
7
7
  - spec/support/coverage.rb
data/CHANGELOG.md CHANGED
@@ -1,35 +1,85 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
- ## 0.11.0 2022-11-11
3
+ ## 0.13.0 2025-01-21
4
+
5
+
6
+ ### Added
7
+
8
+ - Support for unique options in `fake` DSL (via #94) (@sean-dickinson)
9
+
10
+ ```ruby
11
+ Factory.define(:user) do |f|
12
+ f.name { fake(:name, unique: true) }
13
+ end
14
+ ```
15
+
16
+ Be advised there's `Faker::UniqueGenerator.clear` to clear the cache of unique values.
17
+
18
+ - Support for setting traits with a keyword argument for associations (via #84) (@parndt)
19
+
20
+ ```ruby
21
+ Factory.define :category do |f|
22
+ f.association :image, traits: [:fancy]
23
+ end
24
+ ```
25
+
26
+
27
+ ### Changed
28
+
29
+ - Minimum Ruby version is now 3.1 (@flash-gordon)
30
+
31
+ [Compare v0.12.0...v0.13.0](https://github.com/rom-rb/rom-factory/compare/v0.12.0...v0.13.0)
32
+
33
+ ## 0.12.0 2024-01-19
34
+
35
+
36
+ ### Added
37
+
38
+ - Support for many-to-many and one-to-one-through associations (via #86) (@solnic)
39
+ - Support for UUID as PKs in associations (via #87) (@solnic)
4
40
 
5
41
  ### Fixed
6
42
 
7
- - Support for plural Faker generators (@wuarmin)
43
+ - Relations without PKs should work too (via #87) (@solnic)
44
+ - Relations with PK values generated on the Ruby side should work in SQlite too (via #87) (@solnic)
45
+
46
+
47
+ [Compare v0.11.0...v0.12.0](https://github.com/rom-rb/rom-factory/compare/v0.11.0...v0.12.0)
48
+
49
+ ## 0.11.0 2022-11-11
50
+
8
51
 
9
52
  ### Added
10
53
 
11
54
  - Support for one-to-one associations (@ianks)
12
55
  - [internal] cache for Faker constants (@flash-gordon)
13
56
 
57
+ ### Fixed
58
+
59
+ - Support for plural Faker generators (@wuarmin)
60
+
14
61
  ### Changed
15
62
 
16
63
  - [BREAKING] attributes are always passed as keywords (@alassek)
17
- This may affect your code in places where attributes are passed as hashes.
18
- Places like
64
+ This may affect your code in places where attributes are passed as hashes.
65
+ Places like
66
+
67
+ ```ruby
68
+ user_attributes = { name: 'Jane' }
69
+ Factory[:user, user_attributes]
70
+
71
+ ```
72
+
73
+ must be updated to
74
+
75
+ ```ruby
76
+ user_attributes = { name: 'Jane' }
77
+ Factory[:user, **user_attributes]
78
+ ```
19
79
 
20
- ```ruby
21
- user_attributes = { name: 'Jane' }
22
- Factory[:user, user_attributes]
23
- ```
24
- must be updated to
25
- ```ruby
26
- user_attributes = { name: 'Jane' }
27
- Factory[:user, **user_attributes]
28
- ```
29
80
  - Upgraded to the latest versions of dry-rb dependencies, compatible with rom 5.3 (@flash-gordon)
30
81
  - Support for Faker 1.x was dropped (@alassek)
31
82
 
32
-
33
83
  [Compare v0.10.2...v0.11.0](https://github.com/rom-rb/rom-factory/compare/v0.10.2...v0.11.0)
34
84
 
35
85
  ## 0.10.2 2020-04-05
data/Gemfile CHANGED
@@ -6,28 +6,38 @@ gemspec
6
6
 
7
7
  eval_gemfile "Gemfile.devtools"
8
8
 
9
- gem "faker", "~> 2.8"
9
+ gem "faker", "~> 3.0"
10
10
 
11
11
  gem "rspec", "~> 3.0"
12
12
 
13
- git "https://github.com/rom-rb/rom.git", branch: "release-5.3" do
14
- gem "rom-core"
13
+ gem "dotenv"
14
+
15
+ git "https://github.com/rom-rb/rom.git", branch: "release-5.4" do
16
+ gem "rom"
15
17
  gem "rom-changeset"
18
+ gem "rom-core"
16
19
  gem "rom-repository"
17
- gem "rom"
18
20
  end
19
21
 
20
22
  group :test do
21
- gem "pry", "~> 0.12.0", "<= 0.13"
22
- gem "pry-byebug", "~> 3.8", platforms: :ruby
23
- gem "rom-sql", github: "rom-rb/rom-sql", branch: "release-3.6"
23
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4")
24
+ gem "debug"
25
+ else
26
+ gem "pry"
27
+ gem "pry-byebug", "~> 3.8", platforms: :ruby
28
+ end
29
+ gem "rom-sql", github: "rom-rb/rom-sql", branch: "release-3.7"
24
30
 
25
31
  gem "jdbc-postgres", platforms: :jruby
26
- gem "pg", "~> 0.21", platforms: :ruby
32
+ gem "pg", "~> 1.5", platforms: :ruby
27
33
  end
28
34
 
29
35
  group :tools do
30
- gem "byebug", platform: :mri
36
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4")
37
+ gem "byebug", platform: :mri
38
+ else
39
+ gem "pry-byebug", "~> 3.8", platforms: :ruby
40
+ end
31
41
  gem "redcarpet" # for yard
32
42
  end
33
43
 
data/Gemfile.devtools CHANGED
@@ -16,5 +16,5 @@ end
16
16
 
17
17
  group :tools do
18
18
  # this is the same version that we use on codacy
19
- gem "rubocop", "1.26.1"
19
+ gem "rubocop", "1.69.2"
20
20
  end
data/README.md CHANGED
@@ -21,8 +21,8 @@
21
21
 
22
22
  This library officially supports the following Ruby versions:
23
23
 
24
- * MRI >= `2.5`
25
- * jruby >= `9.2`
24
+ * MRI >= `3.1`
25
+ * jruby >= `9.4` (not tested in CI)
26
26
 
27
27
  ## License
28
28
 
data/changelog.yml CHANGED
@@ -1,19 +1,54 @@
1
1
  ---
2
+ - version: 0.13.0
3
+ date: 2025-01-21
4
+ added:
5
+ - |
6
+ Support for unique options in `fake` DSL (via #94) (@sean-dickinson)
7
+
8
+ ```ruby
9
+ Factory.define(:user) do |f|
10
+ f.name { fake(:name, unique: true) }
11
+ end
12
+ ```
13
+
14
+ Be advised there's `Faker::UniqueGenerator.clear` to clear the cache of unique values.
15
+ - |
16
+ Support for setting traits with a keyword argument for associations (via #84) (@parndt)
17
+
18
+ ```ruby
19
+ Factory.define :category do |f|
20
+ f.association :image, traits: [:fancy]
21
+ end
22
+ ```
23
+ changed:
24
+ - Minimum Ruby version is now 3.1 (@flash-gordon)
25
+ - version: 0.12.0
26
+ date: 2024-01-19
27
+ added:
28
+ - "Support for many-to-many and one-to-one-through associations (via #86) (@solnic)"
29
+ - "Support for UUID as PKs in associations (via #87) (@solnic)"
30
+ fixed:
31
+ - "Relations without PKs should work too (via #87) (@solnic)"
32
+ - "Relations with PK values generated on the Ruby side should work in SQlite too (via #87) (@solnic)"
2
33
  - version: 0.11.0
3
34
  date: 2022-11-11
4
35
  added:
5
- - Support for one-to-one associations (@ianks)
36
+ - "Support for one-to-one associations (@ianks)"
6
37
  - "[internal] cache for Faker constants (@flash-gordon)"
7
38
  changed:
8
39
  - |
9
40
  [BREAKING] attributes are always passed as keywords (@alassek)
10
41
  This may affect your code in places where attributes are passed as hashes.
11
42
  Places like
43
+
12
44
  ```ruby
13
45
  user_attributes = { name: 'Jane' }
14
46
  Factory[:user, user_attributes]
47
+
15
48
  ```
49
+
16
50
  must be updated to
51
+
17
52
  ```ruby
18
53
  user_attributes = { name: 'Jane' }
19
54
  Factory[:user, **user_attributes]
data/compose.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ services:
3
+ db:
4
+ image: postgres
5
+ ports:
6
+ - 5432
7
+ env_file: .postgres.env
@@ -44,7 +44,7 @@ end
44
44
 
45
45
  #### Specify namespace for your structs
46
46
 
47
- Struct `User` will be find in MyApp::Entities namespace
47
+ Struct `User` will be found in `MyApp::Entities` namespace
48
48
 
49
49
  ```ruby
50
50
  Factory.define(:user, struct_namespace: MyApp::Entities) do |f|
@@ -86,7 +86,7 @@ end
86
86
 
87
87
  Factory.define(:user) do |f|
88
88
  f.name 'John'
89
- f.association(:user)
89
+ f.association(:group)
90
90
  end
91
91
  ```
92
92
 
@@ -115,7 +115,7 @@ Factory.define(admin: :user) do |f|
115
115
  f.admin true
116
116
  end
117
117
 
118
- # Factory.structs(:admin)
118
+ # Factory.structs[:admin]
119
119
  ```
120
120
 
121
121
  #### Traits
@@ -130,7 +130,7 @@ Factory.define(:user) do |f|
130
130
  end
131
131
  end
132
132
 
133
- # Factory.structs(:user, :with_age)
133
+ # Factory.structs[:user, :with_age]
134
134
  ```
135
135
 
136
136
  #### Build-in [Faker](https://github.com/faker-ruby/faker) objects
@@ -141,6 +141,14 @@ Factory.define(:user) do |f|
141
141
  end
142
142
  ```
143
143
 
144
+ ##### Unique values with fake
145
+ Passing the unique: true option will use Faker's [unique](https://github.com/faker-ruby/faker#ensuring-unique-values) feature
146
+ ```ruby
147
+ Factory.define(:user) do |f|
148
+ f.email { fake(:internet, :email, unique: true) }
149
+ end
150
+ ```
151
+
144
152
  #### Dependent attributes
145
153
 
146
154
  Attributes can be based on the values of other attributes:
@@ -159,11 +167,15 @@ end
159
167
 
160
168
  ```ruby
161
169
  # Create in-memory object
162
- Factory.structs[:user]
170
+ Factory.build(:user)
163
171
 
164
172
  # Persist struct in database
165
- Factory[:user]
173
+ Factory.create(:user)
166
174
 
167
175
  # Override attributes
168
- Factory[:user, age: 24]
176
+ Factory.create(:user, age: 24)
177
+
178
+ # Build and Create via #[] accessors
179
+ Factory.structs[:user]
180
+ Factory[:user]
169
181
  ```
@@ -18,14 +18,10 @@ module ROM
18
18
  end
19
19
 
20
20
  # @api private
21
- def each(&block)
22
- elements.each(&block)
23
- end
21
+ def each(&) = elements.each(&)
24
22
 
25
23
  # @api private
26
- def [](name)
27
- detect { |e| e.name.equal?(name) }
28
- end
24
+ def [](name) = detect { |e| e.name.equal?(name) }
29
25
 
30
26
  # @api private
31
27
  def <<(element)
@@ -36,30 +32,32 @@ module ROM
36
32
  end
37
33
 
38
34
  # @api private
39
- def dup
40
- self.class.new(elements.dup)
41
- end
35
+ def dup = self.class.new(elements.dup)
42
36
 
43
37
  # @api private
44
- def values
45
- self.class.new(elements.select(&:value?))
46
- end
38
+ def values = self.class.new(elements.select(&:value?))
47
39
 
48
40
  # @api private
49
41
  def associations
50
42
  self.class.new(elements.select { |e| e.is_a?(Attributes::Association::Core) })
51
43
  end
52
44
 
53
- private
45
+ def reject(&) = self.class.new(elements.reject(&))
54
46
 
55
47
  # @api private
56
- def tsort_each_node(&block)
57
- each(&block)
48
+ def inspect
49
+ "#<#{self.class} #{elements.inspect}>"
58
50
  end
51
+ alias_method :to_s, :inspect
52
+
53
+ private
54
+
55
+ # @api private
56
+ def tsort_each_node(&) = each(&)
59
57
 
60
58
  # @api private
61
- def tsort_each_child(attr, &block)
62
- attr.dependency_names.map { |name| self[name] }.compact.each(&block)
59
+ def tsort_each_child(attr, &)
60
+ attr.dependency_names.map { |name| self[name] }.compact.each(&)
63
61
  end
64
62
  end
65
63
  end